Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new Instance of the Game calss(the Game window).
        /// </summary>
        public Game()
        {
            InitializeComponent();
            FormBorderStyle  = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            mushrooms        = new List <Bite>();

            interval       = 200;
            timer.Interval = interval;
            this.BackColor = Color.Beige;
            ImageLoad();
            Tiles = new PictureBox[tileRows, tileCols];
            InitializeField();
            henry = new Snake(new int[] { tileRows / 2, (tileCols / 2) + 1 }, new int[] { tileRows / 2,
                                                                                          (tileCols / 2) }, new int[] { tileRows / 2, (tileCols / 2) - 1 });

            this.snakeBite = NewBite();

            currentGame      = new GameObject(0, DateTime.Now, 4, 0);
            lbGameState.Text = "A játék indításához momj meg egy billentyűt.";
            ticked           = true;
            lastPointsEarned = 0;
            pointsMultiplier = 1;


            DrawBite(snakeBite);

            InitializeSnake();

            this.Show();
            this.KeyDown += GameStart;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Makes the necessary steps when the snake eats, makes the snake grow, calculates points, and places a
        /// new Bite on the field. (And mushrooms if necessary)
        /// </summary>
        private void CollisionBite()
        {
            if (henry.SnakeHead.X == snakeBite.X && henry.SnakeHead.Y == snakeBite.Y)
            {
                int bitepoints = 10 * pointsMultiplier;

                lastPointsEarned    = bitepoints;
                currentGame.Points += lastPointsEarned;
                henry.Growing       = true;


                this.snakeBite = NewBite();
                DrawBite(snakeBite);

                if (currentGame.Difficulty == 4)
                {
                    int mushroompoints = -10;
                    int mc             = mushrooms.Count;
                    for (int i = 0; i < 5; i++)
                    {
                        int[] xy = BiteCoordinates();
                        mushrooms.Add(new Bite(xy[0], xy[1], mushroomImage, mushroompoints, BiteTypes.Mushroom));
                        DrawBite(mushrooms[mc + i]);
                    }
                    if (henry.Snakelength % 6 == 0)
                    {
                        pointsMultiplier++;
                    }
                }

                SetDifficulty();
            }
        }
Ejemplo n.º 3
0
 private void DrawBite(Bite m)
 {
     Tiles[m.X, m.Y].Image = m.Img;
 }