public void Score_FirstRound_ShouldHasCorrectScore() { var rpsGame = new RPSGame(); var playerPick = Pick.Paper; var computerPick = rpsGame.GetComputerPick(playerPick); var expectedScore = new Score(); if (playerPick == computerPick) { expectedScore.ComputerScore = 0; } else if (computerPick == Pick.Rock) { expectedScore.HumanScore = 1; } else if (computerPick == Pick.Scissor) { expectedScore.ComputerScore = 1; } Assert.Equal(expectedScore.HumanScore, rpsGame.Score.HumanScore); Assert.Equal(expectedScore.ComputerScore, rpsGame.Score.ComputerScore); }
public void WhosTheWinner_FistPlayerRockSecondPlayerScissor_FirstPlayerWins() { RPSGame testRPSGame = new RPSGame ("Paper", "Rock"); List<string> expected = new List<string> {"FistPlayer Wins"}; List<string> actual = testRPSGame.GameWinner(); CollectionAssert.AreEqual(expected, actual); }
public void RoundClassWinner_TestRoundFirst_ShouldReturnWinner() { var rpsGame = new RPSGame(); var playerPick = Pick.Paper; var computerPick = rpsGame.GetComputerPick(playerPick); var winner = rpsGame.Rounds[0].Winner; Player?expectedWinner; if (playerPick == computerPick) { expectedWinner = null; } else if (computerPick == Pick.Rock) { expectedWinner = Player.Human; } else { expectedWinner = Player.Computer; } Assert.Equal(expectedWinner, winner); }
public void RPSGameClassWinner_TestRound_CheckingIfSomeoneWins() { var rpsGame = new RPSGame(); var playerPick = Pick.Rock; var computerPick = rpsGame.GetComputerPick(playerPick); var expectedWinner = rpsGame.Winner; var score = new Score(); Player winner = new Player(); do { rpsGame.GetComputerPick(playerPick); }while (!rpsGame.IsGameOver); if (score.HumanScore == 3) { winner = Player.Human; } else if (score.ComputerScore == 3) { winner = Player.Computer; } Assert.Equal(expectedWinner, winner); }
public MainPage() { GetPicksImages(); InitializeComponent(); SetDefaultPicksImages(); SetAvatarsImages(); SetButtonImages(); _game = new RPSGame(); }
public void PaperBeatsRock() { var userChoice = Choice.Rock; var g = new RPSGame(new AlwaysPickPaper()); var result = g.PlayRound(userChoice); Assert.AreEqual(GameResult.Loss, result.Result); }
private void GameStatusOnClicked(object sender, EventArgs e) { _game = new RPSGame(); ChangePickButtonStatus(true); GameStatus.IsVisible = false; GameStatus.IsEnabled = false; SetDefaultPicksImages(); UpdateScore(); }
public void GetComputerPick_ThirdRound_ShouldReturnLosingWithLastPick() { var rpsGame = new RPSGame(); var computerPick = rpsGame.GetComputerPick(Pick.Paper); rpsGame.GetComputerPick(Pick.Rock); rpsGame.GetComputerPick(Pick.Scissor); computerPick = rpsGame.GetComputerPick(Pick.Scissor); Assert.Equal(Pick.Paper, computerPick); }
private void GameStart() { StartButton.Visible = false; ButtonRestart.Visible = true; // <-- Error bejbe RockButton.Enabled = true; PaperButton.Enabled = true; ScissorsButton.Enabled = true; Game = new RPSGame(); }
public async Task Should_throw_exception_if_not_all_games_completed() { // Arrange var newRpsGame = new RPSGame(10, 1); rpsGameStore.GetGame().Returns(newRpsGame); // Act && Assert rpsPlayer.Invoking(async r => await r.Result(Outcome.Win)) .Should().Throw <Exception>().WithMessage(Constants.NotAllGamesCompleted); }
public void GetComputerPick_TestRounds_ShouldReturnLosingWithLessFrequentlyChoosenPick() { var rpsGame = new RPSGame(); var computerPick = rpsGame.GetComputerPick(Pick.Rock); rpsGame.GetComputerPick(Pick.Rock); rpsGame.GetComputerPick(Pick.Paper); computerPick = rpsGame.GetComputerPick(Pick.Paper); Assert.Equal(Pick.Rock, computerPick); }
public void Should_throw_exception_if_no_game_in_progress() { // Arrange var newRpsGame = new RPSGame(10, 0); rpsGameStore.GetGame().Returns(newRpsGame); // Act && Assert rpsPlayer.Invoking(async r => await r.GameResult(Outcome.Win, Move.Rock)) .Should().Throw <Exception>().WithMessage(Constants.NoGameProgress); }
public void Should_throw_exception_if_game_already_in_progress() { // Arrange var rpsGame = new RPSGame(2, 1); rpsGame.AddGame(Move.Rock); rpsGameStore.GetGame().Returns(rpsGame); // Act & Assert rpsPlayer.Invoking(async r => await r.MakeMove()).Should().Throw <Exception>().WithMessage(Constants.GameInProgress); }
public void Should_throw_exception_if_no_games_left_to_play() { // Arrange var rpsGame = new RPSGame(1, 1); rpsGame.AddGame(Move.Rock); rpsGameStore.GetGame().Returns(rpsGame); // Act & Assert rpsPlayer.Invoking(async r => await r.MakeMove()) .Should().Throw <Exception>().WithMessage(Constants.NoGamesLeftToPlay); }
public void Should_throw_exception_if_opponent_dynamites_greater_than_allowed() { // Arrange var newRpsGame = new RPSGame(10, 0); newRpsGame.AddGame(Move.Paper); rpsGameStore.GetGame().Returns(newRpsGame); // Act && Assert rpsPlayer.Invoking(async r => await r.GameResult(Outcome.Win, Move.Dynamite)) .Should().Throw <ArgumentException>().WithMessage(string.Format(Constants.TooManyDynamite, 0)); }
public void Should_throw_exception_if_outcome_doesnt_match_moves(Outcome yourOutcome, Move move, Move opponentMove) { // Arrange var newRpsGame = new RPSGame(10, 0); newRpsGame.AddGame(move); rpsGameStore.GetGame().Returns(newRpsGame); // Act & Assert rpsPlayer.Invoking(async r => await r.GameResult(yourOutcome, opponentMove)).Should().Throw <ArgumentException>() .WithMessage(Constants.InvalidOutcome); }
public void GetComputerPick_TestRound_ShouldntReturnComputerPickAsANull() { var rpsGame = new RPSGame(); var playerPick = Pick.Rock; var computerPick = rpsGame.GetComputerPick(playerPick); rpsGame.GetComputerPick(playerPick); rpsGame.GetComputerPick(playerPick); Pick?nullPick = null; Assert.NotEqual(nullPick, computerPick); }
public void CurrentRound_SecondRound_ShouldReturnOppositePick() { var rpsGame = new RPSGame(); var playerPick = Pick.Paper; rpsGame.GetComputerPick(playerPick); var eachRound = rpsGame.GetComputerPick(playerPick); var computerPick = rpsGame.CurrentRound.ComputerPick; Assert.NotEqual(playerPick, computerPick); }
public HomeModule() { Get["/"] = _ => { return View["index.cshtml"]; }; Post["/output"] = _ => { string output; RPSGame newRPSGame = new RPSGame(Request.Form["player1"], Request.Form["player2"]); output = newRPSGame.RPSWinner(); return View["output.cshtml", output]; }; }
public ActionResult <RPSPlayer> rps_game_winner(IEnumerable <RPSPlayer> players) { try { var game = new RPSGame(players); return(game.GetWinner()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void GetComputerPick_SecondRound_ShouldReturnRock() { var rpsGame = new RPSGame(); var playerPick = Pick.Paper; rpsGame.GetComputerPick(playerPick); var computerPick = rpsGame.GetComputerPick(playerPick); Pick expectedPick = Pick.Rock; Assert.Equal(expectedPick, computerPick); }
public void IsGameOver_GetComputerPickAfterGameOver_ShouldThrowApplicationException() { var rpsGame = new RPSGame(); var playerPick = Pick.Paper; var computerPick = rpsGame.GetComputerPick(playerPick); do { rpsGame.GetComputerPick(playerPick); }while (!rpsGame.IsGameOver); Action getPickAfterGameOver = () => rpsGame.GetComputerPick(playerPick); Assert.Throws <ApplicationException>(getPickAfterGameOver); }
public void Rounds_ThirdRound_ShouldReturnProperRoundValue() { var rpsGame = new RPSGame(); var playerPick = Pick.Paper; int expectedRoundCount = 3; for (int i = 0; i < expectedRoundCount; i++) { rpsGame.GetComputerPick(playerPick); } int gamePlayCount = rpsGame.Rounds.Count; Assert.Equal(expectedRoundCount, gamePlayCount); }
static void Main(string[] args) { var rps = new RPSGame("scissors", "paper", "rock"); int wins = 0, losses = 0, draws = 0; Console.WriteLine(FiggleFonts.Standard.Render("Rock, Paper, Scissors!")); while (true) { Console.WriteLine("Select your weapon: " + string.Join(", ", rps.Weapons) + ", quit"); string weapon = Console.ReadLine().Trim().ToLower(); if (weapon == "quit") { break; } if (!rps.Weapons.Contains(weapon)) { Console.WriteLine("Invalid weapon!"); continue; } int result = rps.Next(weapon); Console.WriteLine("You chose {0} and your opponent chose {1}!", weapon, rps.LastAIWeapon); switch (result) { case 1: Console.WriteLine("{0} beats {1}. You win!", weapon, rps.LastAIWeapon); wins++; break; case 0: Console.WriteLine("Draw!"); draws++; break; case -1: Console.WriteLine("{0} beats {1}. Get Wrecked!", rps.LastAIWeapon, weapon); losses++; break; } Console.WriteLine(); } Console.WriteLine("\nPlayer Statistics\nWins: {0}\nLosses: {1}\nDraws: {2}", wins, losses, draws); }
public static void Main(string[] args) { Console.Clear(); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("BNU CO453 Applications Programming Jan start"); Console.WriteLine("Evan Castro"); Console.WriteLine(); string[] choices = new string[] { "Distance Coverter", "BMI Calculator", "Student Grades", "Social Network", "RSP Game" }; ConsoleHelper.OutputTitle("Please select the application you wish to use "); choice = ConsoleHelper.SelectChoice(choices); if (choice == 1) { DistanceConverter converter = new DistanceConverter(); converter.Run(); } else if (choice == 2) { BMICalculator calculator = new BMICalculator(); calculator.Run(); } else if (choice == 3) { StudentGrades grades = new StudentGrades(); grades.Run(); } else if (choice == 4) { NetworkApp App04 = new NetworkApp(); App04.DisplayMenu(); } else if (choice == 5) { RPSGame game = new RPSGame(); game.Run(); } }
private void ButtonRestart_Click(object sender, EventArgs e) { PlayerPictureBox.Image = null; ComputerPictureBox.Image = null; RockButton.Enabled = true; PaperButton.Enabled = true; ScissorsButton.Enabled = true; //Clear GUI RoundCounter.Text = 0.ToString(); HumanScore.Text = 0.ToString(); ComputerScore.Text = 0.ToString(); //Create New RPSGame Instance Game = new RPSGame(); }
public async Task <string> GetReady(int numGames, int numDynamite) { if (await rpsGameStore.GetGame() != null) { throw new Exception(Constants.MatchAlreadyInProgress); } if (numGames <= 0 || numDynamite < 0) { throw new ArgumentException(Constants.InvalidParameters); } if (numDynamite > numGames) { throw new ArgumentException(Constants.InvalidNumberOfDynamite); } var rpsGame = new RPSGame(numGames, numDynamite); await rpsGameStore.Add(rpsGame); return(Constants.GameSuccessfullySetup); }
public void RPSResult_PaperScissors_Player2() { RPSGame testRPSGame = new RPSGame(); Assert.AreEqual("Player 2", testRPSGame.GameResult(2, 3)); }
public RPSGame_GameWinnerTest() { _rpsGame = new RPSGame(); }
public async Task Add(RPSGame game) { await context.RPSGames.AddAsync(game); await context.SaveChangesAsync(); }
public async Task Update(RPSGame game) { context.RPSGames.Update(game); await context.SaveChangesAsync(); }