private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Down) { Player2TimerDown.Start(); } else if (e.KeyCode == Keys.Up) { Player2TimerUp.Start(); } if (e.KeyCode == Keys.W) { Player1TimerUp.Start(); } else if (e.KeyCode == Keys.S) { Player1TimerDown.Start(); } if (e.KeyCode == Keys.Enter) { label1.Text = ""; BallTimer.Start(); } }
/* Nastan koj se povikuva pri klik na kopcheto New Game (Nova igra). * So ovoj nastan se kreira nov objekt od klasata Game so shto * se startuva novata igra. Dopolnitelno, se setira i tajmerot za soodvetnoto * nivo, preostanatie zhivoti na igrachoot... */ private void PbNewGame_Click(object sender, EventArgs e) { CurrentGame = new Game(this.Width, this.Height); Player.Instance.ResetScore(); lblScore.Text = Player.Instance.GetScore().ToString(); TimeRemainingLevel.Maximum = CurrentGame.Level.getTimeLimit(); TimeRemainingLevel.Value = CurrentGame.Level.getTimeLimit(); Player.Instance.LivesRemaining = 3; BallTimer.Enabled = true; BallTimer.Start(); if (this.Width >= 2000 && this.Width < 3000) { BallTimer.Interval = 20; } if (this.Width >= 3000) { BallTimer.Interval = 10; } ReadyTimer.Enabled = true; ReadyTimer.Start(); lblCoundown.Text = "READY!\n" + countdown.ToString(); lblCoundown.Visible = true; activated = true; lblLevelNumber.Text = "1"; Invalidate(true); }
/// <summary> /// Listens for keys pressed /// </summary> /// <param name="sender">key pressed object</param> /// <param name="e">Key event arguments</param> private void GameForm_KeyDown(object sender, KeyEventArgs e) { if (AnimationTimer.Enabled) { switch (e.KeyData) { case Keys.Left: { if (!KeyList.Contains(Keys.Left)) { KeyList.Add(Keys.Left); } break; } case Keys.Right: { if (!KeyList.Contains(Keys.Right)) { KeyList.Add(Keys.Right); } break; } case Keys.Up: { if (!KeyList.Contains(Keys.Up)) { KeyList.Add(Keys.Up); } break; } case Keys.Down: { if (!KeyList.Contains(Keys.Down)) { KeyList.Add(Keys.Down); } break; } } } if (e.KeyData == Keys.Space) { if (gameStart) { gameStart = false; } if (AnimationTimer.Enabled) { paused = true; AnimationTimer.Stop(); BallTimer.Stop(); Invalidate(); } else { paused = false; AnimationTimer.Start(); BallTimer.Start(); } } }