Skip to content

Commit

Permalink
Merge pull request #127 from emmamickas/AddConstantArraylistAccessMod…
Browse files Browse the repository at this point in the history
…ifiers

Add constant arraylist access modifiers
  • Loading branch information
hhaslam11 authored Oct 22, 2021
2 parents 0a87d50 + a70ddb8 commit 555f731
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 95 deletions.
16 changes: 8 additions & 8 deletions src/com/hotmail/kalebmarc/textfighter/item/Chest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ public static void view() {
Ui.println(" Recovery: " + Potion.get("recovery"));
Ui.println("Coins: " + Coins.get());
Ui.println("POWERS: " + Power.get());
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
if (Weapon.arrayWeapon.get(i).owns()) {
Ui.println(Weapon.arrayWeapon.get(i).getName());
if (!Weapon.arrayWeapon.get(i).melee)
Ui.println(" (Ammo: " + Weapon.arrayWeapon.get(i).getAmmo() + ")");
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
if (Weapon.getWeapons().get(i).owns()) {
Ui.println(Weapon.getWeapons().get(i).getName());
if (!Weapon.getWeapons().get(i).melee)
Ui.println(" (Ammo: " + Weapon.getWeapons().get(i).getAmmo() + ")");
}
}
for (int i = 1; i < Armour.getArmours().size(); i++) {
if (Armour.getArmours().get(i).isOwns()) {
Ui.println(Armour.getArmours().get(i).toString());
}
}
for (int i = 0; i < Food.arrayFood.size(); i++) {
if (Food.arrayFood.get(i).getQuantity() > 0)
Ui.println(Food.arrayFood.get(i).getName() + "(x" + Food.arrayFood.get(i).getQuantity() + ")");
for (int i = 0; i < Food.getFoods().size(); i++) {
if (Food.getFoods().get(i).getQuantity() > 0)
Ui.println(Food.getFoods().get(i).getName() + "(x" + Food.getFoods().get(i).getQuantity() + ")");
}
Ui.println();
Ui.println("------------------------------");
Expand Down
28 changes: 14 additions & 14 deletions src/com/hotmail/kalebmarc/textfighter/main/Cheats.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ private static void cheatSelect() {
Coins.set(5000, false);
FirstAid.set(5000, false);
InstaHealth.set(5000, false);
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).setAmmo(5000, false);
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).setAmmo(5000, false);
}
Power.set(5000, false);
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).owns = true;
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).owns = true;
}
Stats.timesCheated++;
for (int i = 0; i < Food.arrayFood.size(); i++)
Food.arrayFood.get(i).setQuantity(5000);
for (int i = 0; i < Food.getFoods().size(); i++)
Food.getFoods().get(i).setQuantity(5000);
Potion.set("Survival", 5000, false);
Potion.set("Recovery", 5000, false);
break;
case "weaponstash":
for (int i = 0; i <= Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).setAmmo(5000, false);
for (int i = 0; i <= Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).setAmmo(5000, false);
}

