私はゲームを作っていて、さまざまなスコアでテキストを表示したいと考えています。しかし、現時点では、タイマーは最初の場合にのみ機能します (テキストのみが表示されます) (つまり、スコアが 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();
}