예제 #1
0
 public override void startGame()
 {
     print("Starting game");
     gameRunning = true;
     broadcastStartTimer(currentPlayer().color, maxTimePerMove(), (Game.TurnBasedCommProtocol)protocol);
     protocol.requestMove(currentPlayer().client.peerID, mBoard.ToString(), currentPlayer().color);
     startTimer();
 }
예제 #2
0
        public void onPlayerMove(object stringMsg, ConnectedClient c)
        {
            CommProtocol.StringMessage msg = (CommProtocol.StringMessage)stringMsg;
            ConnectedPlayer            p   = mainGame.getCurrentPlayer();

            mainGame.debugPrint("Incoming from: " + msg.color);
            if (msg.color != p.color || c.peerID != p.client.peerID || gameOver)
            {
                return;
            }

            string move = msg.msg;
            int    col;

            if (!int.TryParse(move, out col) || !board.isAllowedMove(col))
            {
                protocol.requestMove(p.client.peerID, board.ToString(), mainGame.getCurrentPlayer().color);
                return;
            }

            //Valid move was made
            mainGame.pushToRawLog(move);
            moveCounter++;
            board.dropPiece(p.color == Game.PlayerColor.Yellow ? BoardLogic.Piece.Yellow : BoardLogic.Piece.Red, col);
            RPCMove RPCmsg = new RPCMove(int.Parse(move), p.color);

            mainGame.broadcastRPCMove(RPCmsg);

            Game.PlayerColor winColor = board.hasWinner();
            if (winColor != Game.PlayerColor.None || moveCounter == 42)
            {
                mainGame.setGameOver(winColor);
                return;
            }

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