Power.set(5000, false);
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).owns = true;
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).owns = true;
}
Stats.timesCheated++;
break;
Expand All @@ -73,8 +73,8 @@ private static void cheatSelect() {
InstaHealth.set(500, false);
Potion.set("Survival", 500, false);
Potion.set("Recovery", 500, false);
for (int i = 0; i < Food.arrayFood.size(); i++)
Food.arrayFood.get(i).setQuantity(100);
for (int i = 0; i < Food.getFoods().size(); i++)
Food.getFoods().get(i).setQuantity(100);
Stats.timesCheated++;
break;
case "healme":
Expand Down Expand Up @@ -103,8 +103,8 @@ private static void cheatSelect() {
Stats.timesCheated++;
break;
case "thirstforfood":
for (int i = 0; i < Food.arrayFood.size(); i++)
Food.arrayFood.get(i).setQuantity(10);
for (int i = 0; i < Food.getFoods().size(); i++)
Food.getFoods().get(i).setQuantity(10);
Stats.timesCheated++;
break;

Expand Down
14 changes: 7 additions & 7 deletions src/com/hotmail/kalebmarc/textfighter/main/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public static void menu() {
Xp.set(Ui.getValidInt(), false);
break;
case 3:
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).owns = true;
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).owns = true;
}
Power.set(100, true);
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).setAmmo(10000, false);
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).setAmmo(10000, false);
}
Ui.println("You now have all weapons");
Ui.pause();
Expand All @@ -84,10 +84,10 @@ public static void menu() {
break;
case 8:
Ui.cls();
for (int i = 0; i < Food.arrayFood.size(); i++) {
Ui.println(i + ") " + Food.arrayFood.get(i).getName());
for (int i = 0; i < Food.getFoods().size(); i++) {
Ui.println(i + ") " + Food.getFoods().get(i).getName());
}
Food.arrayFood.get(Ui.getValidInt()).setQuantity(10);
Food.getFoods().get(Ui.getValidInt()).setQuantity(10);
break;
case 9:
return;
Expand Down
11 changes: 8 additions & 3 deletions src/com/hotmail/kalebmarc/textfighter/main/Enemy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hotmail.kalebmarc.textfighter.main;

import com.hotmail.kalebmarc.textfighter.item.Armour;
import com.hotmail.kalebmarc.textfighter.player.*;

import javax.swing.*;
Expand Down Expand Up @@ -72,6 +73,10 @@ public static void set(int i) {
current = arrayEnemy.get(i);
}

public static ArrayList<Enemy> getEnemies() {
return arrayEnemy;
}

public static Enemy get() {
return current;
}
Expand All @@ -84,9 +89,9 @@ public static void findEnemy() {
int playerLevel = Xp.getLevel();
ArrayList<Enemy> suitableEnemies = new ArrayList<>();

for (int i = 0; i < arrayEnemy.size(); i++) {
if (arrayEnemy.get(i).levelMin <= playerLevel && playerLevel <= arrayEnemy.get(i).levelMax) {
suitableEnemies.add(arrayEnemy.get(i));
for (int i = 0; i < getEnemies().size(); i++) {
if (getEnemies().get(i).levelMin <= playerLevel && playerLevel <= getEnemies().get(i).levelMax) {
suitableEnemies.add(getEnemies().get(i));
}
}
current = suitableEnemies.get(Random.RInt(0, suitableEnemies.size() -1));
Expand Down
19 changes: 12 additions & 7 deletions src/com/hotmail/kalebmarc/textfighter/main/Food.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hotmail.kalebmarc.textfighter.main;

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

import java.util.ArrayList;
Expand Down Expand Up @@ -32,10 +33,10 @@ public static void list() {
while (true) {
Ui.cls();
int j = 0;
int[] offset = new int[arrayFood.size()];
for (int i = 0; i < arrayFood.size(); i++) {
if (arrayFood.get(i).quantity > 0) {
Ui.println((j + 1) + ") " + arrayFood.get(i).getName() + "(" + arrayFood.get(i).quantity + ")");
int[] offset = new int[getFoods().size()];
for (int i = 0; i < getFoods().size(); i++) {
if (getFoods().get(i).quantity > 0) {
Ui.println((j + 1) + ") " + getFoods().get(i).getName() + "(" + getFoods().get(i).quantity + ")");
offset[j] = i - j;
j++;
}
Expand All @@ -57,14 +58,14 @@ public static void list() {

//TODO once more status effects are implemented, use a switch here if appropriate.
//Testing to make sure the option is valid goes here:
if (arrayFood.get(menuItem).getStatusEffect() == StatusEffect.type.HEALTH && Health.get() == Health.getOutOf()) {
if (getFoods().get(menuItem).getStatusEffect() == StatusEffect.type.HEALTH && Health.get() == Health.getOutOf()) {
Ui.msg("Your health is already full. No need to eat this!");
return;
}

//Results go here:
if (arrayFood.get(menuItem).quantity > 0) {
Food.arrayFood.get(menuItem).eat();
if (getFoods().get(menuItem).quantity > 0) {
Food.getFoods().get(menuItem).eat();
}
return;

Expand All @@ -76,6 +77,10 @@ public static void list() {
}
}

public static ArrayList<Food> getFoods() {
return arrayFood;
}

public String getName() {
return this.name;
}
Expand Down
38 changes: 19 additions & 19 deletions src/com/hotmail/kalebmarc/textfighter/main/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ private static void info_enemy() {
Ui.println(" ENEMY INFO ");
Ui.println("Which enemy would you like to know about?");
Ui.println();
for (int i = 0; i < Enemy.arrayEnemy.size(); i++) {
Ui.println((i + 1) + ") " + Enemy.arrayEnemy.get(i).getName());
for (int i = 0; i < Enemy.getEnemies().size(); i++) {
Ui.println((i + 1) + ") " + Enemy.getEnemies().get(i).getName());
}
Ui.println((Enemy.arrayEnemy.size() + 1) + ") Back");
Ui.println((Enemy.getEnemies().size() + 1) + ") Back");
Ui.println("------------------------------------------------------------");

int menuItem = Ui.getValidInt();

try {
Enemy.arrayEnemy.get(menuItem - 1).viewAbout();
Enemy.getEnemies().get(menuItem - 1).viewAbout();
} catch (Exception e) {
if (menuItem == (Enemy.arrayEnemy.size() + 1)) return;
if (menuItem == (Enemy.getEnemies().size() + 1)) return;
Ui.println(menuItem + " is not an option.");
Ui.pause();
}
Expand Down Expand Up @@ -115,18 +115,18 @@ private static void info_weapons() {
Ui.println(" WEAPON INFO ");
Ui.println("Which weapon would you like to know about?");
Ui.println();
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Ui.println((i + 1) + ") " + Weapon.arrayWeapon.get(i).getName());
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Ui.println((i + 1) + ") " + Weapon.getWeapons().get(i).getName());
}
Ui.println((Weapon.arrayWeapon.size() + 1) + ") Back");
Ui.println((Weapon.getWeapons().size() + 1) + ") Back");
Ui.println("------------------------------------------------------------");

int menuItem = Ui.getValidInt();

try {
Weapon.arrayWeapon.get(menuItem - 1).viewAbout();
Weapon.getWeapons().get(menuItem - 1).viewAbout();
} catch (Exception e) {
if (menuItem == (Weapon.arrayWeapon.size() + 1)) return;
if (menuItem == (Weapon.getWeapons().size() + 1)) return;
Ui.println(menuItem + " is not an option.");
Ui.pause();
}
Expand Down Expand Up @@ -176,18 +176,18 @@ private static void info_food() {
Ui.println(" FOOD INFO ");
Ui.println("Which food would you like to know about?");
Ui.println();
for (int i = 0; i < Food.arrayFood.size(); i++) {
Ui.println((i + 1) + ") " + Food.arrayFood.get(i).getName());
for (int i = 0; i < Food.getFoods().size(); i++) {
Ui.println((i + 1) + ") " + Food.getFoods().get(i).getName());
}
Ui.println((Food.arrayFood.size() + 1) + ") Back");
Ui.println((Food.getFoods().size() + 1) + ") Back");
Ui.println("------------------------------------------------------------");

int menuItem = Ui.getValidInt();

try {
Food.arrayFood.get(menuItem - 1).viewAbout();
Food.getFoods().get(menuItem - 1).viewAbout();
} catch (Exception e) {
if (menuItem == (Food.arrayFood.size() + 1)) return;
if (menuItem == (Food.getFoods().size() + 1)) return;
Ui.println(menuItem + " is not an option.");
Ui.pause();
}
Expand Down Expand Up @@ -266,10 +266,10 @@ private static void info_achs() {
Ui.println(" Enemy Slayer | Kill a total of 100 enemies");
Ui.println(" First Kill | Kill one enemy");
Ui.println(" Time For An Upgrade | Buy any weapon from the shop");
for (int i = 0; i < Enemy.arrayEnemy.size(); i++) {
Ui.print(" Goodbye, " + Enemy.arrayEnemy.get(i).getName());
for (int x = 0; x < (14 - Enemy.arrayEnemy.get(i).getName().length()); x++) Ui.print(" ");
Ui.println("| Kill a " + Enemy.arrayEnemy.get(i).getName());
for (int i = 0; i < Enemy.getEnemies().size(); i++) {
Ui.print(" Goodbye, " + Enemy.getEnemies().get(i).getName());
for (int x = 0; x < (14 - Enemy.getEnemies().get(i).getName().length()); x++) Ui.print(" ");
Ui.println("| Kill a " + Enemy.getEnemies().get(i).getName());

}
Ui.println(" Text-Fighter Master | Get all other achievements");
Expand Down
34 changes: 17 additions & 17 deletions src/com/hotmail/kalebmarc/textfighter/main/Saves.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ public static void save() {
set("Stats.Kills", Stats.kills);
set("Stats.Total_Kills", Stats.totalKills);
set("Stats.High_Score", Stats.highScore);
set("User.Weapons.Current", Weapon.arrayWeapon.indexOf(Weapon.get()));
set("User.Weapons.Current", Weapon.getWeapons().indexOf(Weapon.get()));


for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
if (Weapon.arrayWeapon.get(i).owns()) {
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
if (Weapon.getWeapons().get(i).owns()) {
set(("User.Weapons." + i), true);
} else {
set(("User.Weapons." + i), false);
}
set(("User.Weapons.Ammo." + i), Weapon.arrayWeapon.get(i).getAmmo());
set(("User.Weapons.Ammo." + i), Weapon.getWeapons().get(i).getAmmo());
}


Expand All @@ -120,7 +120,7 @@ public static void save() {
set("User.Armour.Current", Armour.get());

//Enemy
set("Battle.Current.Enemy", Enemy.arrayEnemy.indexOf(Enemy.get()));
set("Battle.Current.Enemy", Enemy.getEnemies().indexOf(Enemy.get()));
set("Battle.Current.Enemy_Health", Enemy.get().getHealth());
set("Battle.Current.Enemy_Max_Health", Enemy.get().getHealthMax());
set("Battle.Current.Enemy_First_Aid_Kit", Enemy.get().getFirstAidKit());
Expand All @@ -133,9 +133,9 @@ public static void save() {

List<String> enemiesKilled = new ArrayList<>();

for (int i = 0; i < Enemy.arrayEnemy.size(); i++)
for (int i = 0; i < Enemy.getEnemies().size(); i++)
if (Achievements.arrayKilled.get(i))
enemiesKilled.add(Enemy.arrayEnemy.get(i).getName());
enemiesKilled.add(Enemy.getEnemies().get(i).getName());
set("Achievements.Enemies_Killed", enemiesKilled);
set("Achievements.Text_Fighter_Master", Achievements.textFighterMaster);
set("Achievements.YAY_POWER", Achievements.YAYPOWER);
Expand Down Expand Up @@ -249,11 +249,11 @@ public static boolean load() {
Stats.totalKills = getInteger("Stats.Total_Kills");
Weapon.set(getInteger("User.Weapons.Current"));

for(int i = 0; i < Weapon.arrayWeapon.size(); i++){
for(int i = 0; i < Weapon.getWeapons().size(); i++){
if (getBoolean("User.Weapons." + i)){
Weapon.arrayWeapon.get(i).owns = true;
Weapon.getWeapons().get(i).owns = true;
}
Weapon.arrayWeapon.get(i).setAmmo(getInteger("User.Weapons.Ammo." + i), false);
Weapon.getWeapons().get(i).setAmmo(getInteger("User.Weapons.Ammo." + i), false);
}

Power.set(getInteger("User.Power"), false);
Expand Down Expand Up @@ -283,8 +283,8 @@ public static boolean load() {
List<String> achSet = (List<String>) getList("Achievements.Enemies_Killed");

for (int i = 0; i < achSet.size(); i++){
for (int x = 0; x < Enemy.arrayEnemy.size(); x++){
if(Enemy.arrayEnemy.get(x).getName().equals(achSet.get(i))){
for (int x = 0; x < Enemy.getEnemies().size(); x++){
if(Enemy.getEnemies().get(x).getName().equals(achSet.get(i))){
Achievements.arrayKilled.set(x, true);
}
}
Expand Down Expand Up @@ -457,10 +457,10 @@ public static boolean convert() {
Stats.highScore = readInt();
Stats.totalKills = readInt();
Weapon.set(readInt());
for (int i = 0; i < Weapon.arrayWeapon.size(); i++)
Weapon.arrayWeapon.get(i).owns = readBoolean();
for (int i = 0; i < Weapon.arrayWeapon.size(); i++)
Weapon.arrayWeapon.get(i).setAmmo(readInt(), false);
for (int i = 0; i < Weapon.getWeapons().size(); i++)
Weapon.getWeapons().get(i).owns = readBoolean();
for (int i = 0; i < Weapon.getWeapons().size(); i++)
Weapon.getWeapons().get(i).setAmmo(readInt(), false);
Power.set(readInt(), false);
Power.used = readInt();
Stats.totalDamageDealt = readInt();
Expand All @@ -479,7 +479,7 @@ public static boolean convert() {
Achievements.enemySlayer = readBoolean();
Achievements.firstKill = readBoolean();
Achievements.timeForAnUpgrade = readBoolean();
for (int i = 0; i < Enemy.arrayEnemy.size(); i++)
for (int i = 0; i < Enemy.getEnemies().size(); i++)
Achievements.arrayKilled.set(i, readBoolean());
Achievements.textFighterMaster = readBoolean();
Achievements.YAYPOWER = readBoolean();
Expand Down
Loading

0 comments on commit 555f731

Please sign in to comment.