public GameInfo(string username, Game.PlayerColor myColor, bool gameOver = false, Game.PlayerColor winnerColor = Game.PlayerColor.None)
 {
     this.username    = username;
     this.myColor     = myColor;
     this.gameOver    = gameOver;
     this.winnerColor = winnerColor;
 }
Example #2
0
 public GameInfo(int myId, Game.PlayerColor myColor, bool gameOver = false, Game.PlayerColor winnerColor = Game.PlayerColor.None)
 {
     this.myId        = myId;
     this.myColor     = myColor;
     this.gameOver    = gameOver;
     this.winnerColor = winnerColor;
 }
        public BoardUpdate(List <Soldier> soldiers, List <Soldier> deaths, uint updateId, float time, Game.PlayerColor color = Game.PlayerColor.None)
        {
            units         = new float[soldiers.Count, 2];
            teams         = new bool[soldiers.Count];
            ids           = new int[soldiers.Count];
            healths       = new int[soldiers.Count];
            canAttack     = new bool[soldiers.Count];
            states        = new SoldierState[soldiers.Count];
            this.deaths   = new int[deaths.Count];
            this.updateId = updateId;
            this.time     = time;
            this.color    = color;
            for (int i = 0; i < soldiers.Count; i++)
            {
                units [i, 0]  = soldiers [i].transform.position.x;
                units [i, 1]  = soldiers [i].transform.position.z;
                teams [i]     = soldiers [i].team == 1;
                ids [i]       = soldiers [i].id;
                healths [i]   = soldiers [i].HP;
                canAttack [i] = soldiers [i].canDmg;
                states [i]    = soldiers [i].intention;
            }

            for (int i = 0; i < deaths.Count; i++)
            {
                this.deaths [i] = deaths [i].id;
            }
        }
Example #4
0
 public void setWinner(Game.PlayerColor winColor)
 {
     foreach (ConnectedClient c in clients)
     {
         protocol.sendGameInfo(c.peerID, new GameInfo("", Game.PlayerColor.None, true, winColor));
     }
     base.shutdownGameServer();
 }
Example #5
0
        public void initBoard(char[,] charBoard, Game.PlayerColor currentColor)
        {
            myColor = currentColor;
            PlayerBoard currentPlayer = currentColor == Game.PlayerColor.Blue ? p1Board : p2Board;

            gameBoardCreator.initPlayerBoard(charBoard, currentPlayer);
            initColors.Add(currentColor);
        }
Example #6
0
        public void playMove(int target, Game.PlayerColor currentPlayerColor, char targetStatus, ShipType targetType, int[] startPos, bool horizontal)
        {
            PlayerBoard targetedPlayer = currentPlayerColor == Game.PlayerColor.Blue ? p2Board : p1Board;

            targetedPlayer.fireAtGrid(target, myColor != currentPlayerColor, targetStatus, targetType, startPos, horizontal);
            panels [0].setScore(p1Board.calculateHP());
            panels [1].setScore(p2Board.calculateHP());
        }
 public GameUpdate(uint updateNumber, int[] redC, int[] blueC,
                   Game.PlayerColor myColor     = Game.PlayerColor.None, bool gameOver = false,
                   Game.PlayerColor winnerColor = Game.PlayerColor.None)
 {
     this.myColor      = myColor;
     this.updateNumber = updateNumber;
     this.redCoords    = redC;
     this.blueCoords   = blueC;
 }
Example #8
0
        private void broadcastGameOver(Game.PlayerColor winColor)
        {
            GameInfo status = new GameInfo(0, Game.PlayerColor.None, true, winColor);

            foreach (ConnectedPlayer p in players)
            {
                protocol.sendGameInfo(p.peerID, status);
            }
        }
        public static string formatBoardMsgFromServer(string rawBoard, Game.PlayerColor color, BoardState state = BoardState.ongoing)
        {
            rawBoard = replaceServerFormat(rawBoard, color);
            JSONObject jMsg = new JSONObject();

            jMsg.AddField(Consts.Fields.board, createJGrid(rawBoard));
            jMsg.AddField(Consts.Fields.boardState, state.ToString());

            return(jMsg.Print());
        }
Example #10
0
        public void handleRPCMove(NetworkMessage RPCMsg)
        {
            byte[]  bytes = RPCMsg.reader.ReadBytesAndSize();
            RPCMove msg   = Game.ClientController.Deserialize <RPCMove> (bytes);

            Game.PlayerColor color = msg.color;
            int[]            move  = msg.move;

            localRenderer.playMove(move[0], move[1], color == Game.PlayerColor.White);
        }
