///Method: Main() ///Param1: args - Command line arguments ///Return Type: void ///Purpose: Controls the flow of program static void Main(string[] args) { if (maxNumberOfGames % 2 == 0) { throw new Exception("No valid value in the maxNumberOfGames variable"); } int numberOfGamesNeededToWin = (int)Math.Ceiling((double)(maxNumberOfGames / 2)); ComputerPlayer CP = new ComputerPlayer(); HumanPlayer HP = new HumanPlayer(); WelcomeMessage(); ///Loops until a winner is determined while (currentComputerWins < numberOfGamesNeededToWin && currentPlayerWins < numberOfGamesNeededToWin) { RPCEnum computerPlay = CP.makePlay(); RPCEnum humanPlay = HP.makePlay(); EvaluateWinnerOfRound(computerPlay, humanPlay); } ///Displays the winner message if (currentComputerWins == numberOfGamesNeededToWin) { Console.WriteLine("Congratulations Computer, YOU WIN!"); } else { Console.WriteLine("Congratulations human, YOU WIN!"); } Console.WriteLine(DisplayHistory(CP.PreviousPlays, HP.PreviousPlays)); }
///Method: EvaluateWinnerOfRound() ///Param1: CP - The result of the computer play (Rock, Paper, or Scissors) ///Param2: HP - The result of the human play (Rock, Paper, or Scissors) ///Return Type: void ///Purpose: Evaluates the winner of the round static void EvaluateWinnerOfRound(RPCEnum CP, RPCEnum HP) { Console.WriteLine("Computer Plays: " + CP.ToString()); Console.WriteLine("Human Plays: " + HP.ToString()); if (CP == RPCEnum.Rock) { switch (HP) { case RPCEnum.Rock: Tie(); break; case RPCEnum.Paper: HumanWin(); break; case RPCEnum.Scissors: ComputerWin(); break; } } if (CP == RPCEnum.Paper) { switch (HP) { case RPCEnum.Rock: ComputerWin(); break; case RPCEnum.Paper: Tie(); break; case RPCEnum.Scissors: HumanWin(); break; } } if (CP == RPCEnum.Scissors) { switch (HP) { case RPCEnum.Rock: HumanWin(); break; case RPCEnum.Paper: ComputerWin(); break; case RPCEnum.Scissors: Tie(); break; } } }
/// <summary> /// ペットの同期メソッド名を返す /// </summary> public static string GetRPCMethod(RPCEnum type) { return(RPCMethods[(int)type]); }