/// <summary> /// Main method resembles the high-level algorithm for the program /// </summary> /// <param name="args"></param> public static void Main(string[] args) { Random randomChoice = new Random(); bool tie; bool again; DisplayWelcomeMessage(); do { tie = false; again = false; PromptUser(); StateOfPlay userSelection = UserChoice(); StateOfPlay compSelection = ComputerChoice(randomChoice); DisplayChoices(userSelection, compSelection); tie = DetermineWinner(userSelection, compSelection); if (!tie) { again = PlayAgain(); } } while (tie || again); } // end Main
} // end Display Choices /// <summary> /// Calculate who the winner of the game is /// </summary> /// <param name="user">The human player</param> /// <param name="computer">The human player's computer oponent</param> /// <returns>True if there has been a tie, False otherwise</returns> public static bool DetermineWinner(StateOfPlay user, StateOfPlay computer) { bool tie = false; // when the user wins if ((user == StateOfPlay.PAPER) && (computer == StateOfPlay.ROCK) || (user == StateOfPlay.SCISSORS) && (computer == StateOfPlay.PAPER) || (user == StateOfPlay.ROCK) && (computer == StateOfPlay.SCISSORS)) { Console.WriteLine("You won, lucky choice!"); tie = false; // when user and computer have chosen the same thing } else if (user == computer) { tie = true; Console.WriteLine("Great minds think alike!"); // all other cases - computer wins } else { Console.WriteLine("I won!"); tie = false; } return(tie); } // end DetermineWinner
private void SetState(StateOfPlay state) { m_State = state; Debug.Log("New state: " + state.ToString()); switch (m_State) { case StateOfPlay.PlayerWaitForInput: WaitingForPlayerInput(); break; case StateOfPlay.PlayerRolling: RollPlayersDice(); break; case StateOfPlay.OpponentWaitForInput: GetOpponentDecision(); break; case StateOfPlay.OpponentRolling: RollOpponentsDice(); break; case StateOfPlay.AskReroll: AskReroll(); break; case StateOfPlay.RerollingRound: DoRerolls(); break; case StateOfPlay.ScoreTally: GameOver(); break; default: Debug.LogError("Menu state \"" + state + "\" is not supported!"); break; } }
} // end ComputerChoice /// <summary> /// Display the choices made by both players /// </summary> /// <param name="user"></param> /// <param name="computer"></param> public static void DisplayChoices(StateOfPlay user, StateOfPlay computer) { Console.WriteLine("I played {0} and you played {1}", computer, user); } // end Display Choices
// Start is called before the first frame update void Start() { m_State = StateOfPlay.RandomizingStart; m_UIManager.RandomizingUI(); Time.timeScale = m_GameSpeedMultiplier; }