Fix randomInt
This commit is contained in:
@ -257,7 +257,7 @@ input.onButtonPressed(Button.AB, () => {
|
||||
// launch game
|
||||
if (state == GameState.Pairing) {
|
||||
// pick 1 player and infect him
|
||||
patientZero = players[Math.randomInt(players.length)];
|
||||
patientZero = players[Math.randomRange(0, players.length)];
|
||||
while (patientZero.health == HealthState.Healthy) {
|
||||
radio.sendValue("infect", patientZero.id);
|
||||
basic.pause(100);
|
||||
@ -333,7 +333,7 @@ radio.onDataPacketReceived(({ time, receivedNumber, receivedString, signal, seri
|
||||
if (health == HealthState.Healthy && receivedString == "transmit") {
|
||||
serial.writeLine(`signal: ${signal}`);
|
||||
if (signal > RSSI &&
|
||||
Math.randomInt(100) > TRANSMISSIONPROB) {
|
||||
Math.randomRange(0, 100) > TRANSMISSIONPROB) {
|
||||
infectedBy = receivedNumber;
|
||||
infectedTime = input.runningTime();
|
||||
health = HealthState.Incubating;
|
||||
|
@ -18,7 +18,7 @@ show a random number from 0 to 100 when pin ``P0`` is pressed.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.randomInt(101));
|
||||
basic.showNumber(Math.randomRange(0, 101));
|
||||
});
|
||||
```
|
||||
|
||||
@ -29,7 +29,7 @@ Show ``"LOVE METER"`` on the screen when the @boardname@ starts.
|
||||
```blocks
|
||||
basic.showString("LOVE METER");
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.randomInt(101));
|
||||
basic.showNumber(Math.randomRange(0, 101));
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -125,7 +125,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
|
||||
@ -155,13 +155,13 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
if (!(false_start)) {
|
||||
start = input.runningTime()
|
||||
running = true
|
||||
led.stopAnimation()
|
||||
basic.clearScreen()
|
||||
led.plot(Math.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
running = false
|
||||
@ -214,13 +214,13 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
if (!(false_start)) {
|
||||
start = input.runningTime()
|
||||
running = true
|
||||
led.stopAnimation()
|
||||
basic.clearScreen()
|
||||
led.plot(Math.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
running = false
|
||||
@ -247,13 +247,13 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
if (!(false_start)) {
|
||||
start = input.runningTime()
|
||||
running = true
|
||||
led.stopAnimation()
|
||||
basic.clearScreen()
|
||||
led.plot(Math.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
|
@ -22,7 +22,7 @@ rock, paper, and scissors are the tools you use to challenge your friends!)
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
|
||||
```
|
||||
@ -37,7 +37,7 @@ check whether ``tool`` is equal to ``0``.
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
}
|
||||
})
|
||||
@ -51,7 +51,7 @@ picture of a piece of paper.
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
@ -74,7 +74,7 @@ Click on the gearwheel icon to open up the ``if`` editor; then drag and drop an
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
@ -95,7 +95,7 @@ Place a ``||basic:show leds||`` block under the else if and draw a **rock** imag
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
@ -126,7 +126,7 @@ That's why you can use an ``else`` instead of an ``else if``.
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
|
@ -26,7 +26,7 @@ Let's start out with the code from the original game. The basic version picks on
|
||||
```blocks
|
||||
let tool = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showIcon(IconNames.SmallSquare)
|
||||
} else if (tool == 1) {
|
||||
@ -44,7 +44,7 @@ input.onGesture(Gesture.Shake, () => {
|
||||
```blocks
|
||||
let tool = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
|
||||
basic.forever(() => {
|
||||
@ -67,7 +67,7 @@ We also set the radio group and send the device serial number (a number that uni
|
||||
```blocks
|
||||
let tool = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
|
||||
basic.forever(() => {
|
||||
@ -154,7 +154,7 @@ What if some of the other players leave the game? They would stop broadcasting t
|
||||
```block
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let players: number[] = [0]
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
})
|
||||
```
|
||||
|
||||
@ -185,7 +185,7 @@ let match = false
|
||||
let players: number[] = []
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
players = [0]
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
radio.onDataPacketReceived( ({ receivedNumber, serial: serialNumber }) => {
|
||||
match = tool == receivedNumber
|
||||
|
@ -38,7 +38,7 @@ Choose a random number between 0 and 9.
|
||||
```blocks
|
||||
let randomNbr = 0
|
||||
input.onGesture(Gesture.ScreenUp, () => {
|
||||
randomNbr = Math.randomInt(10)
|
||||
randomNbr = Math.randomRange(0, 10)
|
||||
basic.showNumber(randomNbr)
|
||||
})
|
||||
```
|
||||
@ -50,7 +50,7 @@ let randomNbr = 0
|
||||
input.onGesture(Gesture.ScreenUp, () => {
|
||||
randomNbr = 0
|
||||
while (randomNbr < 1) {
|
||||
randomNbr = Math.randomInt(10)
|
||||
randomNbr = Math.randomRange(0, 10)
|
||||
}
|
||||
basic.showNumber(randomNbr)
|
||||
})
|
||||
|
Reference in New Issue
Block a user