awacke1 commited on
Commit
85be50c
·
verified ·
1 Parent(s): 8035141

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +101 -105
index.html CHANGED
@@ -3,140 +3,136 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Harmonies Game</title>
7
  <style>
8
  body {
9
- font-family: Arial, sans-serif;
10
- background-color: #f0f8ff;
11
  margin: 0;
12
- padding: 0;
13
- display: flex;
14
- flex-direction: column;
15
- align-items: center;
16
  }
17
- h1 {
18
- margin-top: 20px;
19
- }
20
- .game-board {
21
- display: grid;
22
- grid-template-columns: repeat(6, 60px);
23
- gap: 5px;
24
- margin-top: 20px;
25
- }
26
- .tile {
27
- width: 60px;
28
- height: 60px;
29
- background-color: #ccc;
30
- display: flex;
31
- justify-content: center;
32
- align-items: center;
33
- border-radius: 5px;
34
- cursor: pointer;
35
- }
36
- .water {
37
- background-color: #87ceeb;
38
- }
39
- .forest {
40
- background-color: #228b22;
41
- }
42
- .grass {
43
- background-color: #98fb98;
44
- }
45
- .score-board {
46
- margin-top: 20px;
47
- padding: 10px;
48
- background-color: #fff;
49
- border: 1px solid #ddd;
50
- border-radius: 5px;
51
- }
52
- .animal-card {
53
- margin: 10px;
54
- padding: 10px;
55
- border: 1px solid #ccc;
56
- border-radius: 5px;
57
- background-color: #fff;
58
- cursor: pointer;
59
  }
60
  </style>
61
  </head>
62
  <body>
63
- <h1>Harmonies Game</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- <div class="game-board" id="gameBoard">
66
- <!-- Tiles will be dynamically inserted here -->
67
- </div>
 
 
 
 
 
 
 
 
 
68
 
69
- <div class="score-board" id="scoreBoard">
70
- <p>Player 1 Score: <span id="player1Score">0</span></p>
71
- <p>Player 2 Score: <span id="player2Score">0</span></p>
72
- </div>
 
 
 
 
 
 
73
 
74
- <script>
75
- // Game data
76
- const tileTypes = ['water', 'forest', 'grass'];
77
  const animalCards = [
78
- { name: 'Swan', habitat: 'water', points: 5 },
79
- { name: 'Deer', habitat: 'grass', points: 4 },
80
- { name: 'Bear', habitat: 'forest', points: 6 },
81
  ];
82
-
83
- const board = [];
84
- const boardSize = 6;
 
 
 
 
 
 
85
 
86
  // Game state
87
  let currentPlayer = 1;
88
  const scores = { 1: 0, 2: 0 };
89
 
90
- // Initialize the game board
91
- function initBoard() {
92
- const gameBoard = document.getElementById('gameBoard');
93
- for (let i = 0; i < boardSize * boardSize; i++) {
94
- const tile = document.createElement('div');
95
- const tileType = tileTypes[Math.floor(Math.random() * tileTypes.length)];
96
- tile.classList.add('tile', tileType);
97
- tile.dataset.index = i;
98
- tile.dataset.type = tileType;
99
- tile.addEventListener('click', () => placeAnimal(i));
100
- board.push({ type: tileType, animal: null });
101
- gameBoard.appendChild(tile);
102
- }
103
- }
104
 
105
- // Handle animal placement
106
- function placeAnimal(index) {
107
- const tile = board[index];
108
- if (tile.animal) {
109
- alert('This tile already has an animal!');
110
- return;
111
- }
112
 
113
- const selectedAnimal = animalCards[Math.floor(Math.random() * animalCards.length)];
 
114
 
115
- if (selectedAnimal.habitat !== tile.type) {
116
- alert(`${selectedAnimal.name} cannot live on ${tile.type} tile!`);
117
- return;
118
- }
119
 
120
- tile.animal = selectedAnimal;
121
- scores[currentPlayer] += selectedAnimal.points;
122
- updateScores();
123
- switchPlayer();
124
- }
 
125
 
126
- // Update scores
127
- function updateScores() {
128
- document.getElementById('player1Score').textContent = scores[1];
129
- document.getElementById('player2Score').textContent = scores[2];
 
 
 
 
 
 
 
 
 
 
 
130
  }
131
 
132
- // Switch players
133
  function switchPlayer() {
134
  currentPlayer = currentPlayer === 1 ? 2 : 1;
135
  alert(`Player ${currentPlayer}'s turn!`);
136
  }
137
 
138
- // Initialize the game
139
- initBoard();
 
 
 
 
 
 
 
 
 
 
 
140
  </script>
141
  </body>
142
- </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Harmonies Game 3D</title>
7
  <style>
