-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameV1.html
More file actions
223 lines (162 loc) · 7.08 KB
/
gameV1.html
File metadata and controls
223 lines (162 loc) · 7.08 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
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
<!DOCTYPE html>
<html>
<!DOCTYPE html>
<html>
<head>
<title>Age of flying legends v1.0</title>
</title>
<style>
h1 {
text-align: center;
color: gold;
font-size: 30px;
}
h2 {
text-align: center;
color: gray;
font-size: 18px;
}
input {
background-color: #333;
color: goldenrod;
border: none;
padding: 2px;
margin: 5px;
width: 50px;
}
body {
text-align: center;
color: darkgray;
background-color: black;
font-weight: bold;
font-size: 19px;
}
div.game {
background-image: url('pozadi4.png');
background-color: black;
background-repeat: no-repeat;
background-position: center;
text-align: center;
}
#form {
color: gold;
}
</style>
</head>
<body>
<h1>Age of flying legends v1.0</h1>
<div class="game">
<BR><BR>
<p>Year: <span id="year">1852</span></p>
<p>Total airships: <span id="airship_total">1</span></p>
<p>Cost of hydrogen last year: <span id="inflace">200</span> $</p>
<p>Total dolars: <span id="money_total">7000</span> $</p>
<p>Total workers: <span id="workers_total">10</span></p>
<p>Price of an airship: <span id="airship_price">4000</span> $</p>
<p>Profit from air tickets for last year: <span id="ticket_price">1500</span> $ </p>
<form id="form">
<p>How many airships to buy: <input type="number" id="airship_buy" min="0" ></p>
<p>How many airships to sel: <input type="number" id="airship_sel" min="0"></p>
<p>How many airships to send: <input type="number" id="airship_send" min="0"></p>
<p>How many $ to put on salaries: <input type="number" id="money_pay" min="0"></p>
<BR>
</form>
<button onclick="playTurn()">OK</button>
<BR><BR><BR><BR>
</div>
<BR><BR><H2>
Each employee needs 100 dollars per year.
<P>
One airship requires 5 people to operate. The cost of sending one airship is 200 dollars.
</H2>
<script>
let year = 1852;
let workers = 0;
let workers_total = 10;
let airship_total = 1;
let airship_sel = 0;
let airship_buy = 0;
let airship_type = 1;
let airship_price = 4000;
let ticket_price = 1500;
let money_pay = 0;
let money_total = 7000;
let airship_send = 0;
let counter_error = 0;
let event = 0;
let havarie = 0;
let expenses = 100;
let inflace = 200;
let bonus = 0;
let workers_death = 0;
function playTurn() {
money_pay = parseInt(document.getElementById("money_pay").value);
airship_buy = parseInt(document.getElementById("airship_buy").value);
airship_sel = parseInt(document.getElementById("airship_sel").value);
airship_send = parseInt(document.getElementById("airship_send").value);
// Empty form
if (isNaN(airship_buy)) { airship_buy = 0; }
if (isNaN(airship_sel)) { airship_sel = 0; }
if (isNaN(money_pay)) { money_pay = 0; }
if (isNaN(airship_send)) { airship_send = 0; }
// calculation money,airship for checking source and urther processing
money = money_total - (airship_buy * airship_price) + (airship_sel * airship_price) - money_pay - (airship_send * expenses);
airship = airship_total + airship_buy - airship_sel;
// calculation workers (worker = 100 dolorars/year)
workers_expenses = workers_total * 100 - money_pay;
if (workers_expenses <= 0) { workers_expenses = 0; }
new_workers = Math.floor(Math.random() * 3) + 0;
workers = workers_total - workers_expenses / 100 + new_workers;
// 1 airship = 5 workers
workers_error = workers_total /5 ;
// check source
if (airship_send > workers_error ) { counter_error = counter_error + 1; alert( "You don't have that many workers." ); }
if (money < 0) { counter_error = counter_error + 1; alert( "You don't have that many dollars."); }
if (airship_send > airship) {counter_error = counter_error + 1; alert( "You don't have that many airships."); }
// if everything is OK, move on to the next year
if (counter_error == 0) { next_year(); }
else { document.getElementById("form").reset(); airship_send = 0; airship_buy = 0; airship_sel = 0; money_pay = 0;}
counter_error = 0;
}
function next_year() {
// generating inflation,ticket_price, event
inflace = Math.floor(Math.random() * 200) + 100;
ticket_price = Math.floor(Math.random() * 3000) + 1;
event = Math.floor(Math.random() * 5) + 1;
// random event
if (event == 3 && year > 1855 ) { havarie = 1; alert( "Hydrogen exploded. Unfortunately, you've lost an airship a 5 workers!"); workers_death = 5; }
if (event == 2 && year > 1855 ) { alert( "You have received a $2000 bonus from sponsors"); bonus = 2000; }
// calculation money_total, airship_total , workers
money_total = money - inflace + bonus + (airship_send * ticket_price);
airship_total = airship - havarie ;
workers_total = Math.round(workers) - workers_death;
// Game Over
if (airship_total <= 0) { alert( "You've lost all your airships. Game over!"); resetall(); }
if (workers_total <= 0) { alert( "You've lost all your workers. Game over!"); resetall(); }
if (money_total <= 0) { alert( "Bankruptcy - you have no money.Game over!"); resetall(); }
// END GAME
if (year > 1922 ) { alert( "Congratulations!!! You've kept the company running for a total of 70 years. You started with 10 employees, $7000, and 1 airship. Now you have - Workers: " + workers_total + " , Dolars: " + money_total + " ,Airships: " + airship_total ); resetall(); }
// Gen airship_price
airship_price = Math.floor(Math.random() * (3000)) + 3000;
// Next year and reset val
year++;
counter_error = 0;
havarie = 0;
bonus = 0;
workers_death = 0;
document.getElementById("ticket_price").textContent = ticket_price;
document.getElementById("money_total").textContent = money_total;
document.getElementById("workers_total").textContent = workers_total;
document.getElementById("inflace").textContent = inflace;
document.getElementById("year").textContent = year;
document.getElementById("airship_total").textContent = airship_total;
document.getElementById("airship_price").textContent = airship_price;
document.getElementById("form").reset();
// New game
}
function resetall() {
location.reload();
}
</script>
</body>
</html>