static void Main(string[] args) { string player = ""; string move = ""; List <Game> list = new List <Game>(); Console.WriteLine("****** GAME - ROCK-PAPER-SCISSORS ****** "); for (int i = 0; i < 2; i++) { Console.WriteLine("Player " + (i + 1) + ": "); player = Console.ReadLine(); Console.WriteLine("Move Player " + (i + 1) + ": Choose Between: [R (rock) - P(papper) - S(scissors)]: "); move = Console.ReadLine().ToUpper(); list.Add(new Game(player, move)); } Console.WriteLine(" Winner !!!!!!!!!!!!!!!!!!!"); Console.WriteLine(" Player: " + QuickGame.rps_game_winner(list).ToString()); Console.ReadKey(); Console.Clear(); Console.WriteLine("***** TOURNAMENT ROCK-PAPER-SCISSORS *****"); list = new List <Game>(); list = MultiPlayer.FillList(); Console.WriteLine(" Winner !!!!!!!!!!!!!!!!!!!"); Console.WriteLine(" Player: " + Tournament.rps_tournament_winner(list).ToString()); Console.ReadKey(); }
public Player rps_tournament_winner() { if (this.ListMatches != null) { Tournament t1 = new Tournament(this.ListMatches[0]); Player winnerT1 = t1.rps_tournament_winner(); Tournament t2 = new Tournament(this.ListMatches[1]); Player winnerT2 = t2.rps_tournament_winner(); Match finalMatch = new Match(winnerT1, winnerT2); return(finalMatch.rps_game_winner()); } else if (this.Matches != null) { List <Match> resultMatches = new List <Match>(); if (this.Matches.Length > 1) { for (int i = 0; i < this.Matches.Length; i += 2) { Player winner1 = this.Matches[i].rps_game_winner(); Player winner2 = this.Matches[i + 1].rps_game_winner(); Match winnerMatch = new Match(winner1, winner2); resultMatches.Add(winnerMatch); } Tournament t3 = new Tournament(resultMatches.ToArray()); return(t3.rps_tournament_winner()); } else { return(this.Matches[0].rps_game_winner()); } } else { return(null); } }
static void Main(string[] args) { //Tournament 1 // Side 1 List <Match> t1s1 = new List <Match>(); t1s1.Add(new Match(new Player("Armando", "P"), new Player("Dave", "S"))); t1s1.Add(new Match(new Player("Richard", "R"), new Player("Michael", "S"))); // Side 2 List <Match> t1s2 = new List <Match>(); t1s2.Add(new Match(new Player("Allen", "S"), new Player("Omer", "P"))); t1s2.Add(new Match(new Player("David E.", "R"), new Player("Richard X.", "P"))); List <Match[]> tournament1 = new List <Match[]>(); tournament1.Add(t1s1.ToArray()); tournament1.Add(t1s2.ToArray()); Tournament t1 = new Tournament(tournament1); try { Player winner = t1.rps_tournament_winner(); Console.WriteLine(string.Format("Tournament 1 Winner: {0} with move {1}!", winner.Name, winner.Strategy)); } catch (WrongNumberOfPlayersError) { Console.WriteLine("Error: the number of players is not equal to 2"); } catch (NoSuchStrategyError) { Console.WriteLine("Error: invalid strategy"); } // Tournament 2 // Side 1 List <Match> t2s1 = new List <Match>(); t2s1.Add(new Match(new Player("Armando", "r"), new Player("Dave", "P"))); t2s1.Add(new Match(new Player("Richard", "P"), new Player("Michael", "R"))); t2s1.Add(new Match(new Player("John", "S"), new Player("Jake", "P"))); t2s1.Add(new Match(new Player("Jack", "P"), new Player("Steve", "R"))); // Side 2 List <Match> t2s2 = new List <Match>(); t2s2.Add(new Match(new Player("Allen", "P"), new Player("Omer", "R"))); t2s2.Add(new Match(new Player("David E.", "R"), new Player("Richard X.", "R"))); t2s2.Add(new Match(new Player("Mike", "S"), new Player("Jamal", "P"))); t2s2.Add(new Match(new Player("Hurley", "R"), new Player("Will.", "P"))); List <Match[]> tournament2 = new List <Match[]>(); tournament2.Add(t2s1.ToArray()); tournament2.Add(t2s2.ToArray()); Tournament t2 = new Tournament(tournament2); try { Player winner = t2.rps_tournament_winner(); Console.WriteLine(string.Format("Tournament 2 Winner: {0} with move {1}!", winner.Name, winner.Strategy)); } catch (WrongNumberOfPlayersError) { Console.WriteLine("Error: the number of players is not equal to 2"); } catch (NoSuchStrategyError) { Console.WriteLine("Error: invalid strategy"); } Console.ReadKey(); }