@@ -6,8 +6,7 @@ public class Game {
6
6
private ArrayList <ArrayList <Integer >> graph ;
7
7
private HashMap <Integer , Monster > Monster_map ;
8
8
private int visited [];
9
- private static java .util .Scanner s = new java .util .Scanner (System .in );
10
- ;
9
+ private static java .util .Scanner s = new java .util .Scanner (System .in );;
11
10
12
11
public Game () {
13
12
Hero_list = new ArrayList <>();
@@ -26,14 +25,14 @@ public static void menu_display() {
26
25
27
26
public void New_User () {
28
27
System .out .println ("Enter Username" );
29
- //s.nextLine();
28
+ // s.nextLine();
30
29
String name = s .nextLine ();
31
30
System .out .println ("Choose Class" );
32
31
System .out .println ("1) Warrior" );
33
32
System .out .println ("2) Thief" );
34
33
System .out .println ("3) Mage" );
35
34
System .out .println ("4) Healer" );
36
- int choice = s . nextInt ( );
35
+ int choice = Integer . parseInt ( s . nextLine () );
37
36
switch (choice ) {
38
37
case 1 :
39
38
Hero_list .add (new Warrior (name ));
@@ -47,6 +46,8 @@ public void New_User() {
47
46
case 4 :
48
47
Hero_list .add (new Healer (name ));
49
48
break ;
49
+ default :
50
+ System .out .println ("give correct input" );
50
51
}
51
52
System .out .println ("User Creation done. Log in to play game . Exiting" );
52
53
}
@@ -104,7 +105,7 @@ public void load_graph() {
104
105
}
105
106
106
107
public int choose_path (int start_pos ) {
107
- System .out .println ("You are at location " + start_pos + " Choose path: " );
108
+ System .out .println ("You are at location " + start_pos + " Choose path: " );
108
109
int count = 1 ;
109
110
int flag = 1 ;
110
111
int temp_i = 10 ;
@@ -125,11 +126,11 @@ public int choose_path(int start_pos) {
125
126
choice_find .put (count , temp_i );
126
127
}
127
128
System .out .println ("Enter -1 to exit" );
128
- int choice = s . nextInt ( );
129
+ int choice = Integer . parseInt ( s . nextLine () );
129
130
if (choice != count ) {
130
131
visited [start_pos ] = 1 ;
131
132
}
132
- if (choice == -1 ){
133
+ if (choice == -1 ) {
133
134
return -1 ;
134
135
}
135
136
return choice_find .get (choice );
@@ -148,21 +149,23 @@ public int fight(Hero hero, Monster monster) {
148
149
if (move_count >= 4 && hero .getSpecial_move_count () == move_count ) {
149
150
System .out .println ("3)Special Attack" );
150
151
}
151
- int choice = s . nextInt ( );
152
+ int choice = Integer . parseInt ( s . nextLine () );
152
153
if (choice != 3 && move_count >= 4 && hero .getSpecial_move_count () == move_count ) {
153
154
hero .setSpecial_move_count (hero .getSpecial_move_count () + 1 );
154
- } else if (choice == 3 ) {
155
+ } else if (choice == 3 ) {
155
156
hero .setSpecial_move_count (hero .getSpecial_move_count () + 4 );
156
157
}
157
158
if (hero .getSpecial_power () == 0 ) {
158
159
if (choice == 1 ) {
159
160
System .out .println ("You choose to attack" );
160
161
monster .setHp (monster .getHp () - hero .getAttack ());
161
- System .out .println ("Your Hp: " +hero .getHp ()+"/" +hero .getHp_limit ()+"Monsters Hp :" +monster .getHp ()+"/" +monster .getHp_limit ());
162
+ System .out .println ("Your Hp: " + hero .getHp () + "/" + hero .getHp_limit () + "Monsters Hp :"
163
+ + monster .getHp () + "/" + monster .getHp_limit ());
162
164
} else if (choice == 2 ) {
163
165
System .out .println ("You choose to defend" );
164
166
def = hero .getDefense ();
165
- System .out .println ("Your Hp: " +hero .getHp ()+"/" +hero .getHp_limit ()+"Monsters Hp :" +monster .getHp ()+"/" +monster .getHp_limit ());
167
+ System .out .println ("Your Hp: " + hero .getHp () + "/" + hero .getHp_limit () + "Monsters Hp :"
168
+ + monster .getHp () + "/" + monster .getHp_limit ());
166
169
} else if (choice == 3 ) {
167
170
special_power_count = move_count ;
168
171
System .out .println ("Special power activated" );
@@ -191,7 +194,8 @@ public int fight(Hero hero, Monster monster) {
191
194
}
192
195
System .out .println ("Monster attack!" );
193
196
hero .setHp (hero .getHp () - damage );
194
- System .out .println ("Your Hp: " +hero .getHp ()+"/" +hero .getHp_limit ()+"Monsters Hp :" +monster .getHp ()+"/" +monster .getHp_limit ());
197
+ System .out .println ("Your Hp: " + hero .getHp () + "/" + hero .getHp_limit () + "Monsters Hp :" + monster .getHp ()
198
+ + "/" + monster .getHp_limit ());
195
199
196
200
if (hero .getHp () <= 0 ) {
197
201
monster .respawn ();
@@ -202,30 +206,32 @@ public int fight(Hero hero, Monster monster) {
202
206
return 0 ;
203
207
}
204
208
205
- public void Load_game (Hero hero ){
209
+ public void Load_game (Hero hero ) {
206
210
load_graph ();
207
- int flag =1 ;
208
- int init_pos =10 ;
209
- while (init_pos !=-1 ) {
210
- flag =1 ;init_pos =10 ;
211
+ int flag = 1 ;
212
+ int init_pos = 10 ;
213
+ while (init_pos != -1 ) {
214
+ flag = 1 ;
215
+ init_pos = 10 ;
211
216
while (flag == 1 ) {
212
217
init_pos = choose_path (init_pos );
213
- if (init_pos == -1 ){
218
+ if (init_pos == -1 ) {
214
219
break ;
215
220
}
216
221
visited [init_pos ] = 0 ;
217
222
if (init_pos != 10 ) {
218
223
int result = fight (hero , Monster_map .get (init_pos ));
219
224
if (result == 0 ) {
220
225
System .out .println ("You have died start over" );
221
- flag = 0 ;
226
+ flag = 0 ;
222
227
} else {
223
228
System .out .println ("Fight won proceed to next location" );
224
229
}
225
230
}
226
231
}
227
232
}
228
233
}
234
+
229
235
public void Existing_User (String name ) {
230
236
for (Hero i : Hero_list ) {
231
237
if (i .getUsername ().equals (name )) {
0 commit comments