示例#1
0
        /// <summary>
        /// ทำให้เกมมีการทำงานซ้ำ สั่งให้งูเคลื่อนที่ข้างหน้าไปเรื่อย แสดงอาหารให้งูเข้าไปจับกินได้
        /// </summary>
        public static void Loop()
        {
            while (true) {
                Thread.Sleep(1); //sleep for 1 second

                if (Console.KeyAvailable) {
                    keyboardInput = Console.ReadKey(true).Key; // get key input
                    snake.LastKeyBoardInput = keyboardInput;
                }
                snake.Forward();

                if (snake.IsCollide()) {
                    Console.SetCursorPosition(grassField.Left,
                        grassField.Bottom + 2);
                    Console.WriteLine("Game Over");
                    return;
                }

                if (snake.IsEatFood()) {
                    food = new Food(grassField);
                    snake.Food = food;
                    food.Render();

                    snake.Lengthen();
                }
                snake.Render();
            }
        }
示例#2
0
        /// <summary>
        /// จุดเริ่มต้นของ Game
        /// </summary>
        public static void Main()
        {
            Console.CursorVisible = false;
            grassField = new GrassField();
            snake = new Snake(grassField);
            food = new Food(grassField);
            snake.Food = food;
            scoreBoard = new ScoreBoard(grassField);

            grassField.Render();
            snake.Render();
            food.Render();
            scoreBoard.Render();

            Loop();
        }
示例#3
0
        private Player NewPlayer(ref Player NewPlayer)
        {
            NewPlayer = new Player(SnakeHeadTexture, SnakeBodyTexture, 5);
            NewPlayer.AddEdges(leftWall.BBox, topWall.BBox, rightWall.BBox2, bottomWall.BBox2);

            Food = new Food(FoodTexture);
            return NewPlayer;
        }
示例#4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            CheckRestart();
            if (PlayerOne.CheckSnakeFoodCollision(Food.BBFood))
                Food = new Food(FoodTexture);
            PlayerOne.Update(gameTime);
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
示例#5
0
 //called when the program first starts. OKA a constructor.
 public MainFrm()
 {
     InitializeComponent();
     food = new Food(randFood);
     // assigned the new instance of the class food to a new data type of Food
 }
示例#6
0
 /// <summary>
 /// Inicjalizacja i rysowanie jedzenia na planszy w trybie Multiplayer
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="typeOfFood"></param>
 void InitFoodInMulti(int x, int y, int typeOfFood)
 {
     food = new Food(x, y);
     food.RedrawFoodForMulti(typeOfFood);
     BoardCanvas.Children.Insert(0, food.Ellipse);
 }
示例#7
0
 /// <summary>
 /// Inicjalizacja i przerysowywanie jedzenia na planszy
 /// </summary>
 void InitFood()
 {
     food = new Food(rd.Next(0, 49) * 10, rd.Next(0, 49) * 10);
     food.RedrawFood();
     BoardCanvas.Children.Insert(0, food.Ellipse);
 }