8
  body {
 
 
9
  margin: 0;
10
+ overflow: hidden;
 
 
 
11
  }
12
+ canvas {
13
+ display: block;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
15
  </style>
16
  </head>
17
  <body>
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
19
+ <script>
20
+ // Initialize scene, camera, and renderer
21
+ const scene = new THREE.Scene();
22
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
23
+ const renderer = new THREE.WebGLRenderer();
24
+ renderer.setSize(window.innerWidth, window.innerHeight);
25
+ document.body.appendChild(renderer.domElement);
26
+
27
+ // Create the game board (grid of tiles)
28
+ const boardSize = 6;
29
+ const tileSize = 1;
30
+ const tiles = [];
31
+ const tileTypes = [
32
+ { type: 'water', color: 0x87ceeb },
33
+ { type: 'forest', color: 0x228b22 },
34
+ { type: 'grass', color: 0x98fb98 }
35
+ ];
36
 
37
+ for (let x = 0; x < boardSize; x++) {
38
+ for (let z = 0; z < boardSize; z++) {
39
+ const tileType = tileTypes[Math.floor(Math.random() * tileTypes.length)];
40
+ const geometry = new THREE.BoxGeometry(tileSize, 0.1, tileSize);
41
+ const material = new THREE.MeshBasicMaterial({ color: tileType.color });
42
+ const tile = new THREE.Mesh(geometry, material);
43
+ tile.position.set(x - boardSize / 2, 0, z - boardSize / 2);
44
+ tile.userData = { type: tileType.type, occupied: false };
45
+ scene.add(tile);
46
+ tiles.push(tile);
47
+ }
48
+ }
49
 
50
+ // Add light
51
+ const light = new THREE.AmbientLight(0xffffff, 0.8);
52
+ scene.add(light);
53
+
54
+ // Add animals
55
+ const animalModels = {
56
+ swan: { model: null, color: 0xffffff },
57
+ deer: { model: null, color: 0x8b4513 },
58
+ bear: { model: null, color: 0x000000 }
59
+ };
60
 
 
 
 
61
  const animalCards = [
62
+ { name: 'Swan', habitat: 'water', color: 0xffffff },
63
+ { name: 'Deer', habitat: 'grass', color: 0x8b4513 },
64
+ { name: 'Bear', habitat: 'forest', color: 0x000000 }
65
  ];
66
+
67
+ const animalGeometry = new THREE.SphereGeometry(0.2, 32, 32);
68
+
69
+ for (const animal in animalModels) {
70
+ animalModels[animal].model = new THREE.Mesh(
71
+ animalGeometry,
72
+ new THREE.MeshBasicMaterial({ color: animalModels[animal].color })
73
+ );
74
+ }
75
 
76
  // Game state
77
  let currentPlayer = 1;
78
  const scores = { 1: 0, 2: 0 };
79
 
80
+ // Handle mouse click events
81
+ const raycaster = new THREE.Raycaster();
82
+ const mouse = new THREE.Vector2();
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ function onMouseClick(event) {
85
+ mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
86
+ mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
 
 
 
 
87
 
88
+ raycaster.setFromCamera(mouse, camera);
89
+ const intersects = raycaster.intersectObjects(tiles);
90
 
91
+ if (intersects.length > 0) {
92
+ const tile = intersects[0].object;
 
 
93
 
94
+ if (tile.userData.occupied) {
95
+ alert('This tile is already occupied!');
96
+ return;
97
+ }
98
+
99
+ const selectedAnimal = animalCards[Math.floor(Math.random() * animalCards.length)];
100
 
101
+ if (selectedAnimal.habitat !== tile.userData.type) {
102
+ alert(`${selectedAnimal.name} cannot live on ${tile.userData.type} tile!`);
103
+ return;
104
+ }
105
+
106
+ const animal = animalModels[selectedAnimal.name.toLowerCase()].model.clone();
107
+ animal.position.copy(tile.position);
108
+ animal.position.y += 0.2;
109
+ scene.add(animal);
110
+
111
+ tile.userData.occupied = true;
112
+ scores[currentPlayer] += 5;
113
+
114
+ switchPlayer();
115
+ }
116
  }
117
 
 
118
  function switchPlayer() {
119
  currentPlayer = currentPlayer === 1 ? 2 : 1;
120
  alert(`Player ${currentPlayer}'s turn!`);
121
  }
122
 
123
+ window.addEventListener('click', onMouseClick);
124
+
125
+ // Set camera position
126
+ camera.position.set(0, 5, 5);
127
+ camera.lookAt(0, 0, 0);
128
+
129
+ // Animation loop
130
+ function animate() {
131
+ requestAnimationFrame(animate);
132
+ renderer.render(scene, camera);
133
+ }
134
+
135
+ animate();
136
  </script>
137
  </body>
138
+ </html>