Пример #1
0
        /// <summary>
        /// Creates a thread safety Singleton instance of the GameEngine. 
        /// </summary>
        /// <param name="player">Accepts any instance of IPlayer.</param>
        /// <param name="renderer">Accepts any instance of IRenderer.</param>
        /// <param name="scoreboard">Accepts any instance of IScoreBoardObserver.</param>
        /// <param name="matrix">Accepts instance of the class LabyrinthMatrix.</param>
        /// <returns>Instance of the GameEngine class.</returns>
        public static GameEngine Instance(IPlayer player, IRenderer renderer, IScoreBoardObserver scoreboard, LabyrinthMatrix matrix)
        {
            if (gameInstance == null)
            {
                lock (syncLock)
                {
                    if (gameInstance == null)
                    {
                        gameInstance = new GameEngine(player, renderer, scoreboard, matrix);
                    }
                }
            }

            return gameInstance;
        }
        public void IntanceReturnsGameEngineObject()
        {
            this.localScoreBoard = new LocalScoreBoard();
            this.scoreBoard = new ScoreBoardHandler(localScoreBoard);
            this.renderer = new ConsoleRenderer();
            this.player = new Player("Goshou");
            this.matrix = new LabyrinthMatrix();

            this.game = GameEngine.Instance(this.player, this.renderer, this.scoreBoard, this.matrix);
            this.context = this.game.GetCurrentContext();

            Assert.IsTrue(game is GameEngine);
            Assert.AreEqual(8, this.player.PositionRow);
        }