コード例 #1
0
        public void PrintBoardState()
        {
            StringBuilder boardPrint = new StringBuilder("\n BOARD STATE: \n");

            for (int y = (int)GetBoard.Height - 1; y >= 0; y--)
            {
                boardPrint.Append("[" + y);
                if (y < 10)
                {
                    boardPrint.Append(" ");
                }
                boardPrint.Append("] ");
                for (int x = 0; x < GetBoard.Width; x++)
                {
                    var field = GetBoard.GetField(x, y);
                    boardPrint.Append(field.ToString());
                }
                boardPrint.AppendLine();
            }
            for (int x = 0; x < GetBoard.Width; x++)
            {
                if (x == 0)
                {
                    boardPrint.Append("     ");
                }
                boardPrint.Append("[ " + x + " ]");
            }
            ConsoleWriter.Show(boardPrint.ToString());
        }
コード例 #2
0
        // helpers ---------------------

        protected DataMessage PrepareKnowledgeExchangeMessage(KnowledgeExchangeRequestMessage messageObject)
        {
            var responseData = new DataMessage(messageObject.SenderPlayerId)
            {
                Goals = GetBoard.GetRedGoalAreaFields.Union(GetBoard.GetBlueGoalAreaFields).Select(f => new GameArea.GameObjects.GoalField(f)).ToArray(),
                Tasks = GetBoard.TaskFields.Select(q => new GameArea.GameObjects.TaskField(q)).ToArray()
            };
            var xCoord = Location.X;
            var yCoord = Location.Y;

            // do Data musi też dodać, na Field na ktorym stoi, swoj stan !!!
            if (GetBoard.GetField(xCoord, yCoord) is GameArea.GameObjects.GoalField)
            {
                var field = responseData.Goals.Where(f => f.X == xCoord && f.Y == yCoord).FirstOrDefault();
                field.Player    = new GameArea.GameObjects.Player(this.ID, this.Team, this.Role);
                field.TimeStamp = DateTime.Now;
                field.PlayerId  = (long)this.ID;
            }
            else // is TaskField
            {
                var field = responseData.Tasks.Where(f => f.X == xCoord && f.Y == yCoord).FirstOrDefault();
                field.Player = new GameArea.GameObjects.Player(this.ID, this.Team, this.Role);
                if (this.HasPiece)
                {
                    field.Piece = new GameArea.GameObjects.Piece(this.GetPiece.ID, this.GetPiece.TimeStamp, this.GetPiece.Type, this.GetPiece.PlayerId);
                }
                field.TimeStamp = DateTime.Now;
                field.PlayerId  = (long)this.ID;
            }

            return(responseData);
        }
コード例 #3
0
        public void UnregisterPlayer(ulong id)
        {
            var player = Players.Where(p => p.ID == id).FirstOrDefault();

            if (player != null)
            {
                GetBoard.GetField(player.Location.X, player.Location.Y).Player = null;
                Players.Remove(player);
            }
        }
コード例 #4
0
        public bool UpdateLocalBoard(DataMessage responseMessage)
        {
            bool updated = false;

            gameFinished = gameFinished || responseMessage.GameFinished;

            var playerId = responseMessage.PlayerId;

            if (playerId == this.ID && !gameFinished)
            {
                GetBoard.UpdateGoalFields(responseMessage.Goals);
                GetBoard.UpdateTaskFields(responseMessage.Tasks);
                GetBoard.UpdatePieces(responseMessage.Pieces);

                if (responseMessage.Pieces != null && responseMessage.Pieces.Length == 1)
                {
                    var piece = responseMessage.Pieces[0];
                    if (piece != null)
                    {
                        if (GetPiece == null)
                        // Player picks up piece
                        {
                            this.SetPiece(piece);
                            GetBoard.GetTaskField(Location).Piece = null;
                        }
                        else if (GetPiece.ID == piece.ID && piece.Type != PieceType.destroyed)
                        // Player tests piece
                        {
                            this.SetPiece(piece);
                        }
                        else if (GetPiece.ID == piece.ID && piece.Type == PieceType.destroyed)
                        // Player tests piece
                        {
                            this.SetPiece(null);
                        }
                    }
                }

                if (responseMessage.Tasks != null && responseMessage.Tasks.Length == 1)
                {
                    var field = responseMessage.Tasks[0];
                    if (field != null && GetPiece != null)
                    {
                        if (field.Piece != null && field.X == Location.X && field.Y == Location.Y && field.Piece.ID == GetPiece.ID)
                        // player put down a piece
                        {
                            SetPiece(null);
                        }
                    }
                }

                if (responseMessage.Goals != null && responseMessage.Goals.Length == 1)
                {
                    var field = responseMessage.Goals[0];
                    if (field.X == Location.X && field.Y == Location.Y)
                    {
                        if (field.Type == GoalFieldType.goal) //tylko wtedy ustawia się null
                        {
                            SetPiece(null);
                        }
                        //zawsze aktualizacja timestamp, bo jak już raz był na danym polu typu goal, to ma już do niego nie wracać
                        var goalPlayer = PlayerBoard.GetGoalField(Location.X, Location.Y);
                        goalPlayer.TimeStamp = DateTime.Now.AddYears(100);
                        goalPlayer.Type      = field.Type == GoalFieldType.goal ? GoalFieldType.goal : GoalFieldType.nongoal;
                    }
                }

                if (responseMessage.PlayerLocation != null)
                {
                    SetLocation(responseMessage.PlayerLocation.X, responseMessage.PlayerLocation.Y);
                }

                updated = true;
            }
            else if (gameFinished)
            {
                //wypisywnaie planszy po otryzmaniu Data, wymóg specyfikacji
                Console.WriteLine("!!!ACHTUNG!!!\nReceived DATA MESSAGE from GameMaster with GameFinished == true. PlayerId/ClientId:" + ID + "\nGUID: " + GUID);
                State = AgentState.SearchingForGame;
                PrintBoardState();
            }
            ActionToComplete = ActionType.none;
            return(updated);
        }