public void onGameEvent(GameEvent.GameEvent ge) { Board board = Board.get(); switch (ge.type) { case GameEvent.GameEventType.ChatMessage: GameEvent.ChatMessage cm = (GameEvent.ChatMessage)ge; if (!cm.bounced) { if (LotusGame.get().net != null) LotusGame.get().net.Send(ge); } else LotusGame.get().Chat(cm.message); break; case GameEvent.GameEventType.UpdateLobby: GameEvent.UpdateLobby ul = (GameEvent.UpdateLobby)ge; LotusGame.get().SetLobby(ul.lobby); break; case GameEvent.GameEventType.SetName: GameEvent.SetName sn = (GameEvent.SetName)ge; if (LotusGame.get().net != null) LotusGame.get().net.Send(ge); break; case GameEvent.GameEventType.GameStart: GameEvent.GameStart gs = (GameEvent.GameStart)ge; Player[] players = gs.players; new Board(players); LotusGame.get().LaunchGame(players); break; case GameEvent.GameEventType.RegionClick: GameEvent.RegionClick rc = (GameEvent.RegionClick)ge; if (LotusGame.get().net != null) LotusGame.get().net.Send(ge); break; case GameEvent.GameEventType.MovePiece: GameEvent.Move move = (GameEvent.Move)ge; board.movePiece(move.frompos, move.topos); board.selectedId = int.MinValue; break; case GameEvent.GameEventType.SelectPiece: GameEvent.Select select = (GameEvent.Select)ge; board.selectedId = select.pos; break; case GameEvent.GameEventType.GameOver: GameEvent.GameOver gameover = (GameEvent.GameOver)ge; break; case GameEvent.GameEventType.AITurn: break; case GameEvent.GameEventType.SetPlayer: GameEvent.ChangePlayer playerchange = (GameEvent.ChangePlayer)ge; LotusGame.get().setCurrentPlayer(playerchange.player); break; } }
public void onGameEvent(GameEvent.GameEvent ge) { Board board = Board.get(); switch (ge.type) { case GameEvent.GameEventType.ChatMessage: GameEvent.ChatMessage cm = (GameEvent.ChatMessage)ge; LotusGame.get().Chat(cm.message); if (LotusGame.get().net != null) { cm.bounced = true; LotusGame.get().net.Send(ge); } break; case GameEvent.GameEventType.UpdateLobby: GameEvent.UpdateLobby ul = (GameEvent.UpdateLobby)ge; if (LotusGame.get().net != null) LotusGame.get().net.Send(ge); break; case GameEvent.GameEventType.SetName: GameEvent.SetName sn = (GameEvent.SetName)ge; LotusGame.get().AddName(sn.name); break; case GameEvent.GameEventType.GameStart: GameEvent.GameStart gs = (GameEvent.GameStart)ge; new Board(gs.players); if (LotusGame.get().net != null) LotusGame.get().net.Send(ge); LotusGame.get().LaunchGame(gs.players); currentPlayer = -1; cyclePlayer(); break; case GameEvent.GameEventType.RegionClick: GameEvent.RegionClick rc = (GameEvent.RegionClick)ge; if (rc.name == LotusGame.get().players[currentPlayer].name || LotusGame.get().players[currentPlayer].getAI() != null) { if (board.selectedId == int.MinValue) // Select Piece { if (rc.pos == -100) { if (!canMove(LotusGame.get().players[currentPlayer])) { LotusGame.get().FireEvent(new GameEvent.ChatMessage(LotusGame.get().players[currentPlayer].name + " skipped his turn.")); cyclePlayer(); } } else if (isSelectValid(rc.pos, LotusGame.get().players[currentPlayer])) { LotusGame.get().FireEvent(new GameEvent.Select(rc.pos)); } else//Deselect { LotusGame.get().FireEvent(new GameEvent.Select(int.MinValue)); } } else if (isMoveValid(board.selectedId, rc.pos, LotusGame.get().players[currentPlayer])) // Move Piece { LotusGame.get().FireEvent(new GameEvent.Move(board.selectedId, rc.pos)); } else //Deselect { LotusGame.get().FireEvent(new GameEvent.Select(int.MinValue)); } } break; case GameEvent.GameEventType.MovePiece: GameEvent.Move move = (GameEvent.Move)ge; board.selectedId = int.MinValue; if (move.frompos != move.topos) { board.movePiece(move.frompos, move.topos); if (LotusGame.get().net != null) LotusGame.get().net.Send(ge); cyclePlayer(); } break; case GameEvent.GameEventType.SelectPiece: GameEvent.Select select = (GameEvent.Select)ge; board.selectedId = select.pos; if(LotusGame.get().net != null) LotusGame.get().net.Send(ge); break; case GameEvent.GameEventType.GameOver: GameEvent.GameOver gameover = (GameEvent.GameOver)ge; if (LotusGame.get().net != null) LotusGame.get().net.Send(ge); break; case GameEvent.GameEventType.AITurn: GameEvent.AITurn aiturn = (GameEvent.AITurn) ge; LotusGame.get().players[aiturn.ai].getAI().doMove(LotusGame.get().players[aiturn.ai], board); break; case GameEvent.GameEventType.SetPlayer: GameEvent.ChangePlayer playerchange = (GameEvent.ChangePlayer)ge; LotusGame.get().setCurrentPlayer(playerchange.player); if(LotusGame.get().net != null) LotusGame.get().net.Send(ge); break; } }