Ejemplo n.º 1
0
 // 3개이상일때 키 두개 같이 입력되면 죽음 키 중복입력 막아야함
 // 해결했지만 게임 재미가 없어져서 취소
 public frmNormal()
 {
     InitializeComponent();
     snake                = new Snake();
     food                 = new Food(rand);
     sFood                = new SpecialFood();
     gameLoop.Interval    = 75;
     gameLoop.Tick       += Update;
     musicSeeker.Interval = 1000;
     musicSeeker.Tick    += CntTime;
     player.URL           = "snake.mp3";
     player.controls.stop();
     player1.URL = "Eat.mp3";
     player1.controls.stop();
     keyOn = 0;
 }
Ejemplo n.º 2
0
 private void Restart()
 {
     //MessageBox.Show("점수: " + score + " " + stage + "단계\n분발하세요");
     gameLoop.Stop();
     musicSeeker.Stop();
     graphics.Clear(SystemColors.Control);
     snake             = new Snake();
     food              = new Food(rand);
     sFood             = new SpecialFood();
     gameLoop.Interval = 75;
     direction         = 0;
     score             = 1;
     stage             = 1;
     player.controls.stop();
     lblMenu.Visible = true;
 }
Ejemplo n.º 3
0
 private void Restart()
 {
     lbScore.Text = "점수: " + score + "\n단계: " + stage + "\n분발하세요~";
     gameLoop.Stop();
     musicSeeker.Stop();
     graphics.Clear(SystemColors.Control);
     snake             = new Snake();
     food              = new Food(rand);
     sFood             = new SpecialFood();
     gameLoop.Interval = 75;
     timeCnt           = 0;
     direction         = 0;
     score             = 1;
     stage             = 1;
     player.controls.stop();
     player1.controls.stop();
     orPanel.Visible   = true;
     backBtn.Enabled   = true;
     replayBtn.Enabled = true;
     stopBtn.Enabled   = true;
 }
Ejemplo n.º 4
0
        //main segment when game is running
        public void Update(GameTime gameTime)
        {
            this.gameTime = gameTime;
            // Add time elapsed since last frame to counter
            timeCount += gameTime.ElapsedGameTime.Milliseconds;

            // Update input controller
            snake.InputController.Update();
            if (hasSnake2)
            {
                snake2.InputController.Update();
            }

            //add specialFood
            if (foodCount > SEPCIAL_FOOD_INTERVAR)
            {
                do
                {
                    specialFood = new SpecialFood();
                } while (snake.Collision(food.Position.X, food.Position.Y, snake.Head));
                foodCount=foodCount - SEPCIAL_FOOD_INTERVAR;
            }
            //reset the game
            if (InputController.IsReset)
            {
                snake.InputController.Clear();
                Initialize();
                if (hasSnake2)
                {
                    snake2.InputController.Clear();
                    snake2 = null;
                    hasSnake2 = false;
                    numberOfSnake = 0;
                }
            }

            //add second snake when press insert key
            if (InputController.IsInsertPressed && numberOfSnake == 0)
            {
                numberOfSnake++;
                snake2 = new Snake(inputControllerP2, Resources.player2);
                hasSnake2 = true;
            }

            //increse speed
            if (InputController.IsIncrease)
            {
                INTERVAL+=100;
            }

            // Check if time passed is greater than the interval
            if (timeCount > INTERVAL)
            {
                //check collision of snake
                    if (hasSnake2)
                {
                    updateSnake(snake, snake2);
                }
                else
                {
                    if (!snake.BodyCollision())
                    { // Update snake
                        snake.Update(gameTime);
                    }
                }

                if (hasSnake2)
                {
                    updateSnake(snake2, snake);
                }

                // Check collision snake food
                foodCollision(snake);
                SpecialfoodCollision(snake);
                if (hasSnake2)
                {
                    foodCollision(snake2);
                    SpecialfoodCollision(snake2);
                }

                // Clear input controller
                snake.InputController.Clear();
                if (hasSnake2)
                {
                    snake2.InputController.Clear();
                }

                // Clear counter
                timeCount = 0;
            }
        }
Ejemplo n.º 5
0
 //snake eat specialFood
 public void SpecialfoodCollision(Snake snake)
 {
     if (specialFood!=null&&snake.Collision(specialFood.Position.X, specialFood.Position.Y, snake.Head))
     {
         snake.BodyGrow();
         snake.BodyGrow();
         score += 2;
         specialFood = null;
     }
 }