Пример #1
0
 public void StartNextTurn()
 {
     (bool over, PlayerType winner) = CheckGameOver();
     if (!over)
     {
         if (!Started)
         {
             currentPlayer = PlayerType.Player1;
             Started       = true;
         }
         else if (currentPlayer == PlayerType.Player1)
         {
             currentPlayer = PlayerType.Player2;
         }
         else
         {
             currentPlayer = PlayerType.Player1;
         }
         if (ForcedMoves)
         {
             CheckForcedPieces(currentPlayer);
         }
         NextTurn?.Invoke(currentPlayer, forcedPieces);
     }
     else
     {
         GameOver?.Invoke(winner);
     }
 }
Пример #2
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Return))
     {
         nextTurn.Invoke();
     }
 }
Пример #3
0
 public void TurnChange()
 {
     if (NextTurnCallBack != null)
     {
         NextTurnCallBack.Invoke();
         StartCoroutine(waiting());
         currentTurn++;
     }
 }
Пример #4
0
 public void Play()
 {
     while (!IsGameOver)
     {
         RefreshDisplay?.Invoke(this, null);
         var diceRes = new int[2];
         NextTurn?.Invoke(this, new DiceEventArgs(diceRes));
         PlayNewTurn(diceRes);
     }
     Message?.Invoke(this, $"The Winner is the {Winner.Color} player!");
 }
Пример #5
0
 //is invoked after the player moves.  This signals that the enemy is now okay to move and
 //take its actions
 public void TurnChange()
 {
     if (NextTurnCallBack != null)
     {
         enemyList = GameObject.FindGameObjectsWithTag("Enemy");
         enemyMoves.Clear();
         StartCoroutine(waiting());
         isMoving = true;                                    //triggering delegate
         NextTurnCallBack.Invoke();
     }
 }
Пример #6
0
 public void NextStep(BodyPart bodyPart)
 {
     roundIndex++;
     if (roundIndex % 2 == 0)
     {
         Player0.Blocked = bodyPart;
         Player0.GetHit(Bot.choseBodyPart());
     }
     else
     {
         Player1.Blocked = Bot.choseBodyPart();
         Player1.GetHit(bodyPart);
     }
     NextTurn?.Invoke(this, new EventArgs());
 }
Пример #7
0
        public void ChangeTurn()
        {
            addMoveNote();

            LastMove   = to;
            from.Piece = null;

            if (WhosPlaying == PieceColor.Black)
            {
                WhosPlaying = PieceColor.White;
            }
            else
            {
                WhosPlaying = PieceColor.Black;
                TurnId++;
            }

            NextTurn?.Invoke(this, null);
        }
Пример #8
0
 public void StartGame()
 {
     roundIndex = new Random().Next(0, PlayersAmount);
     if (Player0.HealthPoints == Player.MaxHealth && Player1.HealthPoints == Player.MaxHealth &&
         roundIndex % 2 == 1)
     {
         NextTurn?.Invoke(this, new EventArgs());
     }
     if (Player0.HealthPoints == 0 && roundIndex % 2 == 1)
     {
         NextTurn?.Invoke(this, new EventArgs());
     }
     if (Player1.HealthPoints == 0 && roundIndex % 2 == 0)
     {
         NextTurn?.Invoke(this, new EventArgs());
     }
     Player0.HealthPoints = Player.MaxHealth;
     Player1.HealthPoints = Player.MaxHealth;
     Start?.Invoke(this, new GameModelEventArgs(roundIndex));
 }
Пример #9
0
        /// Current thinker makes its move
        private Winner Play()
        {
            // Get a reference to the current thinker
            IThinker thinker = matchData.CurrentThinker;

            // Determine the color of the current thinker
            PColor color = board.Turn;

            // Match result so far
            Winner winner = Winner.None;

            // Thinking start time
            DateTime startTime = DateTime.Now;

            // Real think time in milliseconds
            int thinkTimeMillis;

            // Apparent thinking time left
            int timeLeftMillis;

            // Task to execute the thinker in a separate thread
            Task <FutureMove> thinkTask;

            // Notify listeners that next turn is about to start
            NextTurn?.Invoke(color, thinker.ToString());

            // Ask thinker to think about its next move
            thinkTask = Task.Run(
                () => thinker.Think(board.Copy(), ts.Token));

            // The thinking process might throw an exception, so we wrap
            // task waiting in a try/catch block
            try
            {
                // Wait for thinker to think... until the allowed time limit
                if (thinkTask.Wait(timeLimitMillis))
                {
                    // Thinker successfully made a move within the time limit

                    // Get the move selected by the thinker
                    FutureMove move = thinkTask.Result;

                    // Was the thinker able to chose a move?
                    if (move.IsNoMove)
                    {
                        // Thinker was not able to chose a move

                        // Raise an invalid play event and set the other
                        // thinker as the winner of the match
                        winner = OnInvalidPlay(
                            color, thinker,
                            "Thinker unable to perform move");
                    }
                    else
                    {
                        // Thinker was able to chose a move

                        // Perform move in game board, get column where move
                        // was performed
                        int row = board.DoMove(move.shape, move.column);

                        // If the column had space for the move...
                        if (row >= 0)
                        {
                            // Obtain thinking end time
                            thinkTimeMillis = (int)(DateTime.Now - startTime)
                                              .TotalMilliseconds;

                            // How much time left for the minimum apparent move
                            // time?
                            timeLeftMillis =
                                minMoveTimeMillis - thinkTimeMillis;

                            // Was the minimum apparent move time reached
                            if (timeLeftMillis > 0)
                            {
                                // If not, wait until it is reached
                                Thread.Sleep(timeLeftMillis);
                            }

                            // Notify listeners of the move performed
                            MovePerformed?.Invoke(
                                color, thinker.ToString(),
                                move, thinkTimeMillis);

                            // Get possible winner and solution
                            winner = board.CheckWinner(solution);
                        }
                        else
                        {
                            // If we get here, column didn't have space for the
                            // move, which means that thinker made an invalid
                            // move and should lose the game

                            // Raise an invalid play event and set the other
                            // thinker as the winner of the match
                            winner = OnInvalidPlay(
                                color, thinker,
                                "Tried to place piece in column "
                                + $"{move.column}, which is full");
                        }
                    }
                }
                else // Did the time limit expired?
                {
                    // Notify thinker to voluntarily stop thinking
                    ts.Cancel();

                    // Raise an invalid play event and set the other thinker
                    // as the winner of the match
                    winner = OnInvalidPlay(
                        color, thinker, "Time limit expired");
                }
            }
            catch (Exception e)
            {
                // Is this an inner exception?
                if (e.InnerException != null)
                {
                    // If so, use it for error message purposes
                    e = e.InnerException;
                }

                // Raise an invalid play event and set the other thinker as
                // the winner of the match
                winner = OnInvalidPlay(
                    color, thinker,
                    $"Thinker exception: '{e.Message}'");
            }

            // Notify listeners that the board was updated
            BoardUpdate?.Invoke(board);

            // Return winner
            return(winner);
        }
Пример #10
0
 public void StartNextTurn(PlayerType player, List <GamePiece> forcedPieces)
 {
     NextTurn?.Invoke(player, forcedPieces);
 }
Пример #11
0
 private void TurnManager_NextTurn(object sender, EventArgs e)
 {
     NextTurn?.Invoke(sender, e);
 }
Пример #12
0
 public static void OnNextTurn(object sender, NextTurnEventArgs args)
 {
     NextTurn?.Invoke(sender, args);
 }