Ejemplo n.º 1
0
        private void Update(object sender, EventArgs e)
        {
            //Text = string.Format("{0}     Score: {1}     Level: {2}    Speed: {3} Snake: {4} food: {5}",playerName, playerScore, level, speed, snakeColor, foodColor);
            Text = string.Format("{0}     Score: {1}     Level: {2}  ", playerName, playerScore, level);
            snake.Move(direction);
            for (int i = 1; i < snake.Body.Length; i++)
            {
                if (snake.Body[0].IntersectsWith(snake.Body[i]))
                {
                    Restart();
                }
            }
            if (snake.Body[0].X < 0 || snake.Body[0].X > 575)
            {
                Restart();
            }
            if (snake.Body[0].Y < 0 || snake.Body[0].Y > 455)
            {
                Restart();
            }
            if (snake.Body[0].IntersectsWith(obstacle[0]) || snake.Body[0].IntersectsWith(obstacle2[0]))
            {
                Restart();
            }
            if (snake.Body[0].IntersectsWith(obstacle3[0]) || snake.Body[0].IntersectsWith(obstacle4[0]))
            {
                Restart();
            }
            if (snake.Body[0].IntersectsWith(obstacle5[0]) || snake.Body[0].IntersectsWith(obstacle6[0]))
            {
                Restart();
            }
            if (food.Piece.IntersectsWith(obstacle[0]) || food.Piece.IntersectsWith(obstacle2[0]))
            {
                food.Generate(rand);
            }
            if (food.Piece.IntersectsWith(obstacle3[0]) || food.Piece.IntersectsWith(obstacle4[0]))
            {
                food.Generate(rand);
            }
            if (food.Piece.IntersectsWith(obstacle5[0]) || food.Piece.IntersectsWith(obstacle6[0]))
            {
                food.Generate(rand);
            }
            if (snake.Body[0].IntersectsWith(food.Piece))
            {
                playerScore++;
                snake.Grow();
                food.Generate(rand);


                if (playerScore > 29)
                {
                    gameLoop.Stop();
                    graphics.Clear(SystemColors.Control);
                    Level1Form playGame = new Level1Form(playerName, playerScore, foodColor, snakeColor, speed, snake, food);
                    playGame.ShowDialog();
                }
            }
            //if (snakeColor == 1)
            //{
            //    snake.Draw(graphics.FillRectangles(Brushes.Red, snake.Body));
            //}

            this.Invalidate();
            //if (speed == 1)
            //{
            //    gameLoop.Interval += 10;
            //}
            //else if (speed == 2)
            //{
            //    gameLoop.Interval += 5;
            //}
            //else
            //{
            //    gameLoop.Interval += 0;
            //}
        }
Ejemplo n.º 2
0
        private void retryButton_MouseClick(object sender, MouseEventArgs e)
        {
            Level1Form playGame = new Level1Form(playerName, playerScore, speed, snake, food);

            playGame.ShowDialog();
        }
Ejemplo n.º 3
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            if (orangeSnakeRadio.Checked)
            {
                snakeColor = 3;
            }
            else if (blueSnakeRadio.Checked)
            {
                snakeColor = 2;
            }
            else
            {
                snakeColor = 1;
            }
            if (yellowFoodRadio.Checked)
            {
                foodColor = 3;
            }
            else if (indigoFoodRadio.Checked)
            {
                foodColor = 2;
            }
            else
            {
                foodColor = 1;
            }

            if (slowRadio.Checked)
            {
                speed = 1;
            }
            else if (fastRadio.Checked)
            {
                speed = 3;
            }
            else
            {
                speed = 2;
            }


            if (snakeColor == 3)
            {
                snake.Brush = Brushes.DarkOrange;
            }
            else if (snakeColor == 2)
            {
                snake.Brush = Brushes.Blue;
            }
            else
            {
                snake.Brush = Brushes.Green;
            }



            if (foodColor == 3)
            {
                food.Brush = Brushes.Yellow;
            }
            else if (foodColor == 2)
            {
                food.Brush = Brushes.Indigo;
            }
            else
            {
                food.Brush = Brushes.Red;
            }


            //if (speed == 1)
            //{
            //    gameLoop.Interval = 150;
            //}
            //else if (speed == 2)
            //{
            //    gameLoop.Interval = 100;
            //}
            //else
            //{
            //    gameLoop.Interval = 75;
            //}
            Level1Form playGame = new Level1Form(playerName, playerScore, foodColor, snakeColor, speed, snake, food);

            playGame.ShowDialog();
        }