about summary refs log tree commit diff stats
path: root/html/tower/js/gameState.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/tower/js/gameState.js')
-rw-r--r--html/tower/js/gameState.js77
1 files changed, 73 insertions, 4 deletions
diff --git a/html/tower/js/gameState.js b/html/tower/js/gameState.js
index 3cee9ed..ac7a968 100644
--- a/html/tower/js/gameState.js
+++ b/html/tower/js/gameState.js
@@ -1,8 +1,29 @@
+/**
+ * Game State Module
+ * 
+ * This module defines the game state and game phases
+ * 
+ * @module gameState
+ */
+
+
+/**
+ * Game phases
+ * 
+ * @enum {string}
+ * @readonly
+ */
 const GamePhase = {
     PLACEMENT: 'place',
     COMBAT: 'run'
 };
 
+/**
+ * Tower types
+ * 
+ * @enum {string}
+ * @readonly
+ */
 const TowerTypes = {
     BASIC: {
         name: 'Basic',
@@ -55,6 +76,12 @@ const TowerTypes = {
     }
 };
 
+/**
+ * Particle types
+ * 
+ * @enum {string}
+ * @readonly
+ */
 const ParticleTypes = {
     DEATH_PARTICLE: {
         lifetime: 1000, // milliseconds
@@ -81,6 +108,12 @@ const ParticleTypes = {
     }
 };
 
+/**
+ * Enemy types
+ * 
+ * @enum {string}
+ * @readonly
+ */
 const EnemyTypes = {
     BASIC: {
         color: '#c0392b',
@@ -100,6 +133,12 @@ const EnemyTypes = {
     }
 };
 
+/**
+ * Creates a tower
+ * 
+ * @param {string} type - Tower type
+ * @param {Object} position - Position of the tower
+ */
 function createTower(type, position) {
     const towerType = TowerTypes[type];
     return {
@@ -113,6 +152,11 @@ function createTower(type, position) {
     };
 }
 
+/**
+ * Creates an enemy
+ * 
+ * @param {Object} startPosition - Starting position of the enemy
+ */
 function createEnemy(startPosition) {
     // 20% chance for ranged enemy
     const type = Math.random() < 0.2 ? 'RANGED' : 'BASIC';
@@ -138,6 +182,12 @@ function createEnemy(startPosition) {
     };
 }
 
+/**
+ * Creates a particle
+ * 
+ * @param {string} type - Particle type
+ * @param {Object} position - Position of the particle
+ */
 function createParticle(type, position, angle) {
     return {
         position: { ...position },
@@ -154,7 +204,12 @@ function createParticle(type, position, angle) {
     };
 }
 
-// Initialize game state at the bottom of the file
+
+/**
+ * Game state
+ * 
+ * @type {Object}
+ */
 const gameState = {
     grid: Array(20).fill().map(() => Array(20).fill('empty')),
     path: [],
@@ -169,6 +224,9 @@ const gameState = {
     enemiesEscaped: 0,
     level: 1,
     
+    /**
+     * Resets the game state
+     */
     resetGame() {
         this.grid = Array(20).fill().map(() => Array(20).fill('empty'));
         this.path = [];
@@ -184,7 +242,10 @@ const gameState = {
         this.level = 1;
     },
     
-    // Define the function as part of the initial object
+
+    /**
+     * Awards the enemy destroyed
+     */
     awardEnemyDestroyed() {
         this.enemiesDestroyed++;
         // Random reward between 1 and 3
@@ -192,14 +253,22 @@ const gameState = {
         this.currency += reward;
     },
     
-    // Add method to check for level completion
+
+    /**
+     * Checks if the level is complete
+     * 
+     * @returns {boolean}
+     */
     checkLevelComplete() {
         return this.enemies.length === 0 && 
                enemiesRemaining === 0 && 
                this.phase === GamePhase.COMBAT;
     },
     
-    // Add method to advance to next level
+
+    /**
+     * Advances to the next level
+     */
     advanceToNextLevel() {
 
         let ammoBonus = 0;