public Missle CreateMissle(Size size, int speed, int playerNo) { Missle missle = new Missle(size, speed, playerNo); missle.SetLocation(x + this.size.Width / 2, y); return(missle); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { // move --> if (timer.Enabled && e.KeyCode == Keys.Right) { player.MoveRight(); } // move <-- if (timer.Enabled && e.KeyCode == Keys.Left) // && e.Modifiers == Keys.Control { player.MoveLeft(); } // shoot if (timer.Enabled && e.KeyCode == Keys.Space) { Missle missle = player.CreateMissle(missleSize, missleSpeed, 1); missle.InitializeSprite(); missle.SetSpriteLocation(); missles.Add(missle); Controls.Add(missle.Sprite); } // pause if (e.KeyCode == Keys.P) { timer.Enabled = !timer.Enabled; } // restart if (!timer.Enabled && e.KeyCode == Keys.Enter) { Controls.Clear(); asteroids.Clear(); missles.Clear(); player.Lives = numberOfLives; player.Reposition(this.Width, this.Height, 1); player.PositionSprite(); numberOfLivesLabel.Text = String.Format("Number of lives = {0}", player.Lives); scoreLabel.Text = String.Format("Score = {0:D2}", player.Score = 0); Controls.Add(numberOfLivesLabel); Controls.Add(scoreLabel); Controls.Add(player.Sprite); timer.Start(); } //exit if (timer.Enabled && e.KeyCode == Keys.Escape) { this.Close(); } if (!timer.Enabled && e.KeyCode == Keys.E) { Scoreboard scr = new Scoreboard(); scr.updateScoreboard(player); scr.updateFile(); ScoreBoardDisplay scrBoard = new ScoreBoardDisplay(scr); scrBoard.Show(); this.Close(); } }
// Controls private void Form1_KeyDown(object sender, KeyEventArgs e) { // move Player 1--> if (timer.Enabled && e.KeyCode == Keys.Right && Player1.Lives != 0) { Player1.MoveRight(); } // move Player 1<-- if (timer.Enabled && e.KeyCode == Keys.Left && Player1.Lives != 0) // && e.Modifiers == Keys.Control { Player1.MoveLeft(); } // shoot Player 1 if (timer.Enabled && e.KeyCode == Keys.Space && Player1.Lives != 0) { Missle missle = Player1.CreateMissle(missleSize, missleSpeed, 1); missle.InitializeSprite(); missle.SetSpriteLocation(); missles.Add(missle); Controls.Add(missle.Sprite); } // move Player 2--> if (timer.Enabled && e.KeyCode == Keys.D && Player2.Lives != 0) { Player2.MoveRight(); } // move Player 2<-- if (timer.Enabled && e.KeyCode == Keys.A && Player2.Lives != 0) // && e.Modifiers == Keys.Control { Player2.MoveLeft(); } // shoot Player 2 if (timer.Enabled && e.KeyCode == Keys.F && Player2.Lives != 0) { MissleVs2 missle2 = Player2.CreateMissle2(missleSize, missleSpeed); missles2.Add(missle2); Controls.Add(missle2.Sprite); } // pause if (e.KeyCode == Keys.P) { timer.Enabled = !timer.Enabled; } // exit if (e.KeyCode == Keys.Escape) { this.Close(); } // restart if (!timer.Enabled && e.KeyCode == Keys.Enter) { // clear everything on screen Controls.Clear(); //asteroids.Clear(); missles.Clear(); // retrieve new number of lives Player1.Lives = numberOfLives; Player2.Lives = numberOfLives; // reset Player position Player1.Reposition(this.Width, this.Height, 1); Player2.Reposition2(this.Width, this.Height, 2); // update number of lives display numberOfLivesLabel.Text = String.Format("Lives = {0}", Player1.Lives); numberOfLivesLabel1.Text = String.Format("Lives = {0}", Player2.Lives); // re-display Controls.Add(numberOfLivesLabel); // number of lives for Player 1 Controls.Add(numberOfLivesLabel1); // number of lives for Player 2 Controls.Add(Player1.Sprite); // Player 1 Controls.Add(Player2.Sprite); // Player 2 timer.Start(); // restart timer } }
// Controls private void Form1_KeyDown(object sender, KeyEventArgs e) { // move player 1--> if (timer.Enabled && e.KeyCode == Keys.Right && player1.Lives != 0) { player1.MoveRight(); } // move player 1<-- if (timer.Enabled && e.KeyCode == Keys.Left && player1.Lives != 0) // && e.Modifiers == Keys.Control { player1.MoveLeft(); } // shoot player 1 if (timer.Enabled && e.KeyCode == Keys.Space && player1.Lives != 0) { Missle missle = player1.CreateMissle(missleSize, missleSpeed, 1); missles.Add(missle); Controls.Add(missle.Sprite); } // move player 2--> if (timer.Enabled && e.KeyCode == Keys.D && player2.Lives != 0) { player2.MoveRight(); } // move player 2<-- if (timer.Enabled && e.KeyCode == Keys.A && player2.Lives != 0) // && e.Modifiers == Keys.Control { player2.MoveLeft(); } // shoot player 2 if (timer.Enabled && e.KeyCode == Keys.F && player2.Lives != 0) { Missle missle = player2.CreateMissle(missleSize, missleSpeed, 2); missles.Add(missle); Controls.Add(missle.Sprite); } // pause if (e.KeyCode == Keys.P) { timer.Enabled = !timer.Enabled; } // exit if (e.KeyCode == Keys.Escape) { this.Close(); } // restart if (!timer.Enabled && e.KeyCode == Keys.Enter) { // clear everything on screen Controls.Clear(); asteroids.Clear(); missles.Clear(); // retrieve new number of lives player1.Lives = numberOfLives; player2.Lives = numberOfLives; // reset player position player1.Reposition(this.Width, this.Height, 1); player2.Reposition(this.Width, this.Height, 2); // update number of lives display numberOfLivesLabel.Text = String.Format("Lives = {0}", player1.Lives); numberOfLivesLabel1.Text = String.Format("Lives = {0}", player2.Lives); // reset score scoreLabel.Text = String.Format("Score = {0:D2}", player1.Score = 0); scoreLabel1.Text = String.Format("Score = {0:D2}", player2.Score = 0); // re-display Controls.Add(numberOfLivesLabel); // number of lives for player 1 Controls.Add(numberOfLivesLabel1); // number of lives for player 2 Controls.Add(scoreLabel); // score label for player 1 Controls.Add(scoreLabel1); // score label for player 2 Controls.Add(player1.Sprite); // player 1 Controls.Add(player2.Sprite); // player 2 timer.Start(); // restart timer } }