-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandParser.java
More file actions
137 lines (113 loc) · 3.42 KB
/
CommandParser.java
File metadata and controls
137 lines (113 loc) · 3.42 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
134
135
136
137
import java.util.*;
import java.io.*;
class CommandParser{
private PokemonFarm pokemonFarm;
private Scanner commandScanner;
private boolean isRunning;
private String pokemonName;
private String pokemonType;
private float pokemonWeight;
private float pokemonStepLength;
private Forest forest;
private Bag bag;
public CommandParser(PokemonFarm pokemonFarm){
this.pokemonFarm = pokemonFarm;
commandScanner = new Scanner(System.in);
isRunning = false;
}
public void run(){
isRunning = true;
String command;
System.out.println("Hello Pokemon Game");
while(isRunning){
System.out.print("\nWhat do you want? Type: ");
command = commandScanner.next();
if(command.equals("quit")){
isRunning = false;
System.out.println("Good bye, See you next time.");
}
else if(command.equals("add"))
this.addPokemon();
else if(command.equals("list"))
this.listPokemons();
else if(command.equals("feed"))
this.feedPokemons();
else if(command.equals("walk"))
this.walkPokemons();
else if(command.equals("remove"))
this.removePokemon();
else if(command.equals("forest"))
this.goForest();
}
}
private void addPokemon(){
commandScanner.nextLine();
System.out.print("Enter Type: ");
pokemonType = commandScanner.nextLine();
System.out.print("Name: ");
pokemonName = commandScanner.nextLine();
if(pokemonType.equals("Vulpix")){
Vulpix vulpix = new Vulpix(pokemonName);
pokemonFarm.addPokemon(vulpix);
}
if(pokemonType.equals("Pikachu")){
Pikachu pikachu = new Pikachu(pokemonName);
pokemonFarm.addPokemon(pikachu);
}
if(pokemonType.equals("Swinub")){
Swinub swinub = new Swinub(pokemonName);
pokemonFarm.addPokemon(swinub);
}
}
private void listPokemons(){
System.out.println("=============================================");
System.out.println("Pokemon list");
System.out.println("=============================================");
this.pokemonFarm.list();
System.out.println("=============================================");
}
private void feedPokemons(){
System.out.print("Which pokemon do you want to feed? ");
pokemonName = this.commandScanner.next();
if(pokemonName.equals("all")){
this.pokemonFarm.feed("all");
}
else
this.pokemonFarm.feed(pokemonName);
}
private void walkPokemons(){
System.out.print("Which pokemon do you want to promenade? ");
pokemonName = this.commandScanner.next();
System.out.print("How many step? ");
int step = this.commandScanner.nextInt();
if(pokemonName.equals("all"))
this.pokemonFarm.walk("all", step);
else
this.pokemonFarm.walk(pokemonName, step);
}
private void removePokemon(){
System.out.print("Which pokemon do you want to remove? ");
pokemonName = this.commandScanner.next();
this.pokemonFarm.remove(pokemonName);
}
private void goForest(){
bag = new Bag();
forest = new Forest();
String choice;
System.out.println("Welcome to Forest");
System.out.println("=================================================");
do{
forest.pokemonFound();
System.out.print("Do you want to catch it? ");
choice = this.commandScanner.next();
if(choice.equals("yes"))
forest.catchPokemon(bag);
else if(choice.equals("No"))
forest.pokemonFound();
System.out.print("What do you do next? (Back / Catch) ");
choice = this.commandScanner.next();
} while(!(choice.equals("Back")));
pokemonFarm.push(bag.getPokemon());
System.out.println("Welcome Home!");
}
}