// --------------------------------------    API
        #region API
        /// <summary>
        /// Method to request a Test Piece action
        /// </summary>
        /// <param name="playerGuid">guid of player requesting an action</param>
        /// <param name="gameId">id of current game</param>
        /// <returns></returns>
        public DataMessage HandleTestPieceRequest(TestPieceMessage msg)
        {
            ConsoleWriter.Show("Received TestingPiece...");
            string playerGuid = msg.PlayerGUID;
            ulong gameId = msg.GameId;
            Monitor.Enter(lockObject);
            GameObjects.Piece pieceDataToSend = null;
            var Player = Players.Where(q => q.GUID == playerGuid).First();
            try
            {
                if (Player.GetPiece != null)
                {
                    pieceDataToSend = new GameObjects.Piece(Player.GetPiece.ID, DateTime.Now, pieces.Where(p => p.ID == Player.GetPiece.ID).First().Type, (long)Player.ID);
                }
            }
            finally
            {
                Monitor.Exit(lockObject);
            }
            PrintBoardState();
            Thread.Sleep((int)GetCosts.TestDelay);
            if (msg.ReceiveDate > GameStartDate)
            {
                return new DataMessage(Player.ID)
                {
                    GameFinished = IsGameFinished,
                    Pieces = new GameObjects.Piece[] { pieceDataToSend }
                };
            }
            else
                return null; //obsluga wiadomosci ktore jeszcze nie zostaly wyslane ze wzgledu na delay


        }
Ejemplo n.º 2
0
 /// <summary>
 /// Method to send request to test the piece
 /// </summary>
 /// <param name="gameMaster">Addressee of the request</param>
 /// <returns>True - request was valid; False - request was not valid</returns>
 public bool TestPiece()
 {
     if (gameFinished != true)
     {
         if (GetPiece != null)
         {
             ConsoleWriter.Show(GUID + " tries to test piece: " + GetPiece.ID + " on location: " + Location);
         }
         TestPieceMessage msg = new TestPieceMessage(GUID, GameId);
         LastActionTaken = ActionToComplete = ActionType.TestPiece;
         Controller.BeginSend(msg.Serialize()); //każda akcja od razu się wysyła, ustawia również LastActionTaken i dla move LastMoveTaken !!!!!
         return(true);
     }
     return(false);
 }