public static void Main(string[] args) { Console.WriteLine("Welcome to Bowling 2000\n\nPlease enter your name"); var playerName = Console.ReadLine(); var ball = Ball.Instance; _bowling = new Bowling(playerName); Console.WriteLine($"\nWelcome {playerName}! Press any key to roll your first ball."); Console.ReadLine(); _bowling.Bowl(ball.Roll()); while (_bowling.Status() != GameStatus.Ended) { Console.WriteLine($"Your current score is {_bowling.TotalScore()}"); Console.WriteLine("Press Enter to roll your next ball..."); Console.ReadLine(); _bowling.Bowl(ball.Roll()); } Console.WriteLine($"Congratulations! You scored {_bowling.TotalScore()}"); Console.ReadLine(); Console.ReadLine(); }
/// <summary> /// Set bowling by given type. If type not found, throw exception. /// </summary> public void Execute() { switch (type) { case DEFAULT_TYPE: Bowling = new SimpleBowling(); break; } if (Bowling == null) { throw new ArgumentNullException("Type '" + type + "' of bowling not found"); } }
/// <summary> /// Count final score for every one BowlingScore in collection /// </summary> /// <param name="bowling">Bowling</param> /// <param name="scores">Collection of BowlingScore</param> protected void CountFinalScore(ref IBowling bowling, ref ICollection <BowlingScore> scores) { try { var it = scores.GetEnumerator(); it.MoveNext(); while (it.Current != null) { BowlingScore score = it.Current; bowling.CountScore(ref score); it.MoveNext(); } } catch (Exception ex) { ExecuteErrorCommand("Can not count final score. Please check file"); ExitFailed(); } }
/// <summary> /// Set custom or default Bowling /// </summary> /// <param name="bowling">Bowling</param> protected void TypeBowlingBranch(out IBowling bowling) { string arg; if ((arg = ArgsContainsFlag(Constants.BOWLING_TYPE_COMMAND_FULL_FLAG, Constants.BOWLING_TYPE_COMMAND_SHORT_FLAG)) != null) { try { command = factory.CreateCommand(Constants.BOWLING_TYPE_COMMAND_FULL_FLAG); command.SetData(arg); command.Execute(); bowling = ((BowlingTypeCommand)command).Bowling; }catch (Exception ex) { ExecuteErrorCommand("Can not found type of bowling.", "Use simple type."); bowling = new SimpleBowling(); } } else { bowling = new SimpleBowling(); } }
public BowlingGameTotalTest(ITestOutputHelper output) { _bowling = new Bowling("Player 1"); _output = output; }