summary refs log tree commit diff stats
path: root/widgets
ModeNameSize
-rw-r--r--account.go4625log stats plain blame
-rw-r--r--aerc.go5754log stats plain blame
-rw-r--r--dirlist.go3186log stats plain blame
-rw-r--r--exline.go2959log stats plain blame
-rw-r--r--msglist.go4008log stats plain blame
-rw-r--r--msgviewer.go6798log stats plain blame
-rw-r--r--spinner.go1385log stats plain blame
-rw-r--r--status.go1706log stats plain blame
-rw-r--r--tabhost.go185log stats plain blame
-rw-r--r--terminal.go10776log stats plain blame
t/tour/commit/js/puzzle-dungeon/game.js?id=83140c20ccbd7c251e45aa560de4b99475b975b5'>83140c2 ^
5dc7854 ^


83140c2 ^









3a3a78a ^

83140c2 ^






5dc7854 ^
3a3a78a ^
83140c2 ^
3a3a78a ^
83140c2 ^





5dc7854 ^
83140c2 ^

3a3a78a ^
83140c2 ^





3a3a78a ^
83140c2 ^

5dc7854 ^
83140c2 ^
3a3a78a ^
83140c2 ^


5dc7854 ^
83140c2 ^





5dc7854 ^
83140c2 ^
5dc7854 ^
83140c2 ^
3a3a78a ^
83140c2 ^

3a3a78a ^
83140c2 ^
5dc7854 ^
83140c2 ^
5dc7854 ^
83140c2 ^



3a3a78a ^

83140c2 ^

f0aeda1 ^
83140c2 ^


e48af81 ^







83140c2 ^




3a3a78a ^
83140c2 ^

9ccf051 ^
83140c2 ^


3a3a78a ^

83140c2 ^






3a3a78a ^
83140c2 ^


5dc7854 ^
83140c2 ^
e48af81 ^
83140c2 ^
3a3a78a ^
83140c2 ^

















e48af81 ^

83140c2 ^
3a3a78a ^


83140c2 ^
f0aeda1 ^

83140c2 ^












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




                                                           
              
             
             
           


                                    
 







                                        
     
                

 











                                                                                
                                                      
                                                             
                               


                                   









                                                                                           

 






                                                                            
                                                         
     
 
 





                                                                     
                                                                                             

                                                                  
 





                                                                                          
 

                                  
                                        
                                                                           
 


                                                                             
                                          





                                                       
                                                        
                                                       
                                                       
                                                                                             
             

           
 
                  
                                                          
                                                                                                 
                              



                                                                                                                

 

                                             
                                         


                                                                                                                         







                                                                   




                                     
 

                                                         
                                                                        


                          

 






                                                  
 


                                                                                                                     
                                                                                  
                                                                                                           
                                                                                  
 
 

















                                                                                     

                                                                          
                                                                          


     
                                 

                                                                                                       












                                 
export let grid = createGrid(10, 10);  // Example grid size
export let player = {
    position: { x: 0, y: 0 },
    inventory: [],
    health: 10,
    power: 10,
    level: 0,
    steps: 0,
    par: 0,
    flashing: false
};
let targetPosition = { x: 0, y: 0 };

function createGrid(rows, cols) {
    let grid = [];
    for (let i = 0; i < rows; i++) {
        let row = [];
        for (let j = 0; j < cols; j++) {
            row.push(null);
        }
        grid.push(row);
    }
    return grid;
}

export let levelPar;
function generatePar(level) {
    let par;
    if (level < 6) {
        par = 7;
    } else {
        par = Math.floor(Math.random() * 7) + 1;
    }
    document.getElementById('par').textContent = `Par: ${player.par} of ${par}`;
    return par;
}

function generateCollectables(grid, numCollectables) {
    const collectableTypes = ['potion', 'shield', 'battery'];
    const collectableColors = {
        'potion': 'peachpuff',
        'shield': 'cornflowerBlue',
        'battery': 'gold'
    };
    for (let i = 0; i < numCollectables; i++) {
        let x, y;
        do {
            x = Math.floor(Math.random() * grid.length);
            y = Math.floor(Math.random() * grid[0].length);
        } while (x === 0 && y === 0);  // Ensure no items at (0,0)
        const type = collectableTypes[Math.floor(Math.random() * collectableTypes.length)];
        grid[x][y] = { type, color: collectableColors[type] };
    }
}

function generateDamagingSpaces(grid, numSpaces) {
    for (let i = 0; i < numSpaces; i++) {
        let x, y;
        do {
            x = Math.floor(Math.random() * grid.length);
            y = Math.floor(Math.random() * grid[0].length);
        } while (x === 0 && y === 0);  // Ensure no damaging spaces at (0,0)
        grid[x][y] = { type: 'damage', color: 'tomato' };
    }
}

