Beispiel #1
0
        private void PlayDoubleTurn(int[] diceRes)
        {
            int movesRemain = 4;
            var moveArgs    = new int[2];

            do
            {
                GetNextMove?.Invoke(this, new MoveEventArgs(moveArgs, diceRes));
                var src   = moveArgs[0];
                var steps = moveArgs[1];
                try
                {
                    PlayTurn(steps, src, ref movesRemain);

                    if (movesRemain > 0)
                    {
                        Message?.Invoke(this, $"Turn number {4-movesRemain} Complete");
                        RefreshDisplay?.Invoke(this, null);
                    }
                }
                catch (MissMatchException e)
                {
                    Message?.Invoke(this, e.Message);
                    RefreshDisplay?.Invoke(this, new DiceEventArgs(diceRes));
                }
                catch (StuckException e)
                {
                    Message?.Invoke(this, e.Message);
                    movesRemain = 0;
                }
            } while (movesRemain > 0 && !IsGameOver);
        }
Beispiel #2
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!");
 }
Beispiel #3
0
        private void PlayRegularTurn(int[] diceRes)
        {
            var movesRemain = 2;
            var moveArgs    = new int[2];

            do
            {
                GetNextMove?.Invoke(this, new MoveEventArgs(moveArgs, diceRes));
                var src   = moveArgs[0];
                var steps = moveArgs[1];
                try
                {
                    PlayTurn(steps, src, ref movesRemain);
                    if (steps == diceRes[0])
                    {
                        diceRes[0] = 0;
                    }
                    else
                    {
                        diceRes[1] = 0;
                    }

                    if (!(diceRes[0] == 0 && diceRes[1] == 0))
                    {
                        Message?.Invoke(this, "First turn Complete");
                        RefreshDisplay?.Invoke(this, new DiceEventArgs(diceRes));
                    }
                }
                catch (MissMatchException e)
                {
                    Message?.Invoke(this, e.Message);
                    RefreshDisplay?.Invoke(this, new DiceEventArgs(diceRes));
                }
                catch (StuckException e)
                {
                    Message?.Invoke(this, e.Message);
                    movesRemain--;
                    if (steps == diceRes[0])
                    {
                        diceRes[0] = 0;
                    }
                    else
                    {
                        diceRes[1] = 0;
                    }
                }
            } while (movesRemain > 0 && !IsGameOver);
        }