-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInvaderRow.cs
More file actions
179 lines (148 loc) · 3.57 KB
/
InvaderRow.cs
File metadata and controls
179 lines (148 loc) · 3.57 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Drawing;
namespace SpaceInvaders
{
/// <summary>
/// Summary description for InvaderRow.
/// </summary>
public class InvaderRow
{
public Invader[] Invaders = new Invader[11];
public Point LastPosition = new Point(0, 0);
public const int kBombIntervalSpacing = 50;
public InvaderRow(Bitmap image1, Bitmap image2, int rowNum)
{
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i] = new Invader(image1, image2);
Invaders[i].Position.X = i * Invaders[i].GetBounds().Width + 5;
Invaders[i].Position.Y = rowNum * Invaders[i].GetBounds().Height + 10;
Invaders[i].SetCounter(i * kBombIntervalSpacing);
}
LastPosition = Invaders[Invaders.Length - 1].Position;
}
public InvaderRow(string gif1, string gif2, int rowNum)
{
//
// TODO: Add constructor logic here
//
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i] = new Invader(gif1, gif2);
Invaders[i].Position.X = i * Invaders[i].GetBounds().Width + 5;
Invaders[i].Position.Y = rowNum * Invaders[i].GetBounds().Height + 10;
Invaders[i].SetCounter(i*kBombIntervalSpacing);
}
LastPosition = Invaders[Invaders.Length - 1].Position;
}
public void ResetBombCounters()
{
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i].ResetBombPosition();
Invaders[i].SetCounter(i*kBombIntervalSpacing);
}
}
public Invader this [int index] // indexer declaration
{
get
{
return Invaders[index];
}
}
public void Draw(Graphics g)
{
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i].Draw(g);
}
}
public int CollisionTest(Rectangle aRect)
{
for (int i = 0; i < Invaders.Length; i++)
{
if ((Invaders[i].GetBounds().IntersectsWith(aRect)) && (!Invaders[i].BeenHit))
return i;
}
return -1;
}
public bool DirectionRight
{
set
{
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i].DirectionRight = value;
}
}
}
public void Move()
{
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i].Move();
}
if (Invaders[0].DirectionRight)
LastPosition = Invaders[Invaders.Length - 1].Position;
else
LastPosition = Invaders[0].Position;
}
public void MoveInPlace()
{
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i].MoveInPlace();
}
}
public Invader GetFirstInvader()
{
int count = 0;
Invader TheInvader = Invaders[count];
while ((TheInvader.BeenHit == true) && (count < Invaders.Length-1))
{
count++;
TheInvader = Invaders[count];
}
return TheInvader;
}
public Invader GetLastInvader()
{
int count = Invaders.Length - 1;
Invader TheInvader = Invaders[count];
while ((TheInvader.BeenHit == true) && (count > 0))
{
count--;
TheInvader = Invaders[count];
}
return TheInvader;
}
public int NumberOfLiveInvaders()
{
int count = 0;
for (int i = 0; i < Invaders.Length; i++)
{
if (Invaders[i].Died == false)
count++;
}
return count;
}
public bool AlienHasLanded(int bottom)
{
for (int i = 0; i < Invaders.Length; i++)
{
if ( (Invaders[i].GetBounds().Bottom >= bottom) &&
(Invaders[i].BeenHit = false))
return true;
}
return false;
}
public void MoveDown()
{
for (int i = 0; i < Invaders.Length; i++)
{
Invaders[i].Position.Y += Invaders[i].GetBounds().Height/8;
Invaders[i].UpdateBounds();
}
}
}
}