diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java b/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java index debf515..ca6b3e7 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Beef.java @@ -38,7 +38,7 @@ public Beef(boolean use){ this.setIcon('+'); } - /** + /** 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 97c25ce..b02915b 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Elixir.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Elixir.java @@ -3,19 +3,19 @@ import java.util.Random; /** - @author Ishjot Walia & Josue Montenegro - @version cs56 Winter 16 - This class represents a class of Item called a Elixir which increases the Player's speed, allowing them to move 2 spaces instead of 1. - This item is very rare. - its in game icon is E - */ + @author Ishjot Walia & Josue Montenegro + @version cs56 Winter 16 + This class represents a class of Item called a Elixir which increases the Player's speed, allowing them to move 2 spaces instead of 1. + This item is very rare. + its in game icon is E +*/ public class Elixir extends Item{ private char icon; /** - default consturctor for Elixir - its default value is 1; with icon S + default consturctor for Elixir + its default value is 1; with icon S */ public Elixir(){ super(1); @@ -25,15 +25,15 @@ public Elixir(){ /** * this is an 1 arg consrtuctor that will set whether the item has been used or not * @param use is the param to set the use state of the item to true or false. - */ + */ public Elixir(boolean use){ super(use); this.setIcon('S'); } - /** - this method uses the effect value in someway. - in this method it adds the speed value to the player. + /** + this method uses the effect value in someway. + in this method it adds the speed value to the player. */ @Override public void UseEffect(Player p){ p.setSpeed(p.getSpeed()+this.getEffect()); diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/GUI.java b/src/edu/ucsb/cs56/projects/games/roguelike/GUI.java index 5e9c0bd..69db7a8 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/GUI.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/GUI.java @@ -64,7 +64,7 @@ public void actionPerformed(ActionEvent e) { System.exit(0); } - }); + }); guiFrame.add(playButton); guiFrame.add(instrButton); diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/GamePieceTest.java b/src/edu/ucsb/cs56/projects/games/roguelike/GamePieceTest.java index 3577667..4b6077e 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/GamePieceTest.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/GamePieceTest.java @@ -16,8 +16,8 @@ public class GamePieceTest{ /** this tests that the monster constructor works and the type should be monster - with icon M - */ + with icon M + */ @Test public void test_defaultMonsterType_Constructor(){ Monster m=new Monster(); assertEquals("monster",m.getTypeOfPiece()); @@ -25,8 +25,8 @@ public class GamePieceTest{ } /** this tests that the player constructor works and the type should be player - with icon @ - */ + with icon @ + */ @Test public void test_defaultPlayerType_Constructor(){ Player p=new Player(); assertEquals("player",p.getTypeOfPiece()); @@ -34,8 +34,8 @@ public class GamePieceTest{ } /** this test that the Bat constructor works and is a Monster type - with icon B - */ + with icon B + */ @Test public void test_defaulBatType_Constructor(){ Bat b=new Bat(); assertEquals("monster",b.getTypeOfPiece()); @@ -43,8 +43,8 @@ public class GamePieceTest{ } /** this test that the Golem constructor works and is a Monster type - with icon G - */ + with icon G + */ @Test public void test_defaultGolemType_Constructor(){ Golem g=new Golem(); assertEquals("monster",g.getTypeOfPiece()); @@ -52,8 +52,8 @@ public class GamePieceTest{ } /** this test that the Troll constructor works and is a Monster type - with icon T - */ + with icon T + */ @Test public void test_defaultTrollType_Constructor(){ Troll t=new Troll(); assertEquals("monster",t.getTypeOfPiece()); @@ -89,8 +89,8 @@ public class GamePieceTest{ /**tests the monsters 3arg Constructor to see if it is still a Monster Type - with icon M - */ + with icon M + */ @Test public void test_3ArgConstructorMonster(){ Monster m=new Monster(1,2,0); assertEquals("monster",m.getTypeOfPiece()); @@ -99,7 +99,7 @@ public class GamePieceTest{ /**tests the Bat 3arg Constructor to see if it is still a Monster Type with icon B - */ + */ @Test public void test_3ArgConstructorBat(){ Bat m=new Bat(1,2,0); assertEquals("monster",m.getTypeOfPiece()); @@ -108,7 +108,7 @@ public class GamePieceTest{ /**tests the Golem 3arg Constructor to see if it is still a Monster Type with icon G - */ + */ @Test public void test_3ArgConstructorGolem(){ Golem m=new Golem(1,2,0); assertEquals("monster",m.getTypeOfPiece()); @@ -124,7 +124,7 @@ public class GamePieceTest{ /**test the Snake 3arg Constructor to see if it is still a Monster Type with icon S - */ + */ @Test public void test_3ArgConstructorSnake(){ Snake s = new Snake(1,2,0); assertEquals("monster",s.getTypeOfPiece()); @@ -133,7 +133,7 @@ public class GamePieceTest{ /**test the Zombie 3arg Constructor to see if it is still a Monster Type with icon Z - */ + */ @Test public void test_3ArgConstructorZombie(){ Zombie z = new Zombie(1,2,0); assertEquals("monster",z.getTypeOfPiece()); @@ -142,7 +142,7 @@ public class GamePieceTest{ /**test the Pirate 3arg Constructor to see if it is still a Monster Type with icon P - */ + */ @Test public void test_3ArgConstructorPirate(){ Pirate p = new Pirate(1,2,0); assertEquals("monster",p.getTypeOfPiece()); @@ -151,8 +151,8 @@ public class GamePieceTest{ /**tests the Monster 4arg Constructor to see if it is still a Monster Type - with icon M - */ + with icon M + */ @Test public void test_4argConstructorMonsterType(){ Monster b=new Monster(1,2,0,3); assertEquals("monster",b.getTypeOfPiece()); @@ -161,8 +161,8 @@ public class GamePieceTest{ } /**tests the Bat 4arg Constructor to see if it is still a Monster Type - with icon B - */ + with icon B + */ @Test public void test_4argConstructorBatType(){ Bat b=new Bat(1,2,0,3); assertEquals("monster",b.getTypeOfPiece()); @@ -171,7 +171,7 @@ public class GamePieceTest{ /**tests the Golem 4arg Constructor to see if it is still a Monster Type with icon G - */ + */ @Test public void test_4argConstructorGolemType(){ Golem b=new Golem(1,2,0,3); assertEquals("monster",b.getTypeOfPiece()); @@ -179,8 +179,8 @@ public class GamePieceTest{ } /**tests the Troll 4arg Constructor to see if it is still a Monster Type - with icon T - */ + with icon T + */ @Test public void test_4argConstructorTrollType(){ Troll b=new Troll(1,2,0,3); assertEquals("monster",b.getTypeOfPiece()); diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Item.java b/src/edu/ucsb/cs56/projects/games/roguelike/Item.java index dd29fac..fe88cf9 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Item.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Item.java @@ -3,10 +3,10 @@ import java.util.Random; /** -* An Item class to represent Items in the Dungeon. -*@author Hans Marasigan & Richard Nguyen -*@version cs56 s13 -*/ + * An Item class to represent Items in the Dungeon. + *@author Hans Marasigan & Richard Nguyen + *@version cs56 s13 + */ public class Item implements GamePiece{ @@ -58,8 +58,8 @@ public Item(boolean CanUse){ gets the item's effect value */ public int getEffect(){ - return this.effect; - } + return this.effect; + } /** sets the item's effect value @param NewEffect this is the value the computer/programmer can set diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/ItemTest.java b/src/edu/ucsb/cs56/projects/games/roguelike/ItemTest.java index c98acb9..edb5b93 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/ItemTest.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/ItemTest.java @@ -7,9 +7,9 @@ import static org.junit.Assert.assertFalse; /** test class for my Item class -@author Hans Marasigan & Richard Nguyen -@version cs56 S13 -@see Item + @author Hans Marasigan & Richard Nguyen + @version cs56 S13 + @see Item */ public class ItemTest{ @@ -64,7 +64,7 @@ public class ItemTest{ assertEquals(true,i.getUse()); assertEquals("gameitem",i.getTypeOfPiece()); } - /** + /** this tests the default constructor. the effect should be 10 and used is false and it is an item and has icon H @@ -115,7 +115,7 @@ public class ItemTest{ assertEquals(true,i.getUse()); assertEquals("gameitem",i.getTypeOfPiece()); } - /** + /** this tests the default constructor. the effect should be 20 and used is false and it is an item and has icon ! @@ -166,7 +166,7 @@ public class ItemTest{ assertEquals(true,i.getUse()); assertEquals("gameitem",i.getTypeOfPiece()); } - /** + /** this tests the default constructor. the effect should be 20 and used is false and it is an item and has icon + @@ -217,45 +217,45 @@ public class ItemTest{ assertEquals(true,i.getUse()); assertEquals("gameitem",i.getTypeOfPiece()); } - /** - this tests how an Item affects a player - */ - @Test public void test_itemOnPlayer(){ - Item i= new Item(); - Player p=new Player(); - i.UseEffect(p); - assertEquals(10,p.getScore()); - } + /** + this tests how an Item affects a player + */ + @Test public void test_itemOnPlayer(){ + Item i= new Item(); + Player p=new Player(); + i.UseEffect(p); + assertEquals(10,p.getScore()); + } - /** - this tests how a HealthPotion affects a player - */ - @Test public void test_HealthPotionOnPlayer(){ - HealthPotion i= new HealthPotion(); - Player p=new Player(); - i.UseEffect(p); - assertEquals(120,p.getHitPoints()); - } + /** + this tests how a HealthPotion affects a player + */ + @Test public void test_HealthPotionOnPlayer(){ + HealthPotion i= new HealthPotion(); + Player p=new Player(); + i.UseEffect(p); + assertEquals(120,p.getHitPoints()); + } - /** - this tests how a Poison affects a player - */ - @Test public void test_PoisonOnPlayer(){ - Poison i= new Poison(); - Player p=new Player(); - i.UseEffect(p); - assertEquals(80,p.getHitPoints()); - } + /** + this tests how a Poison affects a player + */ + @Test public void test_PoisonOnPlayer(){ + Poison i= new Poison(); + Player p=new Player(); + i.UseEffect(p); + assertEquals(80,p.getHitPoints()); + } - /** - this tests how a Beef affects a player - */ - @Test public void test_BeefOnPlayer(){ - Beef i= new Beef(); - Player p=new Player(); - i.UseEffect(p); - assertEquals(40,p.getAttack()); - } + /** + this tests how a Beef affects a player + */ + @Test public void test_BeefOnPlayer(){ + Beef i= new Beef(); + Player p=new Player(); + i.UseEffect(p); + assertEquals(40,p.getAttack()); + } } diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngineTest.java b/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngineTest.java index 1a0ee85..ac7ae52 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngineTest.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/LogicEngineTest.java @@ -16,8 +16,8 @@ public class LogicEngineTest test to see if a player can move to a spot with a monster @see LogicEngine#movable - */ - @Test public void testMovable() + */ + @Test public void testMovable() { LogicEngine engine = new LogicEngine(); @@ -28,8 +28,8 @@ public class LogicEngineTest test to see if a monster can move to a spot with a player @see LogicEngine#movable - */ - @Test public void testMovable2() + */ + @Test public void testMovable2() { LogicEngine engine = new LogicEngine(); @@ -41,8 +41,8 @@ public class LogicEngineTest test to see if a monster/player can move to a spot that is empty @see LogicEngine#movable - */ - @Test public void testMovable3() + */ + @Test public void testMovable3() { LogicEngine engine = new LogicEngine(); @@ -54,8 +54,8 @@ public class LogicEngineTest test to see if a monster/player can move to a spot that is out of bound @see LogicEngine#movable - */ - @Test public void testMovable4() + */ + @Test public void testMovable4() { LogicEngine engine = new LogicEngine(); @@ -66,8 +66,8 @@ public class LogicEngineTest test to see if a monster/player can move to a spot that is out of bound @see LogicEngine#movable - */ - @Test public void testMovable5() + */ + @Test public void testMovable5() { LogicEngine engine = new LogicEngine(); @@ -78,20 +78,20 @@ public class LogicEngineTest test to see if a monster/player can move to a spot that is out of bound @see LogicEngine#movable - */ - @Test public void testMovable6() + */ + @Test public void testMovable6() { LogicEngine engine = new LogicEngine(); assertEquals(false,engine.movable(6,0,40,12)); } - /** + /** test to see if a monster/player can move to a spot that is out of bound @see LogicEngine#movable - */ - @Test public void testMovable7() + */ + @Test public void testMovable7() { LogicEngine engine = new LogicEngine(); @@ -103,8 +103,8 @@ public class LogicEngineTest test for a dead player @see LogicEngine#playerIsDead() - */ - @Test public void testPlayerStatus() + */ + @Test public void testPlayerStatus() { LogicEngine engine = new LogicEngine(); @@ -116,8 +116,8 @@ public class LogicEngineTest test for a player that isnt dead @see LogicEngine#playerIsDead() - */ - @Test public void testPlayerStatus2() + */ + @Test public void testPlayerStatus2() { LogicEngine engine = new LogicEngine(); @@ -129,8 +129,8 @@ public class LogicEngineTest test for a monster that is dead @see LogicEngine#monsterIsDead - */ - @Test public void testMonsterStatus() + */ + @Test public void testMonsterStatus() { LogicEngine engine = new LogicEngine(); @@ -143,8 +143,8 @@ public class LogicEngineTest test for a monster that isnt dead @see LogicEngine#monsterIsDead - */ - @Test public void testMonsterStatus2() + */ + @Test public void testMonsterStatus2() { LogicEngine engine = new LogicEngine(); diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java b/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java index 630d28c..dc6487e 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Monster.java @@ -9,12 +9,12 @@ *@version cs56 s13 */ public class Monster implements GamePiece{ - private int hitPoints; - private int attack; - private int direction = 0; - private int typeOfMovement; - private int[] position = new int[2]; - private int pointValue=5; + private int hitPoints; + private int attack; + private int direction = 0; + private int typeOfMovement; + private int[] position = new int[2]; + private int pointValue=5; private char icon; // Default attributes for monsters. To add a new monster, add a new array with the values for hitPoints, attack, pointValue, and icon @@ -26,28 +26,28 @@ public class Monster implements GamePiece{ 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.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; - } - /** - * 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 - */ + /** + * creates a monster with 20 hitPoints and 10 attack and no random movement + * + */ + public Monster(){ + 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; + } + /** + * 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(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 @@ -129,7 +129,7 @@ public void setAttack(int attack){ * */ public int getAttack(){ - return this.attack; + return this.attack; } /** @@ -176,115 +176,115 @@ public void setLevelBonus(int level){ } - /** - * a method for attacking the player - * @param mainChar the player being attacked - */ + /** + * a method for attacking the player + * @param mainChar the player being attacked + */ public void attacking(Player mainChar){ mainChar.setHitPoints(mainChar.getHitPoints()-this.attack); - } + } - public void setMonsterPosition(int x, int y){ - this.position[0] = x; - this.position[1] = y; - } - /** - * chooses what direction the monster moves in - * @return a vector that represents the direction - */ + public void setMonsterPosition(int x, int y){ + this.position[0] = x; + this.position[1] = y; + } + /** + * chooses what direction the monster moves in + * @return a vector that represents the direction + */ - public int[] getDirection(int[] playerPosition){ + public int[] getDirection(int[] playerPosition){ - int[] vector= new int[2]; - Random directionGenerator = new Random(); + int[] vector= new int[2]; + Random directionGenerator = new Random(); - switch(typeOfMovement){ - case 0 : direction++; - if(direction==4){ - direction=0; - } - break; + switch(typeOfMovement){ + case 0 : direction++; + if(direction==4){ + direction=0; + } + break; - case 1 : direction = directionGenerator.nextInt(4); - break; + case 1 : direction = directionGenerator.nextInt(4); + break; - case 2 : int randomer = directionGenerator.nextInt(3); - if((position[0] - playerPosition[0] == 0)){ - if(position[1]-playerPosition[1] > 0){ - if(randomer == 0){ - direction = 1; - }else if(randomer == 1){ - direction = 0; - }else if(randomer == 2){ - direction = 2; - } - }else{ - if(randomer == 0){ - direction = 3; - }else if(randomer == 1){ - direction = 0; - }else if(randomer == 2){ - direction = 2; - } - } - }else if((position[1] - playerPosition[1] == 0)){ - if(position[0]-playerPosition[0] > 0){ - if(randomer == 0){ - direction = 2; - }else if(randomer == 1){ - direction = 1; - }else if(randomer == 2){ - direction = 3; - } - }else{ - if(randomer == 0){ - direction = 0; - }else if(randomer == 1){ - direction = 1; - }else if(randomer == 2){ - direction = 3; - } - } - }else if((position[0] - playerPosition[0] > 0) && (position[1]-playerPosition[1] > 0)){ - if(directionGenerator.nextInt(2) == 1){ - direction = 1; - }else{ - direction = 2; - } - }else if((position[0] - playerPosition[0] > 0) && (position[1]-playerPosition[1] < 0)){ - if(directionGenerator.nextInt(2) == 1){ - direction = 3; - }else{ - direction = 2; - } - - }else if((position[0] - playerPosition[0] < 0) && (position[1]-playerPosition[1] > 0)){ - if(directionGenerator.nextInt(2) == 1){ - direction = 1; - }else{ - direction = 0; - } + case 2 : int randomer = directionGenerator.nextInt(3); + if((position[0] - playerPosition[0] == 0)){ + if(position[1]-playerPosition[1] > 0){ + if(randomer == 0){ + direction = 1; + }else if(randomer == 1){ + direction = 0; + }else if(randomer == 2){ + direction = 2; + } + }else{ + if(randomer == 0){ + direction = 3; + }else if(randomer == 1){ + direction = 0; + }else if(randomer == 2){ + direction = 2; + } + } + }else if((position[1] - playerPosition[1] == 0)){ + if(position[0]-playerPosition[0] > 0){ + if(randomer == 0){ + direction = 2; + }else if(randomer == 1){ + direction = 1; + }else if(randomer == 2){ + direction = 3; + } + }else{ + if(randomer == 0){ + direction = 0; + }else if(randomer == 1){ + direction = 1; + }else if(randomer == 2){ + direction = 3; + } + } + }else if((position[0] - playerPosition[0] > 0) && (position[1]-playerPosition[1] > 0)){ + if(directionGenerator.nextInt(2) == 1){ + direction = 1; + }else{ + direction = 2; + } + }else if((position[0] - playerPosition[0] > 0) && (position[1]-playerPosition[1] < 0)){ + if(directionGenerator.nextInt(2) == 1){ + direction = 3; + }else{ + direction = 2; + } - }else if((position[0] - playerPosition[0] < 0) && (position[1]-playerPosition[1] < 0)){ - if(directionGenerator.nextInt(2) == 1){ - direction = 3; - }else{ - direction = 0; - } + }else if((position[0] - playerPosition[0] < 0) && (position[1]-playerPosition[1] > 0)){ + if(directionGenerator.nextInt(2) == 1){ + direction = 1; + }else{ + direction = 0; + } - } - } - - switch (direction){ - case 0 : vector[0]=1; break; - case 1 : vector[1]=-1; break; - case 2 : vector[0]=-1; break; - case 3 : vector[1]=1; break; - default : break; + }else if((position[0] - playerPosition[0] < 0) && (position[1]-playerPosition[1] < 0)){ + if(directionGenerator.nextInt(2) == 1){ + direction = 3; + }else{ + direction = 0; } - return vector; + } + } + + switch (direction){ + case 0 : vector[0]=1; break; + case 1 : vector[1]=-1; break; + case 2 : vector[0]=-1; break; + case 3 : vector[1]=1; break; + default : break; } + + return vector; + } } diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Player.java b/src/edu/ucsb/cs56/projects/games/roguelike/Player.java index 569d5d1..195a256 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Player.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Player.java @@ -9,14 +9,14 @@ */ public class Player implements GamePiece { - //character hit points and attack - private int hitPoints; - private int attack; + //character hit points and attack + private int hitPoints; + private int attack; private int speed; - private int[] playerPosition; - private int score; - private String typeOfPiece; - private char icon; + private int[] playerPosition; + private int score; + private String typeOfPiece; + private char icon; /** * creates a player with 100 hitPoints, 20 attack, and 1 speed @@ -39,8 +39,8 @@ public int getHitPoints(){ } /** - sets the player's speed - @param speed this is the new value of the player's speed, can only be from 1 to 5 + sets the player's speed + @param speed this is the new value of the player's speed, can only be from 1 to 5 */ public void setSpeed(int speed) { @@ -51,25 +51,25 @@ public void setSpeed(int speed) } /** - * @return the player's speed - * - */ + * @return the player's speed + * + */ public int getSpeed(){ return this.speed; } - /** - * @return the player's score + /** + * @return the player's score * */ public int getScore(){ return this.score; } - /** + /** sets that player's attack @param atk this is the amount of points you want to set the player with - */ + */ public void setAttack(int atk){ if(atk >= 100){this.attack=100;} else @@ -117,7 +117,7 @@ public void setScore(int newScore){ public void attacking(Monster mon){ if(hitPoints > 0){ this.score+= mon.getPointValue(); - mon.setHitPoints(mon.getHitPoints()-this.attack); + mon.setHitPoints(mon.getHitPoints()-this.attack); } } diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java b/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java index 2e3f356..6a82412 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/Poison.java @@ -3,18 +3,18 @@ import java.util.Random; /** - @author Hans Marasigan & Richard Nguyen - @version cs56 Spring 13 - This class represents a class of Item called a Poison which takes away HP from the players Health Points (hit points) - its in game icon is ! - */ + @author Hans Marasigan & Richard Nguyen + @version cs56 Spring 13 + This class represents a class of Item called a Poison which takes away HP from the players Health Points (hit points) + its in game icon is ! +*/ public class Poison extends Item{ private char icon; /** - this is the default constructor for the Poison. - its default value is 20; with icon ! + this is the default constructor for the Poison. + its default value is 20; with icon ! */ public Poison(){ super(20); @@ -23,7 +23,7 @@ public Poison(){ /** * this is an 1 arg consrtuctor that will set how much the poison will take away * @param Health this will be the value the programmer or computer wants the poison to damage for. - */ + */ public Poison(int Health){ super(Health); this.setIcon('!'); @@ -31,15 +31,15 @@ public Poison(int Health){ /** * this is an 1 arg consrtuctor that will set whether the item has been used or not * @param use is the param to set the use of the item to true or false. - */ + */ public Poison(boolean use){ super(use); this.setIcon('!'); } - /** - this method uses the effect value in someway. - in this method it just subtracts health from the player. + /** + this method uses the effect value in someway. + in this method it just subtracts health from the player. */ @Override public void UseEffect(Player p){ p.setHitPoints(p.getHitPoints()-this.getEffect()); diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java b/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java index d503db6..769db3b 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/RogueController.java @@ -18,50 +18,50 @@ public class RogueController extends JFrame implements KeyListener { - //Unique serialVersion identification. Generated by Eclipse. - //private static final long serialVersionUID = 8465305666089157172L; - //x and y is the player intial position + //Unique serialVersion identification. Generated by Eclipse. + //private static final long serialVersionUID = 8465305666089157172L; + //x and y is the player intial position private int x=3; private int y=2; private GamePiece[][]floor; - //startx and starty are the locations the player should spawn after a new level begins - public final int startx = x; - public final int starty = y; + //startx and starty are the locations the player should spawn after a new level begins + public final int startx = x; + public final int starty = y; - private Random randomNumber = new Random(); + private Random randomNumber = new Random(); - // origX and origY is the position the character is at before the it moves - private int origX; - private int origY; + // origX and origY is the position the character is at before the it moves + private int origX; + private int origY; - private int currentLevel= 1; + private int currentLevel= 1; - //Canvas - The RoguePanel instance everything is drawn to. - public RoguePanel canvas; + //Canvas - The RoguePanel instance everything is drawn to. + public RoguePanel canvas; - // handles all game state from attack and damage to remove of monsters and player - public LogicEngine logicHandler; + // handles all game state from attack and damage to remove of monsters and player + public LogicEngine logicHandler; //Matrix indicating which grid space has been discovered yet //1 = discovered, any other value = not discovered private int[][] discoveredArea; - /** - * No parameters. - * Constructor initializes the RoguePanel canvas, logicEngine logicHandler and declares that it is listening for keys. - */ - public RogueController(){ - super(); - canvas = new RoguePanel(); - add(canvas); - pack(); - logicHandler = new LogicEngine(); - addKeyListener(this); - discoveredArea = new int[ canvas.getGridWidth() ][ canvas.getGridHeight()-1 ]; - } + /** + * No parameters. + * Constructor initializes the RoguePanel canvas, logicEngine logicHandler and declares that it is listening for keys. + */ + public RogueController(){ + super(); + canvas = new RoguePanel(); + add(canvas); + pack(); + logicHandler = new LogicEngine(); + addKeyListener(this); + discoveredArea = new int[ canvas.getGridWidth() ][ canvas.getGridHeight()-1 ]; + } /** * Handles movement of player by checking if it can move there first through the logic engine @@ -70,14 +70,14 @@ public RogueController(){ * if its a monster the player will attack it and its its dead the canvas will animate the removal of the monster */ public void moveHero(){ -// if(!logicHandler.movable(x,y,origX, origY)){ + // if(!logicHandler.movable(x,y,origX, origY)){ // if(logicHandler.monsterIsDead(x,y)){ // canvas.clear(x,y); - // } + // } - // x = origX; - // y = origY; + // x = origX; + // y = origY; // } // canvas.moveHeroAnimated(x, y,logicHandler.getPlayer().getHitPoints(),logicHandler.getPlayer().getScore()); @@ -88,89 +88,89 @@ 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.attackable(x, y, origX, origY)) { - logicHandler.attack(x, y, origX, origY); - if (logicHandler.monsterIsDead(x,y)){ - if (logicHandler.getObject(x,y) instanceof Item){ - canvas.drawItem(x,y, logicHandler.getItem(x,y)); - } else { - canvas.clear(x,y); - } + logicHandler.attack(x, y, origX, origY); + if (logicHandler.monsterIsDead(x,y)){ + if (logicHandler.getObject(x,y) instanceof Item){ + canvas.drawItem(x,y, logicHandler.getItem(x,y)); + } else { + canvas.clear(x,y); } - x = origX; - y = origY; - } else if (logicHandler.movable(x, y)) { - logicHandler.move(x, y, origX, origY); + } + x = origX; + y = origY; + } else if (logicHandler.movable(x, y)) { + logicHandler.move(x, y, origX, origY); } canvas.moveHeroAnimated(x, y,logicHandler.getPlayer().getHitPoints(), logicHandler.getPlayer().getAttack(), logicHandler.getPlayer().getSpeed(), logicHandler.getLevel(), logicHandler.getPlayer().getScore()); } /** * Handles movement of all monsters by checking if it can move there first through the logic engine - * if it can move, invoke the canvas to animate it - * if it can't, it checks if its because of out of bounds or a monster or a player - * if its a player, the monster will attack it and if its a monster it will eat it - */ - public void moveMonster(){ - //xPos,yPos is the position the monster is going to move to - int gridWidth, gridHeight, xPos, yPos; - int[] direction = new int[2]; - Monster mon[][] = logicHandler.getMonsters(); - gridHeight = canvas.getGridHeight(); - gridWidth = canvas.getGridWidth(); + * if it can move, invoke the canvas to animate it + * if it can't, it checks if its because of out of bounds or a monster or a player + * if its a player, the monster will attack it and if its a monster it will eat it + */ + public void moveMonster(){ + //xPos,yPos is the position the monster is going to move to + int gridWidth, gridHeight, xPos, yPos; + int[] direction = new int[2]; + Monster mon[][] = logicHandler.getMonsters(); + gridHeight = canvas.getGridHeight(); + gridWidth = canvas.getGridWidth(); - /* loops through all the monsters - xOrig,yOrig is the position the monster is at right now */ - for (int xOrig = 0; xOrig < gridWidth; xOrig++) { - for (int yOrig = 0; yOrig < gridHeight; yOrig++) { + /* loops through all the monsters + xOrig,yOrig is the position the monster is at right now */ + for (int xOrig = 0; xOrig < gridWidth; xOrig++) { + for (int yOrig = 0; yOrig < gridHeight; yOrig++) { - if(mon[xOrig][yOrig]!=null) { - // gets the direction of movement of the monster at xOrig, yOrig - direction = mon[xOrig][yOrig].getDirection(logicHandler.getPlayerPosition()); - xPos = xOrig + direction[0]; - yPos = yOrig + direction[1]; + if(mon[xOrig][yOrig]!=null) { + // gets the direction of movement of the monster at xOrig, yOrig + direction = mon[xOrig][yOrig].getDirection(logicHandler.getPlayerPosition()); + xPos = xOrig + direction[0]; + yPos = yOrig + direction[1]; - if (logicHandler.attackable(xPos, yPos, xOrig, yOrig)) { - logicHandler.attack(xPos, yPos,xOrig,yOrig); - if(xPos>0 && xPos<=78 && yPos>0 && yPos<=20){ - //display the you were attacked flag if the collision was with a player - if(logicHandler.getObject(xPos, yPos) instanceof Player){ - canvas.monsterAttack(); - canvas.moveHeroAnimated(x, y, logicHandler.getPlayer().getHitPoints(), - logicHandler.getPlayer().getAttack(), - logicHandler.getPlayer().getSpeed(), logicHandler.getLevel() - ,logicHandler.getPlayer().getScore()); - } - canvas.moveMonster(xOrig, yOrig,logicHandler.getObject(xOrig,yOrig)); - } - } else if (logicHandler.movable(xPos, yPos)) { - logicHandler.move(xPos, yPos,xOrig,yOrig); - canvas.moveMonster(xPos, yPos,logicHandler.getObject(xPos,yPos)); - } + if (logicHandler.attackable(xPos, yPos, xOrig, yOrig)) { + logicHandler.attack(xPos, yPos,xOrig,yOrig); + if(xPos>0 && xPos<=78 && yPos>0 && yPos<=20){ + //display the you were attacked flag if the collision was with a player + if(logicHandler.getObject(xPos, yPos) instanceof Player){ + canvas.monsterAttack(); + canvas.moveHeroAnimated(x, y, logicHandler.getPlayer().getHitPoints(), + logicHandler.getPlayer().getAttack(), + logicHandler.getPlayer().getSpeed(), logicHandler.getLevel() + ,logicHandler.getPlayer().getScore()); + } + canvas.moveMonster(xOrig, yOrig,logicHandler.getObject(xOrig,yOrig)); } + } else if (logicHandler.movable(xPos, yPos)) { + logicHandler.move(xPos, yPos,xOrig,yOrig); + canvas.moveMonster(xPos, yPos,logicHandler.getObject(xPos,yPos)); } } - - //update the monster list in logic handler - logicHandler.storeMonsters(); - fillEmptySpace(); + } } + + //update the monster list in logic handler + logicHandler.storeMonsters(); + fillEmptySpace(); + } - public void fillEmptySpace(){ - Object floor[][]; - floor = logicHandler.getFloor(); - for (int x= 0; x < canvas.getGridWidth()-1; x++) { - for (int y = 0; y < canvas.getGridHeight()-1; y++) { - if(floor[x][y]== null){ - canvas.emptySpace(x,y,logicHandler.getLevel()); - } + public void fillEmptySpace(){ + Object floor[][]; + floor = logicHandler.getFloor(); + for (int x= 0; x < canvas.getGridWidth()-1; x++) { + for (int y = 0; y < canvas.getGridHeight()-1; y++) { + if(floor[x][y]== null){ + canvas.emptySpace(x,y,logicHandler.getLevel()); } - } + } + } /** * Draws all walls using RoguePanel @@ -233,10 +233,10 @@ public void trackDiscovery(){ playerX+i >= canvas.getGridWidth()-1 || playerY+j < 0 || playerY+j >= canvas.getGridHeight()-1 ) ){ - //If the specified area has not been discovered (i.e. != 1) - if(discoveredArea[playerX+i][playerY+j] != 1){ - discoveredArea[playerX+i][playerY+j] = 1; - } + //If the specified area has not been discovered (i.e. != 1) + if(discoveredArea[playerX+i][playerY+j] != 1){ + discoveredArea[playerX+i][playerY+j] = 1; + } }//if }//for(j) }//for(i) @@ -319,9 +319,9 @@ public void checkPlayerStatus(){ } - /** - * Check to see if all monsters are dead and creates more monsters!!! OMG!! - */ + /** + * Check to see if all monsters are dead and creates more monsters!!! OMG!! + */ public void checkAllMonsterStatus(){ int gridWidth, gridHeight; Monster mon[][] = logicHandler.getMonsters(); @@ -341,94 +341,94 @@ public void checkAllMonsterStatus(){ discoveredArea = new int[ canvas.getGridWidth() ][ canvas.getGridHeight()-1 ];//resets exploration logicHandler.createMonster();//creates monsters clearAllItems(); - logicHandler.resetPlayerPosition();//moves the player back to the starting position + logicHandler.resetPlayerPosition();//moves the player back to the starting position canvas.moveHeroAnimated(startx, starty, logicHandler.getPlayer().getHitPoints(), logicHandler.getPlayer().getAttack(), - logicHandler.getPlayer().getSpeed(), logicHandler.getLevel(), logicHandler.getPlayer().getScore()); - this.x = startx; - this.y = starty; + logicHandler.getPlayer().getSpeed(), logicHandler.getLevel(), logicHandler.getPlayer().getScore()); + this.x = startx; + this.y = starty; } - /** - * Method mandated by KeyListener interface. - * Calls moveHero(). - * @param key Keystroke event fired by keyboard. - */ - public void keyPressed(KeyEvent key){ + /** + * Method mandated by KeyListener interface. + * Calls moveHero(). + * @param key Keystroke event fired by keyboard. + */ + public void keyPressed(KeyEvent key){ - //WASD moves - origX = x; - origY = y; - switch (key.getKeyChar()){ - case 'w' : this.y = this.y - logicHandler.getPlayer().getSpeed(); break; - case 'a' : this.x = this.x - logicHandler.getPlayer().getSpeed(); break; - case 'd' : this.x = this.x + logicHandler.getPlayer().getSpeed(); break; - case 's' : this.y = this.y + logicHandler.getPlayer().getSpeed(); break; - default : return; - } + //WASD moves + origX = x; + origY = y; + switch (key.getKeyChar()){ + case 'w' : this.y = this.y - logicHandler.getPlayer().getSpeed(); break; + case 'a' : this.x = this.x - logicHandler.getPlayer().getSpeed(); break; + case 'd' : this.x = this.x + logicHandler.getPlayer().getSpeed(); break; + case 's' : this.y = this.y + logicHandler.getPlayer().getSpeed(); break; + default : return; + } - canvas.clear(); - drawAllWalls(); - //Writes last received input. - canvas.write(key.getKeyChar(),7,23,RoguePanel.white,RoguePanel.black); - moveHero(); - moveMonster(); + canvas.clear(); + drawAllWalls(); + //Writes last received input. + canvas.write(key.getKeyChar(),7,23,RoguePanel.white,RoguePanel.black); + moveHero(); + moveMonster(); - checkPlayerStatus(); - checkAllMonsterStatus(); - trackDiscovery(); + checkPlayerStatus(); + checkAllMonsterStatus(); + trackDiscovery(); - canvas.recordShadows(discoveredArea); - if(logicHandler.getGameOver()==false) - canvas.setInGame(true); - else - canvas.setInGame(false); - canvas.repaint(); - } + canvas.recordShadows(discoveredArea); + if(logicHandler.getGameOver()==false) + canvas.setInGame(true); + else + canvas.setInGame(false); + canvas.repaint(); + } - /** - * Method required by the KeyListener interface. - * Doesn't do anything yet. - */ - public void keyReleased(KeyEvent key){ + /** + * Method required by the KeyListener interface. + * Doesn't do anything yet. + */ + public void keyReleased(KeyEvent key){ - } + } - /** - * Method required by the KeyListener interface. - * Doesn't do anything yet. - */ - public void keyTyped(KeyEvent key){ + /** + * Method required by the KeyListener interface. + * Doesn't do anything yet. + */ + public void keyTyped(KeyEvent key){ - } + } - public static void goToLosingScreen(){ - RogueController mainControl = new RogueController(); - mainControl.setVisible(true); - mainControl.setLocationRelativeTo(null); - mainControl.logicHandler.setGameOver(true); - mainControl.checkPlayerStatus(); - } + public static void goToLosingScreen(){ + RogueController mainControl = new RogueController(); + mainControl.setVisible(true); + mainControl.setLocationRelativeTo(null); + mainControl.logicHandler.setGameOver(true); + mainControl.checkPlayerStatus(); + } - public static void main(String[] args){ - RogueController mainControl = new RogueController(); - mainControl.setVisible(true); - mainControl.setLocationRelativeTo(null); // center the window + public static void main(String[] args){ + RogueController mainControl = new RogueController(); + mainControl.setVisible(true); + mainControl.setLocationRelativeTo(null); // center the window - //Initially fills the map with monsters - mainControl.logicHandler.createMonster(); + //Initially fills the map with monsters + mainControl.logicHandler.createMonster(); - //Screen that shows after game is opened - mainControl.canvas.write("MOVE WITH W A S D. Survive the waves. Eat monsters to earn points.",9,12,RoguePanel.white,RoguePanel.black); + //Screen that shows after game is opened + mainControl.canvas.write("MOVE WITH W A S D. Survive the waves. Eat monsters to earn points.",9,12,RoguePanel.white,RoguePanel.black); - }//Main Delimit + }//Main Delimit }//Class Delimit diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/RoguePanel.java b/src/edu/ucsb/cs56/projects/games/roguelike/RoguePanel.java index 700abcc..adeb532 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/RoguePanel.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/RoguePanel.java @@ -23,274 +23,274 @@ public class RoguePanel extends JPanel { - // private static final long serialVersionUID = L; + // private static final long serialVersionUID = L; - // list of colors our grid will use - public static Color white = new Color(0xFFFFFF); - public static Color black = new Color(0x000000); - public static Color red = new Color(0xFF0000); - public static Color blue = new Color(0x0000FF); - public static Color cyan = new Color(0x00FFFF); - public static Color green = new Color(0x00FF00); - public static Color yellow = new Color(0xFFFF00); - public static Color magenta = new Color(0xFF00FF); - public static Color gray = new Color(0x808080); - public static Color brown = new Color(0x663300); + // list of colors our grid will use + public static Color white = new Color(0xFFFFFF); + public static Color black = new Color(0x000000); + public static Color red = new Color(0xFF0000); + public static Color blue = new Color(0x0000FF); + public static Color cyan = new Color(0x00FFFF); + public static Color green = new Color(0x00FF00); + public static Color yellow = new Color(0xFFFF00); + public static Color magenta = new Color(0xFF00FF); + public static Color gray = new Color(0x808080); + public static Color brown = new Color(0x663300); //Array of colors that change the color of the ground with each level public static Color[] groundColor = new Color[] {gray,white,yellow,green,cyan,blue,magenta,brown}; //first level starts at index 1 - //attributes for handling things such as the Background and Foreground colors - //as well as character placement - private Image offscreenBuffer; - private Graphics offscreenGraphics; - private char[][] chars; - private int charHeight = 16; - private int charWidth = 9; - private int gridHeight; - private int gridWidth; - private int Xcoord; - private int Ycoord; - private BufferedImage glyphSprite; - private BufferedImage[] glyphs; - private Color defaultBackgroundColor = black; - private Color defaultForegroundColor = white; - private Color[][] backgroundColors; - private Color[][] foregroundColors; - private char[][] oldChars; - private Color[][] oldBackgroundColors; - private Color[][] oldForegroundColors; + //attributes for handling things such as the Background and Foreground colors + //as well as character placement + private Image offscreenBuffer; + private Graphics offscreenGraphics; + private char[][] chars; + private int charHeight = 16; + private int charWidth = 9; + private int gridHeight; + private int gridWidth; + private int Xcoord; + private int Ycoord; + private BufferedImage glyphSprite; + private BufferedImage[] glyphs; + private Color defaultBackgroundColor = black; + private Color defaultForegroundColor = white; + private Color[][] backgroundColors; + private Color[][] foregroundColors; + private char[][] oldChars; + private Color[][] oldBackgroundColors; + private Color[][] oldForegroundColors; private int[][] discoveredArea; private boolean inGame;//whether the player is playing the game for shadows to be drawn - // char [][] floor = new char [40][40]; + // char [][] floor = new char [40][40]; - /** - * @return the chars - */ - public char[][] getChars() - { - return chars; - } - /** - * @param chars the chars to set - */ - public void setChars(char[][] chars) - { - this.chars = chars; - } - /** - * @return the charHeight - */ - public int getCharHeight() - { - return charHeight; - } - /** - * sets the height of a character. Measured in pixels. - * @param charHeight the charHeight to set - */ - public void setCharHeight(int charHeight) - { - this.charHeight = charHeight; - } - /** - * @return the charWidth - */ - public int getCharWidth() - { - return charWidth; - } - /** - * sets the width of a character. Measured in pixels. - * @param charWidth the charWidth to set - */ - public void setCharWidth(int charWidth) - { - this.charWidth = charWidth; - } - /** - * @return the gridHeight - */ - public int getGridHeight() - { - return gridHeight; - } - /** - * set the height of the grid. Measured in characters. - * @param gridHeight the gridHeight to set - */ - public void setGridHeight(int gridHeight) - { - this.gridHeight = gridHeight; - } - /** - * @return the gridWidth - */ - public int getGridWidth() - { - return gridWidth; - } - /** - * set the width of the grid. Measured in characters. - * @param gridWidth the gridWidth to set - */ - public void setGridWidth(int gridWidth) - { - this.gridWidth = gridWidth; - } - /** - * @return the xcoord - */ - public int getXcoord() - { - return Xcoord; - } - /**Sets the X coordinate for where the character is draw, must be within the size or the frame - * @param xcoord the xcoord to set - */ - public void setXcoord(int xcoord) - { - if (xcoord < 0 || xcoord >= gridWidth) - throw new IllegalArgumentException("Xcoord " + Xcoord + " must be within range [0," + gridWidth + ")." ); - Xcoord = xcoord; - } - /** - * @return the ycoord - */ - public int getYcoord() - { - return Ycoord; - } - /** - * Set the Y coordinate for where the character is to be drawn, must be within the size of the frame - * @param ycoord the ycoord to set - */ - public void setYcoord(int ycoord) - { - if (ycoord < 0 || ycoord >= gridHeight) - throw new IllegalArgumentException("Ycoord " + Ycoord + " must be within range [0," + gridHeight + ")." ); - Ycoord = ycoord; - } + /** + * @return the chars + */ + public char[][] getChars() + { + return chars; + } + /** + * @param chars the chars to set + */ + public void setChars(char[][] chars) + { + this.chars = chars; + } + /** + * @return the charHeight + */ + public int getCharHeight() + { + return charHeight; + } + /** + * sets the height of a character. Measured in pixels. + * @param charHeight the charHeight to set + */ + public void setCharHeight(int charHeight) + { + this.charHeight = charHeight; + } + /** + * @return the charWidth + */ + public int getCharWidth() + { + return charWidth; + } + /** + * sets the width of a character. Measured in pixels. + * @param charWidth the charWidth to set + */ + public void setCharWidth(int charWidth) + { + this.charWidth = charWidth; + } + /** + * @return the gridHeight + */ + public int getGridHeight() + { + return gridHeight; + } + /** + * set the height of the grid. Measured in characters. + * @param gridHeight the gridHeight to set + */ + public void setGridHeight(int gridHeight) + { + this.gridHeight = gridHeight; + } + /** + * @return the gridWidth + */ + public int getGridWidth() + { + return gridWidth; + } + /** + * set the width of the grid. Measured in characters. + * @param gridWidth the gridWidth to set + */ + public void setGridWidth(int gridWidth) + { + this.gridWidth = gridWidth; + } + /** + * @return the xcoord + */ + public int getXcoord() + { + return Xcoord; + } + /**Sets the X coordinate for where the character is draw, must be within the size or the frame + * @param xcoord the xcoord to set + */ + public void setXcoord(int xcoord) + { + if (xcoord < 0 || xcoord >= gridWidth) + throw new IllegalArgumentException("Xcoord " + Xcoord + " must be within range [0," + gridWidth + ")." ); + Xcoord = xcoord; + } + /** + * @return the ycoord + */ + public int getYcoord() + { + return Ycoord; + } + /** + * Set the Y coordinate for where the character is to be drawn, must be within the size of the frame + * @param ycoord the ycoord to set + */ + public void setYcoord(int ycoord) + { + if (ycoord < 0 || ycoord >= gridHeight) + throw new IllegalArgumentException("Ycoord " + Ycoord + " must be within range [0," + gridHeight + ")." ); + Ycoord = ycoord; + } - /** - * sets the coordinates of where we want to draw of character - * @param x the x coordinate - * @param y the y coordinate - */ - public void setCoords(int x, int y){ - setXcoord(x); - setYcoord(y); - } + /** + * sets the coordinates of where we want to draw of character + * @param x the x coordinate + * @param y the y coordinate + */ + public void setCoords(int x, int y){ + setXcoord(x); + setYcoord(y); + } - /** - * @return the defaultBackgroundColor - */ - public Color getDefaultBackgroundColor() - { - return defaultBackgroundColor; - } - /** - * @param defaultBackgroundColor the defaultBackgroundColor to set - */ - public void setDefaultBackgroundColor(Color defaultBackgroundColor) - { - if (defaultBackgroundColor == null) - throw new NullPointerException("defaultBackgroundColor must not be null."); - this.defaultBackgroundColor = defaultBackgroundColor; - } - /** - * @return the defaultForegroundColor - */ - public Color getDefaultForegroundColor() - { - return defaultForegroundColor; - } - /** - * @param defaultForegroundColor the defaultForegroundColor to set - */ - public void setDefaultForegroundColor(Color defaultForegroundColor) - { - if (defaultForegroundColor == null) - throw new NullPointerException("defaultForegroundColor must not be null."); - this.defaultForegroundColor = defaultForegroundColor; - } - /** - * @return the backgroundColors - */ - public Color[][] getBackgroundColors() - { - return backgroundColors; - } - /** - * @param backgroundColors the backgroundColors to set - */ - public void setBackgroundColors(Color[][] backgroundColors) - { - this.backgroundColors = backgroundColors; - } - /** - * @return the foregroundColors - */ - public Color[][] getForegroundColors() - { - return foregroundColors; - } - /** - * @param foregroundColors the foregroundColors to set - */ - public void setForegroundColors(Color[][] foregroundColors) - { - this.foregroundColors = foregroundColors; - } - /** - * @return the oldChars - */ - public char[][] getOldChars() - { - return oldChars; - } - /** - * @param oldChars the oldChars to set - */ - public void setOldChars(char[][] oldChars) - { - this.oldChars = oldChars; - } - /** - * @return the oldBackgroundColors - */ - public Color[][] getOldBackgroundColors() - { - return oldBackgroundColors; - } - /** - * @param oldBackgroundColors the oldBackgroundColors to set - */ - public void setOldBackgroundColors(Color[][] oldBackgroundColors) - { - this.oldBackgroundColors = oldBackgroundColors; - } - /** - * @return the oldForegroundColors - */ - public Color[][] getOldForegroundColors() - { - return oldForegroundColors; - } - /** - * @param oldForegroundColors the oldForegroundColors to set - */ - public void setOldForegroundColors(Color[][] oldForegroundColors) - { - this.oldForegroundColors = oldForegroundColors; - } + /** + * @return the defaultBackgroundColor + */ + public Color getDefaultBackgroundColor() + { + return defaultBackgroundColor; + } + /** + * @param defaultBackgroundColor the defaultBackgroundColor to set + */ + public void setDefaultBackgroundColor(Color defaultBackgroundColor) + { + if (defaultBackgroundColor == null) + throw new NullPointerException("defaultBackgroundColor must not be null."); + this.defaultBackgroundColor = defaultBackgroundColor; + } + /** + * @return the defaultForegroundColor + */ + public Color getDefaultForegroundColor() + { + return defaultForegroundColor; + } + /** + * @param defaultForegroundColor the defaultForegroundColor to set + */ + public void setDefaultForegroundColor(Color defaultForegroundColor) + { + if (defaultForegroundColor == null) + throw new NullPointerException("defaultForegroundColor must not be null."); + this.defaultForegroundColor = defaultForegroundColor; + } + /** + * @return the backgroundColors + */ + public Color[][] getBackgroundColors() + { + return backgroundColors; + } + /** + * @param backgroundColors the backgroundColors to set + */ + public void setBackgroundColors(Color[][] backgroundColors) + { + this.backgroundColors = backgroundColors; + } + /** + * @return the foregroundColors + */ + public Color[][] getForegroundColors() + { + return foregroundColors; + } + /** + * @param foregroundColors the foregroundColors to set + */ + public void setForegroundColors(Color[][] foregroundColors) + { + this.foregroundColors = foregroundColors; + } + /** + * @return the oldChars + */ + public char[][] getOldChars() + { + return oldChars; + } + /** + * @param oldChars the oldChars to set + */ + public void setOldChars(char[][] oldChars) + { + this.oldChars = oldChars; + } + /** + * @return the oldBackgroundColors + */ + public Color[][] getOldBackgroundColors() + { + return oldBackgroundColors; + } + /** + * @param oldBackgroundColors the oldBackgroundColors to set + */ + public void setOldBackgroundColors(Color[][] oldBackgroundColors) + { + this.oldBackgroundColors = oldBackgroundColors; + } + /** + * @return the oldForegroundColors + */ + public Color[][] getOldForegroundColors() + { + return oldForegroundColors; + } + /** + * @param oldForegroundColors the oldForegroundColors to set + */ + public void setOldForegroundColors(Color[][] oldForegroundColors) + { + this.oldForegroundColors = oldForegroundColors; + } /** @return the inGame */ @@ -307,161 +307,161 @@ public void setInGame(boolean b){ - /** - * Creates a grid of size 80 x 24 chars - */ - public RoguePanel(){ - this(80,24); - } + /** + * Creates a grid of size 80 x 24 chars + */ + public RoguePanel(){ + this(80,24); + } - /** - * Creates a grid of a specified width and height - * @param width - * @param height - */ - public RoguePanel(int width, int height) - { - super(); + /** + * Creates a grid of a specified width and height + * @param width + * @param height + */ + public RoguePanel(int width, int height) + { + super(); - if (width < 1) - throw new IllegalArgumentException("width " + width + " must be greater than 0." ); + if (width < 1) + throw new IllegalArgumentException("width " + width + " must be greater than 0." ); - if (height < 1) - throw new IllegalArgumentException("height " + height + " must be greater than 0." ); + if (height < 1) + throw new IllegalArgumentException("height " + height + " must be greater than 0." ); - gridWidth = width; - gridHeight = height; - setPreferredSize(new Dimension(charWidth * gridWidth, charHeight * gridHeight)); + gridWidth = width; + gridHeight = height; + setPreferredSize(new Dimension(charWidth * gridWidth, charHeight * gridHeight)); - defaultBackgroundColor = black; - defaultForegroundColor = white; + defaultBackgroundColor = black; + defaultForegroundColor = white; - chars = new char[gridWidth][gridHeight]; - backgroundColors = new Color[gridWidth][gridHeight]; - foregroundColors = new Color[gridWidth][gridHeight]; + chars = new char[gridWidth][gridHeight]; + backgroundColors = new Color[gridWidth][gridHeight]; + foregroundColors = new Color[gridWidth][gridHeight]; - oldChars = new char[gridWidth][gridHeight]; - oldBackgroundColors = new Color[gridWidth][gridHeight]; - oldForegroundColors = new Color[gridWidth][gridHeight]; + oldChars = new char[gridWidth][gridHeight]; + oldBackgroundColors = new Color[gridWidth][gridHeight]; + oldForegroundColors = new Color[gridWidth][gridHeight]; - glyphs = new BufferedImage[256]; + glyphs = new BufferedImage[256]; - discoveredArea = new int[gridWidth][gridHeight-1]; - inGame = false; + discoveredArea = new int[gridWidth][gridHeight-1]; + inGame = false; - loadGlyphs(); + loadGlyphs(); - RoguePanel.this.clear(); - } + RoguePanel.this.clear(); + } - @Override - public void update(Graphics g) { - paint(g); - } - - @Override - public void paint(Graphics g) { - if (g == null) - throw new NullPointerException(); + @Override + public void update(Graphics g) { + paint(g); + } + + @Override + public void paint(Graphics g) { + if (g == null) + throw new NullPointerException(); - if (offscreenBuffer == null){ - offscreenBuffer = createImage(this.getWidth(), this.getHeight()); - offscreenGraphics = offscreenBuffer.getGraphics(); - } + if (offscreenBuffer == null){ + offscreenBuffer = createImage(this.getWidth(), this.getHeight()); + offscreenGraphics = offscreenBuffer.getGraphics(); + } - for (int x = 0; x < gridWidth; x++) { - for (int y = 0; y < gridHeight; y++) { - if (oldBackgroundColors[x][y] == backgroundColors[x][y] - && oldForegroundColors[x][y] == foregroundColors[x][y] - && oldChars[x][y] == chars[x][y]) - continue; + for (int x = 0; x < gridWidth; x++) { + for (int y = 0; y < gridHeight; y++) { + if (oldBackgroundColors[x][y] == backgroundColors[x][y] + && oldForegroundColors[x][y] == foregroundColors[x][y] + && oldChars[x][y] == chars[x][y]) + continue; - Color bg = backgroundColors[x][y]; - Color fg = foregroundColors[x][y]; + Color bg = backgroundColors[x][y]; + Color fg = foregroundColors[x][y]; - LookupOp op = setColors(bg, fg); - BufferedImage img = op.filter(glyphs[chars[x][y]], null); - offscreenGraphics.drawImage(img, x * charWidth, y * charHeight, null); + LookupOp op = setColors(bg, fg); + BufferedImage img = op.filter(glyphs[chars[x][y]], null); + offscreenGraphics.drawImage(img, x * charWidth, y * charHeight, null); - oldBackgroundColors[x][y] = backgroundColors[x][y]; - oldForegroundColors[x][y] = foregroundColors[x][y]; - oldChars[x][y] = chars[x][y]; + oldBackgroundColors[x][y] = backgroundColors[x][y]; + oldForegroundColors[x][y] = foregroundColors[x][y]; + oldChars[x][y] = chars[x][y]; - } - } + } + } - g.drawImage(offscreenBuffer,0,0,this); + g.drawImage(offscreenBuffer,0,0,this); - if(inGame){ - //draw shadows that cover undiscovered areas - for(int x = 0; x < gridWidth; x++){ - for(int y = 0; y < gridHeight-1; y++){ - if(discoveredArea[x][y] != 1){ - g.setColor(backgroundColors[x][y]); - g.fillRect(x*charWidth,y*charHeight,charWidth,charHeight); - }//if - }//for - }//for - }//if + if(inGame){ + //draw shadows that cover undiscovered areas + for(int x = 0; x < gridWidth; x++){ + for(int y = 0; y < gridHeight-1; y++){ + if(discoveredArea[x][y] != 1){ + g.setColor(backgroundColors[x][y]); + g.fillRect(x*charWidth,y*charHeight,charWidth,charHeight); + }//if + }//for + }//for + }//if - } - - private void loadGlyphs() { - try { - glyphSprite = ImageIO.read(RoguePanel.class.getResource("cp437.png")); - } catch (IOException e) { - System.err.println("loadGlyphs(): " + e.getMessage()); } + + private void loadGlyphs() { + try { + glyphSprite = ImageIO.read(RoguePanel.class.getResource("cp437.png")); + } catch (IOException e) { + System.err.println("loadGlyphs(): " + e.getMessage()); + } - for (int i = 0; i < 256; i++) { - int sx = (i % 32) * charWidth + 8; - int sy = (i / 32) * charHeight + 8; + for (int i = 0; i < 256; i++) { + int sx = (i % 32) * charWidth + 8; + int sy = (i / 32) * charHeight + 8; - glyphs[i] = new BufferedImage(charWidth, charHeight, BufferedImage.TYPE_INT_ARGB); - glyphs[i].getGraphics().drawImage(glyphSprite, 0, 0, charWidth, charHeight, sx, sy, sx + charWidth, sy + charHeight, null); + glyphs[i] = new BufferedImage(charWidth, charHeight, BufferedImage.TYPE_INT_ARGB); + glyphs[i].getGraphics().drawImage(glyphSprite, 0, 0, charWidth, charHeight, sx, sy, sx + charWidth, sy + charHeight, null); + } } -} -/** - * Create a LookupOp object (lookup table) mapping the original - * pixels to the background and foreground colors, respectively. - * @param bgColor the background color - * @param fgColor the foreground color - * @return the LookupOp object (lookup table) - */ -private LookupOp setColors(Color bgColor, Color fgColor) { - short[] a = new short[256]; - short[] r = new short[256]; - short[] g = new short[256]; - short[] b = new short[256]; - - byte bgr = (byte) (bgColor.getRed()); - byte bgg = (byte) (bgColor.getGreen()); - byte bgb = (byte) (bgColor.getBlue()); - - byte fgr = (byte) (fgColor.getRed()); - byte fgg = (byte) (fgColor.getGreen()); - byte fgb = (byte) (fgColor.getBlue()); - - for (int i = 0; i < 256; i++) { - if (i == 0) { - a[i] = (byte) 255; - r[i] = bgr; - g[i] = bgg; - b[i] = bgb; - } else { - a[i] = (byte) 255; - r[i] = fgr; - g[i] = fgg; - b[i] = fgb; - } - } + /** + * Create a LookupOp object (lookup table) mapping the original + * pixels to the background and foreground colors, respectively. + * @param bgColor the background color + * @param fgColor the foreground color + * @return the LookupOp object (lookup table) + */ + private LookupOp setColors(Color bgColor, Color fgColor) { + short[] a = new short[256]; + short[] r = new short[256]; + short[] g = new short[256]; + short[] b = new short[256]; + + byte bgr = (byte) (bgColor.getRed()); + byte bgg = (byte) (bgColor.getGreen()); + byte bgb = (byte) (bgColor.getBlue()); + + byte fgr = (byte) (fgColor.getRed()); + byte fgg = (byte) (fgColor.getGreen()); + byte fgb = (byte) (fgColor.getBlue()); + + for (int i = 0; i < 256; i++) { + if (i == 0) { + a[i] = (byte) 255; + r[i] = bgr; + g[i] = bgg; + b[i] = bgb; + } else { + a[i] = (byte) 255; + r[i] = fgr; + g[i] = fgg; + b[i] = fgb; + } + } - short[][] table = {r, g, b, a}; - return new LookupOp(new ShortLookupTable(0, table), null); -} + short[][] table = {r, g, b, a}; + return new LookupOp(new ShortLookupTable(0, table), null); + } /** * Clear the entire screen to whatever the default background color is. @@ -476,7 +476,7 @@ public RoguePanel clear() { * @return this for convenient chaining of method calls */ public RoguePanel clear(int x, int y){ - return clear(' ', x, y, 1, 1, defaultForegroundColor, defaultBackgroundColor); + return clear(' ', x, y, 1, 1, defaultForegroundColor, defaultBackgroundColor); } /** @@ -594,82 +594,82 @@ public RoguePanel write(char character, int x, int y, Color foreground, Color ba foregroundColors[x][y] = foreground; backgroundColors[x][y] = background; if(character=='@'){ - Xcoord = x + 1; - Ycoord = y; + Xcoord = x + 1; + Ycoord = y; } return this; } - /** - * Draw an "@" symbol at x,y using the RoguePanel's write(string,int,int,color,color) method. - */ + /** + * Draw an "@" symbol at x,y using the RoguePanel's write(string,int,int,color,color) method. + */ - public void drawChar(int xPos, int yPos){ - write("@",xPos,yPos,RoguePanel.white,RoguePanel.black); - } + public void drawChar(int xPos, int yPos){ + write("@",xPos,yPos,RoguePanel.white,RoguePanel.black); + } - /** - * Draw HUD: text for information like the last read input, x and y coordinate of the character. - * Prints the x and y coordinates of the character. - */ + /** + * Draw HUD: text for information like the last read input, x and y coordinate of the character. + * Prints the x and y coordinates of the character. + */ - public void drawHUD(){ - write("Input:",0,23,RoguePanel.white,RoguePanel.black); - write("X:",10,23,RoguePanel.white,RoguePanel.black); - write("Y:",14,23,RoguePanel.white,RoguePanel.black); - write("Hp:",20,23,RoguePanel.white,RoguePanel.black); - write("Ap:",27,23,RoguePanel.white,RoguePanel.black); - write("Speed:", 34,23,RoguePanel.white,RoguePanel.black); - write("Level:",43,23,RoguePanel.white,RoguePanel.black); - write("Score:",53,23,RoguePanel.white,RoguePanel.black); - } + public void drawHUD(){ + write("Input:",0,23,RoguePanel.white,RoguePanel.black); + write("X:",10,23,RoguePanel.white,RoguePanel.black); + write("Y:",14,23,RoguePanel.white,RoguePanel.black); + write("Hp:",20,23,RoguePanel.white,RoguePanel.black); + write("Ap:",27,23,RoguePanel.white,RoguePanel.black); + write("Speed:", 34,23,RoguePanel.white,RoguePanel.black); + write("Level:",43,23,RoguePanel.white,RoguePanel.black); + write("Score:",53,23,RoguePanel.white,RoguePanel.black); + } - /** - * moves the player to position xPosition,yPosition and updates its hp using write - */ + /** + * moves the player to position xPosition,yPosition and updates its hp using write + */ public void moveHeroAnimated(int xPosition, int yPosition, int hp, int ap, int speed, int level, int score){ - drawHUD(); + drawHUD(); - try{ - write("@",xPosition,yPosition,RoguePanel.white,RoguePanel.black); - }catch(Exception ex){ - write("HERE BE DRAGONS",0,22,RoguePanel.red,RoguePanel.black); - } - - write(""+xPosition,12,23,RoguePanel.white,RoguePanel.black); - write(""+yPosition,16,23,RoguePanel.white,RoguePanel.black); - write(""+hp+ " ",22,23,RoguePanel.white,RoguePanel.black); - write(""+ap+ " ",29,23,RoguePanel.white,RoguePanel.black); - write(""+speed+ " ",40,23,RoguePanel.white,RoguePanel.black); - write(""+level+ " ",49,23,RoguePanel.white,RoguePanel.black); - write(""+score+ " ",59,23,RoguePanel.white,RoguePanel.black); + try{ + write("@",xPosition,yPosition,RoguePanel.white,RoguePanel.black); + }catch(Exception ex){ + write("HERE BE DRAGONS",0,22,RoguePanel.red,RoguePanel.black); } + + write(""+xPosition,12,23,RoguePanel.white,RoguePanel.black); + write(""+yPosition,16,23,RoguePanel.white,RoguePanel.black); + write(""+hp+ " ",22,23,RoguePanel.white,RoguePanel.black); + write(""+ap+ " ",29,23,RoguePanel.white,RoguePanel.black); + write(""+speed+ " ",40,23,RoguePanel.white,RoguePanel.black); + write(""+level+ " ",49,23,RoguePanel.white,RoguePanel.black); + write(""+score+ " ",59,23,RoguePanel.white,RoguePanel.black); + } public void drawItem(int xPosition, int yPosition, Item i){ - write(i.getIcon(),xPosition,yPosition,RoguePanel.white,RoguePanel.black); + write(i.getIcon(),xPosition,yPosition,RoguePanel.white,RoguePanel.black); - } + } - /** - *moves the monster to position xPosition,yPosition - * Prints the x and y coordinates of the character. - */ + /** + *moves the monster to position xPosition,yPosition + * Prints the x and y coordinates of the character. + */ public void moveMonster(int xPosition, int yPosition, GamePiece piece){ write(piece.getIcon(),xPosition,yPosition,RoguePanel.red,RoguePanel.black); - } + } - /** - * display the you were hit flag - */ - public void monsterAttack(){ - write("You were hit",60,23,RoguePanel.yellow,RoguePanel.black); + /** + * display the you were hit flag + */ + public void monsterAttack(){ + write("You were hit",60,23,RoguePanel.yellow,RoguePanel.black); - } + } /** * display that the player has advanced to the next level @@ -678,37 +678,37 @@ public void nextLevel(){ write("NEXT LEVEL!",60,23,RoguePanel.yellow,RoguePanel.black); } - /** - * displays the losing screen with player's score and HighScores - */ + /** + * displays the losing screen with player's score and HighScores + */ public void displayLosingScreen(int score,int[] array){ write("To play again: close this window and press play on the main menu.", 7,10,RoguePanel.green,RoguePanel.black); - write("YOU LOSE",35,6,RoguePanel.red,RoguePanel.black); - write("Score:"+score,35,14,RoguePanel.white,RoguePanel.black); - write("High Scores", 35,16,RoguePanel.white,RoguePanel.black); - int b = 17; - int rank = 1; - for( int a: array){ - write("" + rank +":" + a, 40,b,RoguePanel.white,RoguePanel.black); - b++; - rank++; - } + write("YOU LOSE",35,6,RoguePanel.red,RoguePanel.black); + write("Score:"+score,35,14,RoguePanel.white,RoguePanel.black); + write("High Scores", 35,16,RoguePanel.white,RoguePanel.black); + int b = 17; + int rank = 1; + for( int a: array){ + write("" + rank +":" + a, 40,b,RoguePanel.white,RoguePanel.black); + b++; + rank++; + } } - /** - * displays the winning screen - */ - public void displayWinningScreen(){ - write("YOU WIN",40,12,RoguePanel.green,RoguePanel.black); - } + /** + * displays the winning screen + */ + public void displayWinningScreen(){ + write("YOU WIN",40,12,RoguePanel.green,RoguePanel.black); + } public void emptySpace(int xPosition, int yPosition, int colorNum){ - write("_",xPosition,yPosition,groundColor[colorNum%groundColor.length],RoguePanel.black); - } + write("_",xPosition,yPosition,groundColor[colorNum%groundColor.length],RoguePanel.black); + } public void drawWall(int xPosition, int yPosition, int colorNum){ - write("0",xPosition,yPosition,groundColor[colorNum%groundColor.length],RoguePanel.black); - } + write("0",xPosition,yPosition,groundColor[colorNum%groundColor.length],RoguePanel.black); + } /** Covers the areas where the player has not discovered yet diff --git a/src/edu/ucsb/cs56/projects/games/roguelike/SubMonsterTest.java b/src/edu/ucsb/cs56/projects/games/roguelike/SubMonsterTest.java index 34d3c8d..4e0fff6 100644 --- a/src/edu/ucsb/cs56/projects/games/roguelike/SubMonsterTest.java +++ b/src/edu/ucsb/cs56/projects/games/roguelike/SubMonsterTest.java @@ -27,19 +27,19 @@ public class SubMonsterTest{ tests for a bat with 10 hp 10 att and 10points - */ + */ @Test public void test_defaultConstructor_and_GettersBat(){ Bat b=new Bat(); assertEquals(10,b.getHitPoints()); assertEquals(10,b.getAttack()); assertEquals(10,b.getPointValue()); - } + } /** - tests for a Troll with 15 hp 10 att and 15points + tests for a Troll with 15 hp 10 att and 15points - */ + */ @Test public void test_defaultConstructor_and_GettersTroll(){ Troll t=new Troll(); assertEquals(15,t.getHitPoints()); @@ -50,8 +50,8 @@ public class SubMonsterTest{ /** - tests for a Golem with 50 hp 20 att and 20points - */ + tests for a Golem with 50 hp 20 att and 20points + */ @Test public void test_defaultConstructor_and_GettersGolem(){ Golem g=new Golem(); assertEquals(50,g.getHitPoints()); @@ -91,7 +91,7 @@ public class SubMonsterTest{ /** tests for a bat with 20 hp 24 att and 10points - */ + */ @Test public void test_3ArgConstructorBat(){ Bat b=new Bat(20,24,0); assertEquals(20,b.getHitPoints()); @@ -102,7 +102,7 @@ public class SubMonsterTest{ /** tests for a Troll with 20 hp 25 att and 10points - */ + */ @Test public void test_3ArgConstructorTroll(){ Troll t=new Troll(20,25,0); @@ -162,13 +162,13 @@ public class SubMonsterTest{ assertEquals(20,b.getHitPoints()); assertEquals(30,b.getAttack()); assertEquals(40,b.getPointValue()); - } + } /** tests for a Troll with 30 hp 20 att and 40points - */ + */ @Test public void test_4argConstructorTroll(){ Troll t=new Troll(30,20,0,40); assertEquals(30,t.getHitPoints()); @@ -179,7 +179,7 @@ public class SubMonsterTest{ /** tests for a Golem with 50 hp 40 att and 20points - */ + */ @Test public void test_4argConstructorGolem(){ Golem g=new Golem(50,40,0,30); assertEquals(50,g.getHitPoints()); @@ -233,7 +233,7 @@ public class SubMonsterTest{ /** tests for a monster with 1 hp 2 att and 3points - */ + */ @Test public void test_MonsterSetter(){ Monster m = new Monster(); m.setHitPoints(1); @@ -244,7 +244,7 @@ public class SubMonsterTest{ assertEquals(3,m.getPointValue()); } - /** + /** * *tests for a Bat with 1hp 2 att and 3points */ @@ -263,7 +263,7 @@ public class SubMonsterTest{ /** tests for a Troll with 1 hp 2 att and 3points - */ + */ @Test public void test_TrollSetter(){ Troll t = new Troll(); @@ -280,7 +280,7 @@ public class SubMonsterTest{ /** tests for a Golem with 1 hp 2 att and 3points - */ + */ @Test public void test_GolemSetter(){ Golem g = new Golem(); g.setHitPoints(1);