From c8c2148e69fd3c94fb2d1b71b39945e34d5e4801 Mon Sep 17 00:00:00 2001 From: Artem Jivotovski Date: Thu, 17 Nov 2016 15:26:20 -0800 Subject: [PATCH 1/3] Refactored Monster class hierarchy to treat Monsters as data instead of subclasses --- Score.txt | 2 +- .../cs56/projects/games/roguelike/Bat.java | 72 ----------------- .../projects/games/roguelike/GamePiece.java | 14 +--- .../cs56/projects/games/roguelike/Golem.java | 72 ----------------- .../projects/games/roguelike/LogicEngine.java | 28 +++---- .../projects/games/roguelike/Monster.java | 78 +++++++------------ .../cs56/projects/games/roguelike/Pirate.java | 68 ---------------- .../cs56/projects/games/roguelike/Snake.java | 68 ---------------- .../cs56/projects/games/roguelike/Troll.java | 68 ---------------- .../cs56/projects/games/roguelike/Zombie.java | 68 ---------------- 10 files changed, 42 insertions(+), 496 deletions(-) delete mode 100644 src/edu/ucsb/cs56/projects/games/roguelike/Bat.java delete mode 100644 src/edu/ucsb/cs56/projects/games/roguelike/Golem.java delete mode 100644 src/edu/ucsb/cs56/projects/games/roguelike/Pirate.java delete mode 100644 src/edu/ucsb/cs56/projects/games/roguelike/Snake.java delete mode 100644 src/edu/ucsb/cs56/projects/games/roguelike/Troll.java delete mode 100644 src/edu/ucsb/cs56/projects/games/roguelike/Zombie.java diff --git a/Score.txt b/Score.txt index 16a88e6..2401eea 100644 --- a/Score.txt +++ b/Score.txt @@ -2,4 +2,4 @@ 785 580 580 -315 +350 diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Bat.java b/src/edu/ucsb/cs56/projects/games/roguelike/Bat.java deleted file mode 100644 index 8319b38..0000000 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Bat.java +++ /dev/null @@ -1,72 +0,0 @@ -package edu.ucsb.cs56.projects.games.roguelike; - -import java.util.Random; - -/** - *@author Clayven Anderson - *@author Hans Marasigan & Richard Nguyen - *@author Rick Lee - *@version cs56 Winter 14 - */ - -/** - *This class represents a class of monster called a Bat which is a weak melee monster. Bat icon is B - */ - -public class Bat extends Monster{ - private char icon; - /** - *creates a Bat with 5 hitPoints and 1 attack with no random movement - *with icon B - */ - public Bat(){ - super(5,1,0,10); - this.setIcon('B'); - - } - /** - * creates a Bat with 5 HP and 1 attack with icon B - * @param typeOfMovement whether or not the bat will move randomly - */ - public Bat(int typeOfMovement){ - super(5,1,typeOfMovement,10); - this.setIcon('B'); - } - - /** - * creates a Bat with hit points, attack, and random movement with icon B - * @param hitPoints the Bat's hitPoints - * @param attack the Bat's attack - * @param typeOfMovement whether or not the Bat will move randomly or not - */ - public Bat(int hitPoints, int attack, int typeOfMovement){ - super(hitPoints,attack,typeOfMovement,10); - this.setIcon('B'); - } - /** - *creates a Bat to the parameters given to it, with icon B - * @param hp the Bat's hitPoints - * @param att the Bat's attack - * @param typeOfMove whether or not the Bat will move randomly or not - * @param points the amount of points the Bat is worth - */ - public Bat(int hp,int att,int typeOfMove, int points){ - super(hp,att,typeOfMove,points); - this.setIcon('B'); - } - - /** - *This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - - } -} diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/GamePiece.java b/src/edu/ucsb/cs56/projects/games/roguelike/GamePiece.java index f9adb04..457a968 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/GamePiece.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/GamePiece.java @@ -7,19 +7,7 @@ *@version cs56 s13 */ -public interface GamePiece { - - /** - *This is the getter to figure out what piece it is. - */ - public String getTypeOfPiece(); - - /** - *This is the setter for the TypeOfPiece it will be - *@param newTypeOfPiece is the type of piece that will be in the game - */ - public void setTypeOfPiece(String newTypeOfPiece); - +public interface GamePiece { /** *This is the getter to figure out what piece icon it is. diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Golem.java b/src/edu/ucsb/cs56/projects/games/roguelike/Golem.java deleted file mode 100644 index ee3ceaa..0000000 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Golem.java +++ /dev/null @@ -1,72 +0,0 @@ -package edu.ucsb.cs56.projects.games.roguelike; - -import java.util.Random; - -/** - *@author Clayven Anderson - *@author Hans Marasigan & Richard Nguyen - *@author Rick Lee - *@version cs56 Winter 14 - */ -/** - *This is a monster called a golem that is very healthy with a ton of attack. - Golems have icon G - */ - -public class Golem extends Monster{ - private char icon; - - /** - *creates a Golem with 25 hitPoints and 5 attack with no random movement - * - */ - public Golem(){ - super(25,5,0,30); - this.setIcon('G'); - } - /** - * creates a Golem with 25 HP and 5 attack - * @param typeOfMovement whether or not the Golem will move randomly - */ - public Golem(int typeOfMovement){ - super(25,5,typeOfMovement,30); - this.setIcon('G'); - } - - /** - * creates a Golem with hit points, attack, and random movement - * @param hitPoints the Golem's hitPoints - * @param attack the Golem's attack - * @param typeOfMovement whether or not the Golem will move randomly or not - */ - public Golem(int hitPoints, int attack, int typeOfMovement){ - super(hitPoints,attack,typeOfMovement,30); - this.setIcon('G'); - } - /** - *creates a Golem to the parameters given to it - * @param hp the Golem's hitPoints - * @param att the Golem's attack - * @param typeOfMove whether or not the Golem will move randomly or not - * @param points the amount of points the Golem is worth - */ - public Golem(int hp,int att,int typeOfMove, int points){ - super(hp,att,typeOfMove,points); - this.setIcon('G'); - - } - /** - *This is the getter to figure out what piece icon it is. Golem = G - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be. Golem = G - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - } - -} diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java b/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java index 9c0021b..0b4fb27 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java @@ -371,43 +371,43 @@ public void createMonster(){ if(floor[xPos][yPos]==null){ switch(n){ - case 0 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1); + case 0 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1, Monster.MONSTER); listOfMonsters[xPos][yPos] = (Monster) floor[xPos][yPos]; listOfMonsters[xPos][yPos].setLevelBonus(level); listOfMonsters[xPos][yPos].setMonsterPosition(xPos,yPos); break; - case 1 : floor[xPos][yPos] = new Troll(numGenerator.nextInt(2)+1); - listOfMonsters[xPos][yPos] = (Troll) floor[xPos][yPos]; + case 1 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1, Monster.TROLL); + listOfMonsters[xPos][yPos] = (Monster) floor[xPos][yPos]; listOfMonsters[xPos][yPos].setLevelBonus(level); listOfMonsters[xPos][yPos].setMonsterPosition(xPos,yPos); break; - case 2 : floor[xPos][yPos] = new Golem(numGenerator.nextInt(2)+1); - listOfMonsters[xPos][yPos] = (Golem) floor[xPos][yPos]; + case 2 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1, Monster.GOLEM); + listOfMonsters[xPos][yPos] = (Monster) floor[xPos][yPos]; listOfMonsters[xPos][yPos].setLevelBonus(level); listOfMonsters[xPos][yPos].setMonsterPosition(xPos,yPos); break; - case 3 : floor[xPos][yPos] = new Bat(numGenerator.nextInt(2)+1); - listOfMonsters[xPos][yPos] = (Bat) floor[xPos][yPos]; + case 3 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1, Monster.BAT); + listOfMonsters[xPos][yPos] = (Monster) floor[xPos][yPos]; listOfMonsters[xPos][yPos].setLevelBonus(level); listOfMonsters[xPos][yPos].setMonsterPosition(xPos,yPos); break; - case 4 : floor[xPos][yPos] = new Snake(numGenerator.nextInt(2)+1); - listOfMonsters[xPos][yPos] = (Snake) floor[xPos][yPos]; + case 4 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1, Monster.SNAKE); + listOfMonsters[xPos][yPos] = (Monster) floor[xPos][yPos]; listOfMonsters[xPos][yPos].setLevelBonus(level); listOfMonsters[xPos][yPos].setMonsterPosition(xPos,yPos); break; - case 5 : floor[xPos][yPos] = new Zombie(numGenerator.nextInt(2)+1); - listOfMonsters[xPos][yPos] = (Zombie) floor[xPos][yPos]; + case 5 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1, Monster.ZOMBIE); + listOfMonsters[xPos][yPos] = (Monster) floor[xPos][yPos]; listOfMonsters[xPos][yPos].setLevelBonus(level); listOfMonsters[xPos][yPos].setMonsterPosition(xPos,yPos); break; - case 6 : floor[xPos][yPos] = new Pirate(numGenerator.nextInt(2)+1); - listOfMonsters[xPos][yPos] = (Pirate) floor[xPos][yPos]; + case 6 : floor[xPos][yPos] = new Monster(numGenerator.nextInt(2)+1, Monster.PIRATE); + listOfMonsters[xPos][yPos] = (Monster) floor[xPos][yPos]; listOfMonsters[xPos][yPos].setLevelBonus(level); listOfMonsters[xPos][yPos].setMonsterPosition(xPos,yPos); break; - //Add new monsters here. Copy the case and change just the class names + //Add new monsters here. Copy the case and change the parameter passed in diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java b/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java index 2ae0a4b..c506520 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java @@ -15,58 +15,44 @@ public class Monster implements GamePiece{ private int typeOfMovement; private int[] position = new int[2]; private int pointValue=5; - private String typeOfPiece; private char icon; + + // Default attributes for monsters + public static final int[] BAT = {5,1,10,66}; + public static final int[] GOLEM = {25,5,30,71}; + public static final int[] MONSTER = {20,10,5,77}; + public static final int[] PIRATE = {15,4,20,80}; + public static final int[] SNAKE = {5,3,15,83}; + public static final int[] TROLL = {10,3,15,84}; + public static final int[] ZOMBIE = {15,2,15,90}; + /** * creates a monster with 20 hitPoints and 10 attack and no random movement * */ public Monster(){ - this.hitPoints=20; - this.attack=10; + this.setHitPoints(MONSTER[0]); + this.setAttack(MONSTER[1]); + this.setPointValue(MONSTER[2]); + char[] iconArray = Character.toChars(MONSTER[3]); + char iconChar = iconArray[0]; + this.setIcon(iconChar); this.typeOfMovement=0; - this.setTypeOfPiece("monster"); - this.setIcon('M'); - } - /** - * creates a player with 20 hitPoints and 10 attack - * @param typeOfMovement whether or not the monster will move randomly or not - */ - public Monster(int typeOfMovement){ - this.hitPoints = 20; - this.attack=10; - this.typeOfMovement=typeOfMovement; - this.setTypeOfPiece("monster"); - this.setIcon('M'); } /** * creates a player with 20 hitPoints and 10 attack - * @param hitPoints the monster's hitPoints - * @param attack the monster's attack * @param typeOfMovement whether or not the monster will move randomly or not */ - public Monster(int hitPoints, int attack, int typeOfMovement){ - this.hitPoints = hitPoints; - this.attack = attack; - this.typeOfMovement = typeOfMovement; - this.setTypeOfPiece("monster"); - this.setIcon('M'); + public Monster(int typeOfMovement, int[] typeOfMonster){ + this.setHitPoints(typeOfMonster[0]); + this.setAttack(typeOfMonster[1]); + this.setPointValue(typeOfMonster[2]); + char[] iconArray = Character.toChars(typeOfMonster[3]); + char iconChar = iconArray[0]; + this.setIcon(iconChar); + this.typeOfMovement=typeOfMovement; } - /** - *creates a monster with the makers preference of status - *@param hp hit points of the monster - *@param att the attack power of the monster - *@param typeOfMovement determines whether it is random or not - *@param points determines how many points it is. - */ - public Monster (int hp, int att, int typeOfMovement,int points){ - this.hitPoints = hp; - this.attack = att; - this.typeOfMovement = typeOfMovement; - this.pointValue=points; - this.setTypeOfPiece("monster"); - this.setIcon('M'); - } + /** * @return the monster's hitPoints * @@ -111,19 +97,7 @@ public void setPointValue(int pointValue){ this.pointValue=pointValue; } - /** - this gets the type of piece of the monster - */ - public String getTypeOfPiece(){ - return this.typeOfPiece; - } - /** - this sets the type of piece of the monster - */ - public void setTypeOfPiece(String newTypeOfPiece){ - this.typeOfPiece=newTypeOfPiece; - } - + /** *This is the getter to figure out what piece icon it is. */ diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Pirate.java b/src/edu/ucsb/cs56/projects/games/roguelike/Pirate.java deleted file mode 100644 index cdf6318..0000000 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Pirate.java +++ /dev/null @@ -1,68 +0,0 @@ -package edu.ucsb.cs56.projects.games.roguelike; - -import java.util.Random; - -/** - *@author Rick Lee - *@version cs56 Winter 14 - */ -/** - *This class represents a monster called a Pirate that is a medium health, medium damaged melee creature. Pirate have icon P - */ - -public class Pirate extends Monster{ - private char icon; - - /** - *creates a Pirate with 15 hitPoints and 4 attack with no random movement - *with icon P - */ - public Pirate(){ - super(15,4,0,20); - this.setIcon('P'); - } - /** - * creates a pirate with 15 HP and 4 attack with icon P - * @param typeOfMovement whether or not the monster will move randomly - */ - public Pirate(int typeOfMovement){ - super(15,4,typeOfMovement,20); - this.setIcon('P'); - } - - /** - * creates a pirate with hit points, attack, and random movement with icon P - * @param hitPoints the Pirate's hitPoints - * @param attack the Pirate's attack - * @param typeOfMovement whether or not the Pirate will move randomly or not - */ - public Pirate(int hitPoints, int attack, int typeOfMovement){ - super(hitPoints, attack, typeOfMovement,20); - this.setIcon('P'); - } - /** - *creates a Pirate to the parameters given to it - * @param hitPoints the Pirate's hitPoints - * @param att the Pirate's attack - * @param typeOfMove whether or not the Pirate will move randomly or not - * @param points the amount of points the Pirate is worth - */ - public Pirate(int hitPoints,int att,int typeOfMove, int points){ - super(hitPoints,att,typeOfMove,points); - this.setIcon('P'); - } - /** - *This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - - } -} diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Snake.java b/src/edu/ucsb/cs56/projects/games/roguelike/Snake.java deleted file mode 100644 index c3ef046..0000000 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Snake.java +++ /dev/null @@ -1,68 +0,0 @@ -package edu.ucsb.cs56.projects.games.roguelike; - -import java.util.Random; - -/** - *@author Rick Lee - *@version cs56 Winter 14 - */ -/** - *This class represents a monster called a snake that is low health, medium damaged melee creature. Snakes have icon S - */ - -public class Snake extends Monster{ - private char icon; - - /** - *creates a snake with 5 hitPoints and 3 attack with no random movement - *with icon S - */ - public Snake(){ - super(5,3,0,15); - this.setIcon('S'); - } - /** - * creates a snake with 5 HP and 3 attack with icon S - * @param typeOfMovement whether or not the monster will move randomly - */ - public Snake(int typeOfMovement){ - super(5,3,typeOfMovement,15); - this.setIcon('S'); - } - - /** - * creates a snake with hit points, attack, and random movement with icon S - * @param hitPoints the Snake's hitPoints - * @param attack the Snake's attack - * @param typeOfMovement whether or not the Snake will move randomly or not - */ - public Snake(int hitPoints, int attack, int typeOfMovement){ - super(hitPoints, attack, typeOfMovement,15); - this.setIcon('S'); - } - /** - *creates a Snake to the parameters given to it - * @param hitPoints the Snake's hitPoints - * @param att the Snake's attack - * @param typeOfMove whether or not the Snake will move randomly or not - * @param points the amount of points the Snake is worth - */ - public Snake(int hitPoints,int att,int typeOfMove, int points){ - super(hitPoints,att,typeOfMove,points); - this.setIcon('S'); - } - /** - *This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - - } -} diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Troll.java b/src/edu/ucsb/cs56/projects/games/roguelike/Troll.java deleted file mode 100644 index 34b4e20..0000000 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Troll.java +++ /dev/null @@ -1,68 +0,0 @@ -package edu.ucsb.cs56.projects.games.roguelike; - -import java.util.Random; - -/** - *@author Hans Marasigan & Richard Nguyen - *@version cs56 Spring 13 - */ -/** - *This class represents a monster called a troll that is a medium damaged melee creature. Trolls have icon T - */ - -public class Troll extends Monster{ - private char icon; - - /** - *creates a troll with 10 hitPoints and 3 attack with no random movement - *with icon T - */ - public Troll(){ - super(10,3,0,15); - this.setIcon('T'); - } - /** - * creates a troll with 10 HP and 3 attack with icon T - * @param typeOfMovement whether or not the monster will move randomly - */ - public Troll(int typeOfMovement){ - super(10,3,typeOfMovement,15); - this.setIcon('T'); - } - - /** - * creates a troll with hit points, attack, and random movement with icon T - * @param hitPoints the Troll's hitPoints - * @param attack the Trolls's attack - * @param typeOfMovement whether or not the Troll will move randomly or not - */ - public Troll(int hitPoints, int attack, int typeOfMovement){ - super(hitPoints, attack, typeOfMovement,15); - this.setIcon('T'); - } - /** - *creates a Troll to the parameters given to it - * @param hitPoints the Troll's hitPoints - * @param att the Troll's attack - * @param typeOfMove whether or not the Troll will move randomly or not - * @param points the amount of points the Troll is worth - */ - public Troll(int hitPoints,int att,int typeOfMove, int points){ - super(hitPoints,att,typeOfMove,points); - this.setIcon('T'); - } - /** - *This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - - } -} diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Zombie.java b/src/edu/ucsb/cs56/projects/games/roguelike/Zombie.java deleted file mode 100644 index b3debd5..0000000 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Zombie.java +++ /dev/null @@ -1,68 +0,0 @@ -package edu.ucsb.cs56.projects.games.roguelike; - -import java.util.Random; - -/** - *@author Rick Lee - *@version cs56 Winter 14 - */ -/** - *This class represents a monster called a zombie that is a medium health, low damaged melee creature. Zombie have icon Z - */ - -public class Zombie extends Monster{ - private char icon; - - /** - *creates a zombie with 15 hitPoints and 2 attack with no random movement - *with icon Z - */ - public Zombie(){ - super(15,2,0,15); - this.setIcon('Z'); - } - /** - * creates a Zombie with 15 HP and 2 attack with icon Z - * @param typeOfMovement whether or not the monster will move randomly - */ - public Zombie(int typeOfMovement){ - super(15,2,typeOfMovement,15); - this.setIcon('Z'); - } - - /** - * creates a zombie with hit points, attack, and random movement with icon Z - * @param hitPoints the Zombie's hitPoints - * @param attack the Zombie's attack - * @param typeOfMovement whether or not the Zombie will move randomly or not - */ - public Zombie(int hitPoints, int attack, int typeOfMovement){ - super(hitPoints, attack, typeOfMovement,15); - this.setIcon('Z'); - } - /** - *creates a Zombie to the parameters given to it - * @param hitPoints the Zombie's hitPoints - * @param att the Zombie's attack - * @param typeOfMove whether or not the Zombie will move randomly or not - * @param points the amount of points the Zombie is worth - */ - public Zombie(int hitPoints,int att,int typeOfMove, int points){ - super(hitPoints,att,typeOfMove,points); - this.setIcon('Z'); - } - /** - *This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - - } -} From 419046b9e65d4bbdde53a0f11865b2959dffc39f Mon Sep 17 00:00:00 2001 From: Artem Jivotovski Date: Thu, 17 Nov 2016 17:51:44 -0800 Subject: [PATCH 2/3] Added createMonster method, also minor adjustments to item files --- .../cs56/projects/games/roguelike/Beef.java | 13 ---- .../cs56/projects/games/roguelike/Elixir.java | 16 ----- .../games/roguelike/HealthPotion.java | 18 +---- .../projects/games/roguelike/Monster.java | 68 ++++++++++++++++--- .../cs56/projects/games/roguelike/Poison.java | 13 ---- 5 files changed, 60 insertions(+), 68 deletions(-) diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java b/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java index 41d8132..debf515 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java @@ -38,19 +38,6 @@ public Beef(boolean use){ this.setIcon('+'); } - /** - *This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - } /** this method uses the effect value in someway. in this method it just adds attack points to the player diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Elixir.java b/src/edu/ucsb/cs56/projects/games/roguelike/Elixir.java index e98f81d..97c25ce 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Elixir.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Elixir.java @@ -31,22 +31,6 @@ public Elixir(boolean use){ this.setIcon('S'); } - /** - This is the getter to figure out what piece icon it is. - */ - @Override - public char getIcon(){ - return this.icon; - } - - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - } - /** this method uses the effect value in someway. in this method it adds the speed value to the player. diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/HealthPotion.java b/src/edu/ucsb/cs56/projects/games/roguelike/HealthPotion.java index 3e1b335..29e3ad9 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/HealthPotion.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/HealthPotion.java @@ -39,23 +39,7 @@ public HealthPotion(boolean use){ this.setIcon('H'); } - /** - *This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - } - /** - this method uses the effect value in someway. - in this method it just adds health to the player. - */ + @Override public void UseEffect(Player p){ p.setHitPoints(this.getEffect()+p.getHitPoints()); } diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java b/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java index c506520..630d28c 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java @@ -17,7 +17,7 @@ public class Monster implements GamePiece{ private int pointValue=5; private char icon; - // Default attributes for monsters + // Default attributes for monsters. To add a new monster, add a new array with the values for hitPoints, attack, pointValue, and icon public static final int[] BAT = {5,1,10,66}; public static final int[] GOLEM = {25,5,30,71}; public static final int[] MONSTER = {20,10,5,77}; @@ -40,18 +40,68 @@ public Monster(){ this.typeOfMovement=0; } /** - * creates a player with 20 hitPoints and 10 attack + * creates a monster with 20 hitPoints and 10 attack * @param typeOfMovement whether or not the monster will move randomly or not + * @param typeOfMonster integer array containing monster's stats */ public Monster(int typeOfMovement, int[] typeOfMonster){ - this.setHitPoints(typeOfMonster[0]); - this.setAttack(typeOfMonster[1]); - this.setPointValue(typeOfMonster[2]); - char[] iconArray = Character.toChars(typeOfMonster[3]); - char iconChar = iconArray[0]; - this.setIcon(iconChar); - this.typeOfMovement=typeOfMovement; + this(typeOfMovement, typeOfMonster[0], typeOfMonster[1], + typeOfMonster[2], Character.toChars(typeOfMonster[3])[0]); } + /** + * Creates a monster with the stats passed in + * @param typeOfMovement determines the monster's movement behavior + * @param hitPoints the monster's hitPoints + * @param attack the monster's attack + * @param pointValue how many points the monster is worth + * @param icon the icon which will represent the monster on screen + */ + + public Monster(int typeOfMovement, int hitPoints, int attack, int pointValue, char icon) { + this.setHitPoints(hitPoints); + this.setAttack(attack); + this.setPointValue(pointValue); + this.setIcon(icon); + this.typeOfMovement = typeOfMovement; + } + + /** + * Static factory method for generating a monster based on an input string + * @param typeOfMovement determines the monster's movement behavior + * @param monsterName a string containing the name of the monster you want to create + */ + + public static Monster createMonster(int typeOfMovement, String monsterName) { + monsterName = monsterName.toUpperCase(); + Monster retMonster; + switch (monsterName) { + case "BAT" : + retMonster = new Monster(typeOfMovement, BAT); + break; + case "GOLEM" : + retMonster = new Monster(typeOfMovement, GOLEM); + break; + case "MONSTER" : + retMonster = new Monster(typeOfMovement, MONSTER); + break; + case "PIRATE" : + retMonster = new Monster(typeOfMovement, PIRATE); + break; + case "SNAKE" : + retMonster = new Monster(typeOfMovement, SNAKE); + break; + case "TROLL" : + retMonster = new Monster(typeOfMovement, TROLL); + break; + case "ZOMBIE" : + retMonster = new Monster(typeOfMovement, ZOMBIE); + break; + default : + retMonster = new Monster(typeOfMovement, MONSTER); + } + + return retMonster; + } /** * @return the monster's hitPoints diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java b/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java index 1566340..2e3f356 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java @@ -37,19 +37,6 @@ public Poison(boolean use){ this.setIcon('!'); } - /** - This is the getter to figure out what piece icon it is. - */ - @Override public char getIcon(){ - return this.icon; - } - /** - *This is the setter for the Icon it will be - *@param NewIcon is the icon of piece that will be in the game - */ - @Override public void setIcon(char NewIcon){ - this.icon=NewIcon; - } /** this method uses the effect value in someway. in this method it just subtracts health from the player. From 2b4c4454b840cb766372788d7708940d3299492b Mon Sep 17 00:00:00 2001 From: Artem Jivotovski Date: Sat, 19 Nov 2016 15:54:23 -0800 Subject: [PATCH 3/3] Fixed elixir/wall bug, added isGround() function --- .gitignore | 1 + .../projects/games/roguelike/LogicEngine.java | 15 +++++++++------ .../cs56/projects/games/roguelike/Player.java | 2 +- .../projects/games/roguelike/RogueController.java | 8 +++++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 15ad1ee..9bcde79 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ Score.txt build/ *~ +*#* # Package Files # *.jar diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java b/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java index 0b4fb27..82639bd 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java @@ -164,8 +164,10 @@ public void move(int x,int y,int xOrig,int yOrig){ consumeItem(x,y); } - floor[x][y] = floor[xOrig][yOrig]; - floor[xOrig][yOrig] = null; + if (x != xOrig || y != yOrig) { + floor[x][y] = floor[xOrig][yOrig]; + floor[xOrig][yOrig] = null; + } int[] position = {x,y}; if(floor[x][y] instanceof Player) { @@ -237,10 +239,11 @@ public boolean movable(int x,int y,int xOrig, int yOrig){ } public boolean inBounds(int x, int y) { - if ((x < 1 || x >= floorWidth - 1) || (y < 1 || y >= floorHeight - 1)) - return false; - else - return true; + return !((x < 1 || x >= floorWidth - 1) || (y < 1 || y >= floorHeight - 1)); + } + + public boolean isGround(int x, int y) { + return (inBounds(x,y)); } /** diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Player.java b/src/edu/ucsb/cs56/projects/games/roguelike/Player.java index 4f005c2..5bc4ade 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Player.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Player.java @@ -24,7 +24,7 @@ public class Player implements GamePiece { public Player(){ this.hitPoints = 100; this.attack = 20; - this.speed = 1; + this.speed = 3; this.score= 0; this.setTypeOfPiece("player"); this.setIcon('@'); diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java b/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java index 73223c3..20cc7b3 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java @@ -81,8 +81,14 @@ public void moveHero(){ // } // canvas.moveHeroAnimated(x, y,logicHandler.getPlayer().getHitPoints(),logicHandler.getPlayer().getScore()); + while (!logicHandler.isGround(x, y)) { + if (x != origX) + x = (x > origX) ? x-1 : x+1; + else if (y != origY) + y = (y > origY) ? y-1 : y+1; + } - //Draws all items even when the player tries to move outside the boundaries + //Draws all items even when the player tries to move outside the boundaries drawAllItems(); if ( logicHandler.movable(x,y,origX, origY)) { logicHandler.move(x,y,origX,origY);