Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Roulette_Game/GameManager.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
64 lines (57 sloc)
3.01 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GameManager | |
{ | |
private Wheel wheel; // The wheel used in the game | |
private Player player; // The player object | |
private GameRules gameRules; // Object containing the rules of the game | |
private RoundHistory roundHistory; // Object to keep track of round history | |
private ResultDisplay resultDisplay; // Object to display game results | |
// Constructor to initialize the game manager with the provided initial balance, game rules, round history, and result display | |
public GameManager(int initialBalance, GameRules gameRules, RoundHistory roundHistory, ResultDisplay resultDisplay) | |
{ | |
wheel = new Wheel(); // Initialize the wheel | |
player = new Player(initialBalance); // Initialize the player with the provided initial balance | |
this.gameRules = gameRules; // Set the game rules | |
this.roundHistory = roundHistory; // Set the round history | |
this.resultDisplay = resultDisplay; // Set the result display | |
} | |
// Method to play a round of the game | |
public void PlayRound() | |
{ | |
// Prompt the player to enter the bet amount | |
Console.Write("Please enter your bet amount: "); | |
// Try to parse the bet amount entered by the player | |
if (!int.TryParse(Console.ReadLine(), out int betAmount)) | |
{ | |
// If the entered bet amount is invalid, display an error message and return | |
Console.WriteLine("Invalid bet amount. Please try again."); | |
return; | |
} | |
// Prompt the player to enter the bet type | |
Console.Write("Please enter your bet type (Red, Black, or a specific number): "); | |
string betType = Console.ReadLine(); | |
// Create a bet object with the provided bet amount and bet type | |
Bet bet = new Bet(betAmount, betType); | |
// Place the bet | |
player.PlaceBet(bet); | |
// Spin the wheel to get the winning number | |
int winningNumber = wheel.SpinWheel(); | |
// Get the color of the winning number | |
string winningColor = wheel.GetColor(winningNumber); | |
// Calculate the winnings based on the bet, winning number, and winning color | |
int winnings = gameRules.CalculateWinnings(bet, winningNumber, winningColor); | |
// Collect the winnings | |
player.CollectWinnings(winnings); | |
// Create a round result object with the winning number, winning color, bet, and winnings | |
RoundResult result = new RoundResult(winningNumber, winningColor, bet, winnings); | |
// Add the round result to the round history | |
roundHistory.AddRoundResult(result); | |
// Display the result of the round | |
resultDisplay.DisplayRoundResult(result, player.Balance); | |
} | |
// Method to display the history of all rounds played | |
public void DisplayHistory() | |
{ | |
// Display the history of all rounds played | |
resultDisplay.DisplayHistory(roundHistory.GetRoundResults(), player.Balance); | |
} | |
} |