-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
228 lines (211 loc) · 6.77 KB
/
main.js
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//시스템바 불러오기
const helpButton = document.querySelector(".helpButton");
const cash = document.querySelector(".cash");
const store = document.querySelector(".helpButton+button");
//아웃풋 불러오기
const output = document.querySelector("#output");
//프롬프트 불러오기
const typeCode = document.querySelector("#typeCode");
const run = document.querySelector("#run");
//환경변수 정의
let server = false;
let serverLoad = 0;
let level = 1;
let hackingTool = false;
let myCash = 50;
let serverCash = 10;
let loop = false;
let loopNumber = 0;
let commend = "";
let numberN = 0;
let crashing = false;
let crashingKey = false;
let crash = 0;
let key = 0;
let pass = false;
let passHigh = false;
let Store = false;
//function정의
function messge() {
alert("Please read to README file.");
}
function error() {
alert("Holy shit! Error!");
}
function Output(text) {
output.innerText = text;
}
function newKey() {
key = Math.floor(Math.random() * 10 + 1);
//Math.random 0~1 사이의 난수 생성
//Math.floor 소수점을 내림시켜 정수로 만듦
}
function openStore() {
Store = true;
Output("Please write the command to purchase.");
}
function closeStore() {
Store = false;
}
function Run() {
commend = typeCode.value;
// 서버가 활성화 된 경우
if(Store){
if(commend=="pass"){
if(myCash>=50){
Output("I have enough cash.");
myCash -= 50;
pass = true;
closeStore();
cash.innerText = "cash : " + myCash;
} else{
error();
closeStore();
Output("You don't have enough cash!");
}
}else if(commend=="passHigh"){
if(myCash>=200){
Output("I have enough cash.");
myCash -= 200;
pass = false;
passHigh = true;
closeStore();
cash.innerText = "cash : " + myCash;
} else{
error();
closeStore();
Output("You don't have enough cash!");
}
}else {
error();
}
}else if (server) {
if (commend == "level") {
Output(level.toString());
} else if (commend == "crash") {
// level이 1 이상일 때만 crash 명령어 실행
if (level > 1) {
crashingKey = true;
crash = 0;
newKey();
Output("Write down password.");
} else {
// level이 1이면 crash 명령어를 사용할 수 없고, 에러 처리
error();
}
} else if (crashingKey) {
numberN = Number(commend);
// 비밀번호 입력 처리
if (isNaN(numberN)) {
if (commend == "password") {
Output(key.toString());
} else if(pass){
if(commend=="pass"){
crashingKey = false;
crashing = true;
Output("Write down your current level");
} else{
error();
}
}else if(passHigh){
if(commend=="passHigh"){
crashingKey = false;
crashing = false;
level -= 1;
Output("Complate!")
} else{
error();
}
}else {
error();
}
}else {
crash = numberN;
if (key == numberN) {
crashing = true;
crashingKey = false;
Output("Write down your current level");
} else {
Output("It's not password");
}
}
} else if (crashing) {
numberN = Number(commend);
// level을 입력받고 비교 처리
if (isNaN(numberN)) {
if (commend == "level") {
Output(level.toString());
} else {
error();
}
} else {
crash = numberN;
if (level == numberN) {
// `crash` 완료 후 레벨 1 감소
level -= 1; // 레벨 1 감소
crashing = false;
crashingKey = false;
Output("Complete!");
} else {
Output("This is not this level");
}
}
}else if (level == 1) {
if (commend == "hack") {
hackingTool = true;
Output("We planted a hacking tool!!");
} else if (commend == "get") {
if(hackingTool){
myCash += serverCash;
serverCash = 0;
server = false;
serverLoad = 0;
Output("I don't need this server anymore, so I'll throw it away.");
cash.innerText = "Cash : " + myCash;
}else{
error();
}
} else{
error();
}
}else{
error();
}
} else {
if (serverLoad == 0) {
if (commend == "server") {
serverCash = 9;
serverLoad = 1;
Output("Good! Write down your level quickly!");
} else {
error();
}
} else if (serverLoad == 1) {
numberN = Number(commend);
if (isNaN(numberN)) {
error();
} else {
if (numberN > 0) {
serverLoad = 0;
server = true;
level = Math.floor(numberN);
serverCash += level;
Output("Server connection complete!");
} else {
error();
}
}
}
}
}
//이벤트 리스너
helpButton.addEventListener("click", messge);
//`Enter`키 처리 - 페이지 새로고침 방지 및 Run 함수 실행
typeCode.addEventListener("keydown", function(event) {
if (event.key === "Enter") {
event.preventDefault(); // 기본 동작인 새로고침 방지
Run(); // Run 함수 호출
}
});
run.addEventListener("click", Run);
store.addEventListener("click", openStore);