-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
64 lines (60 loc) · 2.42 KB
/
Main.java
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
package com.projects;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Map<Integer,Location> locationMap=new HashMap<>();
locationMap.put(0,new Location(0,"Exit"));
locationMap.put(1,new Location(1,"In Room"));
locationMap.put(2,new Location(2,"In Forest "));
locationMap.put(3,new Location(3,"In HIll"));
locationMap.put(4,new Location(4,"In lake"));
locationMap.put(5,new Location(5,"In temple"));
locationMap.put(6,new Location(6,"In Playground"));
Location room=locationMap.get(1);
room.add_Exit(0,"Exit");
room.add_Exit(2,"N");
room.add_Exit(3,"E");
room.add_Exit(4,"W");
room.add_Exit(6,"S");
Location forest=locationMap.get(2);
forest.add_Exit(3,"SE");
forest.add_Exit(1,"S");
Location hill=locationMap.get(3);
hill.add_Exit(2,"NW");
hill.add_Exit(6,"SW");
Location play=locationMap.get(6);
play.add_Exit(5,"W");
Location temple=locationMap.get(5);
temple.add_Exit(4,"N");
Location lake=locationMap.get(4);
lake.add_Exit(5,"S");
lake.add_Exit(2,"NE");
int loc=1;boolean b=false;
while(true)
{
System.out.println('\u04C1' +" "+locationMap.get(loc).getDescription()+" "+ '\u04C1');
if(loc==0)
break;
System.out.print("Enter the direction : ");
String s=br.readLine();
String[] p = s.split(" ");
for(String i:p)
if ((locationMap.get(loc).getExits().containsKey(i))) {
loc = locationMap.get(loc).getExits().get(i);
b=true;
}
if(!b)
{
System.out.println("#######################################################");
System.out.println("The direction is wrong");
System.out.println("There will be a penalty you have to start from starting");
System.out.println("#######################################################");
loc=1;
}
b=false;
}
}
}