Пример #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);
            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(food.Piece))
            {
                playerScore++;
                snake.Grow();
                food.Generate(rand);


                if (playerScore > 9 && playerScore < 20)
                {
                    Level2Form playGame = new Level2Form(playerName, playerScore, foodColor, snakeColor, speed, ScoreList, snake, food);
                    playGame.ShowDialog();
                }
            }


            this.Invalidate();
            //if (snakeColor == 1)
            //{
            //    snake.Draw(graphics.FillRectangles(Brushes.Red, snake.Body));
            //}
            //if (speed == 1)
            //{
            //    gameLoop.Interval += 10;
            //}
            //else if (speed == 2)
            //{
            //    gameLoop.Interval += 5;
            //}
            //else
            //{
            //    gameLoop.Interval += 0;
            //}
        }
Пример #2
0
        private void Update(object sender, EventArgs e)
        {
            //switch (snakeColor)
            //{
            //    case 1:
            //    {

            //        snake.Brush = Brushes.Orange;
            //    }
            //        break;
            //    case 2:
            //        {
            //            snake.Brush = Brushes.Blue;
            //        }
            //        break;
            //    case 3:
            //        {
            //            snake.Brush = Brushes.Green;
            //        }
            //        break;

            //}

            //if (foodColor == 1)
            //{
            //    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;
            }

            //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(food.Piece))
            {
                playerScore++;
                snake.Grow();
                food.Generate(rand);


                if (playerScore > 9 && playerScore < 20)
                {
                    gameLoop.Stop();
                    graphics.Clear(SystemColors.Control);
                    Level2Form playGame = new Level2Form(playerName, playerScore, foodColor, snakeColor, speed, ScoreList, snake, food);
                    playGame.ShowDialog();
                    this.Dispose();
                }
            }


            this.Invalidate();
        }