public void ThrowTwo5sAndGet10AfterMistake() { DiceGame dicegame = new DiceGame(new Random()); dicegame.ThrowDices(5, 5); Assert.AreEqual($"You threw the dices and got 10! First dice got 5 and the second dice got 5 after 1 tries.", dicegame.Feedback); dicegame.ThrowDices(1, 6); Assert.AreEqual($"Well done you win, you got 7! You threw the dices and got 7! First dice got 1 and the second dice got 6 after 2 tries.", dicegame.Feedback); }
internal override void PlayActionRule(DiceGame game, Player target) { if (ActionTarget == ActionTarget.Target) { target.PlayerStats.ChangeHealth(_changeHealth, this); } else { game.CurrentBoard.GetOtherPlayer(target).PlayerStats.ChangeHealth(_changeHealth, this); } }
internal override void PlayGameAction(DiceGame game) { if (ValidateGameAction(game)) { foreach (var dice in game.CurrentBoard.Dices.FindAll(d => CanDiceBeSaved(d, game))) { game.CurrentBoard.GetDice(dice.Id).AddModifier(DiceModifier.Saved); game.CurrentBoard.GetDice(dice.Id).RemoveModifier(DiceModifier.CanBeRerolled); game.CurrentBoard.GetDice(dice.Id).RemoveModifier(DiceModifier.Selected); } } }
internal override bool ValidateGameAction(DiceGame game) { var board = game.CurrentBoard; if (board.Dices.Any(d => CanDiceBeSaved(d, game))) { return(true); } else { return(false); } }
internal override void PlayActionRule(DiceGame game, Player target) { var targetPlayer = target; var origin = game.CurrentBoard.Players.Find(p => p.PlayerStats.ID != target.PlayerStats.ID); for (int i = 0; i < _amountShoots; i++) { if (origin.PlayerStats.Ammo - _arrowsPerShoot >= 0) { targetPlayer.PlayerStats.ChangeHealth(_changeHealth, this); origin.PlayerStats.ChangeAmmo(-_arrowsPerShoot, this); } } }
internal override bool ValidateGameAction(DiceGame game) { var board = game.CurrentBoard; var dice = board.GetDice(Dice.Id); if (!dice.HasModifier(DiceModifier.Selected) && !dice.HasModifier(DiceModifier.Used)) { return(true); } else { return(false); } }
internal override void PlayActionRule(DiceGame game, Player target) { foreach (var player in game.CurrentBoard.Players) { if (player.PlayerStats.Ammo + _changeAmmo < 0) { player.PlayerStats.ChangeHealth(_changeHealth, this); } else { player.PlayerStats.ChangeAmmo(_changeAmmo, this); } } }
public void PlayAfterRuleAction(DiceGame game, Player target) { var dices = game.CurrentBoard.GetActiveDices(); foreach (var dice in _neededDices) { var foundDice = dices.Find(d => d.Number == dice.Number); dices.Remove(foundDice); var currentDice = game.CurrentBoard.GetDice(foundDice.Id); currentDice.AddModifier(DiceModifier.Used); currentDice.RemoveModifier(DiceModifier.Selected); currentDice.RemoveModifier(DiceModifier.Saved); currentDice.RemoveModifier(DiceModifier.CanBeRerolled); } }
public bool CanPlayRule(DiceGame game, Player target) { bool result = true; foreach (var restriction in _restrictions) { if (!restriction.CheckGameTurn(game, target)) { result = false; break; } } return(result); }
public void PlayAction_Rule() { var diceGame = new DiceGame(DiceGameSettings.CreateDefaultGameSettings()); var enemy = diceGame.CurrentBoard.Players.Find(p => p.PlayerStats.ID != diceGame.CurrentBoard.CurrentPlayer.PlayerStats.ID); var player = diceGame.CurrentBoard.CurrentPlayer; Assert.IsTrue(diceGame.CanBePlayed(new RerollTurn())); diceGame.Play(new RerollTurn()); Assert.IsTrue(diceGame.CanBePlayed(new RerollTurn())); diceGame.Play(new RerollTurn()); Assert.IsFalse(diceGame.CanBePlayed(new RerollTurn())); diceGame.Play(new EndRound()); Assert.IsTrue(diceGame.CanBePlayed(new RerollTurn())); }
public void Right_Guess_Of_Lower_Number_Should_Give_A_Point() { var randomizer = new CheatRandomizer(new List <int> { 6, 5, 4, 3 }); var cheatDice = new Dice(randomizer); var diceGame = new DiceGame(); cheatDice.RollDice(); diceGame.UserGuess = 0; cheatDice.RollDice(); diceGame.GetRoundResult(cheatDice); var pointsGained = diceGame.UserPoints; Assert.IsTrue(pointsGained == 1); }
public void CheckInstantRules(DiceGame game) { bool foundRule = false; do { foundRule = false; foreach (var rule in game.DiceGameSettings.RuleSettings.GetInstantRules()) { if (rule.CanPlayRule(game, game.CurrentBoard.CurrentPlayer)) { rule.PlayRule(game, game.CurrentBoard.CurrentPlayer); foundRule = true; } } } while (foundRule); }
public void Part2() { int[] rollOutcomes = new int[] { 0, 0, 0, 1, 3, 6, 7, 6, 3, 1 }; long p1Wins = 0; long p2Wins = 0; Queue <DiceGame> inProgressGames = new Queue <DiceGame>() { }; inProgressGames.Enqueue(ReadGameFromFile()); while (inProgressGames.Count > 0) { DiceGame previousRound = inProgressGames.Dequeue(); for (int p1Roll = 3; p1Roll < 10; p1Roll++) { DiceGame p1Round = previousRound.Player1Rolls(p1Roll, rollOutcomes[p1Roll]); if (p1Round.IsComplete(21)) { p1Wins += p1Round.Combos; continue; } for (int p2Roll = 3; p2Roll < 10; p2Roll++) { DiceGame p2Round = p1Round.Player2Rolls(p2Roll, rollOutcomes[p2Roll]); if (p2Round.IsComplete(21)) { p2Wins += p2Round.Combos; continue; } inProgressGames.Enqueue(p2Round); } } } long result = Math.Max(p1Wins, p2Wins); Assert.Equal(48868319769358, result); }
private void PlayerAfterActions(DiceGame game, Player target) { foreach (var actionRule in _actionRules) { if (actionRule is IAfterRulePlayedAction afterRule) { afterRule.PlayAfterRuleAction(game, target); } } foreach (var restriction in _restrictions) { if (restriction is IAfterRulePlayedAction afterRule) { afterRule.PlayAfterRuleAction(game, target); } } }
public void ThrowALotWrong() { DiceGame dicegame = new DiceGame(new Random()); dicegame.ThrowDices(4, 1); Assert.AreEqual($"You threw the dices and got 5! First dice got 4 and the second dice got 1 after 1 tries.", dicegame.Feedback); dicegame.ThrowDices(2, 2); Assert.AreEqual($"You threw the dices and got 4! First dice got 2 and the second dice got 2 after 2 tries.", dicegame.Feedback); dicegame.ThrowDices(1, 2); Assert.AreEqual($"You threw the dices and got 3! First dice got 1 and the second dice got 2 after 3 tries.", dicegame.Feedback); dicegame.ThrowDices(2, 4); Assert.AreEqual($"You threw the dices and got 6! First dice got 2 and the second dice got 4 after 4 tries.", dicegame.Feedback); dicegame.ThrowDices(1, 1); Assert.AreEqual($"You threw the dices and got 2! First dice got 1 and the second dice got 1 after 5 tries.", dicegame.Feedback); }
private static void GameLoop(DiceGame diceGame) { diceGame.StartGame(); Console.WriteLine($"First roll is: {diceGame.CurrentRoll}"); while (true) { Console.Write($"Press UP to guess higher and DOWN to guess lower: "); var guess = Console.ReadKey(); bool result = false; switch (guess.Key) { case ConsoleKey.UpArrow: result = diceGame.GuessHigher(); break; case ConsoleKey.DownArrow: result = diceGame.GuessLower(); break; default: WriteLine("\nYou have to press UP or DOWN", ConsoleColor.DarkYellow); continue; } Console.WriteLine($"\nLast roll was: {diceGame.CurrentRoll}"); if (!diceGame.IsRunning) { break; } if (result) { WriteLine("You guessed right!", ConsoleColor.Green); } else { WriteLine("Result was same as last", ConsoleColor.Yellow); } } }
public void Move_SelectionPossible() { var diceGame = new DiceGame(DiceGameSettings.CreateDefaultGameSettings()); var enemy = diceGame.CurrentBoard.Players.Find(p => p.PlayerStats.ID != diceGame.CurrentBoard.CurrentPlayer.PlayerStats.ID); var player = diceGame.CurrentBoard.CurrentPlayer; diceGame.CurrentBoard.SetDices(new List <Dice> { new Dice(0, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(1, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(2, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(3, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(4, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(5, 1, diceGame.DiceGameSettings.DiceSettings) }); Assert.IsTrue(diceGame.CanBePlayed(new RerollTurn())); diceGame.Play(new RerollTurn()); diceGame.CurrentBoard.SetDices(new List <Dice> { new Dice(0, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(1, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(2, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(3, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(4, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(5, 1, diceGame.DiceGameSettings.DiceSettings) }); Assert.IsTrue(diceGame.CanBePlayed(new RerollTurn())); diceGame.Play(new RerollTurn()); diceGame.CurrentBoard.SetDices(new List <Dice> { new Dice(0, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(1, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(2, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(3, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(4, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(5, 1, diceGame.DiceGameSettings.DiceSettings) }); Assert.IsTrue(diceGame.CanBePlayed(new SelectAction(new Dice(0)))); }
public void Two_Right_Guesses_Should_Give_Two_Points() { var randomizer = new CheatRandomizer(new List <int> { 1, 2, 3, 4 }); var cheatDice = new Dice(randomizer); var diceGame = new DiceGame(); //diceGame.SetupDiceRandomizer(randomizer); cheatDice.RollDice(); diceGame.UserGuess = 1; cheatDice.RollDice(); diceGame.GetRoundResult(cheatDice); diceGame.UserGuess = 1; cheatDice.RollDice(); diceGame.GetRoundResult(cheatDice); var pointsGained = diceGame.UserPoints; Assert.IsTrue(pointsGained == 2); }
static void Main() { var diceGame = new DiceGame(new Dice(6)); while (true) { GameLoop(diceGame); WriteLine("Game over!", ConsoleColor.Red); WriteLine($"Your score was: {diceGame.Score}"); Console.Write("\nPlay again (y/n)? "); var again = Console.ReadLine(); if (again.ToLower() != "y") { break; } } }
public void PlayAction_Valid() { var diceGame = new DiceGame(DiceGameSettings.CreateDefaultGameSettings()); diceGame.CurrentBoard.SetDices(new List <Dice> { new Dice(0, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(1, 1, diceGame.DiceGameSettings.DiceSettings), new Dice(2, 2, diceGame.DiceGameSettings.DiceSettings), new Dice(3, 3, diceGame.DiceGameSettings.DiceSettings), new Dice(4, 4, diceGame.DiceGameSettings.DiceSettings), new Dice(5, 6, diceGame.DiceGameSettings.DiceSettings) }); var playAction = new PlayAction(0); var selectAction = new SelectAction(new Dice(1)); diceGame.Play(selectAction); Assert.IsTrue(diceGame.CurrentBoard.Players.TrueForAll(p => p.PlayerStats.Health < p.PlayerStats.MaxHealth)); }
private bool IsPossible(DiceGame game) { bool result = true; var dices = game.CurrentBoard.GetActiveDices(); foreach (var dice in _neededDices) { var foundDice = dices.Find(d => d.Number == dice.Number); if (foundDice == null) { result = false; break; } else { dices.Remove(foundDice); } } return(result); }
public async Task RollDiceGame() { if (Context.IsPrivate == true) { return; } int TossOne = DiceGame.Roll(); int TossTwo = DiceGame.Roll(); int Total = TossOne + TossTwo; var gameChannel = Global.Client.GetGuild(Config.bot.guildID).GetTextChannel(ChannelIds.channels.miniGameID); var embed = new EmbedBuilder(); if (Global.PlayerOneRoll == 0 || Global.PlayerTwoRoll == 0) { if (Global.PlayerOneRoll == 0) { embed.WithTitle($"Dice have been Rolled!") .AddField("The dice are:", $"Dice one: {TossOne}! Dice two: {TossTwo}!") .AddField($"{Context.User} has rolled:", Total); await gameChannel.SendMessageAsync("", false, embed.Build()); Global.PlayerOneId = Context.User as SocketGuildUser; Global.PlayerOneRoll = Total; } else if (Global.PlayerTwoRoll == 0) { embed.WithTitle($"Dice have been Rolled!") .AddField("The dice are:", $"Dice one: {TossOne}! Dice two: {TossTwo}!") .AddField($"{Context.User} has rolled:", Total); await gameChannel.SendMessageAsync("", false, embed.Build()); Global.PlayerTwoId = Context.User as SocketGuildUser; Global.PlayerTwoRoll = Total; } } if (Global.PlayerOneRoll != 0 && Global.PlayerTwoRoll != 0) { await DiceGameFinish(); } }
public void Dice_Board() { var diceGame = new DiceGame(DiceGameSettings.CreateDefaultGameSettings()); diceGame.CurrentBoard.SetDices(new List <Dice> { new Dice(0, 4), new Dice(1, 4), new Dice(2, 4), new Dice(3, 4), new Dice(4, 4), new Dice(5, 4), }); var selectAction = new SelectAction(new Dice(1)); Assert.IsTrue(diceGame.CanBePlayed(selectAction)); diceGame.Play(selectAction); Assert.IsFalse(diceGame.CanBePlayed(selectAction)); }
public void Part1() { DiceGame game = ReadGameFromFile(); int timesRolled = 0; int NextRoll() { int rollSum = ((timesRolled % 100) + 2) * 3; timesRolled += 3; return(rollSum); } while (!(game = game.Player1Rolls(NextRoll())).IsComplete(1000) && !(game = game.Player2Rolls(NextRoll())).IsComplete(1000)) { } long result = timesRolled * Math.Min(game.P1Score, game.P2Score); Assert.Equal(897798, result); }
public void PlayAction_Valid() { var diceGame = new DiceGame(DiceGameSettings.CreateDefaultGameSettings()); diceGame.CurrentBoard.SetDices(new List <Dice> { new Dice(0, 1), new Dice(1, 1), new Dice(2, 2), new Dice(3, 3), new Dice(4, 4), new Dice(5, 5), }); var playAction = new PlayAction(0); var selectAction = new SelectAction(new Dice(1)); Assert.IsFalse(diceGame.CanBePlayed(playAction)); diceGame.Play(selectAction); Assert.IsTrue(diceGame.CanBePlayed(playAction)); }
private static void Gamble(Creature p) { if (p.gold > 0) { Console.Clear(); Console.WriteLine("You head towards the back of the tavern.\nHaving grown up in Marburgh, you know where all the games are, legal and otherwise"); Console.WriteLine("What do you feel like playing? \n\n[B]lackjack [D]ice [T]hree card monty \n[R]eturn"); string choice = Console.ReadKey(true).KeyChar.ToString().ToLower(); if (choice == "r") { Inn(p); } else if (choice != "b" && choice != "t" && choice != "d") { Gamble(p); } Wager(p); if (choice == "b") { BlackJackGame.StartBlackJack(p, wager); } if (choice == "d") { DiceGame.Dice(p, wager); } if (choice == "t") { ThreeCardMonteGame.ThreeCardMonte(p, wager); } } else { Console.WriteLine("You don't have enough money!"); } Utilities.Keypress(); }
public QueueGameRules(DiceGame game) : base(game) { playersList = new List <Player>(game.players); }
public void InitGame(DiceGame diceGame) { _currentGame = diceGame; }
public void describe_a_3_player_game() { before = () => game = new DiceGame(3); context["when the first round begins"] = () => { it["Player count should be 3"] = () => game.Players.Count.should_be(3); it["and the current player should be Player1"] = () => game.CurrentPlayer.Name.should_be("Player1"); it["and the next player should be Player2"] = () => game.NextPlayer.Name.should_be("Player2"); context["when the first player rolls a 4"] = () => { before = () => game.RollDie(4); it["the second player should have 4 inventory"] = () => game.Players[1].Inventory.should_be(4); it["and the current player should be Player2"] = () => game.CurrentPlayer.Name.should_be("Player2"); it["and the next player should be Player3"] = () => game.NextPlayer.Name.should_be("Player3"); context["when the second player rolls a 2"] = () => { before = () => game.RollDie(2); it["the second player should have 2 inventory"] = () => game.Players[1].Inventory.should_be(2); it["the third player should have 2 inventory"] = () => game.Players[2].Inventory.should_be(2); it["and the current player should be Player3"] = () => game.CurrentPlayer.Name.should_be("Player3"); it["and the next player should be null"] = () => game.NextPlayer.should_be(null); context["when the third player rolls a 2"] = () => { before = () => game.RollDie(2); it["the second player should have 2 inventory"] = () => game.Players[1].Inventory.should_be(2); it["the third player should have 0 inventory"] = () => game.Players[2].Inventory.should_be(0); it["the game Throughput should be 2"] = () => game.Throughput.should_be(2); it["and the current player should be Player1"] = () => game.CurrentPlayer.Name.should_be("Player1"); it["and the next player should be Player2"] = () => game.NextPlayer.Name.should_be("Player2"); }; }; }; }; context["when the second round begins"] = () => { before = () => { game.RollDie(4); game.RollDie(2); game.RollDie(2); }; it["Player count should be 3"] = () => game.Players.Count.should_be(3); it["and the current player should be Player1"] = () => game.CurrentPlayer.Name.should_be("Player1"); it["and the next player should be Player2"] = () => game.NextPlayer.Name.should_be("Player2"); it["the second player should have 2 inventory"] = () => game.Players[1].Inventory.should_be(2); it["the third player should have 0 inventory"] = () => game.Players[2].Inventory.should_be(0); it["the game Throughput should be 2"] = () => game.Throughput.should_be(2); context["when the first player rolls a 2"] = () => { before = () => game.RollDie(2); it["the second player should have 2 more inventory, totaling 4"] = () => game.Players[1].Inventory.should_be(4); it["and the current player should be Player2"] = () => game.CurrentPlayer.Name.should_be("Player2"); it["and the next player should be Player3"] = () => game.NextPlayer.Name.should_be("Player3"); context["when the second player rolls a 6"] = () => { before = () => game.RollDie(6); it["the second player should have 0 inventory"] = () => game.Players[1].Inventory.should_be(0); it["the third player should receive only the 4 inventory that Player2 had, totaling 4"] = () => game.Players[2].Inventory.should_be(4); it["and the current player should be Player3"] = () => game.CurrentPlayer.Name.should_be("Player3"); it["and the next player should be null"] = () => game.NextPlayer.should_be(null); context["when the third player rolls a 6"] = () => { before = () => game.RollDie(6); it["the second player should have 0 inventory"] = () => game.Players[1].Inventory.should_be(0); it["the third player should have 0 inventory"] = () => game.Players[2].Inventory.should_be(0); it["the game Throughput receive only the 4 inventory that Player3 had, totaling 6"] = () => game.Throughput.should_be(6); it["and the current player should be Player1"] = () => game.CurrentPlayer.Name.should_be("Player1"); it["and the next player should be Player2"] = () => game.NextPlayer.Name.should_be("Player2"); }; }; }; }; }
public override void OnResponse(NetState state, RelayInfo info) { switch (info.ButtonID) { case 0: break; case 1: TextRelay tr = info.GetTextEntry(0); if (tr != null) { string text = tr.Text; int bet = Utility.ToInt32(text) * 3; if (bet > 0 && bet <= (int)PointsSystem.CasinoData.GetPoints(User)) { PointsSystem.CasinoData.DeductPoints(User, bet, false); Game.CurrentBet = bet; Game.Bet1 = bet / 3; Game.Bet2 = bet / 3; Game.Bet3 = bet / 3; Game.BeginRollDice(); } else { Game.Stage = GameStage.Error; Refresh(); } } break; case 2: if (Game.RollNumber == 2) { PointsSystem.CasinoData.AwardPoints(User, Game.Bet2); Game.Bet2 = 0; } else if (Game.RollNumber == 3) { PointsSystem.CasinoData.AwardPoints(User, Game.Bet3); Game.Bet3 = 0; } Game.Stage = GameStage.Rolling; Game.BeginRollDice(); break; case 3: Game.Stage = GameStage.Rolling; Game.BeginRollDice(); break; case 4: Game.Reset(); Refresh(); break; case 250: DiceGame.Reset(); Refresh(); break; } }
public override bool CheckGameTurn(DiceGame game, Player target) { return(IsPossible(game)); }