This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoom.java
190 lines (175 loc) · 6.53 KB
/
Doom.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import Entities.Monster;
import Entities.Player;
import Entities.Room;
import MonsterSpecialization.Follower;
import MonsterSpecialization.SimpleMonster;
import MonsterSpecialization.TimeBomb;
import MonsterSpecialization.Zombie;
import java.lang.reflect.Array;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Random;
import java.util.Scanner;
/**
* Author Elias De Hondt
* 24/11/2022
*/
public class Doom {
private Room room;
private Random random = new Random();
private String currentDate;
private LocalTime currentTime;
private LocalTime startTime;
private Scanner input;
private int keuze;
private int settingsKeuze;
private int minMobs = 1;
private int maxMobs = 50;
private int speed = 500;
public Doom() {
input = new Scanner(System.in);
}
public boolean isFinished() {
return room.isFinished();
}
public void start() {
startTime = LocalTime.now();
Player player = new Player(random.nextInt(2, Room.getWidth() - 1),random.nextInt(2, Room.getHeight() -1));
Monster[] monsters = new Monster[random.nextInt(minMobs,maxMobs+1)];
for (int i = 0; i < monsters.length; i++){
switch (random.nextInt(0,4)) {
case 0 : Array.set(monsters,i,new Follower(player, random.nextInt(2, Room.getWidth() - 1),random.nextInt(2,Room.getHeight()-1))); break;
case 1 : Array.set(monsters,i, new SimpleMonster(player,random.nextInt(2, Room.getWidth() - 1),random.nextInt(2,Room.getHeight()-1))); break;
case 2 : Array.set(monsters,i, new TimeBomb(player,random.nextInt(2, Room.getWidth() - 1),random.nextInt(2,Room.getHeight()-1))); break;
case 3 : Array.set(monsters,i, new Zombie(player,random.nextInt(2, Room.getWidth() - 1),random.nextInt(2,Room.getHeight()-1))); break;
}
}
this.room = new Room(player, monsters);
while (!isFinished()) {
try {
currentTime = LocalTime.now();
room.update();
showInfo();
Thread.sleep(speed);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void showInfo(){
currentDate = LocalDate.now().format(DateTimeFormatter.ofPattern("dd MMM yyyy"));
String currentTimeString = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM).format(currentTime);
int maxLength = Room.getWidth();
String healthFormat = "Health: %.0f\n";
int length = (maxLength/2) - (healthFormat.length()/2);
String dateFormat = "%-" + length + "s";
String timeFormat = "%-" + length + "s";
String format = dateFormat + " " + timeFormat + " " + healthFormat;
System.out.format(format,currentDate,currentTimeString, room.getPlayer().getHealth() < 0 ? 0 : room.getPlayer().getHealth());
if(isFinished()){
Duration timeAlive = Duration.between(startTime,currentTime);
System.out.printf("The player survived for %d seconds...", timeAlive.getSeconds());
}
}
public void menu(){
do {
System.out.println("""
Welkom op deze DOOM simulatie
=============================
Maak je keuze:
1) settings
2) start
3) exit""");
System.out.print("uw keuze: ");
keuze = input.nextInt();
} while(keuze < 0 || keuze > 3);
if(keuze == 2){
start();
} else if(keuze == 3){
System.exit(0);
}else if(keuze == 1){
settings();
}
}
public void settings(){
do{
System.out.println("""
Settings menu
=============================
Maak je keuze:
1) Size
2) Difficulty
3) Update speed
4) Back to menu
""");
System.out.print("uw keuze: ");
settingsKeuze = input.nextInt();
} while(settingsKeuze < 0 || settingsKeuze > 4);
if(settingsKeuze == 4){
menu();
} else if(settingsKeuze == 1){
sizeSettings();
} else if(settingsKeuze == 2){
difficultySettings();
} else if(settingsKeuze == 3){
updateSpeedSettings();
}
}
public void sizeSettings(){
System.out.printf("""
Settings menu
=============================
Current height: %d
Current width: %d
""", Room.getHeight(), Room.getWidth());
System.out.print("New height: ");
Room.setHeight(input.nextInt());
System.out.print("New Width: ");
Room.setWidth(input.nextInt());
System.out.println("returning to settings...");
try{
Thread.sleep(500);
settings();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void difficultySettings(){
System.out.printf("""
Settings menu
=============================
Current min of mobs: %d
Current max of mobs: %d
""", minMobs, maxMobs);
System.out.print("New min of mobs: ");
minMobs = input.nextInt();
System.out.print("New max of mobs: ");
maxMobs = input.nextInt();
System.out.println("returning to settings...");
try{
Thread.sleep(500);
settings();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void updateSpeedSettings(){
System.out.printf("""
Settings menu
=============================
Current update speed: %d
""", speed);
System.out.print("New update speed: ");
speed = input.nextInt();
System.out.println("returning to settings...");
try{
Thread.sleep(500);
settings();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}