-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainclass.java
More file actions
133 lines (125 loc) · 3.75 KB
/
Mainclass.java
File metadata and controls
133 lines (125 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package game;
import java.util.Scanner;
import java.util.Random;
public class Mainclass {
public static Player player = new Player("No Name", 100, 1, null, null, null, null, null, null);
public static Random randGen = new Random();
public static String itemOnFloor;
private static String commandList = "Available commands: attack, help, check inventory, equip, craft, pickup, wait, exit";
public static Creature encounterCreature;
public static void main(String[] args) {
System.out.println(commandList);
validIDs.validateItems();
gameLoop();
}
public static String peekInv() {
@SuppressWarnings("resource")
Scanner userIn = new Scanner(System.in);
System.out.print("Inv Slot: ");
String choice = userIn.nextLine();
return player.getSpecificInv(choice);
}
public static void chanceCalc() {
int chance = randGen.nextInt(11);
if (chance >= 7) {
int randItemID = randGen.nextInt(validIDs.findableItems.size() + 1);
itemOnFloor = validIDs.lookupFindableID(randItemID);
} else if (chance <= 4) {
encounterCreature = Creature.generateRandomCreature();
System.out.println("A creature approaches!" + " " + encounterCreature.name);
} else {
itemOnFloor = null;
encounterCreature = null;
}
}
public static void gameLoop() {
@SuppressWarnings("resource")
Scanner userInput = new Scanner(System.in);
chanceCalc();
if (itemOnFloor == null) {
System.out.print(">>> ");
} else {
System.out.println("There is a " + itemOnFloor + " on the floor.");
System.out.print(">>> ");
}
String act = userInput.nextLine();
actionParse(act);
gameLoop();
}
public static void crafting(String[] splitString) {
try {
String strItem = splitString[1].toLowerCase() + "_" + splitString[2].toLowerCase();
if (Player.isCraftable(strItem)) {
Item item = Item.stringToItem(strItem);
Item[] currentRecipe = item.recipe;
try {
for (int i = 0; i < currentRecipe.length; i++) {
Player.removeFromInv(currentRecipe[i]);
}
Player.inv.add(item);
} catch (Exception e) {
System.out.println(e);
}
}
} catch (Exception ArrayIndexOutOfBoundsException) {
String strItem = splitString[1].toLowerCase();
Player.isCraftable(strItem);
}
}
public static void actionParse(String action) {
action = action.toLowerCase();
String[] splitString = action.split(" ");
switch(splitString[0]) {
case "craft":
try {
if (Player.inv != null) {
crafting(splitString);
} else {
System.out.println("Your Inventory is Empty!");
}
} catch (Exception ArrayIndexOutOfBounds) {
System.out.println("Type out the name of what you want to craft.");
}
break;
case "equip":
try {
String sanitize = new String();
sanitize = Item.displayNameToItemName(splitString[1] + " " + splitString[2]);
Item itemToEquip = Item.stringToItem(sanitize);
player.equipInHand(itemToEquip);
} catch (Exception ArrayIndexOutOfBoundsException) {
System.out.println("Type out the name of what you want to equip.");
}
break;
case "attack":
if (encounterCreature != null) {
CombatPhase.phaseLoop(encounterCreature, player);
}
break;
case "help":
System.out.println(commandList);
break;
case "check":
player.getInventory();
break;
case "pickup":
if (itemOnFloor != null) {
player.storeInInv(itemOnFloor);
itemOnFloor = null;
} else {
System.out.println("There's nothing there...");
itemOnFloor = null;
}
break;
case "wait":
break;
case "w":
break;
case "exit":
System.exit(0);
break;
default:
System.out.println("Error...");
}
}
}