コード例 #1
0
    static void Main()
    {
        Console.SetBufferSize(80, 35);
        Console.SetWindowSize(80, 35);
        Thread.Sleep(3000);
        string start = "Игра начнется через: ";

        Console.WriteLine(start);
        Thread.Sleep(1000);
        Console.Write("...3");
        Thread.Sleep(1000);
        Console.Write("...2");
        Thread.Sleep(1000);
        Console.Write("...1");
        Thread.Sleep(1000);
        Console.Clear();
        Walls walls = new Walls(80, 35);

        walls.Draw();
        Barrier barrier = new Barrier(80, 35);

        barrier.Draw();
        Point p     = new Point(30, 20, '*');
        Snake snake = new Snake(p, 2, Direction.LEFT);

        snake.Draw();
        FoodCreator foodCreator = new FoodCreator(80, 35, '$');
        Point       food        = foodCreator.CreateFood();

        food.Draw();
        while (true)
        {
            if (walls.IsHit(snake) || barrier.IsHit(snake))
            {
                Console.Clear();
                Console.WriteLine("Игра окончена.\n\nНажмите Enter, чтобы выйти...");
                Console.ReadLine();
                break;
            }
            if (snake.Eat(food))
            {
                snake.Draw();
                food = foodCreator.CreateFood();
                food.Draw();
            }
            else
            {
                snake.Move();
            }
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                snake.HandleKey(key.Key);
            }
            Thread.Sleep(100);
        }
    }
コード例 #2
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Blue);

            walls.Draw(GameRef.spriteBatch, wallColour);
            controlManager.Draw(GameRef.spriteBatch);
            paddleManager.Draw(GameRef.spriteBatch);
            mainBall.Draw(GameRef.spriteBatch);
            brickManager.Draw(GameRef.spriteBatch);

            base.Draw(gameTime);
        }
コード例 #3
0
ファイル: Task6.cs プロジェクト: markyha2012/Snake
        public override void Start()
        {
            Console.CursorVisible = false;
            walls = new Walls(width, height);
            walls.Draw();

            snake = new Snake(new Point(5, 5), 4, Direction.RIGHT);
            snake.Draw();

            var food = GenerateFood();

            food.Draw();

            score = -1;
            UpdateScore();

            var lastUpdate = DateTime.Now;

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey(true);
                    if (keyInfo.Key == ConsoleKey.Escape)
                    {
                        break;
                    }
                    snake.HandleKey(keyInfo.Key);
                }
                if ((DateTime.Now - lastUpdate).TotalMilliseconds > dt)
                {
                    lastUpdate = DateTime.Now;
                    if (snake.IsEatFoot(food))
                    {
                        UpdateScore();
                        food = GenerateFood();
                        food.Draw();
                    }
                    else if (snake.IsEatSelf() || snake.IsEatWall(walls))
                    {
                        break;
                    }
                    else
                    {
                        snake.Move();
                    }
                }
            }
            GameOver();
            Console.CursorVisible = true;
            Console.ReadKey();
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: K9455/Demo05
        public MainPage()
        {
            this.InitializeComponent();

            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();

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

            snake.Draw();

            Food  food  = new Food(80, 25, '$');
            Point ruoka = food.CreateFood();

            ruoka.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(ruoka))
                {
                    food = ruoka.Createruoka();
                    ruoka.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);

            Walls walls = new Walls(120, 30);

            walls.Draw();

            // Отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(120, 30, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            GameOver();
            Console.ReadLine();
        }
コード例 #6
0
        /// <summary>
        /// The main login of the game
        /// </summary>
        public static void Play()
        {
            try
            {
                ConsoleWriter.ConfigureConsole();
            }
            catch
            {
                throw new Exception("Unable to configure the console window with the given parameters");
            }


            InputHandler inputHandler = new InputHandler();

            Snake snake = Snake.Instance;

            snake.Draw();

            Walls walls = Walls.Instance;

            walls.Draw();

            Point food = FoodCreator.CreateFood();

            food.Draw();

            int score = 0;

            ConsoleWriter.WriteScore(score);

            // While the player hadnt lost the game
            while (true)
            {
                if (snake.IsHitTail() || walls.IsHit(snake.Head))
                {
                    break;
                }

                if (snake.IsHitFood(food))
                {
                    food = FoodCreator.CreateFood();
                    food.Draw();

                    score += 10;
                    ConsoleWriter.WriteScore(score);
                }

                else
                {
                    try
                    {
                        snake.Move();
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new IndexOutOfRangeException("Tried to reach illegal coordinates");
                    }
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    inputHandler.KeyPressed(Console.ReadKey().Key);
                }
            }

            ConsoleWriter.WriteGameOver();
        }