private void OnDicePlacement(DiceHolder holder, AbilityCard card) { int diceAmount = 0; foreach (DiceHolder dh in _diceHolders) { if (dh.ContainedDice != null) { diceAmount++; } } if (diceAmount == _diceHolders.Length) { UseAbility(Fight); var dices = Fight.GetPlayerDice(); foreach (DiceHolder dh in _diceHolders) { if (_hideDiceOnUse) { dices.Remove(dh.ContainedDice); } dh.DeselectDice(_hideDiceOnUse); } CheckAvailable(); } }
public void ChooseScoreParser_ShouldSetScoreParserOrThrowIfInvalidInput() { //Arrange GameHelper gamehelper = new GameHelper(); DiceHolder diceHolder = new DiceHolder(); Mock <ScoreParserFactory> mockScoreParserFactory = new Mock <ScoreParserFactory>(); string funInput = "Fun"; mockScoreParserFactory.Setup(x => x.GetScoreParser("FunScoreParser", diceHolder)).Returns(new FunScoreParser(diceHolder)); GamePresenter gamePresenter = new GamePresenter(diceHolder, gamehelper, mockScoreParserFactory.Object); //Assert scoreparser is null before choosing Assert.IsNull(gamePresenter.ScoreParser); gamePresenter.ChooseScoreParser(funInput); //Assert scoreparser implements IScoreParser Assert.IsTrue(gamePresenter.ScoreParser is IScoreParser); gamePresenter = new GamePresenter(diceHolder, gamehelper, mockScoreParserFactory.Object); //Assert throw if invalid input Assert.Throws <InvalidOperationException>(() => gamePresenter.ChooseScoreParser("NotValid")); }
public void GetScore_ShouldGetSumOfAllDice(int inputDiceOne, int inputDiceTwo, int inputDiceThree, int inputDiceFour, int inputDiceFive, int expectedScore) { Mock <IDie> mockDie1 = new Mock <IDie>(); Mock <IDie> mockDie2 = new Mock <IDie>(); Mock <IDie> mockDie3 = new Mock <IDie>(); Mock <IDie> mockDie4 = new Mock <IDie>(); Mock <IDie> mockDie5 = new Mock <IDie>(); mockDie1.Setup(x => x.Value).Returns(inputDiceOne); mockDie2.Setup(x => x.Value).Returns(inputDiceTwo); mockDie3.Setup(x => x.Value).Returns(inputDiceThree); mockDie4.Setup(x => x.Value).Returns(inputDiceFour); mockDie5.Setup(x => x.Value).Returns(inputDiceFive); //Create a dicelist List <IDie> diceList = new List <IDie> { mockDie1.Object, mockDie2.Object, mockDie3.Object, mockDie4.Object, mockDie5.Object, }; var sut = new DiceHolder(diceList); Assert.AreEqual(expectedScore, sut.GetSumOfAllDice()); }
private bool CheckDiceLimitSatisfied(DiceHolder diceHolder) { switch (diceHolder.limit) { case DiceLimit.Over4: if (value < 4) { transform.position = origin; return(false); } break; case DiceLimit.Even: if (value % 2 != 0) { transform.position = origin; return(false); } break; case DiceLimit.Odd: if (value % 2 == 0) { transform.position = origin; return(false); } break; } return(true); }
public void StartGame() { _gameHelper = new GameHelper(); _scoreParserFactory = new ScoreParserFactory(); Die die1 = new Die(); Die die2 = new Die(); Die die3 = new Die(); Die die4 = new Die(); Die die5 = new Die(); List <IDie> diceList = new List <IDie> { die1, die2, die3, die4, die5 }; _diceHolder = new DiceHolder(diceList); _presenter = new GamePresenter(_diceHolder, _gameHelper, _scoreParserFactory); Console.WriteLine("Lets play some Yatzy! What rules do you want to play? write 'Fun' for the fun rules, and 'Boring' for the boring ones!"); string scoreParserToUse = Console.ReadLine(); _presenter.ChooseScoreParser(scoreParserToUse); int [] initialDiceToSave = new int[0]; while (!_gameHelper.IsGameFinished) { _presenter.Roll(initialDiceToSave); //Simulates one Round with two rethrows for (int i = 0; i < 2; i++) { Console.WriteLine("Rethrow " + (i + 1) + " Save the die by typing the die-numbers separated by a comma. E.g '4,1' saves the first and fourth die.\n" + _presenter.PrintDice()); string rerollDiceToSave = Console.ReadLine(); int[] diceToSave = _presenter.ParseDieSelection(rerollDiceToSave); _presenter.Roll(diceToSave); } Console.WriteLine("Time to save the score: see the current list here, and type in what to save."); Console.WriteLine(_presenter.PrintDice()); Console.WriteLine(_presenter.PrintListWithScore()); string scoreToSave = Console.ReadLine(); _presenter.SaveScore(scoreToSave); Console.WriteLine("Score saved: "); Console.WriteLine(_presenter.PrintListWithScore()); } Console.WriteLine("Well done! Final score is: " + _gameHelper.Score); }
public void RollDice_ShouldCallDieRollMethodOnce() { List <IDie> diceList = new List <IDie>(); Mock <IDie> mockDie = new Mock <IDie>(); diceList.Add(mockDie.Object); var sut = new DiceHolder(diceList); sut.RollDice(); mockDie.Verify(x => x.Roll(), Times.Once()); }
public void RollDice_ShouldOnlyRollUnlockedDice() { List <IDie> diceList = new List <IDie>(); Mock <IDie> mockDie = new Mock <IDie>(); mockDie.Setup(x => x.IsLocked).Returns(true); diceList.Add(mockDie.Object); var sut = new DiceHolder(diceList); sut.RollDice(); mockDie.Verify(x => x.Roll(), Times.Never()); }
public void GetDiceList_ShouldReturnAllDice(int input, int expected) { List <IDie> diceList = new List <IDie>(); for (int i = 0; i < input; i++) { Mock <Die> mockDie = new Mock <Die>(); diceList.Add(mockDie.Object); } var sut = new DiceHolder(diceList); Assert.AreEqual(expected, sut.DiceList.Count); }
public void NewGame_ShouldResetAndNotHaveScoreParser() { //Arrange GameHelper gamehelper = new GameHelper(); ScoreParserFactory scoreParserFactory = new ScoreParserFactory(); DiceHolder diceHolder = new DiceHolder(); //Act GamePresenter gamePresenter = new GamePresenter(diceHolder, gamehelper, scoreParserFactory); Assert.AreEqual(gamehelper, gamePresenter.GameHelper); //Assert gamePresenter.NewGame(); Assert.AreNotEqual(gamehelper, gamePresenter.GameHelper); Assert.IsNull(gamePresenter.ScoreParser); }
public void Roll_ShouldLockAndRollUnlockedDice() { //Arrange int[] diceToRoll = new int[2]; diceToRoll[0] = 1; diceToRoll[1] = 4; Mock <IDie> mockDie1 = new Mock <IDie>(); Mock <IDie> mockDie2 = new Mock <IDie>(); Mock <IDie> mockDie3 = new Mock <IDie>(); Mock <IDie> mockDie4 = new Mock <IDie>(); Mock <IDie> mockDie5 = new Mock <IDie>(); List <IDie> diceList = new List <IDie> { mockDie1.Object, mockDie2.Object, mockDie3.Object, mockDie4.Object, mockDie5.Object, }; mockDie1.Setup(x => x.IsLocked).Returns(true); mockDie4.Setup(x => x.IsLocked).Returns(true); IDiceHolder diceholder = new DiceHolder(diceList); Mock <GameHelper> mockGameHelper = new Mock <GameHelper>(); ScoreParserFactory scoreParserFactory = new ScoreParserFactory(); GamePresenter gamePresenter = new GamePresenter(diceholder, mockGameHelper.Object, scoreParserFactory); //Act gamePresenter.Roll(diceToRoll); //assert mockDie1.Verify(x => x.Roll(), Times.Never()); mockDie2.Verify(x => x.Roll(), Times.Once()); mockDie3.Verify(x => x.Roll(), Times.Once()); mockDie4.Verify(x => x.Roll(), Times.Never()); mockDie5.Verify(x => x.Roll(), Times.Once()); }