Skip to content

Commit

Permalink
completely (i hope) fixed weapon shop issue & equip weapon issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaslam11 committed Jul 27, 2016
1 parent 0451c98 commit 796bb26
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
8 changes: 7 additions & 1 deletion src/com/hotmail/kalebmarc/textfighter/main/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ public class NPC {

private static String name;
private static String shop;


private static final String NAME_HEALTH = "Corinna";
private static final String NAME_WEAPON = "Niel";
private static final String NAME_XP = "Halette";
private static final String NAME_ARMOUR = "Leon";


public NPC(){}

public static String getName(String type){
Expand Down
29 changes: 10 additions & 19 deletions src/com/hotmail/kalebmarc/textfighter/main/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,12 @@ private static void weapons(){
Ui.println("Level: " + Xp.getLevel());
Ui.println();
Ui.println("-------------------------------------------------------------------");
int buyableWeaponIndex = 0; //Basically i, except only increments when arrayWeapon[i] is buyable.
// Prevents menu from counting like : 2, 3, 5, 6, 7, 8...
ArrayList<Weapon> buyableWeapons = new ArrayList<Weapon>();
for(int i = 0; i < Weapon.arrayWeapon.size(); i++){
if(Weapon.arrayWeapon.get(i).isBuyable()){
Ui.println((buyableWeaponIndex + 1) + ") " + Weapon.arrayWeapon.get(i).getName());
Ui.println((buyableWeapons.size() + 1) + ") " + Weapon.arrayWeapon.get(i).getName());
Ui.println(" Price: " + Weapon.arrayWeapon.get(i).price);
Ui.println(" Level: " + Weapon.arrayWeapon.get(i).level);
buyableWeaponIndex++;
buyableWeapons.add(Weapon.arrayWeapon.get(i));
Ui.println();
}
Expand Down Expand Up @@ -258,39 +255,33 @@ private static void buyAmmo(){
Ui.println("Level: " + Xp.getLevel());
Ui.println();
Ui.println("-------------------------------------------------------------------");
int j = 0;
int[] ammoShopOffset = new int[Weapon.arrayWeapon.size()];
ArrayList<Weapon> validWeapons = new ArrayList<Weapon>();
for(int i = 0; i < Weapon.arrayWeapon.size(); i++){
if(!Weapon.arrayWeapon.get(i).melee){
Ui.println((j + 1) + ") " + Weapon.arrayWeapon.get(i).getName());
if(Weapon.arrayWeapon.get(i).isBuyable() && !Weapon.arrayWeapon.get(i).melee && Weapon.arrayWeapon.get(i).owns()){
Ui.println((validWeapons.size() + 1) + ") " + Weapon.arrayWeapon.get(i).getName());
Ui.println(" Price: " + Weapon.arrayWeapon.get(i).getAmmoPrice());
Ui.println(" Level: " + Weapon.arrayWeapon.get(i).level);
ammoShopOffset[j] = i - j;
j++;
Ui.println();
validWeapons.add(Weapon.arrayWeapon.get(i));
}
}
Ui.println((j + 1) + ") Back");
Ui.println((validWeapons.size() + 1) + ") Back");

while(true) {//Make it easy to break, without going back to main store menu

int menuItem = Action.getValidInt();

try { //This is probably pretty bad practice. Using exceptions as a functional part of the program.. Use variables!

menuItem = menuItem + ammoShopOffset[menuItem - 1]; //Reverts back to weapon indexing
Weapon.arrayWeapon.get(menuItem - 1).buyAmmo();
validWeapons.get(menuItem - 1).buyAmmo();
NPC.gratitude("Weapon", "purchase");
break;

} catch (Exception e) {

if (menuItem == (j + 1)) {
if (menuItem == (validWeapons.size() + 1)) {
return;
}
Ui.println();
Ui.println(menuItem + " is not an option.");
Action.pause();
Action.cls();
}
}
}
Expand Down
41 changes: 18 additions & 23 deletions src/com/hotmail/kalebmarc/textfighter/main/Weapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,35 +121,30 @@ public static void choose(){
Ui.println("Ammo: " + current.getAmmo());
Ui.println("Equipped weapon: " + current.getName());
Ui.println("----------------------------");
int j = 0;
int[] offset = new int[arrayWeapon.size()];
for(int i = 0; i < arrayWeapon.size(); i++){
if(arrayWeapon.get(i).owns()){
Ui.println((j + 1) + ") " + arrayWeapon.get(i).getName());
offset[j] = i - j;
j++;
}
ArrayList<Weapon> validWeapons = new ArrayList<Weapon>();
for(int i = 0; i < Weapon.arrayWeapon.size(); i++){
if(Weapon.arrayWeapon.get(i).owns()){
Ui.println((validWeapons.size() + 1) + ") " + Weapon.arrayWeapon.get(i).getName());
validWeapons.add(Weapon.arrayWeapon.get(i));
}
}

//Get valid weapon index
int choice = 0;
do{
choice = Action.getValidInt() - 1 + offset[choice];
}while(choice < 0 || choice > arrayWeapon.size());
int menuItem = Action.getValidInt();

//Equip if player has the selected weapon
if(arrayWeapon.get(choice).owns()){
current = arrayWeapon.get(choice);
Action.cls();
Ui.println("You have equipped a " + arrayWeapon.get(choice).getName());
Action.pause();
return;
}else{
try { //This is probably pretty bad practice. Using exceptions as a functional part of the program.. Use variables!
current = validWeapons.get(menuItem - 1);
Action.cls();
Ui.println("You don't have this weapon.");
Ui.println("You have equipped a " + current.getName());
Action.pause();
}
break;
} catch (Exception e) {

if (menuItem == (validWeapons.size() + 1)) {
return;
}
Ui.println();
Ui.println(menuItem + " is not an option.");
}
}
}
public void dealDam(){
Expand Down

0 comments on commit 796bb26

Please sign in to comment.