-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPusheen.java
219 lines (195 loc) · 6.13 KB
/
Pusheen.java
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* Pusheen.java
* Pusheen class creates an object that keeps track of the points collected,
* the donut streak, if the user is home, if the game is over, and where the
* user is in the Paode linked list.
*
* Written by: Brenda Ji
* CS 230 Final Project: Pusheen Donut Dash
* Partners: Jamie Yip and Jesslyn Tannady
* Last Modified: December 16, 2015
* Purpose: Create an "avatar" for the user to play the game as Pusheen
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Pusheen{
// Instance Variables
private Paode user;
private int donutPoints;
private boolean isHome;
private DonutStreak donuts;
private boolean gameOver;
/* Constructor: Create a Pusheen object that can move over the paodes in the
* maze.
*
* Creates a Pusheen at the given Paode, initializes DonutStreak, DonutPoints,
* and isHome
*
* @param p the Paode where Pusheen begins
*/
public Pusheen(){
user = null;
donuts = new DonutStreak();
donutPoints = 0;
}
/**
* move()
* Moves Pusheen to the given Paode while checking the given Paode's status
* (whether it contains a monster, donut, home, or nothing)
*
* @param p A Paode
* @return int Returns actual color of the donut
*/
public boolean move(Paode p){
boolean moved = false;
if (p != null){ // makes sure that the given paode is real first
if (p.getHome()){ // check if home
isHome = true;
gameOver = true;
System.out.println("HOME");
System.out.println("Pusheen says Pusheen is home: " + isHome);
}
if (p.getMonster()){ // check if the Paode contains a monster
donuts.scared();
System.out.println("MONSTER!");
}
if (p.getDonut() != null){ // check if Paode contains a donut
// First add the donut to DonutStreak...
donutPoints += p.getDonut().getVALUE();
donuts.eatAndPoop(p.getDonut());
System.out.println("DONUT");
// Then check if the donut that has been added has created a streak
if (donuts.checkStreak()){
donutPoints += 8;
System.out.println("DONUT STREAK!");
}
}
user = p; // update Pusheen's placement in the maze
moved = true; // Since Pusheen was able to move, set boolean to true
System.out.println("Pusheen was able to move.");
}
return moved;
}
// ******************************* GETTERS ******************************* //
/**
* getPaode()
* Gets the current Paode of Pusheen's position
*
* @param None
* @return Paode The current Paode where the user is
*/
public Paode getPaode(){
return user;
}
/**
* getIsHome()
* Returns whether or not Pusheen is home
*
* @param None
* @return boolean Returns if Pusheen is home
*/
public boolean getIsHome(){
return isHome;
}
/**
* getDonuts()
* Returns the donut queue (Pusheen's stomach)
*
* @param None
* @return DonutStreak The donuts in Pusheen's stomach currently
*/
public DonutStreak getDonuts(){
return donuts;
}
/**
* getPoints()
* Returns the number of points the user has collected
*
* @param None
* @return int The number of points Pusheen has
*/
public int getPoints(){
return donutPoints;
}
public boolean getGameOver(){
return gameOver;
}
// ******************************* SETTERS ******************************* //
/**
* setPaode()
* Sets Pusheen to the Paode given --> mostly used when we begin the game and
* set Pusheen's starting position to the first Paode in the maze
*
* @param Paode The Paode that we want Pusheen to go to
* @return Nothing
*/
public void setPaode(Paode p){
user = p;
}
/**
* setGameOver()
* Sets the gameOver accordingly --> mostly used by the CountdownPanel to tell
* Pusheen that the game is over/time is up
*
* @param g The boolean that needs to be set to
* @return Nothing
*/
public void setGameOver(boolean g){
gameOver = g;
}
/**
* toString()
* Gets the current Paode of Pusheen's position
*
* @param None
* @return String Representation of Pusheen's donut status, Paode location,
* and whether or not she has made it home yet.
*/
public String toString(){
String s = "";
// s += "Poade: " + user;
s += "Donut Points: " + donutPoints;
s += "\nIs Pusheen home? " + isHome;
return s;
}
public static void main(String[] args){
Paode start = new Paode("0101000");
Paode d1 = new Paode("0107100");
Paode d2 = new Paode("0111100");
Paode d3 = new Paode("0209100");
Paode d3B = new Paode("0210000"); // Bottom
Paode d3L = new Paode("0109000"); // Left
Paode d3R = new Paode("0309000"); // Right
Paode home = new Paode("1313001");
Paode monster = new Paode("0506010");
d3.setTop(null);
d3.setBottom(d3B);
d3.setLeft(d3L);
d3.setRight(d3R);
Pusheen user = new Pusheen();
user.setPaode(start);
System.out.println(user);
System.out.println("\nEating Donuts");
user.move(d1);
user.move(d2);
user.move(d3);
System.out.println(user);
System.out.println("\n. . . Moving . . .");
System.out.println("User's CURRENT POSITION at Paode d3: \n" + user.getPaode());
System.out.println("Top of this Paode is null, so Pusheen does not move. \n"
+ "Assuming that UP arrow has been pressed...");
user.move(user.getPaode().getTop());
System.out.println("User's POSITION after trying to go to a null spot: \n" + user.getPaode());
System.out.println("\nBottom of d3 is another Paode.");
System.out.println("User's CURRENT POSITION: " + user.getPaode());
user.move(user.getPaode().getBottom());
System.out.println("Assuming user has pressed down arrow, user's NEW "
+ "POSITION: \n" + user.getPaode());
System.out.println("\nMONSTER!");
user.move(monster);
System.out.println(user);
System.out.println("\nHOME! :)");
user.move(home);
System.out.println(user);
}
}