예제 #1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            if (gamestate == Gamestate.Mainmenu)
            {
                spriteBatch.Begin();
                Mainmenu.Draw(spriteBatch);
                spriteBatch.End();
            }
            if (gamestate == Gamestate.Game)
            {
                spriteBatch.Begin();
                Snake.Draw(spriteBatch);
                Apple.Draw(spriteBatch);
                Upmenu.Draw(spriteBatch);
                spriteBatch.End();
            }

            if (gamestate == Gamestate.Rip)
            {
                spriteBatch.Begin();
                Ripmenu.Draw(spriteBatch);
                spriteBatch.End();
            }
            if (gamestate == Gamestate.Pausemenu)
            {
                spriteBatch.Begin();
                Pausemenu.Draw(spriteBatch);
                spriteBatch.End();
            }

            base.Draw(gameTime);
        }
예제 #2
0
 protected override void Update(GameTime gameTime)
 {
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || ((Keyboard.GetState().IsKeyDown(Keys.Escape)) && (gamestate == Gamestate.Mainmenu)))
     {
         Exit();
     }
     if ((gamestate == Gamestate.Mainmenu) && (Mouse.GetState().X > 877) && (Mouse.GetState().X < 1101) && (Mouse.GetState().Y > 425) && (Mouse.GetState().Y < 479) && (Mouse.GetState().LeftButton == ButtonState.Pressed))
     {
         Exit();
     }
     if ((Mouse.GetState().X > 877) && (Mouse.GetState().X < 1101) && (Mouse.GetState().Y > 250) && (Mouse.GetState().Y < 301) && (Mouse.GetState().LeftButton == ButtonState.Pressed))
     {
         gamestate = Gamestate.Game;
     }
     base.Update(gameTime);
     if (gamestate == Gamestate.Game)
     {
         Snake.Move(speed);
         Snake.Eat();
         Apple.Spawn();
         Snake.Loop();
         Snake.Rip();
         if (Upmenu.Paused())
         {
             gamestate = Gamestate.Pausemenu;
         }
         if ((Keyboard.GetState().IsKeyDown(Keys.Escape)) && (!Pausemenu.IsEscPressedGame))
         {
             gamestate = Gamestate.Pausemenu;
             Pausemenu.IsEscPressed = true;
         }
         if (Keyboard.GetState().IsKeyUp(Keys.Escape))
         {
             Pausemenu.IsEscPressedGame = false;
         }
     }
     if ((Snake.Rip()) && (gamestate == Gamestate.Game))
     {
         gamestate = Gamestate.Rip;
     }
     if (gamestate == Gamestate.Rip)
     {
         if (Ripmenu.Buttons() == "new")
         {
             Random random = new Random();
             gamestate = Gamestate.Game;
             Snake.turns.Clear();
             Snake.bodies.Clear();
             Head.X         = random.Next(300, 600);
             Head.Y         = random.Next(100, 620);
             Head.Direction = Direction.Right;
             Snake.Length   = 1;
             Snake.bodies.Add(new Body());
             Snake.bodies[0].X         = Head.X - 64;
             Snake.bodies[0].Y         = Head.Y;
             Snake.bodies[0].Direction = Head.Direction;
             Apple.IsEaten             = true;
             Snake.Add();
             Upmenu.Score = 0;
         }
         if (Ripmenu.Buttons() == "exit")
         {
             Exit();
         }
     }
     if (gamestate == Gamestate.Pausemenu)
     {
         if (Pausemenu.Buttons() == "continue")
         {
             gamestate = Gamestate.Game;
         }
         if (Pausemenu.Buttons() == "new")
         {
             Random random = new Random();
             gamestate = Gamestate.Game;
             Snake.turns.Clear();
             Snake.bodies.Clear();
             Head.X         = random.Next(300, 600);
             Head.Y         = random.Next(100, 620);
             Head.Direction = Direction.Right;
             Snake.Length   = 1;
             Snake.bodies.Add(new Body());
             Snake.bodies[0].X         = Head.X - 64;
             Snake.bodies[0].Y         = Head.Y;
             Snake.bodies[0].Direction = Head.Direction;
             Apple.IsEaten             = true;
             Snake.Add();
             Upmenu.Score = 0;
         }
         if (Pausemenu.Buttons() == "exit")
         {
             Exit();
         }
         if (Keyboard.GetState().IsKeyUp(Keys.Escape))
         {
             Pausemenu.IsEscPressed = false;
         }
     }
 }