Example #11
0
 public void setGameOver(Game.PlayerColor winColor)
 {
     gamePlaying = false;
     foreach (ConnectedPlayer p in players)
     {
         GameInfo infoMsg = new GameInfo(p.username, p.color, true, winColor);
         try{ protocol.sendGameInfo(gameMaster.getMatchingPlayer(p.color).client.peerID, infoMsg); }
         catch {}
     }
     gameMaster.startShutdownServer();
 }
        public void broadcastStartTimer(Game.PlayerColor playerColor, float startTime, TurnBasedCommProtocol protocol)
        {
            PlayerTimerMsg msg = new PlayerTimerMsg()
            {
                maxTime = startTime, color = playerColor, startTimer = true
            };

            foreach (ConnectedClient c in clients)
            {
                protocol.sendPlayerTimerCommand(c.peerID, msg);
            }
        }
 //Currently re sending alot of data. Should be opted lated
 public void initPlayerTimer(float startTime, Game.PlayerColor initColor, TurnBasedCommProtocol protocol)
 {
     foreach (ConnectedClient c in clients)
     {
         foreach (ConnectedPlayer p in players)
         {
             PlayerTimerMsg msg2 = new PlayerTimerMsg()
             {
                 maxTime = startTime, color = p.color, startTimer = false
             };
             protocol.sendPlayerTimerInit(c.peerID, msg2);
         }
     }
 }
        // In my old variation the server only sent the board as 0 = empty, 1 = yellow, 2 = red
        // So here i do a conversion to the local player to get  0 = empty, 1 = you, -1 = enemy
        private static string replaceServerFormat(string rawBoard, Game.PlayerColor color)
        {
            string tempBoard = "";

            if (color == Game.PlayerColor.Red)
            {
                tempBoard = rawBoard.Replace("2", "-1");
            }
            else
            {
                tempBoard = rawBoard.Replace("1", "-1");
                tempBoard = tempBoard.Replace("2", "1");
            }
            return(tempBoard);
        }
Example #15
0
        public string formatBoard(string rawBoard, Game.PlayerColor color)
        {
            string tempBoard = "";

            if (color == Game.PlayerColor.White)
            {
                tempBoard = rawBoard.Replace("2", "-1");
            }
            else
            {
                tempBoard = rawBoard.Replace("1", "-1");
                tempBoard = tempBoard.Replace("2", "1");
            }

            return(tempBoard);
        }
Example #16
0
        private bool checkIfGameOver()
        {
            if (team1.Count != 0 && team2.Count != 0)
            {
                return(false);
            }

            Game.PlayerColor winColor = Game.PlayerColor.None;
            if (team1.Count > team2.Count)
            {
                winColor = Game.PlayerColor.Blue;
            }
            else
            {
                winColor = Game.PlayerColor.Red;
            }
            setGameOver(winColor);

            return(true);
        }
Example #17
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);
        }
Example #18
0
 public BoardMsg(char[,] board, Game.PlayerColor color)
 {
     this.board = board; this.color = color;
 }
Example #19
0
 public RPCMove(int[] start, int[] target, Game.PlayerColor color)
 {
     this.start = start; this.target = target;  this.color = color;
 }
Example #20
0
 public void sendBoardInitRequest(int targetID, string msg, Game.PlayerColor color)
 {
     sendString(targetID, MsgType.boardInitRequest, msg, color);
 }
Example #21
0
 public void sendMove(int targetID, string move, Game.PlayerColor color)
 {
     sendString(targetID, MsgType.move, move, color);
 }
 private void sendString(int targetID, MsgType type, string str, Game.PlayerColor color)
 {
     sendMsg(new StringMessage(str, color), targetID, (short)type);
 }
 public RPCMove(int[] move, Game.PlayerColor color)
 {
     this.move = move; this.color = color;
 }
 public PlayerCommands(Game.PlayerColor color, List <TCPCommand> commands)
 {
     this.color    = color;
     this.commands = commands.ToArray();
 }
Example #25
0
        public void setPlayerScore(Game.PlayerColor player, int score)
        {
            ClientUserPanelUI panel = player == Game.PlayerColor.White ? p1 : p2;

            panel.setScore(score);
        }
 public PlayerMove(int[] targetCoords, Game.PlayerColor playerColor)
 {
     this.move   = targetCoords;
     this.player = playerColor;
 }
Example #27
0
 //InProgress
 public override void onOutgoingLocalMsg(string msg, Game.PlayerColor color)
 {
     sendServerMsg(msg, color, (short)CommProtocol.MsgType.move);
 }
Example #28
0
 public GameInfo(bool gameOver = false, Game.PlayerColor winnerColor = Game.PlayerColor.None)
 {
     this.gameOver    = gameOver;
     this.winnerColor = winnerColor;
 }
Example #29
0
 private int playerColorToInt(Game.PlayerColor c)
 {
     return(c == Game.PlayerColor.White ? 1 : -1);
 }
Example #30
0
 public RPCMove(int move, Game.PlayerColor color, char targetStatus, ShipType targetType, int[] startPos = null, bool horizontal = false)
 {
     this.move         = move; this.color = color;
     this.targetStatus = targetStatus; this.targetType = targetType;
     this.startPos     = startPos; this.horizontal = horizontal;
 }