Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- namespace Game
- {
- class Game
- {
- double balance;
- History history = new History();
- public Game(double balance) {
- this.balance = balance;
- }
- public bool checkResult(int playerNumIsEven, int resultNum)
- {
- return (playerNumIsEven + resultNum) % 2 == 0;
- }
- public bool changeBalance(bool result, double bet)
- {
- balance += result ? bet : -bet;
- return balance > 0;
- }
- public int generateNum () {
- return new Random().Next();
- }
- public void printInfo(bool b ,bool d) {
- if (b)
- Console.WriteLine("You are win, your balance {0}n", balance);
- else
- Console.WriteLine("You are lose, your balance {0}n", balance);
- if (!d) {
- Console.WriteLine("balance is emptyn");
- theEnd();
- }
- }
- public void theEnd() {
- history.printInfo();
- Console.WriteLine("Enter to exit...");
- Console.ReadLine();
- Environment.Exit(0);
- }
- public void play() {
- while (true)
- {
- Console.WriteLine("input odd or even, or smt else for exit.");
- string forecast = Console.ReadLine().ToLower();
- if (forecast != "even" && forecast != "odd")
- {
- theEnd();
- }
- else {
- double bet;
- while (true)
- {
- Console.WriteLine("input your bet");
- while (true) {
- bet = double.Parse(Console.ReadLine());
- if (bet > 0)
- break;
- else {
- Console.WriteLine("your input is incorrect, please input correct num");
- }
- }
- if (bet > balance)
- Console.WriteLine("incorrect");
- else
- break;
- }
- int random = generateNum();
- Console.WriteLine("generated num: {0}", random);
- bool result = checkResult(forecast == "even" ? 0 : 1, random);
- bool ended = changeBalance(result, bet);
- history.addToHistory(result, balance);
- printInfo(result, ended);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment