我正在制作一个游戏,并希望以不同的分数显示文本。但是目前计时器仅在第一个 if (因此如果分数等于 100)时才起作用(仅显示文本),我需要一些帮助,因为它也需要与 200、300、400、... -1000 一起使用。
这是代码:
void startTimer()
{
if (score == 100)
{
timerWIN.Start();
}
else if (score == 200)
{
timerWIN.Start();
}
else if (score == 300)
{
timerWIN.Start();
}
else if (score == 400)
{
timerWIN.Start();
}
else if (score == 500)
{
timerWIN.Start();
}
else if (score == 600)
{
timerWIN.Start();
}
else if (score == 700)
{
timerWIN.Start();
}
else if (score == 900)
{
timerWIN.Start();
}
else if (score == 1000)
{
timer1000.Start();
}
}
private void timerWIN_Tick_1(object sender, EventArgs e)
{
if (timerTick == 1)
{
lblWin1.Visible = true;
lblWin2.Visible = true;
}
else if (timerTick == 15)
{
lblWin1.Visible = false;
lblWin2.Visible = false;
timerWIN.Stop();
}
timerTick++;
}
private void timer1000_Tick(object sender, EventArgs e)
{
if (timerTick == 1)
{
lblWin1.Text = "500 points!";
lblWin2.Text = "You're doing great.";
lblWin1.Visible = true;
lblWin2.Visible = true;
}
else if (timerTick == 15)
{
lblWin1.Visible = false;
lblWin2.Visible = false;
lblWin1.Text = "Yeah that's it.";
lblWin2.Text = "Keep feeding me baby.";
timer1000.Stop();
}
timerTick++;
}
根据要求,这是我给出分数的方式:(每次碰撞,我都会得到分数)
private void timer1_Tick(object sender, EventArgs e)
{
snakeScoreLabel.Text = Convert.ToString(score);
if (down) { snake.moveDown(); }
if (up) {snake.moveUp(); }
if (right) {snake.moveRight(); }
if (left) {snake.moveLeft(); }
for (int i = 0; i < snake.SnakeRec.Length; i++)
{
if (snake.SnakeRec[i].IntersectsWith(food.foodRec))
{
score += points;
snake.growSnake();
food.foodLocation(randFood);
startTimer();
}
}
collission();
this.Invalidate();
}