예제 #1
0
        public new DrawableShapeList GetRange(int index, int Count)
        {
            DrawableShapeList shapes = new DrawableShapeList();

            for (int i = 0; i < Count; i++)
            {
                shapes.Add(this[index + i]);
            }
            return(shapes);
        }
예제 #2
0
 private static void ShowInstructions()
 {
     MenuScreenShapes.Add(new Rect(0, 0, ScreenWidth, ScreenHeight, '?', ' ', 10));
     MenuScreenShapes.Add(new Text(10, 7, " _____          _                   _   _                 ", 11));
     MenuScreenShapes.Add(new Text(10, 8, "|_   _|        | |                 | | (_)                ", 11));
     MenuScreenShapes.Add(new Text(10, 9, "  | | _ __  ___| |_ _ __ _   _  ___| |_ _  ___  _ __  ___ ", 11));
     MenuScreenShapes.Add(new Text(10, 10, "  | || '_ \\/ __| __| '__| | | |/ __| __| |/ _ \\| '_ \\/ __|", 11));
     MenuScreenShapes.Add(new Text(10, 11, " _| || | | \\__ \\ |_| |  | |_| | (__| |_| | (_) | | | \\__ \\", 11));
     MenuScreenShapes.Add(new Text(10, 12, " \\___/_| |_|___/\\__|_|   \\__,_|\\___|\\__|_|\\___/|_| |_|___/", 11));
     MenuScreenShapes.Add(new Text(30, 15, "Use WASD keys to move", 11));
     MenuScreenShapes.Add(new Text(30, 16, "Press Esc to return to main menu", 11));
     MenuScreenShapes.Add(new Text(30, 17, "Press any key to continue...", 11));
     DrawScreen();
     Console.ReadKey(true);
     MenuScreenShapes.RemoveRange(0, 10);
 }
예제 #3
0
        private static void RunGame()
        {
            state          = GameState.GAME_RUNNING;
            OnScreenShapes = GameScreen;
            if (!mapInitialized)
            {
                InitGameScreen();
            }
            Snake snake = new Snake(25, 9, 4);

            GameScreen.Add(snake);
            Fruit fruit = new Fruit();

            GameScreen.Add(fruit);
            while (state != GameState.MAIN_MENU)
            {
                int        time   = -DateTime.Now.Millisecond;
                ConsoleKey?button = null;
                while (Console.KeyAvailable)
                {
                    button = Console.ReadKey(true).Key;
                }
                switch (button)
                {
                case ConsoleKey.W:
                case ConsoleKey.A:
                case ConsoleKey.S:
                case ConsoleKey.D:
                    snake.Move(button);
                    break;

                case ConsoleKey.Escape:
                    state = GameState.MAIN_MENU;
                    break;

                default:
                    snake.Move();
                    break;
                }
                if (fruit.OverlapsTile(snake.Body[0].x, snake.Body[0].y))
                {
                    snake.Expand();
                    fruit.FindEmptySpot();
                    if (snake.Body.Count > 15)
                    {
                        state = GameState.MAIN_MENU;
                        ShowGameWonScreen();
                    }
                }
                if (GameScreen.GetRange(2, GameScreen.Count - 2).
                    FindTopmostShapeForTile(snake.Body[0].x, snake.Body[0].y) != null ||
                    snake.OverlapsSelf())
                {
                    state = GameState.MAIN_MENU;
                    ShowGameLostScreen();
                }
                DrawScreen();
                time = +DateTime.Now.Millisecond;
                if (state != GameState.MAIN_MENU)
                {
                    System.Threading.Thread.Sleep(200);
                }
            }
            GameScreen.Remove(snake);
            GameScreen.Remove(fruit);
            OnScreenShapes = MenuScreenShapes;
        }