Esempio n. 1
0
        private void UpdateScreen(object sender, EventArgs e)
        {
            foodremaining_lbl.Text = Game.FoodRemaining.ToString();

            if (Settings.LoseLife == true)
            {
                Life_lbl.Text        = Game.Life.ToString();
                gameOver_lbl.Visible = true;

                Lose_life();
                Pause();

                if (Inputs.KeyPressed(Keys.Enter))
                {
                    Settings.LoseLife    = false;
                    gameOver_lbl.Visible = false;
                }
                else
                {
                    return;
                }
            }
            else
            if (Settings.LevelUp == true)
            {
                if (Inputs.KeyPressed(Keys.Enter))
                {
                    Settings.LevelUp     = false;
                    Level_lbl_pb.Visible = false;
                }
                else
                {
                    return;
                }
            }
            else
            if (Settings.Win == true)
            {
                //f2.ShowDialog();
                gameOver_lbl.Visible = true;
                if (Settings.GameOver == false)
                {
                    if (MenuForm.RelaxMode == false)
                    {
                        gameOver_lbl.Text = "Felicitari!Ai terminat jocul\nSPACE pentru Meniu\nENTER ca sa joci din nou";
                    }
                    else
                    {
                        gameOver_lbl.Text = "Ai pierdut!\nScorul tau final:" + Settings.Score + "\nSPACE pentru Meniu\nENTER ca sa joci din nou";
                    }
                }
                else
                {
                    string gameOver = "Ai pierdut!\nScorul tau final :" + Settings.Score + "\nENTER ca sa incerci din nou!\nSPACE pentru meniu";
                    gameOver_lbl.Text = gameOver;
                    //Settings.GameOver = false;
                }

                if (Inputs.KeyPressed(Keys.Enter))
                {
                    StartGame();
                    Game.Level.Wall.Clear();
                }
                if (Inputs.KeyPressed(Keys.Space))
                {
                    Menu f2 = new Menu();
                    Settings.Win = false;
                    gameTimer.Stop();
                    this.Hide();
                    f2.ShowDialog();    // = true;
                    this.Close();
                    return;
                    //this.Hide();
                    //MenuForm.Show();
                    //this.Close();
                }
                return;
            }
            else
            if (Settings.GameOver == true)
            {
                if (Inputs.KeyPressed(Keys.Enter))
                {
                    StartGame();
                    Game.Level.Wall.Clear();
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (Inputs.KeyPressed(Keys.P) && Pause_lbl.Visible == true)
                {
                    Settings.direction = Settings.LastDirection;
                    Pause_lbl.Visible  = false;
                }
                else
                if (Inputs.KeyPressed(Keys.P))
                {
                    Pause();
                    return;
                }
                //if (Pause_lbl.Visible == true) return;
                if (Inputs.KeyPressed(Keys.Right) && Settings.direction != Direction.Left)
                {
                    Game.Snakehead = (Bitmap)Bitmap.FromFile("snakeheadright.png");
                    //Game.Snaketail = (Bitmap)Bitmap.FromFile("snaketailright.png");
                    //switch (Settings.LastDirection)
                    //{
                    //    case Direction.Up:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate90FlipX);
                    //        break;
                    //    case Direction.Down:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate90FlipY);
                    //        break;
                    //    case Direction.None:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate180FlipX);
                    //        break;
                    //}
                    //Game.Snakehead = Game.head;
                    Settings.direction     = Direction.Right;
                    Settings.LastDirection = Settings.direction;
                    Pause_lbl.Visible      = false;
                }
                else if (Inputs.KeyPressed(Keys.Left) && Settings.direction != Direction.Right)
                {
                    Game.Snakehead = (Bitmap)Bitmap.FromFile("snakeheadleft.png");
                    // Game.Snaketail = (Bitmap)Bitmap.FromFile("snaketailleft.png");
                    //switch (Settings.LastDirection)
                    //{
                    //    case Direction.Up:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate90FlipY);
                    //        break;
                    //    case Direction.Down:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate90FlipY);
                    //        break;
                    //    case Direction.None:
                    //        //Game.Snakehead.RotateFlip(RotateFlipType.Rotate180FlipX);
                    //        break;
                    //}
                    //Game.Snakehead = Game.head;

                    Settings.direction     = Direction.Left;
                    Settings.LastDirection = Settings.direction;
                    Pause_lbl.Visible      = false;
                }
                else if (Inputs.KeyPressed(Keys.Up) && Settings.direction != Direction.Down)
                {
                    Game.Snakehead = (Bitmap)Bitmap.FromFile("snakeheadup.png");
                    //Game.Snaketail = (Bitmap)Bitmap.FromFile("snaketailup.png");
                    //switch (Settings.LastDirection)
                    //{
                    //    case Direction.Left:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate90FlipY);
                    //        break;
                    //    case Direction.Right:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate90FlipX);
                    //        break;
                    //    case Direction.None:
                    //        Game.Snakehead.RotateFlip(RotateFlipType.Rotate90FlipX);
                    //        break;
                    //}

                    //Game.Snakehead = Game.head;
                    Settings.direction = Direction.Up;
                    Pause_lbl.Visible  = false;
                }
                else if (Inputs.KeyPressed(Keys.Down) && Settings.direction != Direction.Up)
                {
                    Game.Snakehead = (Bitmap)Bitmap.FromFile("snakeheaddown.png");
                    //Game.Snaketail = (Bitmap)Bitmap.FromFile("snaketaildown.png");
                    //Game.Snakehead = Game.head;
                    Settings.direction = Direction.Down;
                    Pause_lbl.Visible  = false;
                }

                MovePlayer();
            }

            pbCanvas.Invalidate();
        }