-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.java
More file actions
77 lines (64 loc) · 1.82 KB
/
Player.java
File metadata and controls
77 lines (64 loc) · 1.82 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
import java.util.Scanner;
public class Player
{
private String name;
private Scanner input;
private Room currentRoom;
public Player(String name)
{
this.name = name;
this.input = new Scanner(System.in);
this.currentRoom = null;
}
public void setCurrentRoom(Room r)
{
this.currentRoom = r;
}
public void displayToUser(String msg)
{
System.out.println(msg);
}
public void showPrompt()
{
System.out.print("> ");
String userResponse = this.input.nextLine();
System.out.println(userResponse);
//*******
//We need to process the players command to move to a new room
if(userResponse.equalsIgnoreCase("look"))
{
this.currentRoom.displayDetailsToUser();
}
else if(userResponse.equals("create exit"))
{
this.displayToUser("***** Creating Exit *****");
this.displayToUser("Please enter the name of the exit:" );
System.out.print("> ");
userResponse = this.input.nextLine();
String exitName = userResponse;
this.displayToUser("Please enter the name of the return exit:" );
System.out.print("> ");
userResponse = this.input.nextLine();
String returnExit = userResponse;
this.displayToUser("Please enter the name of the new Room" );
System.out.print("> ");
userResponse = this.input.nextLine();
String newRoomName = userResponse;
//Add the new room to our CaveCore
int newRoomID = CaveCore.addRoomToCave(newRoomName, returnExit, this.currentRoom.getId());
//finally add the exit that leads to the new room here!
this.currentRoom.addExit(exitName, newRoomID);
this.displayToUser("New Room Created");
this.showPrompt();
}
else if(userResponse.equals("save"))
{
this.displayToUser("Saving the Cave");
this.displayToUser(CaveCore.theCave.toJSON().exportToJSON());
}
else
{
this.currentRoom.takeExit(userResponse);
}
}
}