This repository was archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInvadersModelDraw.html
More file actions
69 lines (58 loc) · 4.23 KB
/
InvadersModelDraw.html
File metadata and controls
69 lines (58 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html>
<title>League Invaders - Object Manager</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://league-central.github.io/curriculum/style/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<script src="https://league-central.github.io/curriculum/script/headerAndFooter.js"></script>
<body>
<div id ="wrap">
<div id ="main">
<div id = "moduleIndex">
<h1>Model Management</h1>
<br>
<p class="normal">
Since the game characters share common properties, we can manage them via a single Object Manager. They will all have to be drawn, updated, and removed when they are no longer active.</p>
<h2>ObjectManager</h2>
<p class="normal">
1. Create a new class called ObjectManager and add a rocket member variable<br> <font color="red"> BUT DO NOT INITIALIZE IT</font></p>
<br>
<p class="normal">
2. Make a constructor for this class that takes a Rocketship parameter and use it to initialize the member variable created above.</p>
<br>
<p class="normal">
3. Add another member variable <code>projectiles</code> that will hold an ArrayList of Projectile objects. Initialize this variable to an empty ArrayList. Add a void method <code>addProjectile()</code> with a parameter that is a <code>Projectile</code>object. This method needs to add the projectile to the ArrayList.<br>
<br>
<p class="normal">
4. Add another member variable <code>aliens</code> that will hold an ArrayList of Alien objects. Initialize this variable to an empty ArrayList. Add a member variable <code>random</code> and initialize it to a new Random object. Also create an <code>addAlien()</code> method that contains the code below.</p>
<pre> new Alien(random.nextInt(LeagueInvaders.WIDTH),0,50,50);</pre>
<br>
<p class="normal">
5. Create a method called <code>update()</code> that iterates through all the aliens and calls the update method on each alien. After updating, test the alien's x and y values. If they are outside the game window (use LeagueInvaders.HEIGHT), set the alien's isActive variable to false. Note: Iteration will require the use of a for loop of some kind! Next do the same thing for all the projectiles.</p>
<br>
<p class="normal">
6. Create a method called <code>draw()</code> that has a Graphics parameter. Add code to call the rocket's draw method (pass it the graphics object). Then iterate through all the aliens and call the draw method on each. Now do the same thing for all the projectiles.</p>
<br>
<p class="normal">
7. Create a method called <code>purgeObjects()</code>. This method needs to iterate through all the aliens and projectiles and remove any that are marked as not active. Remember: You cannot use a for each loop when you are removing items from an ArrayList.</p>
<h2>GamePanel</h2>
<p class="normal">
8. Inside the <code>GamePanel</code> class, create and initialize a member varable for an <code>ObjectManager</code> object. Use the panel's rocketship as the parameter for the ObjectManager constructor.</p>
<br>
<p class="normal">
9. In the <code>updateGameState</code> method, add a call to the objectManager's update method.</p>
<br>
<p class="normal">
10. In the <code>drawGameState</code> method, delete the call to the rocket's draw method and replace it with a call to the objectManager's draw method.</p>
<br>
<img src="images/InvadersBlueSquare.png" style="width: 150px; height=241px; margin: 0px 20px" align="left"> <h3><u>TESTING</u></h3>
<p class="normal">
11. Run the program. You should see no change from the previous test. That is, you should still see a blue rocket when in the GAME state, and your background color should still change when you press the Enter key.
</p>
<br>
</div></div></div>
<div id="footer">
<script>addFooter();</script>
</div>
</body></html>