Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding potions #138

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a21b35d
Added testing for new type of potion
Oct 21, 2021
6ac4802
Added test cases for Settings Class
Oct 21, 2021
68ab56d
Add Enemy Tests
Oct 21, 2021
e7aa8e1
Updated test cases
Oct 21, 2021
4f40ee4
Localized bugs and implemented changes
Oct 22, 2021
93f3274
Fixed bug pertaining to stats
Oct 22, 2021
74a4467
Add documentation
Oct 22, 2021
6a8f9a5
Conducted regression testing
Oct 22, 2021
4c06bf4
Added tests for brewing potions.
Oct 22, 2021
4c54eb3
Implemented brewing potions, updated documentation
Oct 22, 2021
566a89c
Regression testing, implemented more tests for Potion class
Oct 22, 2021
e9c854e
Performed regression testing and supplied fixes
Oct 22, 2021
f1ab0ee
Code review updated from using Code Inspection static analysis tool
Oct 22, 2021
4af5ee4
Create CHANGES.md
mmccoy3 Oct 24, 2021
7df2252
Adding documentation including diagrams that were utilized
Oct 24, 2021
2fa6550
Add files via upload
mmccoy3 Oct 24, 2021
a0a1767
Delete Before-And-After Changes.PNG
mmccoy3 Oct 24, 2021
796d281
Merge branch 'AddingPotions' of https://github.com/emmamickas/Text-Fi…
Oct 24, 2021
0e4670e
Create TESTING.md
mmccoy3 Oct 24, 2021
477d3f5
Merge branch 'AddingPotions' of https://github.com/emmamickas/Text-Fi…
Oct 24, 2021
5a0d9ac
Adding documentation to repo
Oct 24, 2021
4e4ed07
Delete Before-And-After Changes.PNG
mmccoy3 Oct 24, 2021
84608b2
Update CHANGES.md
mmccoy3 Oct 24, 2021
a8f9fff
Update TESTING.md
mmccoy3 Oct 24, 2021
76e8fa2
Update TESTING.md
mmccoy3 Oct 24, 2021
37bb136
Updating Class diagrams
Oct 24, 2021
1247388
Merge branch 'AddingPotions' of https://github.com/emmamickas/Text-Fi…
Oct 24, 2021
d02210c
Add files via upload
mmccoy3 Oct 24, 2021
17a231e
Add files via upload
mmccoy3 Oct 24, 2021
76fd63e
Add files via upload
mmccoy3 Oct 24, 2021
ee57cc9
Further testing was implemented
Oct 24, 2021
958a7b5
Merge branch 'AddingPotions' of https://github.com/emmamickas/Text-Fi…
Oct 24, 2021
1b4cfd9
Update CHANGES.md
mmccoy3 Oct 24, 2021
795b4eb
Update TESTING.md
mmccoy3 Oct 24, 2021
aa80839
Added test cases
Oct 24, 2021
621f626
Merge branch 'AddingPotions' of https://github.com/emmamickas/Text-Fi…
Oct 24, 2021
a1eeafd
Update CHANGES.md
mmccoy3 Oct 25, 2021
e26f18c
Included Potion class diagram
Oct 25, 2021
3e6a0e1
Merge branch 'AddingPotions' of https://github.com/emmamickas/Text-Fi…
Oct 25, 2021
dac5425
Including Reference Project documentation
Oct 25, 2021
afad781
Including Food class diagram
Oct 25, 2021
4a9dfdb
Including Food dependency matrix
Oct 25, 2021
211b741
Delete Dependency Matrix directory
mmccoy3 Oct 25, 2021
b492665
Update TESTING.md
emmamickas Oct 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changes in this branch

## This branch addresses the following issue:
### Potion Brewing and more options, ([issue #87](https://github.com/hhaslam11/Text-Fighter/issues/87) in the source hhaslam11/Text-Fighter repository, [issue #8](https://github.com/emmamickas/Text-Fighter/issues/8) in the forked emmamickas/Text-Fighter repository)

## Desired modifications:
### In the current implementation, there are only two potion types and the player can only purchase potions. In the updated version there are now three types of potions and players can brew potions.

## Modified files:
### The following files were modified in the change:
* [Chest.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/item/Chest.java)
* [Food.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/Food.java)
* [Game.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/Game.java)
* [Help.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/Help.java)
* [Saves.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/Saves.java)
* [Shop.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/Shop.java)
* [Potion.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/player/Potion.java)
* [Settings.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/player/Settings.java)
* [Stats.java](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/player/Stats.java)

## Testing:
### The following tests were performed to ensure that behavior was preserved after refactoring/changes:
* [Potion](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java)
* [Settings](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/player/SettingsTest.java)
* [Enemy](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java)
* [Food](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java)

