public void broadcastRPCMove(RPCMove move) { foreach (ConnectedClient c in clients) { protocol.sendRPCMove(c.peerID, move); } }
public void onPlayerMove(object msg, ConnectedPlayer p) { if (p != currentPlayer() || gameOver) { return; } //Parse msg string words = Convert.ToString(msg); int[] move = new int[4]; int[] start = new int[2]; int[] target = new int[2]; try{ start = new int[] { int.Parse(words[0].ToString()), int.Parse(words [1].ToString()) }; target = new int[] { int.Parse(words[2].ToString()), int.Parse(words [3].ToString()) }; }catch (Exception e) { print("Corrupt incoming msg: " + Convert.ToString(msg)); protocol.requestMove(currentPlayer().peerID, theGame.ToString()); return; } //Check if Valid move Move playedMove = MoveHandler.isValidMove(theGame, p.color == Game.PlayerColor.White, start, target); if (playedMove == null) { print("Not valid Move: " + Convert.ToString(msg)); protocol.requestMove(currentPlayer().peerID, theGame.ToString()); return; } //Play move & Broadcast theGame = theGame.playMove(playedMove); RPCMove rpcMove = new RPCMove(start, target, p.color); foreach (ConnectedPlayer pl in players) { protocol.sendRPCMove(pl.peerID, rpcMove); } //Check if gameOver nextPlayer(); BoardStatus status = MoveHandler.getGameState(theGame, currentPlayer().color == Game.PlayerColor.White); if (status != BoardStatus.normal) { gameOver = true; Game.PlayerColor winColor; winColor = status == BoardStatus.draw ? Game.PlayerColor.None : p.color; broadcastGameOver(winColor); } else { protocol.requestMove(currentPlayer().peerID, theGame.ToString()); } }
public void broadcastRPCMove(FireResult result, ConnectedPlayer playingPlayer) { RPCMove move; if (result.statusType == FireType.sunk) { move = new RPCMove(result.target, playingPlayer.color, Player.fireTypeToChar(result.statusType), result.ship.type, result.ship.startPos, result.ship.horizontal); } else { move = new RPCMove(result.target, playingPlayer.color, Player.fireTypeToChar(result.statusType), ShipType.battle); //Send Battleship if not sunk, because we don't wanna send all that sweet info just yet. } foreach (ConnectedClient c in clients) { protocol.sendRPCMove(c.peerID, move); } }