示例#1
0
        private void ExecuteEndPlayCommand()
        {
            //ComandCode
            IsPlaying  = false;
            IsGameOver = true;
            GameManager.GameStarted = false;

            //Force to Humman Play for end the endless loop
            if (IsAHummanPlayer && PlausiblesMoves != null && PlausiblesMoves.Any())
            {
                (PlayerThatPlayNow as HummanPlayer).HummanPositionToMove = PlausiblesMoves.First().MovePosition;
            }
            CurrentState = "Stop Game";
            WhiteTimer.Stop();
            BlackTimer.Stop();
        }
示例#2
0
 private void GameManagerOnGameFinished(object sender, GameFinishedEventArgs gameFinishedEventArgs)
 {
     SyncContext.Send((_) =>
     {
         IsPlaying         = false;
         IsGameOver        = true;
         WhiteCount        = gameFinishedEventArgs.WhiteCount;
         BlackCount        = gameFinishedEventArgs.BlackCount;
         var draftString   = "The game is draft";
         var noDraftString = gameFinishedEventArgs.WhiteWins == null
                                                      ? null
                                                      : string.Format("{0} Wins!!!",
                                                                      gameFinishedEventArgs.WhiteWins.Value
                                                                          ? "Whites"
                                                                          : "Blacks");
         WinString    = gameFinishedEventArgs.WhiteWins == null ? draftString : noDraftString;
         CurrentState = WinString;
         BlackTimer.Stop();
         WhiteTimer.Stop();
     }, null);
 }
示例#3
0
        private void GameManagerOnMoveDone(object sender, MoveEventArgs moveEventArgs)
        {
            SyncContext.Send(_ =>
            {
                if (!IsPlaying)
                {
                    return;
                }

                if (!moveEventArgs.IsUndoneMove)
                {
                    MovesCount++;
                    MovesString = string.Format("{0}\n{1}.{2}-{3}", MovesString, MovesCount.ToString("00"),
                                                PlayerThatPlayNow.PlayerKind == PlayerKind.White
                            ? "White"
                            : "Black",
                                                moveEventArgs.Move.IsPassMove
                            ? "Pass"
                            : string.Format("{0}{1}",
                                            (char)('a' +
                                                   moveEventArgs.Move.MovePosition.Item2),
                                            moveEventArgs.Move.MovePosition.Item1 + 1));

                    Board.DoMove(moveEventArgs.Move);
                }
                else
                {
                    MovesCount--;
                    MovesString = string.Format("{0}\n{1}", MovesString, "Move was undone.");
                    Board.ReverseMove(moveEventArgs.Move);
                }

                PlayerThatPlayNow = GameManager.CurrentPlayerAtTurn;
                Board.RefreshCells();
                WhiteCount = Board.Board.WhitePoints.Count;
                BlackCount = Board.Board.BlackPoints.Count;

                MainWindow.UpdateScore(WhiteCount, BlackCount, PlayerThatPlayNow.PlayerKind, moveEventArgs.IsUndoneMove);
                var seconds   = (DateTime.Now - LastTimeMoved).TotalSeconds;
                LastTimeMoved = DateTime.Now;
                if (PlayerThatPlayNow.PlayerKind == PlayerKind.Black)
                {
                    WhiteTimer.Stop();
                    BlackTimer.Start();
                    //While was playing
                    if (WhiteMaxEllapsedTime < seconds)
                    {
                        WhiteMaxEllapsedTime = (int)seconds;
                    }
                }
                else
                {
                    WhiteTimer.Start();
                    BlackTimer.Stop();
                    //Black was playing
                    if (BlackMaxEllapsedTime < seconds)
                    {
                        BlackMaxEllapsedTime = (int)seconds;
                    }
                }
            }, null);
        }