function generateTargetBlock(grid) {
    let x, y;
    do {
        x = Math.floor(Math.random() * grid.length);
        y = Math.floor(Math.random() * grid[0].length);
    } while (x === 0 && y === 0);  // Ensure no target block at (0,0)
    grid[x][y] = { type: 'target', color: 'lightgreen' };  // Target block represented by 'X'
    targetPosition = { x, y };  // Store the target block position
}

export function drawGrid(grid) {
    const canvas = document.getElementById('gameCanvas');
    const ctx = canvas.getContext('2d');
    const cellSize = Math.min(canvas.width / grid.length, canvas.height / grid[0].length);

    ctx.clearRect(0, 0, canvas.width, canvas.height);

    grid.forEach((row, x) => {
        row.forEach((cell, y) => {
            ctx.strokeStyle = '#2d2d2d';
            ctx.strokeRect(x * cellSize, y * cellSize, cellSize, cellSize);

            if (cell && cell.color) {
                ctx.fillStyle = cell.color;
                ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
                ctx.fillStyle = '#2d2d2d';
                ctx.font = `${cellSize / 2}px Arial`;
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                let char = '';
                if (cell.type === 'potion') char = 'p';
                if (cell.type === 'shield') char = 's';
                if (cell.type === 'battery') char = 'b';
                if (cell.type === 'damage') char = '!';
                if (cell.type === 'target') char = '#';
                ctx.fillText(char, x * cellSize + cellSize / 2, y * cellSize + cellSize / 2);
            }
        });
    });

    // Draw player
    ctx.fillStyle = player.flashing ? 'white' : 'thistle';
    ctx.fillRect(player.position.x * cellSize, player.position.y * cellSize, cellSize, cellSize);
    ctx.fillStyle = '#2d2d2d';
    ctx.font = `${cellSize / 2}px Arial`;
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';
    ctx.fillText('@', player.position.x * cellSize + cellSize / 2, player.position.y * cellSize + cellSize / 2);
}

export function initializeGame() {
    grid = createGrid(10, 10);  // Reset grid
    levelPar = generatePar(player.level);
    generateCollectables(grid, 10);  // Adjust the number as needed
    generateDamagingSpaces(grid, Math.floor(Math.random() * 7) + 1);  // Random number of damaging spaces, no more than 7
    generateTargetBlock(grid);  // Add target block

    if (player.level === 0) {
        player.position = { x: 0, y: 0 };  // Reset player position
        player.inventory = [];  // Clear inventory
        player.health = 10;  // Reset health
        player.power = 10;  // Reset endurance
    }

    player.steps = 0;  // Reset steps
    resizeCanvas();
    drawGrid(grid);
    updatePlayerStatus();
}

export function resizeCanvas() {
    const canvas = document.getElementById('gameCanvas');
    const width = Math.min(window.innerWidth, window.innerHeight) * 0.5;
    canvas.width = width;
    canvas.height = width;
    drawGrid(grid);
}

export function updatePlayerPosition(newX, newY) {
    player.position.x = newX;
    player.position.y = newY;
    checkForDamageOrTarget();
    drawGrid(grid);
    updatePlayerStatus();
}

export function updatePlayerStatus() {
    document.getElementById('playerPosition').textContent = `Position: (${player.position.x}, ${player.position.y})`;
    document.getElementById('playerHealth').textContent = `Health: ${player.health}`;
    document.getElementById('playerPower').textContent = `Power: ${player.power}`;
    document.getElementById('playerInventory').textContent = `Inventory: [${player.inventory.join(', ')}]`;
    document.getElementById('playerLevel').textContent = `Level: ${player.level}`;
}

function checkForDamageOrTarget() {
    const { x, y } = player.position;
    const cell = grid[x][y];
    if (cell && cell.type === 'damage') {
        const shieldIndex = player.inventory.indexOf('shield');
        if (shieldIndex > -1) {
            player.inventory.splice(shieldIndex, 1);  // Use one shield
            console.log('Used shield to avoid damage');
        } else {
            player.health -= 2;
            console.log(`Stepped on damaging space, health is now ${player.health}`);
            if (player.health <= 0) {
                alertGameOver();
                return;
            }
            flashPlayer();
        }
    } else if (x === targetPosition.x && y === targetPosition.y) {
        player.level += 1;
        console.log(`Reached target block, level is now ${player.level}`);
        initializeGame();  // Generate new level and reset player position
    }
}

export function alertGameOver() {
    const gameStatsString = `Level: ${player.level}, Health: ${player.health}, Power: ${player.power}`;
    alert('You have lost the game!' + '\n' + gameStatsString);
    initializeGame();
}

function flashPlayer(callback) {
    player.flashing = true;
    drawGrid(grid);
    setTimeout(() => {
        player.flashing = false;
        drawGrid(grid);
        updatePlayerStatus();
        if (callback) callback();
    }, 250); // Flash duration
}