/** *Class Player * *@author Martin Carlsson * *Internetprogrammering 1 - Course */ import java.awt.Color; import javax.swing.*; /** *Player is a subclass to class Thread that takes care of player positons and player status. * *@see java.lang.Thread */ public class Player implements Runnable{ private int frequency = 200; // loops every 200:e millisecond private int xPos; private int yPos; private int width = 4; private int height = 32; private int step; // how big steps the player should move with private int life = 10; private int points = 0; private boolean lost = false; private GameArea gA; private Color color = Color.magenta; private static int bonusLimit = 10; private boolean looping = false; /** *Constructs a Player object(instance)with references to class *GameArea and it's x-position. *@param gA referens till GameArea klassen *@param xPos sin x-position */ public Player(GameArea gA,int xPos) { this.xPos = xPos; yPos = gA.getYmax() / 2 - height / 2; step = gA.getYmax() / 25; } /** *A player change color on each run in the while-loop if the player score is higher than the bonus limit */ public void run() { boolean b = true; // while(looping) { if(points >= bonusLimit) { if(b) color = color.magenta; else color = color.red; } try { Thread.sleep(frequency); } catch(InterruptedException e) { } b = !b; } } // end run() /** *Looping or not *@param b true or false */ public void setLooping(boolean b) { looping = b; } /** *Returns bonus limit *@return the bonus limit integer */ public static int getBonusLimit() { return bonusLimit; } /** *Sets the bonus limit *@param i bonus limit */ public static void setBonusLimit(int i) { bonusLimit = i; } /** *Returns player color *@return player color */ public Color getColor() { return color; } /** *Sets player color *@param c player color */ public void setColor(Color c) { color = c; } /** *Returns a player's x-position *@return player x-position */ public int getXpos() { return xPos; } /** *Returns a player's y-position *@return players y-position */ public int getYpos() { return yPos; } /** *Returns a player's width *@return player width */ public int getWidth() { return width; } /** *Returns a player's height *@return player height */ public int getHeight() { return height; } /** *Returns player score *@return player score */ public int getPoints() { return points; } /** *Sets player score *@param points player score as an integer */ public void setPoints(int points) { this.points=points; } /** *Returns life status, life's left *@return number of life's left */ public int getLife() { return life; } /** *Sets number of lifes *@param life player's number of lifes */ public void setLife(int life) { this.life=life; } /** *Returns info on whether a player lost the game or not *@return spelarens status, förlorat eller ej, sant eller falskt */ public boolean getLostStatus() { return lost; } /** *Sets info on whether a player lost the game or not *@param status förlorat, sant eller falskt */ public void setLostStatus(boolean status) { lost=status; } /** *Sets a player's y-position(vertical position) *@param yPos player y-position */ public void setYpos(int yPos) { this.yPos=yPos; } /** *Sets a player's x-position(horizontal position) *@param xPos player x-position */ public void setXpos(int xPos) { this.xPos=xPos; } /** *Returns the lenght of a players step *@return player step length */ public int getStep() { return step; } /** *Sets the players "step length" *@param step player step length */ public void setStep(int step) { this.step=step; } } // End class Player