도움이 필요하십니까? 그래서 저는 비주얼 스튜디오 2017을 사용하여 대학 친구와 게임을하고 있었는데 프로그램에 이상한 것이 있습니다. 수명이 0 일 때 메시지 상자가 나타나 게임을 다시 시도할지 여부를 결정하지만 게임을 시도 할 때 적어도 20 - 30 초 후에 메시지 상자가 표시되도록 설정했습니다 "timergame.enable = false;"를 추가하더라도 게임을하고 타이머를 사용하는 것은 계속 진행됩니다. 어디에 문제가있는 것 같습니까?메시지 상자 및 시각적 스튜디오의 타이머
private void timerGame_Tick(object sender, EventArgs e)
{
for (int i = 0; i < listOfSardine.Count; i++)
{
listOfSardine[i].Top += (int)listOfSardine[i].Tag;
if (listOfSardine[i].Bounds.IntersectsWith(pictureBoxGrass.Bounds))
{
userLives--;
labelLives.Text = "Lives: " + userLives;
listOfSardine[i].Dispose();
listOfSardine.RemoveAt(i);
if (userLives == 0)
{
highScore = userScore;
timerBonusSpeed.Enabled = false;
timerGame.Enabled = false;
timerHealth.Enabled = false;
timerMatatabi.Enabled = false;
timerSardine.Enabled = false;
DialogResult dialogResultLose = MessageBox.Show
("Sorry.... you have lost, continue?", "Continue??", MessageBoxButtons.YesNo);
if (dialogResultLose == DialogResult.Yes)
{
for (int j = 0; j < listOfHealth.Count; j++)
{
listOfHealth[j].Dispose();
}
listOfHealth.Clear();
for (int q = 0; q < listOfSardine.Count; q++)
{
listOfSardine[q].Dispose();
}
listOfSardine.Clear();
for (int k = 0; k < listOfMatatabi.Count; k++)
{
listOfMatatabi[k].Dispose();
}
listOfMatatabi.Clear();
userLives = USER_LIVES;
userScore = USER_SCORE;
timerBonusSpeed.Enabled = true;
timerGame.Enabled = true;
timerHealth.Enabled = true;
timerMatatabi.Enabled = true;
timerSardine.Enabled = true;
}
else
{
this.Visible = false;
FormMainMenu formMainMenu = new FormMainMenu();
formMainMenu.Owner = this;
formMainMenu.ShowDialog();
}
}
}
else if (listOfSardine[i].Bounds.IntersectsWith(pictureBoxMainCharacter.Bounds))
{
listOfSardine[i].Dispose();
listOfSardine.RemoveAt(i);
userScore += 1;
labelScore.Text = "Score: " + userScore;
if (userScore % 100 == 0)
{
listOfSardine[i].Top += (int)listOfSardine[i].Tag * 4;
}
if(userScore == 1000)
{
timerBonusSpeed.Enabled = false;
timerGame.Enabled = false;
timerHealth.Enabled = false;
timerMatatabi.Enabled = false;
timerSardine.Enabled = false;
highScore = userScore;
}
}
else
{
listOfSardine[i].Refresh();
}
}
for (int i = 0; i < listOfHealth.Count; i++)
{
listOfHealth[i].Top += (int)listOfHealth[i].Tag;
if (listOfHealth[i].Bounds.IntersectsWith(pictureBoxGrass.Bounds))
{
listOfHealth[i].Dispose();
listOfHealth.RemoveAt(i);
}
else if (listOfHealth[i].Bounds.IntersectsWith(pictureBoxMainCharacter.Bounds))
{
listOfHealth[i].Dispose();
listOfHealth.RemoveAt(i);
userLives++;
labelLives.Text = "Lives: " + userLives;
}
else
{
listOfHealth[i].Refresh();
}
이미 행한하지만 여전히 같은 – MVS235
나는 확실하지 않다. 그러나 귀하의 코드에 따라, 당신은 인생 (생명 카운트)을 먼저 확인하고 있습니다. 그리고 0을 얻은 후에 return 키워드를 사용하지 않았습니다.이 이유 때문에 나머지 코드가 실행되고 수명이 늘어나고 타이머가 계속됩니다. 삶의 끝에서 formMainMenu.ShowDialog();) 다음에 return 키워드를 사용하여 코드의 나머지 부분을 실행하지 못하게하거나 끝에 수명 수를 확인하십시오. – Subrata