updated infection
This commit is contained in:
parent
6229d93adc
commit
0d4c5e9630
@ -65,8 +65,8 @@ Player control:
|
|||||||
|
|
||||||
const INCUBATION = 20000; // time before showing symptoms
|
const INCUBATION = 20000; // time before showing symptoms
|
||||||
const DEATH = 40000; // time before dying off the disease
|
const DEATH = 40000; // time before dying off the disease
|
||||||
const RSSI = -45; // db
|
const RSSI = -48; // db
|
||||||
const TRANSMISSIONPROB = 40; // %
|
const TRANSMISSIONPROB = 80; // %
|
||||||
|
|
||||||
enum GameState {
|
enum GameState {
|
||||||
Stopped,
|
Stopped,
|
||||||
@ -107,7 +107,7 @@ function player(id: number): Player {
|
|||||||
// add player to game
|
// add player to game
|
||||||
let p = new Player();
|
let p = new Player();
|
||||||
p.id = id;
|
p.id = id;
|
||||||
p.icon = players.length ? players[0].icon + 1 : 2;
|
p.icon = players.length ? players[players.length - 1].icon + 1 : 2;
|
||||||
p.health = HealthState.Healthy;
|
p.health = HealthState.Healthy;
|
||||||
// don't use sad, happy
|
// don't use sad, happy
|
||||||
if (p.icon == IconNames.Happy) p.icon += 2;
|
if (p.icon == IconNames.Happy) p.icon += 2;
|
||||||
@ -145,8 +145,6 @@ function gameFace() {
|
|||||||
basic.showIcon(IconNames.Sad);
|
basic.showIcon(IconNames.Sad);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//case HealthState.Healthy:
|
|
||||||
//case HealthState.Incubating:
|
|
||||||
basic.showIcon(IconNames.Happy);
|
basic.showIcon(IconNames.Happy);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -213,6 +211,7 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
else {
|
else {
|
||||||
basic.showIcon(icon);
|
basic.showIcon(icon);
|
||||||
gameFace();
|
gameFace();
|
||||||
|
game.showScore();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -275,6 +274,10 @@ radio.onDataPacketReceived(({ time, receivedNumber, receivedString, signal, seri
|
|||||||
health = HealthState.Incubating;
|
health = HealthState.Incubating;
|
||||||
serial.writeLine(`infected ${control.deviceSerialNumber()}`);
|
serial.writeLine(`infected ${control.deviceSerialNumber()}`);
|
||||||
}
|
}
|
||||||
|
if (receivedString == "h" + control.deviceSerialNumber().toString() &&
|
||||||
|
health < receivedNumber) {
|
||||||
|
health = receivedNumber;
|
||||||
|
}
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case GameState.Pairing:
|
case GameState.Pairing:
|
||||||
// medium range in pairing mode
|
// medium range in pairing mode
|
||||||
@ -287,14 +290,14 @@ radio.onDataPacketReceived(({ time, receivedNumber, receivedString, signal, seri
|
|||||||
basic.showString("R");
|
basic.showString("R");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (paired && receivedString == control.deviceSerialNumber().toString()) {
|
else if (paired && receivedString == "i" + control.deviceSerialNumber().toString()) {
|
||||||
icon = receivedNumber;
|
icon = receivedNumber;
|
||||||
basic.showIcon(icon);
|
basic.showIcon(icon);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GameState.Running:
|
case GameState.Running:
|
||||||
// broadcast infection status
|
// broadcast infection status
|
||||||
if (paired && health == HealthState.Healthy && receivedString == "transmit") {
|
if (health == HealthState.Healthy && receivedString == "transmit") {
|
||||||
serial.writeLine(`signal: ${signal}`);
|
serial.writeLine(`signal: ${signal}`);
|
||||||
if (signal > RSSI &&
|
if (signal > RSSI &&
|
||||||
Math.random(100) > TRANSMISSIONPROB) {
|
Math.random(100) > TRANSMISSIONPROB) {
|
||||||
@ -302,6 +305,8 @@ radio.onDataPacketReceived(({ time, receivedNumber, receivedString, signal, seri
|
|||||||
infectedTime = input.runningTime();
|
infectedTime = input.runningTime();
|
||||||
health = HealthState.Incubating;
|
health = HealthState.Incubating;
|
||||||
}
|
}
|
||||||
|
} else if (receivedString == "health" && signal > RSSI) {
|
||||||
|
game.addScore(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -316,11 +321,16 @@ basic.forever(() => {
|
|||||||
// tell each player they are registered
|
// tell each player they are registered
|
||||||
for (const p of players) {
|
for (const p of players) {
|
||||||
radio.sendValue("paired", p.id);
|
radio.sendValue("paired", p.id);
|
||||||
radio.sendValue("" + p.id, p.icon);
|
radio.sendValue("i" + p.id, p.icon);
|
||||||
}
|
}
|
||||||
serial.writeLine(`pairing ${players.length} players`);
|
serial.writeLine(`pairing ${players.length} players`);
|
||||||
basic.pause(500);
|
basic.pause(500);
|
||||||
break;
|
break;
|
||||||
|
case GameState.Running:
|
||||||
|
for (const p of players) {
|
||||||
|
radio.sendValue("h" + p.id, p.health);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
radio.sendValue("state", state); // keep broadcasting the game state
|
radio.sendValue("state", state); // keep broadcasting the game state
|
||||||
} else { // player loop
|
} else { // player loop
|
||||||
@ -350,7 +360,6 @@ basic.forever(() => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
basic.pause(100)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
basic.showIcon(IconNames.Ghost);
|
basic.showIcon(IconNames.Ghost);
|
||||||
|
Loading…
Reference in New Issue
Block a user