public override void startGame()
 {
     print("Starting game");
     gameRunning = true;
     startTimer();
     startPlayerTimer();
     protocol.requestMove(currentPlayer().client.peerID, board.ToString(), currentPlayer().color);
 }
Exemple #2
0
        public void onPlayerMove(object stringMsg, ConnectedClient c)
        {
            CommProtocol.StringMessage msg = (CommProtocol.StringMessage)stringMsg;
            mainGame.debugPrint(msg.color + " sent: " + msg.msg);
            ConnectedPlayer p = mainGame.getCurrentPlayer();

            if (msg.color != p.color || c.peerID != p.client.peerID || gameOver)
            {
                return;
            }
            //Parse incoming msg
            string moveString = msg.msg;

            int[] move = new int[2];
            try{
                int chosenMove = int.Parse(moveString);
                move = new int[] { chosenMove % 8, chosenMove / 8 };
            }
            catch (Exception e) {
                protocol.requestMove(mainGame.getCurrentPlayer().client.peerID, board.ToString(), mainGame.getCurrentPlayer().color);
                return;
            }

            //See if the move is a legit move
            if (board.getAvailabeMoves(p.color == Game.PlayerColor.White).Find(x => x[0] == move[0] && x[1] == move[1]) == null)
            {
                protocol.requestMove(mainGame.getCurrentPlayer().client.peerID, board.ToString(), mainGame.getCurrentPlayer().color);
                return;
            }

            board.playMove(move [0], move [1], p.color == Game.PlayerColor.White);
            RPCMove RPCmsg = new RPCMove(move, p.color);

            mainGame.broadcastRPCMove(RPCmsg);

            mainGame.switchToNextPlayer();
            if (gameIsOver())
            {
                gameOver = true;
                mainGame.setWinner(getWinColor());
                return;
            }

            mainGame.startPlayerTimer();
            protocol.requestMove(mainGame.getCurrentPlayer().client.peerID, board.ToString(), mainGame.getCurrentPlayer().color);
        }