Win conditions
This commit is contained in:
1 parent
4c13945311
commit
9450251416
1 file changed
+28
-8
@@ -39,7 +39,6 @@ for (let color of PLAYER_COLORS) {
|
|||||||
players.push({
|
players.push({
|
||||||
x, y: landHeight(terrain, x)+1, a,
|
x, y: landHeight(terrain, x)+1, a,
|
||||||
p: PLAYER_INITIAL_POWER, c: color,
|
p: PLAYER_INITIAL_POWER, c: color,
|
||||||
// weapon: WEAPON_TYPES[i % WEAPON_TYPES.length],
|
|
||||||
weapon: WEAPON_TYPES[0],
|
weapon: WEAPON_TYPES[0],
|
||||||
energy: PLAYER_MAX_ENERGY,
|
energy: PLAYER_MAX_ENERGY,
|
||||||
ai: i !== 0 ? 'moron' : undefined,
|
ai: i !== 0 ? 'moron' : undefined,
|
||||||
@@ -174,19 +173,29 @@ function update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (state === 'end-turn') {
|
else if (state === 'end-turn') {
|
||||||
let i = 0;
|
let nextPlayer;
|
||||||
let player;
|
|
||||||
|
|
||||||
do {
|
for (let p=0; p<players.length; p++) {
|
||||||
currentPlayer = wrap(0, currentPlayer+1, players.length);
|
const i = wrap(0, currentPlayer+p+1, players.length);
|
||||||
player = players[currentPlayer];
|
if (!players[i].dead) {nextPlayer = i; break}
|
||||||
if (i++ === players.length) state = 'game-over';
|
}
|
||||||
} while (player.dead)
|
|
||||||
|
if (nextPlayer == null) return state = 'game-over';
|
||||||
|
else if (nextPlayer === currentPlayer) return state = 'player-win';
|
||||||
|
else currentPlayer = nextPlayer;
|
||||||
|
|
||||||
projectile = null;
|
projectile = null;
|
||||||
state = 'start-turn';
|
state = 'start-turn';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (state === 'player-win') {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state === 'game-over') {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
throw new Error(`Invalid state, ${state}`);
|
throw new Error(`Invalid state, ${state}`);
|
||||||
}
|
}
|
||||||
@@ -227,6 +236,17 @@ function drawExplosions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawStatus() {
|
function drawStatus() {
|
||||||
|
if (state === 'player-win') {
|
||||||
|
const player = players[currentPlayer];
|
||||||
|
drawText(foreground, `Player ${currentPlayer+1} wins!`, 8, 8, player.c, 'left');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state === 'game-over') {
|
||||||
|
drawText(foreground, `EVERYBODY IS DEAD`, 8, 8, 'white', 'left');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const player = players[currentPlayer];
|
const player = players[currentPlayer];
|
||||||
const {weapon} = player;
|
const {weapon} = player;
|
||||||
drawText(foreground, `AIM:${player.a} PWR:${player.p} ${weapon.name}`, 8, 8, player.c, 'left');
|
drawText(foreground, `AIM:${player.a} PWR:${player.p} ${weapon.name}`, 8, 8, player.c, 'left');
|
||||||
|
|||||||
Reference in new issue
Block a user