我有简单的蛇游戏。有蛇和一种随机食物。但我想要另一种食物,但这种食物会受到时间限制。例如:当蛇达到20点时,它会产生奖励限时食物。该食物将显示 5 秒钟(例如)。我该怎么做?
public partial class Form1 : Form
{
Random randFood = new Random();
private had _model;
Graphics paper;
had snakes = new had();
kocky food;
bool left = false;
bool right = false;
bool up = false;
bool down = false;
int score = 0;
kocky1 food1;
public Form1()
{
InitializeComponent();
food = new kocky(randFood);
food1 = new kocky1(randFood); //time limited food//
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
paper = e.Graphics;
food.drawFood(paper);
food1.drawFood(paper);
snakes.drawSnake(paper);
}
//---------------------------program----------------------------------------------------//
private void timer1_Tick(object sender, EventArgs e)
{
snakeScoreLabel.Text = Convert.ToString(score);
if (down) { snakes.moveDown(); }
if (up) { snakes.moveUp(); }
if (right) { snakes.moveRight(); }
if (left) { snakes.moveLeft(); }
this.Invalidate();
collision();
for (int i = 0; i < snakes.SnakeRec.Length; i++)
{
if (snakes.SnakeRec[i].IntersectsWith(food.foodRec))
{
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "C:\\Users\\Boris\\Desktop\\C# had\\SNOTPLOP.wav";
wplayer.controls.play();
timer1.Enabled = true;
score += 1;
ProgressBar1.Increment(1);
snakes.growSnake();
food.foodlocation(randFood);
food1.foodlocation(randFood);
}
if (snakes.SnakeRec[i].IntersectsWith(food1.foodRec)) //time limited food//
{
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "C:\\Users\\Boris\\Desktop\\C# had\\SNOTPLOP.wav";
wplayer.controls.play();
timer1.Enabled = true;
score += 1;
ProgressBar1.Increment(1);
snakes.growSnake();
food.foodlocation(randFood);
food1.foodlocation(randFood);
}