public static void ChangeScreen(UserControl current, string next) { //f is set to the form that the current control is on Form f = current.FindForm(); f.Controls.Remove(current); UserControl ns = null; //switches screen switch (next) { case "MenuScreen": ns = new MenuScreen(); break; case "GameScreen": ns = new GameScreen(); break; case "HighScreen": ns = new HighScreen(); break; case "NameScreen": ns = new NameScreen(); break; } //centres on the screen ns.Location = new Point((f.Width - ns.Width) / 2, (f.Height - ns.Height) / 2); f.Controls.Add(ns); ns.Focus(); }
private void highButton_Click(object sender, EventArgs e) { // only load highscores if there aren't any in the list if (HighScreen.highscores == null) { HighScreen.loadHighscores(); } Form1.ChangeScreen(this, "HighScreen"); }
private void GameScreen_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { switch (e.KeyCode) { case Keys.A: case Keys.Left: ADown = true; break; case Keys.D: case Keys.Right: DDown = true; break; case Keys.W: case Keys.Up: WDown = true; break; case Keys.S: case Keys.Down: SDown = true; break; case Keys.C: // only load highscores if there aren't any in the list if (HighScreen.highscores == null) { HighScreen.loadHighscores(); } Form1.ChangeScreen(this, "NameScreen"); gameTimer.Enabled = false; break; default: break; } }
private void NameScreen_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { switch (e.KeyCode) { case Keys.W: if (index == 0) { if (FDOrder < 25) { FDOrder++; firstLabel.Text = letters[FDOrder]; } } else if (index == 1) { if (SDOrder < 25) { SDOrder++; secondLabel.Text = letters[SDOrder]; } } else if (index == 2) { if (TDOrder < 25) { TDOrder++; thirdLabel.Text = letters[TDOrder]; } } break; case Keys.S: if (index == 0) { if (FDOrder > 0) { FDOrder--; firstLabel.Text = letters[FDOrder]; } } else if (index == 1) { if (SDOrder > 0) { SDOrder--; secondLabel.Text = letters[SDOrder]; } } else if (index == 2) { if (TDOrder > 0) { TDOrder--; thirdLabel.Text = letters[TDOrder]; } } break; case Keys.A: if (index == 0) { index = 3; } else { index--; } break; case Keys.D: if (index == 3) { index = 0; } else { index++; } break; case Keys.Enter: if (index == 3) { FD = letters[FDOrder]; SD = letters[SDOrder]; TD = letters[TDOrder]; // save initial string initial = FD + SD + TD; // create high score object and add it to the list Highscore hs = new Highscore(initial, GameScreen.score); HighScreen.highscores.Add(hs); // save the highscores that are in the list HighScreen.saveHighscores(); // only load highscores if there aren't any in the list if (HighScreen.highscores == null) { HighScreen.loadHighscores(); } // change to the highscore screen Form1.ChangeScreen(this, "HighScreen"); Refresh(); } break; } }