File size: 10,744 Bytes
559ea42 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Development and Game Programming Resource Management Game</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f0f0f0;
padding: 20px;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.resource, .actions, .events {
margin-bottom: 20px;
padding: 15px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
flex-basis: calc(33% - 20px);
}
h1, h2 {
color: #2c3e50;
}
button {
margin: 5px;
padding: 10px 15px;
font-size: 16px;
background-color: #3498db;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #2980b9;
}
canvas {
border: 1px solid #ccc;
margin-top: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
#resource-list {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.resource-item {
background-color: #ecf0f1;
padding: 10px;
border-radius: 5px;
text-align: center;
flex-grow: 1;
}
#event-result {
font-style: italic;
color: #e74c3c;
}
#game-log {
max-height: 150px;
overflow-y: auto;
background-color: #ecf0f1;
padding: 10px;
border-radius: 5px;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>AI Development and Game Programming Resource Management Game</h1>
<div class="container">
<div class="resource" id="resources">
<h2>Current Resources</h2>
<div id="resource-list"></div>
</div>
<div class="actions">
<h2>Actions</h2>
<button onclick="performAction('Cook Chicken')">Cook Chicken</button>
<button onclick="performAction('Make Salad')">Make Salad</button>
<button onclick="performAction('Drink Water')">Drink Water</button>
<button onclick="performAction('Monster Zero')">Drink Monster Zero</button>
<button onclick="performAction('Code')">Code</button>
<button onclick="performAction('Debug')">Debug</button>
</div>
<div class="events">
<h2>Random Events</h2>
<button onclick="triggerRandomEvent()">Wait for Random Event</button>
<p id="event-result"></p>
</div>
</div>
<canvas id="gameCanvas" width="800" height="400"></canvas>
<div id="game-log"></div>
<script>
let gameState = {
"Monster Zero": 1,
"Water": 10,
"Chicken": 3,
"Salad": 5,
"Air Fryer": 1,
"Microwave": 1,
"Culligan Machine": 1,
"Energy": 100,
"Code Quality": 0,
"Bugs": 0
};
const RESOURCE_COSTS = {
"Cook Chicken": {"Chicken": 1, "Energy": 10},
"Make Salad": {"Salad": 1, "Energy": 5},
"Drink Water": {"Water": 1},
"Monster Zero": {"Monster Zero": 1},
"Code": {"Energy": 15},
"Debug": {"Energy": 20}
};
const RESOURCE_GAINS = {
"Cook Chicken": {"Energy": 20},
"Make Salad": {"Energy": 15},
"Drink Water": {"Energy": 5},
"Monster Zero": {"Energy": 30},
"Code": {"Code Quality": 10, "Bugs": 5},
"Debug": {"Code Quality": 5, "Bugs": -10}
};
function updateResources() {
const resourceList = document.getElementById('resource-list');
resourceList.innerHTML = '';
for (let resource in gameState) {
const resourceItem = document.createElement('div');
resourceItem.className = 'resource-item';
resourceItem.textContent = `${resource}: ${gameState[resource]}`;
resourceList.appendChild(resourceItem);
}
}
function performAction(action) {
if (RESOURCE_COSTS.hasOwnProperty(action)) {
for (let resource in RESOURCE_COSTS[action]) {
if (gameState[resource] < RESOURCE_COSTS[action][resource]) {
logEvent(`Not enough ${resource} to perform ${action}`);
return;
}
}
for (let resource in RESOURCE_COSTS[action]) {
gameState[resource] -= RESOURCE_COSTS[action][resource];
}
for (let resource in RESOURCE_GAINS[action]) {
gameState[resource] += RESOURCE_GAINS[action][resource];
}
logEvent(`Performed action: ${action}`);
updateResources();
drawScene();
checkGameOver();
}
}
function triggerRandomEvent() {
const events = [
"Found Water", "Lost Chicken", "Energy Boost", "Microwave Malfunction",
"Coding Inspiration", "Bug Infestation", "Coffee Break", "Power Outage"
];
const event = events[Math.floor(Math.random() * events.length)];
document.getElementById('event-result').textContent = `Event: ${event}`;
switch (event) {
case "Found Water":
gameState["Water"] += 3;
break;
case "Lost Chicken":
if (gameState["Chicken"] > 0) gameState["Chicken"] -= 1;
break;
case "Energy Boost":
gameState["Energy"] += 20;
break;
case "Microwave Malfunction":
if (gameState["Microwave"] > 0) gameState["Microwave"] -= 1;
break;
case "Coding Inspiration":
gameState["Code Quality"] += 15;
break;
case "Bug Infestation":
gameState["Bugs"] += 20;
break;
case "Coffee Break":
gameState["Energy"] += 10;
gameState["Water"] -= 1;
break;
case "Power Outage":
gameState["Energy"] -= 10;
gameState["Code Quality"] -= 5;
break;
}
logEvent(`Random event occurred: ${event}`);
updateResources();
drawScene();
checkGameOver();
}
function checkGameOver() {
if (gameState["Energy"] <= 0) {
logEvent("Game Over! You ran out of energy.");
} else if (gameState["Chicken"] === 0 && gameState["Salad"] === 0 && gameState["Water"] === 0) {
logEvent("Game Over! You ran out of all food resources.");
} else if (gameState["Bugs"] >= 100) {
logEvent("Game Over! Your code has too many bugs.");
}
}
function drawScene() {
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
const BAR_WIDTH = 40;
const BAR_SPACING = 60;
const MAX_BAR_HEIGHT = 300;
let x = 50;
for (let resource in gameState) {
const value = gameState[resource];
const normalizedHeight = (value / 100) * MAX_BAR_HEIGHT;
// Draw 3D-like bar
ctx.fillStyle = 'rgba(100, 100, 250, 0.7)';
ctx.beginPath();
ctx.moveTo(x, canvas.height - normalizedHeight);
ctx.lineTo(x + BAR_WIDTH, canvas.height - normalizedHeight);
ctx.lineTo(x + BAR_WIDTH, canvas.height);
ctx.lineTo(x, canvas.height);
ctx.closePath();
ctx.fill();
// Draw top of the bar
ctx.fillStyle = 'rgba(150, 150, 255, 0.9)';
ctx.beginPath();
ctx.moveTo(x, canvas.height - normalizedHeight);
ctx.lineTo(x + BAR_WIDTH, canvas.height - normalizedHeight);
ctx.lineTo(x + BAR_WIDTH - 5, canvas.height - normalizedHeight - 5);
ctx.lineTo(x - 5, canvas.height - normalizedHeight - 5);
ctx.closePath();
ctx.fill();
// Draw side of the bar
ctx.fillStyle = 'rgba(80, 80, 200, 0.8)';
ctx.beginPath();
ctx.moveTo(x + BAR_WIDTH, canvas.height - normalizedHeight);
ctx.lineTo(x + BAR_WIDTH, canvas.height);
ctx.lineTo(x + BAR_WIDTH - 5, canvas.height - 5);
ctx.lineTo(x + BAR_WIDTH - 5, canvas.height - normalizedHeight - 5);
ctx.closePath();
ctx.fill();
// Draw outline
ctx.strokeStyle = 'black';
ctx.lineWidth = 2;
ctx.strokeRect(x, canvas.height - normalizedHeight, BAR_WIDTH, normalizedHeight);
// Draw label
ctx.fillStyle = 'black';
ctx.font = '12px Arial';
ctx.textAlign = 'center';
ctx.fillText(resource, x + BAR_WIDTH / 2, canvas.height - normalizedHeight - 10);
ctx.fillText(value, x + BAR_WIDTH / 2, canvas.height - normalizedHeight / 2);
x += BAR_SPACING;
}
}
function logEvent(message) {
const gameLog = document.getElementById('game-log');
const logEntry = document.createElement('p');
logEntry.textContent = message;
gameLog.insertBefore(logEntry, gameLog.firstChild);
if (gameLog.children.length > 5) {
gameLog.removeChild(gameLog.lastChild);
}
}
updateResources();
drawScene();
</script>
</body>
</html> |