Пример #1
0
        public void TryMoveLeft(Labyrinth labyrinth, ref bool gameInProgress, ref int row, ref int col)
        {
            if (labyrinth[row, col - 1] == '-')
            {
                labyrinth[row, col] = '-';
                Console.SetCursorPosition(2 * col, row + 3);
                Console.Write('-');
                col--;
                labyrinth[row, col] = '*';
                Console.SetCursorPosition(2 * (int)col, (int)row + 3);
                Console.Write('*');

                LabyrinthEngine.currentMoves++;
            }

            else
            {
                Console.WriteLine("Invalid move!");
            }

            if (col == 0)
            {
                LabyrinthEngine.GameEndedCongratAndReset(ref gameInProgress);
            }
        }
Пример #2
0
        public void TryMoveLeft(Labyrinth labyrinth, ref bool gameInProgress, ref int row, ref int col)
        {
            if (labyrinth[row, col - 1] == '-')
            {
                labyrinth[row, col] = '-';
                Console.SetCursorPosition(2 * col, row + 3);
                Console.Write('-');
                col--;
                labyrinth[row, col] = '*';
                Console.SetCursorPosition(2 * (int)col, (int)row + 3);
                Console.Write('*');

                LabyrinthEngine.currentMoves++;
            }

            else
            {
                Console.WriteLine("Invalid move!");
            }

            if (col == 0)
            {
                LabyrinthEngine.GameEndedCongratAndReset(ref gameInProgress);
            }
        }
Пример #3
0
        public static void PlayGame(Labyrinth labyrinth, int row, int col)
        {
            bool gameInProgress = true;

            currentMoves = 0;
            Console.WriteLine("\nEnter your move (Left Arrow = left, Right Arrow = right, Down Arrow = down, Up Arrow = up)");
            Console.SetCursorPosition(0, 15);

            LabyrinthNavigation navigation = new LabyrinthNavigation();

            while (gameInProgress)
            {
                ConsoleKeyInfo userChoice = Console.ReadKey(true);

                // Set currsor position outside of labyrinth and deletes previous turn message if any
                // I think this should be edited latter to not use magic numbers
                Console.SetCursorPosition(0, 15);
                ConsoleManipulation.ClearCurrentLine();

                switch (userChoice.Key)
                {
                case ConsoleKey.LeftArrow:
                    navigation.TryMoveLeft(labyrinth, ref gameInProgress, ref row, ref col);
                    break;

                case ConsoleKey.RightArrow:
                    navigation.TryMoveRight(labyrinth, ref gameInProgress, ref row, ref col);
                    break;

                case ConsoleKey.DownArrow:
                    navigation.TryMoveDown(labyrinth, ref gameInProgress, ref row, ref col);
                    break;

                case ConsoleKey.UpArrow:
                    navigation.TryMoveUp(labyrinth, ref gameInProgress, ref row, ref col);
                    break;

                case ConsoleKey.T:
                    PrintTopScores(scores);
                    break;

                case ConsoleKey.R:
                    gameInProgress = false;
                    break;

                case ConsoleKey.E:
                    Console.WriteLine("Good bye!");
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Invalid command!");
                    break;
                }
            }
        }
