View Javadoc

1   /*
2    * Copyright (C) 2010 Unreal Visualizer Authors
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.ut2004.visualizer.gui.action;
18  
19  import java.awt.event.ActionEvent;
20  import java.awt.event.ActionListener;
21  
22  import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
23  
24  import cz.cuni.amis.pogamut.unreal.communication.messages.gbinfomessages.IPlayer;
25  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.ChangeTeam;
26  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
27  import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
28  
29  public class ChangeTeamAction implements ActionListener {
30  
31  	private final IPlayer player;
32  
33  	public ChangeTeamAction(IPlayer bot) {
34  		this.player = bot;
35  	}
36  
37  	@Override
38  	public void actionPerformed(ActionEvent arg0) {
39  		ServerController controller = ServerController.getInstance();
40  		IUT2004Server server = controller.getServer();
41  		assert server != null;
42  
43  		int team = player.getTeam();
44  		if (team != 0 || team != 1) {
45  			team = (int) Math.round(Math.random());
46  		}
47  
48  		ChangeTeam change = new ChangeTeam(player.getId(), team);
49  		server.getAct().act(change);
50  
51  	}
52  }