Beispiel #1
0
        public void game_draw()
        {
            Console.Clear();
            Console.Title = "Snake";
            Console.SetWindowSize(101, 26);
            HorizontalLine upline    = new HorizontalLine(0, 100, 0, '+');
            HorizontalLine downline  = new HorizontalLine(0, 100, 25, '+');
            VerticalLine   leftline  = new VerticalLine(1, 25, 0, '+');
            VerticalLine   rightline = new VerticalLine(1, 25, 100, '+');

            upline.Draw();
            downline.Draw();
            leftline.Draw();
            rightline.Draw();
            Parameters settings = new Parameters();
            //Sounds sound = new Sounds(settings.GetResourceFolder());
            //sound.Play("stardust.mp3");

            Point p     = new Point(4, 5, '*', ConsoleColor.Cyan);
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();
            FoodCreator foodCreator = new FoodCreator(101, 26, '¤', ConsoleColor.Green);
            Point       food        = foodCreator.CreateFood();

            food.Draw();
            Score score = new Score(0, 1);//score =0, level=1

            score.speed = 400;
            score.ScoreWrite();
            while (true)
            {
                if (snake.Eat(food))
                {
                    score.ScoreUp();
                    score.ScoreWrite();
                    food = foodCreator.CreateFood();
                    food.Draw();
                    //sound.Stop("stardust.mp3");
                    if (score.ScoreUp())
                    {
                        score.speed -= 10;
                    }
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(score.speed);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    snake.HandleKey(key.Key);
                }
            }
        }
Beispiel #2
0
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List <Figure>();

            // Отрисовка рамочки
            HorizontalLine upLine    = new HorizontalLine(0, mapWidth - 2, 0, '+');
            HorizontalLine downLine  = new HorizontalLine(0, mapWidth - 2, mapHeight - 1, '+');
            VerticalLine   leftLine  = new VerticalLine(0, mapHeight - 1, 0, '+');
            VerticalLine   rightLine = new VerticalLine(0, mapHeight - 1, mapWidth - 2, '+');

            wallList.Add(upLine);
            wallList.Add(downLine);
            wallList.Add(leftLine);
            wallList.Add(rightLine);
        }