-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdtpv1.html
More file actions
314 lines (267 loc) · 8.6 KB
/
cdtpv1.html
File metadata and controls
314 lines (267 loc) · 8.6 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Car Dealership Tycoon</title>
<style>
body { font-family: Arial; background:#eee; }
.container { width:96%; margin:auto; }
.car { background:#fff; border:1px solid #ccc; padding:10px; margin:8px; width:250px; display:inline-block; }
.button { padding:6px 10px; background:#007BFF; color:#fff; border:none; cursor:pointer; margin:2px; }
.button:hover { background:#0056b3; }
.money { font-size:18px; margin:10px 0; }
.tabs button { margin-right:5px; }
.rarity-Common { color:gray; }
.rarity-Rare { color:blue; }
.rarity-Epic { color:purple; }
.rarity-Legendary { color:gold; }
</style>
</head>
<body>
<div class="container">
<h1>🚗 Car Dealership Tycoon</h1>
<div class="money">
💰 $<span id="money"></span> | 💳 Debt: $<span id="debt"></span>
</div>
<button class="button" onclick="takeLoan()">Take Loan</button>
<button class="button" onclick="saveGame()">Save Code</button>
<button class="button" onclick="loadGame()">Load Code</button>
<h2>Dealerships</h2>
<div class="tabs">
<button class="button" onclick="showDealer('economy')">Economy</button>
<button class="button" onclick="showDealer('used')">Used</button>
<button class="button" onclick="showDealer('performance')">Performance</button>
<button class="button" onclick="showDealer('luxury')">Luxury</button>
<button class="button" onclick="showDealer('classic')">Classic</button>
<button class="button" onclick="showDealer('hyper')">Hypercars</button>
</div>
<div id="dealership"></div>
<h2>Your Cars</h2>
<div id="myCars"></div>
<h2>Public Auction</h2>
<div id="publicAuction"></div>
<h2>Your Auction</h2>
<div id="playerAuction"></div>
<h2>Events</h2>
<div id="events"></div>
</div>
<script>
let money = 120000;
let debt = 0;
let interestRate = 0.05;
let eventMultiplier = 1;
let currentDealer = "economy";
const rarities = { Common:1, Rare:1.3, Epic:1.7, Legendary:2.5 };
/* ---------- DEALERSHIP DATABASE ---------- */
const dealers = {
economy: [
{model:"Toyota Corolla", price:20000, rarity:"Common"},
{model:"Honda Civic", price:22000, rarity:"Common"},
{model:"Hyundai Elantra", price:21000, rarity:"Common"},
{model:"Kia Forte", price:19500, rarity:"Common"}
],
used: [
{model:"Ford Focus 2012", price:9000, rarity:"Common"},
{model:"Toyota Camry 2010", price:8500, rarity:"Common"},
{model:"BMW 328i 2008", price:12000, rarity:"Rare"},
{model:"Nissan Altima 2011", price:7800, rarity:"Common"}
],
performance: [
{model:"Mazda RX-7 FD", price:95000, rarity:"Rare"},
{model:"Toyota Supra MK4", price:140000, rarity:"Epic"},
{model:"Nissan Skyline R34", price:130000, rarity:"Epic"},
{model:"Chevrolet Corvette C7", price:90000, rarity:"Epic"},
{model:"Ford Mustang GT", price:48000, rarity:"Rare"}
],
luxury: [
{model:"BMW M5", price:110000, rarity:"Rare"},
{model:"Mercedes S-Class", price:125000, rarity:"Rare"},
{model:"Audi RS7", price:115000, rarity:"Epic"},
{model:"Porsche Panamera", price:140000, rarity:"Epic"}
],
classic: [
{model:"1969 Ford Mustang", price:85000, rarity:"Epic"},
{model:"1970 Dodge Charger", price:95000, rarity:"Epic"},
{model:"Mercedes 300SL", price:400000, rarity:"Legendary"},
{model:"Ferrari F40", price:1200000, rarity:"Legendary"}
],
hyper: [
{model:"Lamborghini Aventador", price:500000, rarity:"Legendary"},
{model:"McLaren P1", price:1500000, rarity:"Legendary"},
{model:"Bugatti Chiron", price:3000000, rarity:"Legendary"}
]
};
let myCars = [];
/* ---------- UTIL ---------- */
function randomCondition(min=60){
return Math.floor(Math.random()*(100-min))+min;
}
function updateUI(){
document.getElementById("money").textContent = Math.floor(money);
document.getElementById("debt").textContent = Math.floor(debt);
displayDealer();
displayMyCars();
}
/* ---------- DEALER VIEW ---------- */
function showDealer(name){
currentDealer = name;
displayDealer();
}
function displayDealer(){
const d=document.getElementById("dealership");
d.innerHTML="";
dealers[currentDealer].forEach(car=>{
let condition = currentDealer==="used" ? randomCondition(40) : randomCondition(70);
const price = Math.floor(car.price * rarities[car.rarity] * eventMultiplier);
d.innerHTML+=`
<div class="car">
<h3>${car.model}</h3>
<p class="rarity-${car.rarity}">${car.rarity}</p>
<p>Estimated Condition: ${condition}%</p>
<p>Price: $${price}</p>
<button class="button" onclick='buyCar(${JSON.stringify(car)},${condition})'>Buy</button>
</div>`;
});
}
function buyCar(car,condition){
const cost=Math.floor(car.price * rarities[car.rarity] * eventMultiplier);
if(money>=cost){
money-=cost;
myCars.push({...car,condition});
updateUI();
}
}
/* ---------- PLAYER CARS ---------- */
function displayMyCars(){
const m=document.getElementById("myCars");
m.innerHTML="";
myCars.forEach((car,i)=>{
const value=Math.floor(car.price*(car.condition/100)*rarities[car.rarity]);
m.innerHTML+=`
<div class="car">
<h3>${car.model}</h3>
<p class="rarity-${car.rarity}">${car.rarity}</p>
<p>Condition: ${car.condition}%</p>
<p>Value: $${value}</p>
<button class="button" onclick="repairCar(${i})">Repair</button>
<button class="button" onclick="sellCar(${i})">Sell</button>
<button class="button" onclick="startPlayerAuction(${i})">Auction</button>
</div>`;
});
}
function repairCar(i){
const cost=Math.floor((100-myCars[i].condition)*350);
if(money>=cost){
money-=cost;
myCars[i].condition=100;
updateUI();
}
}
function sellCar(i){
const car=myCars.splice(i,1)[0];
money+=Math.floor(car.price*(car.condition/100)*rarities[car.rarity]);
updateUI();
}
/* ---------- PLAYER AUCTION ---------- */
let playerAuction=null;
let auctionTimer=null;
function startPlayerAuction(index){
playerAuction=myCars.splice(index,1)[0];
let bid=Math.floor(playerAuction.price*(playerAuction.condition/100)*0.6);
let time=10;
clearInterval(auctionTimer);
auctionTimer=setInterval(()=>{
bid+=Math.floor(Math.random()*bid*0.12);
time--;
document.getElementById("playerAuction").innerHTML=`
<div class="car">
<h3>${playerAuction.model}</h3>
<p>Current Bid: $${bid}</p>
<p>Time Left: ${time}s</p>
</div>`;
if(time<=0){
clearInterval(auctionTimer);
money+=bid;
document.getElementById("playerAuction").innerHTML=
`<h3>${playerAuction.model} sold for $${bid}!</h3>`;
updateUI();
}
},1000);
updateUI();
}
/* ---------- PUBLIC AUCTION ---------- */
let publicAuction=null;
function spawnAuction(){
const allCars=Object.values(dealers).flat();
const base=allCars[Math.floor(Math.random()*allCars.length)];
publicAuction={...base,condition:randomCondition(),bid:Math.floor(base.price*0.5)};
document.getElementById("publicAuction").innerHTML=`
<div class="car">
<h3>${publicAuction.model}</h3>
<p class="rarity-${publicAuction.rarity}">${publicAuction.rarity}</p>
<p>Condition: ${publicAuction.condition}%</p>
<p>Current Bid: $${publicAuction.bid}</p>
<button class="button" onclick="bidPublicAuction()">Bid</button>
</div>`;
}
function bidPublicAuction(){
const inc=Math.floor(Math.random()*5000)+4000;
if(money>=publicAuction.bid+inc){
publicAuction.bid+=inc;
if(Math.random()>0.6){
money-=publicAuction.bid;
myCars.push(publicAuction);
publicAuction=null;
document.getElementById("publicAuction").innerHTML="You won the auction!";
updateUI();
}
}
}
/* ---------- LOANS ---------- */
function takeLoan(){
const loan=50000;
money+=loan;
debt+=loan*(1+interestRate);
updateUI();
}
/* ---------- EVENTS ---------- */
function randomEvent(){
const r=Math.random();
if(r<0.3){
eventMultiplier=0.8;
showEvent("📉 Market Crash! Prices down");
}else if(r<0.6){
eventMultiplier=1.25;
showEvent("📈 Market Boom! Prices up");
}else{
showEvent("🏆 Classic Cars in High Demand!");
}
setTimeout(()=>eventMultiplier=1,15000);
}
function showEvent(msg){
document.getElementById("events").innerHTML=`<p>${msg}</p>`;
}
/* ---------- SAVE / LOAD ---------- */
function saveGame(){
const code=btoa(JSON.stringify({money,debt,myCars}));
prompt("Copy save code:",code);
}
function loadGame(){
const code=prompt("Paste save code:");
if(code){
const data=JSON.parse(atob(code));
money=data.money;
debt=data.debt;
myCars=data.myCars;
updateUI();
}
}
/* ---------- TIMERS ---------- */
setInterval(spawnAuction,30000);
setInterval(randomEvent,40000);
setInterval(()=>{ if(debt>0) debt*=1.02; updateUI(); },20000);
updateUI();
spawnAuction();
</script>
</body>
</html>