public Engine(ScoreBoard board) { this.scoreBoard = board; this.guessCount = 0; this.cheats = new Cheat(); this.theNumber = new GameNumber(); }
/// <summary> /// Creates the needed requirements for the game, initializes it and starts it. /// </summary> private void Initialize() { NumberCommandProcessor numberCommandProcessor = new NumberCommandProcessor(); HelpCommandProcessor helpCommandProcessor = new HelpCommandProcessor(); numberCommandProcessor.SetSuccessor(helpCommandProcessor); TopCommandProcessor topCommandProcessor = new TopCommandProcessor(); helpCommandProcessor.SetSuccessor(topCommandProcessor); RestartCommandProcessor restartCommandProcessor = new RestartCommandProcessor(); topCommandProcessor.SetSuccessor(restartCommandProcessor); ExitCommandProcessor exitCommandProcessor = new ExitCommandProcessor(); restartCommandProcessor.SetSuccessor(exitCommandProcessor); InvalidCommandProcessor invalidCommandProcessor = new InvalidCommandProcessor(); exitCommandProcessor.SetSuccessor(invalidCommandProcessor); ScoreBoard scoreBoard = new ScoreBoard(MaxPlayersInScoreboard); MessageFactory messageFactory = new MessageFactory(); IPrinter printer = new Printer(messageFactory); IRandomNumberProvider randomNumberProvider = RandomNumberProvider.Instance; BullsAndCowsGame game = new BullsAndCowsGame(randomNumberProvider, scoreBoard, printer, numberCommandProcessor); game.Initialize(); game.Play(); }
static void Main() { ScoreBoard board = new ScoreBoard(ScoresFile); Engine engine = new Engine(board); engine.Run(); board.SaveToFile(ScoresFile); }
/// <summary> /// Singleton pattern. /// </summary> /// <returns>new instance of <see cref="ScoreBoard"/>. /// If an instance already exists, returns a reference to that object </returns> public static ScoreBoard GetInstance() { if (instance == null) { instance = new ScoreBoard(); } return instance; }
public void ScoreBoardKeeps5HighScoresTrueTest() { ScoreBoard scoreBoard = new ScoreBoard(); for (int index = 0; index < 10; index++) { scoreBoard.Add("Pesho", 2); } Assert.AreEqual(5, scoreBoard.Count()); }
public void IsHighScoreTrueTest() { ScoreBoard scoreBoard = new ScoreBoard(); for (int index = 0; index < scoreBoard.BoardSize; index++) { scoreBoard.Add("Pesho", 5); } Assert.IsTrue(scoreBoard.IsHighScore(3)); }
public void IsHighScoreFalseTest() { ScoreBoard scoreBoard = new ScoreBoard(); for (int index = 0; index < scoreBoard.BoardSize; index++) { scoreBoard.Add("Pesho", 1); } Assert.IsFalse(scoreBoard.IsHighScore(4)); }
/// <summary> /// Initializes a new instance of the BullsAndCowsGame class. /// </summary> /// <param name="randomNumberProvider">The randomNumberProvider used to generate random numbers.</param> /// <param name="scoreboard">The scoreboard used to hold player's scores.</param> /// <param name="printer">The printer used for printing messages and different objects.</param> /// <param name="commandProcessor">The first command processor in the chain of responsibility.</param> public BullsAndCowsGame( IRandomNumberProvider randomNumberProvider, ScoreBoard scoreboard, IPrinter printer, ICommandProcessor commandProcessor) { this.RandomNumberProvider = randomNumberProvider; this.ScoreBoard = scoreboard; this.Printer = printer; this.CommandProcessor = commandProcessor; }
public void TestScoreboardPrinting() { int results = 2; ScoreBoard scoreBoard = new ScoreBoard(); for (int index = 0; index < results; index++) { scoreBoard.Add("Pesho", index + 1); } Assert.AreEqual(scoreBoard.ToString(), string.Format("{0}\r\n{1}\r\n{2}\r\n\r\n", "Scoreboard:", "1. Pesho --> 1 guesses", "2. Pesho --> 2 guesses")); }
/// <summary> /// Tests whether the ScoreBoard saves the scores correctly. /// </summary> // [TestMethod] public void ScoreBoardTest() { int maxPlayers = 5; var scoreBoard = new ScoreBoard(maxPlayers); var expectedScoreBoard = new List<PlayerScore>(); expectedScoreBoard.Add(new PlayerScore("Pesho0", 0)); expectedScoreBoard.Add(new PlayerScore("Pesho1", 1)); expectedScoreBoard.Add(new PlayerScore("Pesho2", 2)); expectedScoreBoard.Add(new PlayerScore("Pesho3", 3)); expectedScoreBoard.Add(new PlayerScore("Pesho4", 4)); for (int i = 0; i < maxPlayers; i++) { scoreBoard.AddPlayerScore(new PlayerScore("Pesho" + i, i)); } Assert.AreEqual(expectedScoreBoard, scoreBoard.LeaderBoard, "LeaderBoards is not showing scores properly"); }
public void ScoreBoardAddTest() { ScoreBoard scoreBoard = new ScoreBoard(); scoreBoard.Add("Pesho", 5); Assert.AreEqual(1, scoreBoard.Count()); }
public void EmtpyScoreBoardTest() { ScoreBoard scoreBoard = new ScoreBoard(); string expected = "Scoreboard empty!" + Environment.NewLine; Assert.AreEqual(expected, scoreBoard.ToString()); }