java.lang.Object Game
public class Game
This class represents the gorilla game. It keeps track of buildings, players and the banana. This class handles all the rules of the game.
Field Summary | |
---|---|
static int |
AIMING
Indicates that a gorilla is aiming. |
static int |
BANANA_SPLATTING
Indicates that a banana hit a gorilla or a building and the shock wave is now expanding. |
static int |
BANANA_THROWN
Indicates that a gorilla threw the banana and the banana has not hit a gorilla or a building yet. |
double |
GRAVITY
The gravity constant used in the calculations of a banana's movement. |
Constructor Summary | |
---|---|
Game(int numRounds,
int numOvertimeRounds,
java.lang.String[] playerNames,
int height,
int width,
double gravity)
Makes a new game with the characteristics specified by the parameter values. |
|
Game(int numRounds,
int numOvertimeRounds,
java.lang.String[] playerNames,
int height,
int width,
double gravity,
int ticksPerTurn)
2nd constructor - Makes a new game with the characteristics specified by the parameter values including ticks per turn. |
Method Summary | |
---|---|
static boolean |
circleIntersectsRectangle(double x,
double y,
double radius,
int left,
int bottom,
int width,
int height)
This method checks whether a circle and a rectangle intersect. |
Banana |
getBanana()
Returns a reference to the banana |
java.util.Iterator<Building> |
getBuildingIterator()
Returns an iterator that lets one go through the list of all buildings. |
Gorilla |
getCurrentGorilla()
Returns a reference to the gorilla whose turn it is. |
java.util.Iterator<Gorilla> |
getGorillaIterator()
Returns an iterator that lets one go through the list of all gorillas. |
int |
getHeight()
Returns the height of the game area |
int |
getNumGorillas()
Returns the number of gorillas playing the game, including those that were hit or are not participating in overtime. |
int |
getNumOvertimeRounds()
Returns how many rounds an overtime consists of. |
int |
getNumRounds()
Returns the number of rounds. |
int |
getOvertimeNumber()
Returns the number of overtimes. |
int |
getRound()
Returns the number of the current round. |
int |
getTicksLeftThisTurn()
Returns how many ticks the gorilla whose turn it is right now has left to aim before it loses its turn |
int |
getTicksPerTurn()
Returns how many ticks a gorilla can spend aiming before it loses its turn. |
int |
getTurn()
Returns whose turn it is. |
int |
getTurnState()
Returns which part of the current turn the game is in |
int |
getWidth()
Returns the width of the game area |
double |
getWindSpeed()
Returns the wind speed in the game area |
java.util.ArrayList<java.lang.Integer> |
getWinningGorillas()
Returns the numbers of gorillas that have the highest score. |
boolean |
isGameOver()
Returns whether the game is over |
boolean |
isItOvertime()
Returns whether it's overtime |
void |
splatMidAir()
If a banana is flying and its x coordinate and the x coordinate of the middle of the gorilla who tossed it differ by at least half the gorilla's width plus the banana's shock wave radius, the banana splats, stops moving, and its shock wave starts expanding. |
void |
startNewGame()
Starts a new game. |
void |
tick(double time)
You will need to modify this method for extra credit This method runs one tick of the game. |
void |
tossBanana(double angle,
double velocity)
Makes the gorilla whose turn it is toss a banana, but only if the game is in the aiming state. |
java.lang.String |
toString()
Returns information about the game as a string. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final double GRAVITY
public static final int AIMING
public static final int BANANA_THROWN
public static final int BANANA_SPLATTING
Constructor Detail |
---|
public Game(int numRounds, int numOvertimeRounds, java.lang.String[] playerNames, int height, int width, double gravity)
numRounds
- The number of rounds this game will run for.numOvertimeRounds
- The number of rounds each overtime will consist of.playerNames
- The names of the players. This array will have between
2 and 4 elements in it.height
- The height of the game areawidth
- The width of the game areagravity
- Gravitational constant for the purpose of computing
how the banana flies.public Game(int numRounds, int numOvertimeRounds, java.lang.String[] playerNames, int height, int width, double gravity, int ticksPerTurn)
numRounds
- The number of rounds this game will run for.numOvertimeRounds
- The number of rounds each overtime will consist of.playerNames
- The names of the players. This array will have between
2 and 4 elements in it.height
- The height of the game areawidth
- The width of the game areagravity
- Gravitational constant for the purpose of computing
how the banana flies.ticksPerTurn
- How many ticks a gorilla can spend aiming before
it loses its turn. A value of 0 means that there is no limit.Method Detail |
---|
public int getWidth()
public int getHeight()
public int getNumGorillas()
public int getRound()
public int getNumRounds()
public boolean isItOvertime()
public int getOvertimeNumber()
public int getNumOvertimeRounds()
public int getTurn()
public int getTurnState()
public boolean isGameOver()
public java.util.Iterator<Building> getBuildingIterator()
public java.util.Iterator<Gorilla> getGorillaIterator()
public Banana getBanana()
public Gorilla getCurrentGorilla()
public double getWindSpeed()
public java.util.ArrayList<java.lang.Integer> getWinningGorillas()
public void startNewGame()
public void tossBanana(double angle, double velocity)
angle
- The angle at which the gorilla should toss the banana. The
value is in radians and is between -Math.PI/2 and Math.PI/2velocity
- The velocity at which the gorilla should toss the banana.
The value is a non-negative floating point number.public void splatMidAir()
public void tick(double time)
time
- The tick lengthpublic java.lang.String toString()
toString
in class java.lang.Object
public int getTicksPerTurn()
public int getTicksLeftThisTurn()
public static boolean circleIntersectsRectangle(double x, double y, double radius, int left, int bottom, int width, int height)
x
- The x coordinate of the center of the circle.y
- The y coordinate of the center of the circle.radius
- The radius of the circle.left
- The x coordinate of the bottom left corner of the rectanglebottom
- The y coordinate of the bottom left corner of the rectanglewidth
- The height of the rectangleheight
- The width of the rectangle