私は単純なヘビゲームを持っています。ヘビとランダムな食べ物が 1 つあります。でももう一品食べたいのですが、この料理は時間制限があります。例: ヘビが 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);
}