-
Notifications
You must be signed in to change notification settings - Fork 1
/
Adventure.java
108 lines (88 loc) · 2.19 KB
/
Adventure.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
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
import java.io.IOException;
import java.util.*;
public class Adventure {
public static void main(String[] args) {
Adventure a=new Adventure();
a.run();
}
double chars_per_minute=4800;
boolean debug=false;
public Adventure() {
map=new TUMap(this);
}
Scanner input;
TUMap map;
public void tell(String text) {
tell(text, true);
}
public void tell(String text, boolean wait) {
tell(text, wait, 1);
}
public void tell(String text, boolean wait, double slowdown) {
char[] tarr=(text+"\n").toCharArray();
int i, this_line=0;
for(i=0;i<tarr.length;i++) {
if(tarr[i]=='\n' && wait) {
if(!debug) {
try {
//System.out.print("(press enter)");
//System.out.flush();
byte somebuffer[] = new byte[100];
System.in.read(somebuffer);
System.out.append("\t");
} catch (IOException e) {
// lol.
}
} else {
System.out.append("\n\t");
}
} else {
System.out.append(tarr[i]);
System.out.flush();
if(++this_line>=70 && tarr[i]==' ') { // we have a good chance of word-aware wrapping before we reach column 81 by doing this :D
this_line=0;
System.out.append("\n");
}
try {
if(!debug) {
Thread.sleep((long) (1000*slowdown*60/chars_per_minute));
}
} catch (InterruptedException e) {
// lol.
}
}
}
}
public int ask(String question, List<String> answers) {
tell(question, false);
int i=1;
for(String answer : answers) {
tell("("+(i++)+" "+answer+")", false);
}
for(;;) {
try {
int ret=Integer.parseInt(input.next())-1;
if(ret<answers.size()) return ret;
}
catch(NumberFormatException e) {
}
}
}
public Scene curScene;
public void delay() {
tell(". . . ", false, 20);
}
public void run() {
input = new Scanner(System.in);
curScene=new SAnkunft(this);
//curScene=new SKlausureinsicht(this);
//map.setLocation(map.madritterstock);
//curScene=new SPhysikVL(this);
//map.setLocation(map.wohnheim);
//curScene=new SKlausurRunning(this);
//curScene=new SKlausurBefore(this);
//map.currentLocation=map.wohnheim;
//curScene=new SWohnheim(this);
while(curScene!=null) curScene=curScene.run();
}
}