public bool Destroy() { ConsoleWriter.Show(GUID + " tries to destroy piece: " + piece.ID + " which is: " + piece.Type + "on location: " + Location); DestroyPieceMessage msg = new DestroyPieceMessage(GUID, GameId); LastActionTaken = ActionToComplete = ActionType.Destroy; Controller.BeginSend(msg.Serialize()); //każda akcja od razu się wysyła, ustawia również LastActionTaken i dla move LastMoveTaken !!!!! WaitForActionComplete(); return(!HasPiece); }
/// <summary> /// /// </summary> /// <param name="playerGuid"></param> /// <param name="gameId"></param> /// <returns></returns> public DataMessage HandleDestroyPieceRequest(DestroyPieceMessage msg) { ConsoleWriter.Show("Received DestroyPiece..."); 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 = pieces.Where(p => p.ID == Player.GetPiece.ID).FirstOrDefault(); pieceDataToSend.Type = PieceType.destroyed; pieces.RemoveAll(p => p.ID == Player.GetPiece.ID); Player.SetPiece(null); } } 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 }