-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalloon.java
More file actions
174 lines (155 loc) · 5.52 KB
/
Balloon.java
File metadata and controls
174 lines (155 loc) · 5.52 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
import com.googlecode.lanterna.terminal.Terminal.SGR;
import com.googlecode.lanterna.TerminalFacade;
import com.googlecode.lanterna.input.Key;
import com.googlecode.lanterna.input.Key.Kind;
import com.googlecode.lanterna.terminal.Terminal;
import com.googlecode.lanterna.terminal.Terminal.Color;
import com.googlecode.lanterna.terminal.TerminalSize;
import com.googlecode.lanterna.LanternaException;
import com.googlecode.lanterna.input.CharacterPattern;
import com.googlecode.lanterna.input.InputDecoder;
import com.googlecode.lanterna.input.InputProvider;
import com.googlecode.lanterna.input.Key;
import com.googlecode.lanterna.input.KeyMappingProfile;
import com.googlecode.lanterna.screen.*;
public class Balloon{
private int lives, delay; //tnumber of lives the balloon has; the time between balloon movements
private boolean isAlive; //status of the balloon
private long sinceMoved; //time needed for the next balloon movement
private int xcor, ycor; //x and y coordinates
private int atTile; //the number of the road tile that the balloon is currently on
/**A Balloon constructor
*the default number of lives is 1
*/
public Balloon(){
lives = 1;
isAlive = true;
}
/**A second Balloon constructor
*@param int number of lives can be determined by the user
*the balloon is "placed" at the first road tile
*/
public Balloon(int numLives){
lives = numLives;
isAlive = true;
atTile = 0;
}
/**A third and most specific Balloon constructor
*@param int number of lives can be determined by the user
*@param int delay is the interval of time in seconds that must be passed before the balloon can move to the next road tile
*@param int xcor is its x-coordinate on the screen
*@param int ycor is its y-coordinate on the screen
*the balloon is "placed" at the first road tile
*/
public Balloon(int numLives, int delay, int xcor, int ycor){
lives = numLives;
isAlive = true;
this.delay = delay;
this.xcor = xcor;
this.ycor = ycor;
atTile = 0; //the balloon is "placed" at the first road tile
sinceMoved = 0; //this variable keeps the next time at which a balloon can move again
}
/**A method to get the number of lives a balloon has
*@return int lives
*/
public int getLives(){
return lives;
}
/**A method to get the delay of a balloon, in terms of movement across the road
*@return int delay
*/
public int getDelay(){
return delay;
}
/**A method to check if a balloon is alive
*@return boolean isAlive
*/
public boolean getIsAlive(){
return isAlive;
}
/**A method to get x-coordinate of balloon
*@return int xcor
*/
public int getX(){
return xcor;
}
/**A method to get y-coordinate of balloon
*@return int ycor
*/
public int getY(){
return ycor;
}
/**A method to get the road tile that the balloon is on
*the road tiles are numbered based on their order in the array list of road tiles
*@return int atTile
*/
public int getTile(){
return atTile;
}
/**A method to get the next time the game needs to reach before the balloon can move again
*@return long sinceMoved
*/
public long getSince(){
return sinceMoved;
}
/**A method to change the number of lives a balloon has
*@param int numLives
*/
public void setLives(int numLives){
lives = numLives;
}
/**A method to change the delay time of a balloon
*@param int num
*/
public void setDelay(int num){
delay = num;
}
/**A method to make a balloon 'dead' by changing the isAlive boolean to false
*/
public void makeDead(){
isAlive = false;
}
/**A method to set the road tile of a balloon
*@param int num (of the road tile's position in the list of road tiles)
*/
public void setTile(int num){
atTile = num;
}
/**A method to move the balloon in the terminal to the next road tile using the coordinates of that tile
*@param Tile t is the next road tile
*@param long timer is how long the game has been going on for
*/
public void move(Tile t, long timer){
sinceMoved = timer; //time is updated
xcor = t.getX();
ycor = t.getY();
atTile++;
sinceMoved += delay; //the delay is added to reflect the new time the game needs to reach before the balloon can move again
}
/**A method that draws the balloon onto the terminal
**this is only used when a terminal is used for displaying the game; if a screen is used, this method is not needed
*@param Terminal t
*/
public void draw(Terminal t){
t.moveCursor(xcor, ycor);
t.applyBackgroundColor(Terminal.Color.WHITE);
t.applyForegroundColor(Terminal.Color.RED);
t.putCharacter('Ǫ');
t.applyBackgroundColor(Terminal.Color.DEFAULT);
t.applyForegroundColor(Terminal.Color.DEFAULT);
}
/**A method that draws the balloon onto the screen
*@param Screen s
*the color of the balloon changes depending on the amount of lives it has
*/
public void draw(Screen s){
if (lives == 1) s.putString(xcor,ycor,"\u29ed",Terminal.Color.RED,Terminal.Color.WHITE);
if (lives == 2) s.putString(xcor,ycor,"\u29ed",Terminal.Color.YELLOW,Terminal.Color.WHITE);
if (lives == 3) s.putString(xcor,ycor,"\u29ed",Terminal.Color.GREEN,Terminal.Color.WHITE);
if (lives == 4) s.putString(xcor,ycor,"\u29ed",Terminal.Color.CYAN,Terminal.Color.WHITE);
if (lives == 5) s.putString(xcor,ycor,"\u29ed",Terminal.Color.BLUE,Terminal.Color.WHITE);
if (lives == 6) s.putString(xcor,ycor,"\u29ed",Terminal.Color.MAGENTA,Terminal.Color.WHITE);
if (lives == 7) s.putString(xcor,ycor,"\u29ed",Terminal.Color.BLACK,Terminal.Color.WHITE);
}
}