Exemplo n.º 1
0
        public void ShouldReturnDiceValue()
        {
            model.Dice sut      = new model.Dice();
            int        expected = sut.Roll();

            Assert.That(expected, Is.InRange(1, 6));
        }
Exemplo n.º 2
0
        public void AddDiceNrAndRollThenAddToList_UseWrongArgumentInt0_ThrowsArgumentOutOfRangeException()
        {
            model.Dice dice  = new model.Dice();
            int        input = 0;

            Assert.Throws <ArgumentOutOfRangeException>(() => sut.AddDiceNrAndRollThenAddToList(dice, input));
        }
Exemplo n.º 3
0
        public void StartRound()
        {
            gameView.ClearConsole();
            gameView.DisplayPlayerScore(player.GetScores());
            game.Roll();
            model.Dice dice = game.GetDice();
            gameView.DisplayDiceValues(dice);
            List <model.Scores> options = game.GetPlayerOptions();

            gameView.DislayPlayerOptions(options);
            ConsoleKeyInfo userInput = gameView.GetInput();

            if (userInput.Key == ConsoleKey.D1)
            {
                StartRound();
            }
            else if (userInput.Key == ConsoleKey.D2)
            {
                SelectDice(dice);
            }
            else if (userInput.Key == ConsoleKey.D3)
            {
                if (options.Count > 0)
                {
                    player.AddScore(options[0], dice);
                }
            }
            else if (userInput.Key == ConsoleKey.D4)
            {
                if (options.Count > 1)
                {
                    player.AddScore(options[1], dice);
                }
            }
            else if (userInput.Key == ConsoleKey.D5)
            {
                if (options.Count > 2)
                {
                    player.AddScore(options[2], dice);
                }
            }
            else if (userInput.Key == ConsoleKey.D6)
            {
                if (options.Count > 3)
                {
                    player.AddScore(options[3], dice);
                }
            }
            else if (userInput.Key == ConsoleKey.D7)
            {
                if (options.Count > 4)
                {
                    player.AddScore(options[4], dice);
                }
            }
            StartRound();
        }
Exemplo n.º 4
0
 public void DisplayDiceValues(model.Dice dice)
 {
     Console.WriteLine("Dice values");
     foreach (model.Die die in dice.GetDice())
     {
         System.Threading.Thread.Sleep(400);
         Console.Write(die.Value + ", ");
     }
     Console.WriteLine("\n");
 }
Exemplo n.º 5
0
 public void ToggleSelectDice(model.Dice dice, int i)
 {
     if (dice.GetDice()[i].Save)
     {
         dice.GetDice()[i].Save = false;
     }
     else
     {
         dice.GetDice()[i].Save = true;
     }
 }
Exemplo n.º 6
0
        internal void AddDiceNrAndRollThenAddToList(model.Dice a_dice, int a_diceNumber)
        {
            if (a_diceNumber < 1 || a_diceNumber > 6)
            {
                throw new ArgumentOutOfRangeException();
            }

            a_dice.Dicenumber = (Dices)a_diceNumber;
            a_dice.Roll();
            m_diceList.Add(a_dice);
        }
Exemplo n.º 7
0
        public void Save_Dice1_ShowSaved_ReturnsInt1()
        {
            List <model.Dice> input = sut.Show();

            model.Dice dice1 = input.First(dice => dice.Dicenumber == model.Hand.Dices.Dice_1);

            sut.Save(dice1);

            int actual   = sut.ShowSaved().Count;
            int expected = 1;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 8
0
        private void SaveAndRemoveDice(model.Dice a_dice)
        {
            int index = m_diceList.FindIndex(d => d.Dicenumber == a_dice.Dicenumber);

            if (index == -1)
            {
                throw new DiceNotFoundException();
            }
            else
            {
                model.Dice dice = m_diceList[index];
                m_savedDiceList.Add(dice);
                m_diceList.RemoveAt(index);
            }
        }
Exemplo n.º 9
0
        private async Task Save(IPlayer player, bool a_noTest, model.task.delay.IAsyncDelay a_asyncDelay)
        {
            List <model.Dice> diceList           = player.GetHand();
            List <model.Dice> tempDiceList       = new List <model.Dice>();
            List <model.Dice> dicesToBeSavedList = new List <model.Dice>();
            int dicesInList = 6;

            for (int i = 0; i < dicesInList; i++)
            {
                m_IView.DisplaySaveKeys();
                model.Hand.Dices input = m_IView.GetDiceToSave();

                if (input == model.Hand.Dices.Done)
                {
                    break;
                }

                int index = diceList.FindIndex(d => d.Dicenumber == input);

                if (index == -1)
                {
                    m_IView.DisplayCannotSaveDiceTwice();
                    if (a_noTest)
                    {
                        i--; // Enables endless loop and player can only exit through option "DONE".
                    }
                }
                else
                {
                    model.Dice diceToSave = diceList[index];
                    tempDiceList.Add(diceToSave);
                    diceList.RemoveAt(index);
                }
            }

            foreach (model.Dice d in tempDiceList)
            {
                dicesToBeSavedList.Add(d);
            }

            for (int i = 0; i < dicesToBeSavedList.Count; i++)
            {
                player.Save(dicesToBeSavedList[i]);
            }

            await RollRemainingDicesAfterSave(player, a_asyncDelay);
        }
Exemplo n.º 10
0
        public void SelectDice(model.Dice dice)
        {
            Console.WriteLine("Select dice to keep");
            int i = 1;

            foreach (model.Die die in dice.GetDice())
            {
                Console.Write(i + ". " + die.Value);
                if (die.Save)
                {
                    Console.Write("(Saved)");
                }
                Console.WriteLine();
                i++;
            }
            Console.WriteLine(i + ". Done");
        }
Exemplo n.º 11
0
        public void SelectDice(model.Dice dice)
        {
            gameView.ClearConsole();
            gameView.SelectDice(dice);
            ConsoleKeyInfo userInput = gameView.GetInput();

            if (userInput.Key == ConsoleKey.D1)
            {
                ToggleSelectDice(dice, 0);
                SelectDice(dice);
            }
            else if (userInput.Key == ConsoleKey.D2)
            {
                ToggleSelectDice(dice, 1);
                SelectDice(dice);
            }
            else if (userInput.Key == ConsoleKey.D3)
            {
                ToggleSelectDice(dice, 2);
                SelectDice(dice);
            }
            else if (userInput.Key == ConsoleKey.D4)
            {
                ToggleSelectDice(dice, 3);
                SelectDice(dice);
            }
            else if (userInput.Key == ConsoleKey.D5)
            {
                ToggleSelectDice(dice, 4);
                SelectDice(dice);
            }
            else if (userInput.Key == ConsoleKey.D6)
            {
                StartRound();
            }
        }
Exemplo n.º 12
0
 public void Save(model.Dice a_dice)
 {
     m_hand.Save(a_dice);
 }
Exemplo n.º 13
0
 public DiceTest()
 {
     sut = new model.Dice();
 }
Exemplo n.º 14
0
 public void Save(model.Dice a_dice)
 {
     SaveAndRemoveDice(a_dice);
 }
Exemplo n.º 15
0
 public void DisplayDice(model.Dice a_dice)
 {
     Console.Write("{0} : {1}\n", a_dice.Dicenumber, a_dice.GetValue());
 }