Skip to content

Commit

Permalink
modification of project 1 to add design patterns
Browse files Browse the repository at this point in the history
adding singleton pattern to map
adding a decorator to pokemon to buff/debuff
factory method to generator pokemon into a hashmap
- main responsibilities 
pokemon generator (factory design pattern)
pokemon decorator AtkUp/AtkDown (decorator design pattern)
updating water class
updating entity class
updates on main
  • Loading branch information
diegogarciacs authored Jan 3, 2022
1 parent 8d27968 commit 8a9df9b
Show file tree
Hide file tree
Showing 23 changed files with 2,261 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Project 2/Area1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
n w n p n
i p w n c
s n p i n
w c n w w
n w n p f
5 changes: 5 additions & 0 deletions Project 2/Area2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
n w p f w
c n n p i
n w i n c
p n p w n
w n w n s
5 changes: 5 additions & 0 deletions Project 2/Area3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
w n n s p
n w n i c
f p w w n
p n w n n
w c i n p
23 changes: 23 additions & 0 deletions Project 2/PokemonList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Bulbasaur,Grass
Charmander,Fire
Squirtle,Water
Vulpix,Fire
Oddish,Grass
Psyduck,Water
Growlithe,Fire
Poliwag,Water
Bellsprout,Grass
Tentacool,Water
Ponyta,Fire
Slowpoke,Water
Seel,Water
Shellder,Water
Krabby,Water
Exeggcute,Grass
Tangela,Grass
Horsea,Water
Goldeen,Water
Staryu,Water
Magikarp,Water
Lapras,Water
Moltres,Fire
20 changes: 20 additions & 0 deletions Project 2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CECS277 Project 2

## Tasks
| Team Member #1: Daniel | Team Member #2: Diego | Team Member #3: Chloee |
|------------------------|-----------------------|------------------------|
| Add Singleton to Map | Pokemon Generator | Update Pokemon Class |
| Fire Class | Water Class | Grass Class |
| Pokemon Decorator | Update Entity | Update Trainer |
| Update trainerAttack | AttackUp/AttackDown | HpUp/HpDown |
| Update main | Update main | Update main |

## Rubric
| Correctness: 70% | Completion: 25% | Peer Review: 5% |
|------------------------------|--------------------------|---------------------|
| Runs correctly | Wrote code for tasks | Survey of teammates |
| Satisfies all requirements | How well code is written |
| Written correctly |
| Follows UML |
| Documented properly |
| Conforms to coding standards |
Binary file added Project 2/guidelines/CECS277-Coding Standards.pdf
Binary file not shown.
Binary file added Project 2/guidelines/CECS277-Project2.pdf
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions Project 2/src/AttackDown.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* AttackDown is a decorator for decreasing attack on Pokemon, subclass of PokemonDecorator.
*
* @author Diego Garcia 2021
*/
public class AttackDown extends PokemonDecorator {
/**
* Creates a decorator to decrease attack on a Pokemon
*
* @param p Pokemon to decrease attack on
*/
public AttackDown(Pokemon p) {
super(p, "-ATK", 0);
}

/**
* Gets the attack bonus which is a decrease
*
* @param atkType type of attack (1 for basic, 2 for special)
* @return the attack decrease
*/
@Override
public int getAttackBonus(int atkType) {
return super.getAttackBonus(atkType) - 1;
}
}
26 changes: 26 additions & 0 deletions Project 2/src/AttackUp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* AttackDown is a decorator for increasing attack on Pokemon, subclass of PokemonDecorator.
*
* @author Diego Garcia 2021
*/
public class AttackUp extends PokemonDecorator {
/**
* Creates a decorator to increase attack on a Pokemon
*
* @param p Pokemon to increase attack on
*/
public AttackUp(Pokemon p) {
super(p, "+ATK", 0);
}

/**
* Gets the attack bonus for the buffed Pokemon
*
* @param atkType type of attack (1 for basic, 2 for special)
* @return the attack bonuus
*/
@Override
public int getAttackBonus(int atkType) {
return super.getAttackBonus(atkType) + (int) ((Math.random() * 2) + 1);
}
}
140 changes: 140 additions & 0 deletions Project 2/src/CheckInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import java.util.Scanner;

/**
* Static functions used to check console input for validity.
* <p>
* Use: Place CheckInput class in the same project folder as your code.
* Call CheckInput functions from your code using "CheckInput."
* <p>
* Example: int num = CheckInput.getInt();
*
* @author Shannon Cleary 2021
*/
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;
}
}
94 changes: 94 additions & 0 deletions Project 2/src/Entity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Entity is an abstract representation of an Entity
*
* @author Diego Garcia 2021
*/
public abstract class Entity {
/**
* The name of the Entity
*/
private String name;

/**
* The health points of the Entity
*/
private int hp;

/**
* The maximum health points of the Entity
*/
private int maxHp;

/**
* Constructs an Entity object that initializes name, max hp, and hp of the Entity.
*
* @param n name of the Entity.
* @param h hp of the Entity.
* @param m maximum hp of the Entity.
*/
public Entity(String n, int h, int m) {
this.name = n;
this.hp = h;
this.maxHp = m;
}

/**
* Returns the hp of the Entity.
*
* @return the current hp of the Entity.
*/
public int getHp() {
return this.hp;
}

/**
* Returns the max hp of the Entity.
*
* @return the max hp of the Entity.
*/
public int getMaxHp() {
return this.maxHp;
}

/**
* Accepts damage and afflicts it to the Entity.
* If the damage is greater than the current hp, the Entity's hp is set to 0.
*
* @param d damage to inflict on Entity.
*/
public void takeDamage(int d) {
if (d > 0) {
if (d <= this.hp) {
this.hp -= d;
} else {
this.hp = 0;
}
}
}

/**
* Restores Entity's hp to maxHp.
*/
public void heal() {
this.hp = this.maxHp;
}

/**
* When called returns the name of the entity.
*
* @return the name of the entity.
*/
public String getName() {
return this.name;
}

/**
* Returns a string of name, hp, and maxHp.
*
* @return name, hp, and maxHp in string format.
*/
@Override
public String toString() {
return this.name + " HP: " + this.hp + "/" + this.maxHp;
}
}
Loading

0 comments on commit 8a9df9b

Please sign in to comment.