public void AddNewResult(GameResultRecord newResult) { _logger.Add(newResult); using (StreamWriter file = new StreamWriter(_loggerPath, true)) { file.WriteLine(newResult.ToString()); } }
public void AddNewResult(string username, int gamecode, char status, int balanceChange, string gameInfo) { GameResultRecord newResult = new GameResultRecord(username, gamecode, status, balanceChange, gameInfo); _logger.Add(newResult); using (StreamWriter file = new StreamWriter(_loggerPath, true)) { file.WriteLine(newResult.ToString()); } }
public override GameResultRecord Play(int bet, string username) { GameResultRecord result = null; int balanceChange = 0; Boolean rightInput = false; while (!rightInput) { Console.WriteLine("Please, input sum of dices (from 2 to 12)"); var inputString = Console.ReadLine(); Console.WriteLine(); int sum; var res = Int32.TryParse(inputString, out sum); if (res) { if ((sum > 1) && (sum < 13)) { rightInput = true; int d1 = _rand.Next(1, 6); int d2 = _rand.Next(1, 6); Console.WriteLine("Dices: " + d1 + " " + d2); if (d1 + d2 == sum) { Console.WriteLine("You win!"); balanceChange = bet; result = new GameResultRecord(username, 2, 'W', balanceChange, getInfo(d1, d2, sum)); } else { Console.WriteLine("You Lose!"); balanceChange = -1*bet; result = new GameResultRecord(username, 2, 'L', balanceChange, getInfo(d1, d2, sum)); } } else { Console.WriteLine("Incorrect input. Do it again"); } } else { Console.WriteLine("Incorrect input. Do it again"); } } return result; }
public GameResults GetResultFromRecord(GameResultRecord gameResult) { GameResults result = null; switch (gameResult.GameCode) { case 1: var scoresBJ = gameResult.GameInfo.Split(' ').Select(Int32.Parse).ToArray(); result = new BlackJackGameResults(gameResult.Date.DateTime, GetUserFromRecord(gameResult), GetGameResultStatus(gameResult), gameResult.BalanceChange, scoresBJ[0], scoresBJ[1]); break; case 2: var scoresDice = gameResult.GameInfo.Split(' ').Select(Int32.Parse).ToArray(); result = new DiceGameResults(gameResult.Date.DateTime, GetUserFromRecord(gameResult), GetGameResultStatus(gameResult), gameResult.BalanceChange, scoresDice[0], scoresDice[1]); break; case 3: var dataRoulet = gameResult.GameInfo.Split(' ').ToArray(); string userChoise = dataRoulet[0]; var cell = Int32.Parse(dataRoulet[1]); result = new RouletGameResults(gameResult.Date.DateTime, GetUserFromRecord(gameResult), GetGameResultStatus(gameResult), gameResult.BalanceChange, userChoise, cell); break; } return result; }
public GameResultStatus GetGameResultStatus(GameResultRecord gameResult) { GameResultStatus res = 0; switch (gameResult.Status) { case 'L': res = GameResultStatus.Loose; break; case 'W': res = GameResultStatus.Win; break; } return res; }
public GameCode GetGameCodeFromRecord(GameResultRecord gameResult) { GameCode res = 0; switch (gameResult.GameCode) { case 1: res = GameCode.BJ; break; case 2: res = GameCode.Dice; break; case 3: res = GameCode.Roulet; break; } return res; }