예제 #1
0
        /// <summary>
        /// Represents a method that add <seealso cref="Player.cs"/> score
        /// to the list of <seealso cref="TopScores.cs"/>
        /// </summary>
        /// <param name="player">
        /// An instance of <seealso cref="Player.cs"/> that
        /// will be used as information to be saved with the score.
        /// </param>
        /// <param name="position">
        /// Position to be added to the List depending
        /// on the score.
        /// </param>
        private void AddToTopScore(Player player, int position)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(Message.CONGRATS);
            Console.ResetColor();

            player.Name = Console.ReadLine();
            TopScore.AddPlayer(player, position);
        }
예제 #2
0
        /// <summary>
        /// Represents a method that executes commands
        /// entered from the console depending on the user input.
        /// </summary>
        /// <param name="input">Console Input Commands</param>
        /// <remarks>
        /// Only commands like "exit", "top", "restart" or
        /// number between [1, 15] is valid.
        /// </remarks>
        private void ParseInput(string input)
        {
            bool isMoveValid = false;

            if (input == Message.EXIT)
            {
                this.StopGame();
                return;
            }

            if (input == Message.RESTART)
            {
                this.RestartGame();
                return;
            }

            if (input == Message.TOP)
            {
                TopScore.PrintTopScores();
                return;
            }

            Position currentPosition = field.GetPosition(input);

            if (currentPosition == null)
            {
                isMoveValid = false;
                return;
            }

            // Atempts to move a number in the direction that has empty cell
            Movement.TryMovingInDirection(ref moveCount, ref isMoveValid, currentPosition, MoveDirection.Up, this.field);
            Movement.TryMovingInDirection(ref moveCount, ref isMoveValid, currentPosition, MoveDirection.Down, this.field);
            Movement.TryMovingInDirection(ref moveCount, ref isMoveValid, currentPosition, MoveDirection.Left, this.field);
            Movement.TryMovingInDirection(ref moveCount, ref isMoveValid, currentPosition, MoveDirection.Right, this.field);

            if (!isMoveValid)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(Message.INVALID_MOVE);
                Console.ResetColor();
            }
        }