예제 #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 InitMainMenu()
 {
     Console.SetWindowSize(ScreenWidth + 1, ScreenHeight + 1);
     Console.SetBufferSize(ScreenWidth + 1, ScreenHeight + 1);
     MenuScreenShapes.Add(new Rect(0, 0, ScreenWidth, ScreenHeight, '#', ' ', 0));
     MenuScreenShapes.Add(new Text(30, 15, "Start Game", 1));
     MenuScreenShapes.Add(new Text(30, 16, "Instructions", 1));
     MenuScreenShapes.Add(new Text(30, 17, "Exit", 1));
     MenuScreenShapes.Add(cursor = new Point(28, 15, '>', 1));
     MenuScreenShapes.Add(new Text(25, 7, " _____             _        ", 1));
     MenuScreenShapes.Add(new Text(25, 8, "/  ___|           | |       ", 1));
     MenuScreenShapes.Add(new Text(25, 9, "\\ `--. _ __   __ _| | _____ ", 1));
     MenuScreenShapes.Add(new Text(25, 10, " `--. \\ '_ \\ / _` | |/ / _ \\", 1));
     MenuScreenShapes.Add(new Text(25, 11, "/\\__/ / | | | (_| |   <  __/", 1));
     MenuScreenShapes.Add(new Text(25, 12, "\\____/|_| |_|\\__,_|_|\\_\\___|", 1));
     OnScreenShapes = MenuScreenShapes;
 }
예제 #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;
        }