Пример #1
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);
        }
Пример #2
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());
        }
Пример #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);
            }
        }