diff --git a/Lab 13/CECS277-Lab13.pdf b/Lab 13/CECS277-Lab13.pdf new file mode 100644 index 0000000..f83c146 Binary files /dev/null and b/Lab 13/CECS277-Lab13.pdf differ diff --git a/Lab 13/Lab 13.iml b/Lab 13/Lab 13.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lab 13/Lab 13.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Lab 13/out/production/Lab 13/Alien.class b/Lab 13/out/production/Lab 13/Alien.class new file mode 100644 index 0000000..bdd222f Binary files /dev/null and b/Lab 13/out/production/Lab 13/Alien.class differ diff --git a/Lab 13/out/production/Lab 13/Beast.class b/Lab 13/out/production/Lab 13/Beast.class new file mode 100644 index 0000000..1fdeffa Binary files /dev/null and b/Lab 13/out/production/Lab 13/Beast.class differ diff --git a/Lab 13/out/production/Lab 13/CheckInput.class b/Lab 13/out/production/Lab 13/CheckInput.class new file mode 100644 index 0000000..e17ba48 Binary files /dev/null and b/Lab 13/out/production/Lab 13/CheckInput.class differ diff --git a/Lab 13/out/production/Lab 13/Fire.class b/Lab 13/out/production/Lab 13/Fire.class new file mode 100644 index 0000000..4a254e5 Binary files /dev/null and b/Lab 13/out/production/Lab 13/Fire.class differ diff --git a/Lab 13/out/production/Lab 13/Flying.class b/Lab 13/out/production/Lab 13/Flying.class new file mode 100644 index 0000000..9b930aa Binary files /dev/null and b/Lab 13/out/production/Lab 13/Flying.class differ diff --git a/Lab 13/out/production/Lab 13/Lasers.class b/Lab 13/out/production/Lab 13/Lasers.class new file mode 100644 index 0000000..b5cfd27 Binary files /dev/null and b/Lab 13/out/production/Lab 13/Lasers.class differ diff --git a/Lab 13/out/production/Lab 13/Main.class b/Lab 13/out/production/Lab 13/Main.class new file mode 100644 index 0000000..300392d Binary files /dev/null and b/Lab 13/out/production/Lab 13/Main.class differ diff --git a/Lab 13/out/production/Lab 13/Monster.class b/Lab 13/out/production/Lab 13/Monster.class new file mode 100644 index 0000000..d1e82a3 Binary files /dev/null and b/Lab 13/out/production/Lab 13/Monster.class differ diff --git a/Lab 13/out/production/Lab 13/MonsterDecorator.class b/Lab 13/out/production/Lab 13/MonsterDecorator.class new file mode 100644 index 0000000..53811af Binary files /dev/null and b/Lab 13/out/production/Lab 13/MonsterDecorator.class differ diff --git a/Lab 13/out/production/Lab 13/Poison.class b/Lab 13/out/production/Lab 13/Poison.class new file mode 100644 index 0000000..46f289f Binary files /dev/null and b/Lab 13/out/production/Lab 13/Poison.class differ diff --git a/Lab 13/out/production/Lab 13/Undead.class b/Lab 13/out/production/Lab 13/Undead.class new file mode 100644 index 0000000..f5be85e Binary files /dev/null and b/Lab 13/out/production/Lab 13/Undead.class differ diff --git a/Lab 13/src/Alien.java b/Lab 13/src/Alien.java new file mode 100644 index 0000000..1ca1585 --- /dev/null +++ b/Lab 13/src/Alien.java @@ -0,0 +1,19 @@ +public class Alien extends Monster { + /** + * Basic base monster to be decorated with a name and hp. + * @param n name of monster. + * @param h hp of monster. + */ + public Alien(String n, int h) { + super(n, h); + } + + /** + * Basic attack points of the alien monster. + * @return attack points of alien. + */ + @Override + int attack() { + return 3; + } +} diff --git a/Lab 13/src/Beast.java b/Lab 13/src/Beast.java new file mode 100644 index 0000000..37ab6de --- /dev/null +++ b/Lab 13/src/Beast.java @@ -0,0 +1,18 @@ +public class Beast extends Monster{ + /** + * Basic base monster to be decorated with a name and hp. + * @param n name of monster. + * @param h hp of monster. + */ + public Beast(String n, int h) { + super(n, h); + } + /** + * Basic attack points of the beast monster. + * @return attack points of beast monster. + */ + @Override + int attack() { + return 3; + } +} diff --git a/Lab 13/src/CheckInput.java b/Lab 13/src/CheckInput.java new file mode 100644 index 0000000..b215c8d --- /dev/null +++ b/Lab 13/src/CheckInput.java @@ -0,0 +1,133 @@ +import java.util.Scanner; + +/** + * Static functions used to check console input for validity. + * + * Use: Place CheckInput class in the same project folder as your code. + * Call CheckInput functions from your code using "CheckInput." + * + * Example: int num = CheckInput.getInt(); + * + * @author Shannon Cleary 2020 + */ +public class CheckInput { + + /** + * Checks if the inputted value is an integer. + * @return the valid input. + */ + public static int getInt() { + Scanner in = new Scanner( System.in ); + int input = 0; + boolean valid = false; + while( !valid ) { + if( in.hasNextInt() ) { + input = in.nextInt(); + valid = true; + } else { + in.next(); //clear invalid string + System.out.println( "Invalid Input." ); + } + } + return input; + } + + /** + * Checks if the inputted value is an integer and + * within the specified range (ex: 1-10) + * @param low lower bound of the range. + * @param high upper bound of the range. + * @return the valid input. + */ + public static int getIntRange( int low, int high ) { + Scanner in = new Scanner( System.in ); + int input = 0; + boolean valid = false; + while( !valid ) { + if( in.hasNextInt() ) { + input = in.nextInt(); + if( input <= high && input >= low ) { + valid = true; + } else { + System.out.println( "Invalid Range." ); + } + } else { + in.next(); //clear invalid string + System.out.println( "Invalid Input." ); + } + } + return input; + } + /** + * Checks if the inputted value is a non-negative integer. + * @return the valid input. + */ + public static int getPositiveInt( ) { + Scanner in = new Scanner( System.in ); + int input = 0; + boolean valid = false; + while( !valid ) { + if( in.hasNextInt() ) { + input = in.nextInt(); + if( input >= 0 ) { + valid = true; + } else { + System.out.println( "Invalid Range." ); + } + } else { + in.next(); //clear invalid string + System.out.println( "Invalid Input." ); + } + } + return input; + } + + /** + * Checks if the inputted value is a double. + * @return the valid input. + */ + public static double getDouble() { + Scanner in = new Scanner( System.in ); + double input = 0; + boolean valid = false; + while( !valid ) { + if( in.hasNextDouble() ) { + input = in.nextDouble(); + valid = true; + } else { + in.next(); //clear invalid string + System.out.println( "Invalid Input." ); + } + } + return input; + } + + /** + * Takes in a string from the user. + * @return the inputted String. + */ + public static String getString() { + Scanner in = new Scanner( System.in ); + String input = in.nextLine(); + return input; + } + + /** + * Takes in a yes/no from the user. + * @return true if yes, false if no. + */ + public static boolean getYesNo(){ + boolean valid = false; + while( !valid ) { + String s = getString(); + if( s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("y") ) { + return true; + } else if( s.equalsIgnoreCase("no") || s.equalsIgnoreCase("n") ) { + return false; + } else { + System.out.println( "Invalid Input." ); + } + } + return false; + } +} diff --git a/Lab 13/src/Fire.java b/Lab 13/src/Fire.java new file mode 100644 index 0000000..4fbceac --- /dev/null +++ b/Lab 13/src/Fire.java @@ -0,0 +1,17 @@ +public class Fire extends MonsterDecorator { + /** + * Creates a decorator to give a fire name and health increase to our monster. + * @param m the monster to be decorated. + */ + public Fire(Monster m){ + super(m, " Hotboi", 2); + } + + /** + * Buffs our monsters attack points. + * @return the prior attack points + the buff. + */ + public int attack(){ + return 3 + super.attack(); + } +} diff --git a/Lab 13/src/Flying.java b/Lab 13/src/Flying.java new file mode 100644 index 0000000..eea552d --- /dev/null +++ b/Lab 13/src/Flying.java @@ -0,0 +1,16 @@ +public class Flying extends MonsterDecorator{ + /** + * Creates a decorator to give a flying name and health increase to our monster. + * @param m the monster to be decorated. + */ + public Flying(Monster m) { + super(m, " Flying Raijin", 1); + } + /** + * Buffs our monsters attack points. + * @return the prior attack points + the buff. + */ + public int attack(){ + return 1 + super.attack(); + } +} diff --git a/Lab 13/src/Group1Lab13.zip b/Lab 13/src/Group1Lab13.zip new file mode 100644 index 0000000..a151210 Binary files /dev/null and b/Lab 13/src/Group1Lab13.zip differ diff --git a/Lab 13/src/Lasers.java b/Lab 13/src/Lasers.java new file mode 100644 index 0000000..645478b --- /dev/null +++ b/Lab 13/src/Lasers.java @@ -0,0 +1,16 @@ +public class Lasers extends MonsterDecorator { + /** + * Creates a decorator to give a laser name and health increase to our monster. + * @param m the monster to be decorated. + */ + public Lasers(Monster m) { + super(m, " with Laser Beams", 2); + } + /** + * Buffs our monsters attack points. + * @return the prior attack points + the buff. + */ + public int attack(){ + return 2 + super.attack(); + } +} diff --git a/Lab 13/src/Main.java b/Lab 13/src/Main.java new file mode 100644 index 0000000..072e726 --- /dev/null +++ b/Lab 13/src/Main.java @@ -0,0 +1,45 @@ +public class Main { + public static void main( String [] args ){ + System.out.println("Monster Creator!"); + System.out.println("Choose a monster."); + System.out.println("1. Alien\n2. Beast\n3. Undead"); + int choice = CheckInput.getIntRange(1,3); + monsterBuffer(choice); + } + + /** + * Method that takes the initial choice if user to create a base monster, then buffs. + * @param choice initial choice of monster. + */ + public static void monsterBuffer(int choice){ + Monster m = null; + if (choice == 1){ + m = new Alien("Alien",2); + + } else if (choice == 2){ + m = new Beast("Beast",3); + } else if (choice == 3){ + m = new Undead("Undead",3); + } + boolean again = true; + while (again){ + System.out.println(m.getName() + " has " + m.getHp() +" health, and attacks for " + m.attack()+ " damage" + + "."); + System.out.println("Add an ability:\n1. Fire\n2. Flying\n3. Lasers\n4. Poison\n5. Quit"); + choice = CheckInput.getIntRange(1,5); + if (choice == 1){ + m = new Fire(m); + } else if (choice == 2){ + m = new Flying(m); + } else if (choice == 3){ + m = new Lasers(m); + } else if (choice == 4){ + m = new Poison(m); + } else if (choice == 5){ + again = false; + } + } + + } + +} diff --git a/Lab 13/src/Monster.java b/Lab 13/src/Monster.java new file mode 100644 index 0000000..2701650 --- /dev/null +++ b/Lab 13/src/Monster.java @@ -0,0 +1,39 @@ +public abstract class Monster { + // hp initialization + private int hp; + // name initialization + private String name; + + /** + * Creates a monster with name and hp. + * @param n the name of the monster. + * @param h hp of the monster. + */ + public Monster(String n, int h){ + this.name = n; + this.hp = h; + } + + /** + * Grabs name of the monster. + * @return the name of the monster object. + */ + public String getName(){ + return this.name; + } + + /** + * Grabs the hp of the monster and returns it. + * @return the hp of the monster object. + */ + public int getHp(){ + return this.hp; + } + + /** + * Abstract attack method to be overridden. + * @return returns an integer of the attack points. + */ + abstract int attack(); + +} diff --git a/Lab 13/src/MonsterDecorator.java b/Lab 13/src/MonsterDecorator.java new file mode 100644 index 0000000..6da98fc --- /dev/null +++ b/Lab 13/src/MonsterDecorator.java @@ -0,0 +1,24 @@ +public abstract class MonsterDecorator extends Monster { + // Monster to be decorated + private Monster tempMonster; + + /** + * Creates a monster decorated extended from Monster to be buffed/manipulated. + * @param m the Monster object to be buffed/manipulated + * @param extraName extra name to be added to the Monster. + * @param extraHp additional HP to be added to the Monster. + */ + public MonsterDecorator(Monster m, String extraName, int extraHp) { + super(m.getName() + extraName,m.getHp() + extraHp); + this.tempMonster = m; + } + + /** + * Returns attack points of newly decorated monster. + * @return attack of the newly decorated monster. + */ + @Override + public int attack() { + return tempMonster.attack(); + } +} diff --git a/Lab 13/src/Poison.java b/Lab 13/src/Poison.java new file mode 100644 index 0000000..355d227 --- /dev/null +++ b/Lab 13/src/Poison.java @@ -0,0 +1,16 @@ +public class Poison extends MonsterDecorator { + /** + * Creates a decorator to give a poison name and health increase to our monster. + * @param m the monster to be decorated. + */ + public Poison(Monster m) { + super(m, " Toxic Avenger", 1); + } + /** + * Basic attack points of the undead monster. + * @return attack points of undead. + */ + public int attack(){ + return 3 + super.attack(); + } +} diff --git a/Lab 13/src/Undead.java b/Lab 13/src/Undead.java new file mode 100644 index 0000000..6acf554 --- /dev/null +++ b/Lab 13/src/Undead.java @@ -0,0 +1,18 @@ +public class Undead extends Monster{ + /** + * Basic base monster to be decorated with a name and hp. + * @param n name of monster. + * @param h hp of monster. + */ + public Undead(String n, int h) { + super(n, h); + } + /** + * Basic attack points of the undead monster. + * @return attack points of undead. + */ + @Override + int attack() { + return 3; + } +}