예제 #1
0
        static void Main(string[] args)
        {
            Game game = new Game();
            var GameStatus = GameApp.Game.GameState.Ongoing;

            String[,] gameBoard = new String[4,4];
            game.InitializeBoard(gameBoard);
            Console.WriteLine("Welcome To the Game 2048");
            Console.WriteLine("Choose Moves: Right=a,Left=d,Up=w,Down=s, Q to quit");
            DisplayBoard(gameBoard);

            do
            {
                var inputKey = Console.ReadKey();
                Console.WriteLine("");
                if (inputKey.Key == System.ConsoleKey.W)
                {
                    gameBoard = game.MoveUp(gameBoard);
                    GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
                    if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
                    {
                        break;
                    }
                    gameBoard = game.GenerateNewSquareElement(gameBoard);
                    DisplayBoard(gameBoard);
                }
                else if (inputKey.Key == System.ConsoleKey.S)
                {
                    gameBoard = game.MoveDown(gameBoard);
                    GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
                    if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
                    {
                        break;
                    }
                    gameBoard = game.GenerateNewSquareElement(gameBoard);
                    DisplayBoard(gameBoard);
                }
                else if (inputKey.Key == System.ConsoleKey.A)
                {
                    gameBoard = game.MoveLeft(gameBoard);
                    GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
                    if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
                    {
                        break;
                    }
                    gameBoard = game.GenerateNewSquareElement(gameBoard);
                    DisplayBoard(gameBoard);
                }
                else if (inputKey.Key == System.ConsoleKey.D)
                {
                    gameBoard = game.MoveRight(gameBoard);
                    GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
                    if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
                    {
                        break;
                    }
                    gameBoard = game.GenerateNewSquareElement(gameBoard);
                    DisplayBoard(gameBoard);
                }
                else if (inputKey.Key == System.ConsoleKey.Q)
                {
                    break;
                }
                else
                {
                  Console.WriteLine("You entered an invalid key. Please Choose Moves: Right=a,Left=d,Up=w,Down=s or Q to quit");
                }
            } while (GameStatus.Equals(GameApp.Game.GameState.Ongoing));

            DisplayBoard(gameBoard);
            if (GameStatus.Equals(GameApp.Game.GameState.Lost))
                Console.WriteLine("Well that sucks you lost");
            else if(GameStatus.Equals(GameApp.Game.GameState.Win)){
                 Console.WriteLine("Saaweeeet you WON!!!!");
            }else{
                Console.WriteLine("You Gave up?");
            }

            do
            {
                var inputKey = Console.ReadKey();
                if(inputKey.Key == System.ConsoleKey.Q)
                {
                    break;
                }

            } while (true);
        }