コード例 #1
0
        /// <summary>
        /// Represents a method which starts the game.
        /// </summary>
        public void StartGame()
        {
            this.field = new GameField(BOARD_SIZE, BOARD_SIZE);

            this.moveCount = 0;
            this.field.GenerateField(new RandomFieldGenerator());
            this.isGameRunning      = true;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(Message.WELCOME);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(field.ToString());

            // While the game is running prompts the user to enter
            // new position to move to.
            while (isGameRunning)
            {
                isGameRunning = !IsGameFinished();

                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(Message.MOVE);

                string input = Console.ReadLine();
                this.ParseInput(input);

                if (isGameWon)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(Message.Solved(this.moveCount));
                    this.CheckTopScore();
                    this.StopGame();
                }
            }
            Console.ResetColor();
        }
コード例 #2
0
        /// <summary>
        /// Represents a method that starts a new game
        /// </summary>
        /// <remarks>The game field will have new numbers.</remarks>
        private void RestartGame()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(Message.GAME_RESTARTED);

            this.moveCount = 0;
            this.field     = new GameField(BOARD_SIZE, BOARD_SIZE);
            field.GenerateField(new RandomFieldGenerator());

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(field.ToString());
            Console.ResetColor();
        }
コード例 #3
0
        /// <summary>
        /// Represents a method that moves the number in the available <seealso cref="MoveDirection.cs"/>.
        /// </summary>
        /// <param name="oldPosition">The position that the number was originally set to.</param>
        /// <param name="direction">The direction of the available movement.</param>
        private static void MoveInDirection(Position oldPosition, MoveDirection direction, GameField movingField)
        {
            Position newPosition = CalculatePositionWithDirection(oldPosition,
                                                                  direction);

            if (movingField[newPosition.Row, newPosition.Column] == GameField.EMPTY_CELL)
            {
                string itemToMove = movingField[oldPosition.Row, oldPosition.Column];
                movingField[newPosition.Row, newPosition.Column] = itemToMove;
                movingField[oldPosition.Row, oldPosition.Column] = GameField.EMPTY_CELL;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write(movingField.ToString());
                Console.ResetColor();
            }
        }
コード例 #4
0
ファイル: GameFieldTests.cs プロジェクト: nikolovk/Neodymium
 public void TestToStringSecondTest()
 {
     GameField gamefield = new GameField(4);
     Assert.IsTrue(gamefield.ToString().Contains("|"));
 }
コード例 #5
0
ファイル: GameFieldTests.cs プロジェクト: nikolovk/Neodymium
 public void TestToString()
 {
     GameField gamefield = new GameField(4);
     Assert.IsTrue(gamefield.ToString().StartsWith(" -------------"));
 }