Пример #4
0
        public static void PlayGame(Labyrinth labyrinth, int row, int col)
        {
            bool gameInProgress = true;
            currentMoves = 0;
            Console.WriteLine("\nEnter your move (Left Arrow = left, Right Arrow = right, Down Arrow = down, Up Arrow = up)");
            Console.SetCursorPosition(0, 15);

            LabyrinthNavigation navigation = new LabyrinthNavigation();

            while (gameInProgress)
            {
                ConsoleKeyInfo userChoice = Console.ReadKey(true);

                // Set currsor position outside of labyrinth and deletes previous turn message if any
                // I think this should be edited latter to not use magic numbers
                Console.SetCursorPosition(0, 15);
                ConsoleManipulation.ClearCurrentLine();

                switch (userChoice.Key)
                {
                    case ConsoleKey.LeftArrow:
                        navigation.TryMoveLeft(labyrinth, ref gameInProgress, ref row, ref col);
                        break;

                    case ConsoleKey.RightArrow:
                        navigation.TryMoveRight(labyrinth, ref gameInProgress, ref row, ref col);
                        break;

                    case ConsoleKey.DownArrow:
                        navigation.TryMoveDown(labyrinth, ref gameInProgress, ref row, ref col);
                        break;

                    case ConsoleKey.UpArrow:
                        navigation.TryMoveUp(labyrinth, ref gameInProgress, ref row, ref col);
                        break;

                    case ConsoleKey.T:
                        PrintTopScores(scores);
                        break;

                    case ConsoleKey.R:
                        gameInProgress = false;
                        break;

                    case ConsoleKey.E:
                        Console.WriteLine("Good bye!");
                        Environment.Exit(0);
                        break;

                    default:
                        Console.WriteLine("Invalid command!");
                        break;
                }
            }
        }
Пример #5
0
        protected static void DisplayLabyrinth(Labyrinth labyrinth)
        {
            for (int row = 0; row < labyrinth.LengthX; row++)
            {
                StringBuilder rowBuilder = new StringBuilder(2 * (int)labyrinth.LengthY);
                for (int column = 0; column < labyrinth.LengthY; column++)
                {
                    rowBuilder.Append(labyrinth[row, column]);
                    rowBuilder.Append(" ");
                }

                Console.WriteLine(rowBuilder.ToString());
            }
            Console.WriteLine();
        }
Пример #6
0
        protected static void DisplayLabyrinth(Labyrinth labyrinth)
        {
            for (int row = 0; row < labyrinth.LengthX; row++)
            {
                StringBuilder rowBuilder = new StringBuilder(2 * (int)labyrinth.LengthY);
                for (int column = 0; column < labyrinth.LengthY; column++)
                {
                    rowBuilder.Append(labyrinth[row,column]);
                    rowBuilder.Append(" ");
                }

                Console.WriteLine(rowBuilder.ToString());
            }
            Console.WriteLine();
        }
Пример #7
0
        public void TryMoveDown(Labyrinth labyrinth, ref bool gameInProgress, ref int row, ref int col)
        {
            if (labyrinth[row + 1, col] == '-')
            {
                labyrinth[row, col] = '-';
                Console.SetCursorPosition(2 * col, row + 3);
                Console.Write('-');
                row++;
                labyrinth[row, col] = '*';
                Console.SetCursorPosition(2 * col, row + 3);
                Console.Write('*');

                LabyrinthEngine.currentMoves++;
            }
            else
            {
                Console.WriteLine("Invalid move!");
            }

            if (row == LabyrinthRowLength - 1)
            {
                LabyrinthEngine.GameEndedCongratAndReset(ref gameInProgress);
            }
        }
Пример #8
0
        public void TryMoveDown(Labyrinth labyrinth, ref bool gameInProgress, ref int row, ref int col)
        {
            if (labyrinth[row + 1, col] == '-')
            {
                labyrinth[row, col] = '-';
                Console.SetCursorPosition(2 * col, row + 3);
                Console.Write('-');
                row++;
                labyrinth[row, col] = '*';
                Console.SetCursorPosition(2 * col, row + 3);
                Console.Write('*');

                LabyrinthEngine.currentMoves++;
            }
            else
            {
                Console.WriteLine("Invalid move!");
            }

            if (row == LabyrinthRowLength - 1)
            {
                LabyrinthEngine.GameEndedCongratAndReset(ref gameInProgress);
            }
        }
Пример #9
0
 public void TryMoveLeft(Labyrinth labyrinth, ref bool gameInProgress, ref int row, ref int col)
 {
     throw new NotImplementedException();
 }
Пример #10
0
 public void TryMoveLeft(Labyrinth labyrinth, ref bool gameInProgress, ref int row, ref int col)
 {
     throw new NotImplementedException();
 }