private void HandleTransactionCommand(ITransaction transaction) { commNavigator = CommandNavigator.BaseCommands; commandRequest = "Enter command:"; commandResponse.Clear(); string emptyString = new string(' ', Console.WindowWidth - 1); string responseString; AppendSpaces(ref commandRequest); if (double.TryParse(inputLine.Replace(".", ","), out double amount) && amount > 0) { transaction.Amount = amount; List <string> response = User.RequestTransaction(transaction); commandResponse.AddRange(response); commandResponse.Add(emptyString); } else { responseString = "Error: Wrong amount"; AppendSpaces(ref responseString); commandResponse.Add(responseString); commandResponse.Add(emptyString); commandResponse.Add(emptyString); } }
public Game() { pathToSavedGames = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saved games"); Directory.CreateDirectory(pathToSavedGames); ListOfTrendProbabilities = new List <ValueProbability> { new ValueProbability(1, 25, 1), // 24% chance to get flat trend new ValueProbability(25, 49, 2), // 24% chance to get descending flat new ValueProbability(49, 73, 3), // 24% chance to get ascending flat new ValueProbability(73, 87, 4), // 14% chance to get bull market trend new ValueProbability(87, 101, 5) // 14% chance to get bear market trend }; gameFrame = new List <string>(); commandRequest = "Enter command"; inputLine = ""; commandResponse = new List <string>(); commNavigator = CommandNavigator.BaseCommands; locker = new object(); priceTimer = new System.Timers.Timer(300); trendTimer = new System.Timers.Timer(10000); SetTimers(); }
private void HandleBaseCommand() { string emptyString = new string(' ', Console.WindowWidth - 1); string responseString; List <string> emptyResponse = new List <string> { emptyString, emptyString, emptyString }; commNavigator = CommandNavigator.BaseCommands; commandResponse.Clear(); if (Enum.TryParse(inputLine, true, out Command command)) { switch (command) { case Command.Help: commandRequest = "Enter command:"; AppendSpaces(ref commandRequest); responseString = "\"help\", \"buy\", \"sell\", \"deposit\", \"withdraw\", \"exit\"."; AppendSpaces(ref responseString); commandResponse.Add(responseString); commandResponse.Add(emptyString); commandResponse.Add(emptyString); break; case Command.Buy: commandRequest = "Enter amount, Money:"; AppendSpaces(ref commandRequest); commandResponse.AddRange(emptyResponse); commNavigator = CommandNavigator.Buy; break; case Command.Sell: commandRequest = "Enter amount, Coin:"; AppendSpaces(ref commandRequest); commandResponse.AddRange(emptyResponse); commNavigator = CommandNavigator.Sell; break; case Command.Deposit: commandRequest = "Enter amount, Money:"; AppendSpaces(ref commandRequest); commandResponse.AddRange(emptyResponse); commNavigator = CommandNavigator.Deposit; break; case Command.Withdraw: commandRequest = "Enter amount, Money:"; AppendSpaces(ref commandRequest); commandResponse.AddRange(emptyResponse); commNavigator = CommandNavigator.Withdraw; break; case Command.Exit: Stop(); Save(); Environment.Exit(0); break; default: commandRequest = "Enter command:"; AppendSpaces(ref commandRequest); responseString = "Error: Unknown command"; AppendSpaces(ref responseString); commandResponse.Add(responseString); commandResponse.Add(emptyString); commandResponse.Add(emptyString); break; } } else { commandRequest = "Enter command:"; AppendSpaces(ref commandRequest); responseString = "Error: Unknown command"; AppendSpaces(ref responseString); commandResponse.Add(responseString); commandResponse.Add(emptyString); commandResponse.Add(emptyString); } }