#### See [here](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/TESTING.md) for more information on testing.

## Additional resources:
### Please view the following to find additional documentation of the changes and the code involved in the changes.
* [Class Diagrams](https://github.com/emmamickas/Text-Fighter/tree/AddingPotions/Class%20Diagram) of modified classes.
* [Dependencies](https://github.com/emmamickas/Text-Fighter/tree/AddingPotions/Dependency%20Matrix) of modified or dependent classes.

Binary file added Class Diagram/After Changes 2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/After Changes.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/Before Changes 2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/Before Changes.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/Food fields and methods.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/Potion Class.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dependency Reference/Food Dependency Matrix.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dependency Reference/Potion Dependency Matrix.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Testing potion functionality:
## The following tests were performed to ensure that behavior was preserved after refactoring/changes:
### [Potion Tests](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java) including testing of the methods:
* get(string type)
* set(string type, int quantity, boolean add)
* use(string type)
* used(string type)
* buy(string type)
* getLevel(string type)
* getPrice(string type)
* brewPotion(string type)
* fruitAvailable(string fruit, string type)
* useFruitInPotion(string fruit)
### [Enemy Tests](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java) including testing of the methods:
* TakeDamage()
* TakeDamageDie()
### [Settings Tests](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/player/SettingsTest.java) including testing of the methods:
* GetDif()
### [Food Tests](https://github.com/emmamickas/Text-Fighter/blob/AddingPotions/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java) including testing of the methods:
* UseInPotion()

## Additional Notes on Testing:Testing Brewing and Adding Potion
### Of the changed classes Chest.java, Game.java, Help.java, Stats.java were menu's and UI elements that utilized Potion methods.
### No additional testing was necessary for these classes.
1 change: 1 addition & 0 deletions src/com/hotmail/kalebmarc/textfighter/item/Chest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void view() {
Ui.println(" Potions: ");
Ui.println(" Survival: " + Potion.get("survival"));
Ui.println(" Recovery: " + Potion.get("recovery"));
Ui.println(" Poison: " + Potion.get("poison"));
Ui.println("Coins: " + Coins.get());
Ui.println("POWERS: " + Power.get());
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Expand Down
36 changes: 36 additions & 0 deletions src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.hotmail.kalebmarc.textfighter.main;

import static org.junit.Assert.*;

import org.junit.Test;

import com.hotmail.kalebmarc.textfighter.player.Potion;

public class EnemyTest {

@Test
public void testTakeDamage() {

Enemy darkElf = new Enemy("Dark Elf", 40, 10, 15, 10, 15, 15, 1, 100, true, false);
darkElf.arrayEnemy.add(darkElf);
darkElf.set(0);
Potion.set("poison", 1, true);
Potion.use("poison");
assertEquals(10, darkElf.getHealth());
}

@Test
/*Test is successful if lines Enemy<137,160> are commented out.
*These functions require more of the game to be initialized.
*EncounterNew() needs levels, xp, list of enemies to be initiated which doesn't involve potions.
*/
public void testTakeDamageDie() {

Enemy man = new Enemy("Dark Elf", 30, 10, 15, 10, 15, 15, 1, 100, true, false);
man.arrayEnemy.add(man);
man.set(0);
Potion.set("poison", 1, true);
Potion.use("poison");
assertEquals(0, man.getHealth());
}
}
12 changes: 11 additions & 1 deletion src/com/hotmail/kalebmarc/textfighter/main/Food.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.hotmail.kalebmarc.textfighter.main;

import com.hotmail.kalebmarc.textfighter.player.Health;

import java.io.*;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;

public class Food {
Expand Down Expand Up @@ -119,6 +120,15 @@ public void eat() {
}

}
public void useInPotion() {
Ui.cls();

Ui.println("You have used a " + getName() + " to brew a potion!");
if(this.quantity > 0) this.quantity--;
else {
Ui.println("You dont have enough " + getName() + "'s!");
}
}

public void viewAbout() {

Expand Down
30 changes: 30 additions & 0 deletions src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.hotmail.kalebmarc.textfighter.main;

import static org.junit.Assert.*;

import org.junit.Test;

import com.hotmail.kalebmarc.textfighter.player.Potion;

public class FoodTest {

@Test
public void testUseInPotion() {
//Reduces quantity of fruit if potion is brewed.
Food apple = new Food("Apple", "A boring 'ol apple.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5);
Food mushroom = new Food("Mushroom", "The good kind!", StatusEffect.type.HEALTH, Food.type.OTHER, 5);
assertEquals(1, apple.getQuantity() );
assertEquals(1, mushroom.getQuantity());
Potion.brewPotion("survival");
assertEquals(0, apple.getQuantity() );
assertEquals(0, mushroom.getQuantity());

Food orange = new Food("Orange", "Sort of like an apple, but orange.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5);
assertEquals(1, orange.getQuantity());
orange.useInPotion();
assertEquals(0, orange.getQuantity());
orange.useInPotion();
assertEquals(0, orange.getQuantity());
}

}
40 changes: 25 additions & 15 deletions src/com/hotmail/kalebmarc/textfighter/main/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public void start() {
Ui.println(" Potions: ");
Ui.println(" Survival: " + Potion.get("survival"));
Ui.println(" Recovery: " + Potion.get("recovery"));
Ui.println(" Poison: " + Potion.get("poison"));
Ui.println(" Equipped armour: " + Armour.getEquipped().toString());
Ui.println(" Equipped Weapon: " + Weapon.get().getName());
//Displays ammo only if a weapon is equipped
Expand Down Expand Up @@ -183,7 +184,8 @@ public void start() {
Ui.println("Which potion would you like to use?");
Ui.println("1) Survival Potion");
Ui.println("2) Recovery Potion");
Ui.println("3) Back");
Ui.println("3) Poison Potion");
Ui.println("4) Back");
switch (Ui.getValidInt()) {
case 1:
Potion.use("survival");
Expand All @@ -192,6 +194,9 @@ public void start() {
Potion.use("recovery");
break;
case 3:
Potion.use("poison");
break;
case 4:
break;
default:
break;
Expand Down Expand Up @@ -244,6 +249,7 @@ private static void town() {
Ui.println(" Potions: ");
Ui.println(" Survival: " + Potion.get("survival"));
Ui.println(" Recovery: " + Potion.get("recovery"));
Ui.println(" Poison: " + Potion.get("poison"));
Ui.println(" Equipped Weapon: " + Weapon.get().getName());
Ui.println("------------------------------------------------------------------");
Ui.println("1) Casino");
Expand Down Expand Up @@ -296,19 +302,20 @@ private static void home() {
Ui.println(" Health: " + getStr());
Ui.println(" Coins: " + Coins.get());
Ui.println(" First-Aid kits: " + FirstAid.get());
Ui.println(" Potions: " + (Potion.get("survival") + Potion.get("recovery")));
Ui.println(" Potions: " + (Potion.get("survival") + Potion.get("recovery") + Potion.get("poison") ));
Ui.println(" Equipped Weapon: " + Weapon.get().getName());
Ui.println("------------------------------------------------------------------");
Ui.println("1) Equip weapon");
Ui.println("2) Equip Armour");
Ui.println("3) View Item Chest");
Ui.println("4) Achievements");
Ui.println("5) Stats");
Ui.println("6) About");
Ui.println("7) Settings");
Ui.println("8) Help");
Ui.println("9) Credits");
Ui.println("10) Back");
Ui.println("4) Brew Potions");
Ui.println("5) Achievements");
Ui.println("6) Stats");
Ui.println("7) About");
Ui.println("8) Settings");
Ui.println("9) Help");
Ui.println("10) Credits");
Ui.println("11) Back");
Ui.println("------------------------------------------------------------------");

menuChoice = Ui.getValidInt();
Expand All @@ -324,25 +331,28 @@ private static void home() {
Chest.view();
break;
case 4:
Achievements.view();
Potion.choose();
break;
case 5:
Stats.view();
Achievements.view();
break;
case 6:
Stats.view();
break;
case 7:
About.view(true);
Achievements.viewedAbout = true;
break;
case 7:
case 8:
menu();
break;
case 8:
case 9:
Help.view();
break;
case 9:
case 10:
Credits.view();
break;
case 10:
case 11:
return;
default:
break;
Expand Down
3 changes: 3 additions & 0 deletions src/com/hotmail/kalebmarc/textfighter/main/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ private static void info_health() {
Ui.println("health up to 200. Each upgrade will cost 100 coins on easy, ");
Ui.println("and 150 coins on hard; and it will upgrade your health by 10.");
Ui.println("You will be able to upgrade once per level.");
Ui.println("Use potions to increase your health or decrease your enemies.");
Ui.println("Recovery and Survival potions will increase your health.");
Ui.println("Poison will deduct health points from your enemy.");
//TODO Add more health info
Ui.println("------------------------------------------------------------");
Ui.pause();
Expand Down
11 changes: 9 additions & 2 deletions src/com/hotmail/kalebmarc/textfighter/main/Saves.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static void save() {
set("Stats.Money_Spent.Interest", Stats.coinsSpentOnBankInterest);
set("Stats.Money_Spent.Weapons", Stats.coinsSpentOnWeapons);
set("Stats.Money_Spent.Health", Stats.coinsSpentOnHealth);
set("Stats.Money_Spent.Poison", Stats.coinsSpentOnPoison);
set("Stats.Money_Spent.XP", Stats.xpBought);
set("Stats.Blackjack_Games_Played", Stats.blackjackGamesPlayed);
set("Stats.Lottery_Tickets_Bought", Stats.lotteryTicketsBought);
Expand All @@ -77,9 +78,10 @@ public static void save() {
//Potions
set("Stats.Potions.Survival.Used", Potion.spUsed);
set("Stats.Potions.Recovery.Used", Potion.rpUsed);
set("Stats.Potions.Poison.Used", Potion.ppUsed);
set("User.Potions.Survival", Potion.get("survival"));
set("User.Potions.Recovery", Potion.get("recovery"));

set("User.Potions.Poison", Potion.get("poison"));
//Settings
set("Settings.Difficulty.Level", Settings.getDif());
set("Settings.Difficulty.Locked", Settings.difLocked);
Expand Down Expand Up @@ -216,6 +218,7 @@ public static boolean load() {
Stats.coinsSpentOnBankInterest = getInteger("Stats.Money_Spent.Interest");
Stats.coinsSpentOnWeapons = getInteger("Stats.Money_Spent.Weapons");
Stats.coinsSpentOnHealth = getInteger("Stats.Money_Spent.Health");
Stats.coinsSpentOnPoison = getInteger("Stats.Money_Spent.Poison");
Stats.xpBought = getInteger("Stats.Money_Spent.XP");
Stats.blackjackGamesPlayed = getInteger("Stats.Blackjack_Games_Played");
Stats.lotteryTicketsBought = getInteger("Stats.Lottery_Tickets_Bought");
Expand All @@ -233,9 +236,10 @@ public static boolean load() {
//Potions
Potion.spUsed = getInteger("Stats.Potions.Survival.Used");
Potion.rpUsed = getInteger("Stats.Potions.Recovery.Used");
Potion.ppUsed = getInteger("Stats.Potions.Poison.Used");
Potion.set("survival", getInteger("User.Potions.Survival"), false);
Potion.set("recovery", getInteger("User.Potions.Recovery"), false);

Potion.set("poison", getInteger("User.Potions.Poison"), false);
//Settings
Settings.setDif(getString("Settings.Difficulty.Level"), false, false);
Settings.difLocked = getBoolean("Settings.Difficulty.Locked");
Expand Down Expand Up @@ -427,6 +431,7 @@ public static boolean convert() {
Stats.coinsSpentOnBankInterest = readInt();
Stats.coinsSpentOnWeapons = readInt();
Stats.coinsSpentOnHealth = readInt();
Stats.coinsSpentOnPoison = readInt();
Stats.xpBought = readInt();
Loan.setCurrentLoan(readInt());
Loan.setNetDue(readInt());
Expand All @@ -441,8 +446,10 @@ public static boolean convert() {
//Potions
Potion.spUsed = readInt();
Potion.rpUsed = readInt();
Potion.ppUsed = readInt();
Potion.set("survival", readInt(), false);
Potion.set("recovery", readInt(), false);
Potion.set("poison", readInt(), false);


//Settings
Expand Down
17 changes: 13 additions & 4 deletions src/com/hotmail/kalebmarc/textfighter/main/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void menu() {
Ui.println();
Ui.println("Coins: " + Coins.get());
Ui.println("First-Aid kits: " + FirstAid.get());
Ui.println("Potions: " + (Potion.get("survival") + Potion.get("recovery")));
Ui.println("Potions: " + (Potion.get("survival") + Potion.get("recovery")+ Potion.get("poison")));
Ui.println();
Ui.println("-------------------------------------------------------------------");
Ui.println("1) Health");
Expand Down Expand Up @@ -84,11 +84,15 @@ private static void health() {
Ui.println(" Price - " + Potion.rpPrice + " coins");
Ui.println(" Level - " + Potion.rpLevel);
Ui.println();
Ui.println("4) INSTA-HEALTH");
Ui.println("4) POISON POTION");
Ui.println(" Price - " + Potion.ppPrice + " coins");
Ui.println(" Level - " + Potion.ppLevel);
Ui.println();
Ui.println("5) INSTA-HEALTH");
Ui.println(" Price - " + InstaHealth.price + " coins");
Ui.println(" Level - " + InstaHealth.level);
Ui.println();
Ui.println("5) Back");
Ui.println("6) Back");
Ui.println("-------------------------------------------------------------------");
switch (Ui.getValidInt()) {
case 1:
Expand All @@ -108,10 +112,15 @@ private static void health() {
break;
case 4:
Ui.cls();
InstaHealth.buy();
Potion.buy("poison");
NPC.gratitude("Health", "purchase");
break;
case 5:
Ui.cls();
InstaHealth.buy();
NPC.gratitude("Health", "purchase");
break;
case 6:
return;
default:
break;
Expand Down
Loading