Add game state boolean ref docs (#1694)

* Add game state boolean doc refs

* Add check for _img validity

* JS guru tricks
This commit is contained in:
Galen Nickel 2018-12-02 20:11:17 -08:00 committed by GitHub
parent dda488c08f
commit 55e5125449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 100 additions and 13 deletions

View File

@ -47,6 +47,9 @@ game.startCountdown(10000);
game.gameOver(); game.gameOver();
game.pause(); game.pause();
game.resume(); game.resume();
game.isGameOver()
game.isRunning();
game.isPaused();
``` ```
## See also ## See also
@ -57,4 +60,5 @@ game.resume();
[add score](/reference/game/add-score), [score](/reference/game/score), [set score](/reference/game/set-score), [add score](/reference/game/add-score), [score](/reference/game/score), [set score](/reference/game/set-score),
[set life](/reference/game/set-life), [add life](/reference/game/add-life), [remove life](/reference/game/remove-life), [set life](/reference/game/set-life), [add life](/reference/game/add-life), [remove life](/reference/game/remove-life),
[start countdown](/reference/game/start-countdown), [game over](/reference/game/game-over), [start countdown](/reference/game/start-countdown), [game over](/reference/game/game-over),
[pause](/reference/game/pause), [resume](/reference/game/resume) [pause](/reference/game/pause), [resume](/reference/game/resume),
[is game over](/reference/game/is-game-over,) [is running](/reference/game/is-running), [is paused](/reference/game/is-paused)

View File

@ -0,0 +1,25 @@
# is Game Over
Find out if the game is over or not.
```sig
game.isGameOver()
```
## Returns
* a [boolean](/types/boolean) value that is `true` if the game is over or `false` if not.
# Example
Be kind and give the player some points for trying.
```blocks
if (game.isGameOver() && game.score() < 10) {
game.addScore(10 - game.score())
}
```
## See also
[is running](/reference/game/is-running),
[is paused](/reference/game/is-paused)

View File

@ -0,0 +1,28 @@
# is Paused
Find out if the game is paused or not.
```sig
game.isPaused()
```
## Returns
* a [boolean](/types/boolean) value that is `true` if the game is paused or `false` if not.
## Example
Resume the game if it's paused and button **B** is pressed.
```blocks
input.onButtonPressed(Button.B, function () {
if (game.isPaused()) {
game.resume()
}
})
```
## See also
[is running](/reference/game/is-running),
[is game over](/reference/game/is-game-over)

View File

@ -0,0 +1,28 @@
# is Running
Find out if the game is currently running or not.
```sig
game.isRunning()
```
## Returns
* a [boolean](/types/boolean) value that is `true` if the game is running or `false` if not.
## Example
If the game is currently running, end the game if button **B** is pressed.
```blocks
input.onButtonPressed(Button.B, function () {
if (game.isRunning()) {
game.gameOver()
}
})
```
## See also
[is paused](/reference/game/is-paused),
[is game over](/reference/game/is-game-over)

View File

@ -295,9 +295,9 @@
"game.currentTime": "Gets the remaining time (since `start countdown`) or current time (since the device started or `start stopwatch`) in milliseconds.", "game.currentTime": "Gets the remaining time (since `start countdown`) or current time (since the device started or `start stopwatch`) in milliseconds.",
"game.gameOver": "Displays a game over animation and the score.", "game.gameOver": "Displays a game over animation and the score.",
"game.invalidSprite": "Gets an invalid sprite; used to initialize locals.", "game.invalidSprite": "Gets an invalid sprite; used to initialize locals.",
"game.isGameOver": "Indicates if the game is display the game over sequence.", "game.isGameOver": "Indicates if the game is over and displaying the game over sequence.",
"game.isPaused": "Indicates if the game rendering is paused to allow other animations", "game.isPaused": "Indicates if the game rendering is paused to allow other animations",
"game.isRunning": "Gets a value indicating if the game is still running. Returns `false` if game over.", "game.isRunning": "Indicates if the game is still running. Returns `false` if the game is over or paused.",
"game.level": "Gets the current level", "game.level": "Gets the current level",
"game.levelUp": "Increments the level and display a message.", "game.levelUp": "Increments the level and display a message.",
"game.life": "Gets the current life", "game.life": "Gets the current life",

View File

@ -269,6 +269,9 @@
"game.addScore|block": "change score by|%points", "game.addScore|block": "change score by|%points",
"game.createSprite|block": "create sprite at|x: %x|y: %y", "game.createSprite|block": "create sprite at|x: %x|y: %y",
"game.gameOver|block": "game over", "game.gameOver|block": "game over",
"game.isGameOver|block": "is game over",
"game.isPaused|block": "is paused",
"game.isRunning|block": "is running",
"game.pause|block": "pause", "game.pause|block": "pause",
"game.removeLife|block": "remove life %life", "game.removeLife|block": "remove life %life",
"game.resume|block": "resume", "game.resume|block": "resume",

View File

@ -250,13 +250,12 @@ namespace game {
} }
/** /**
* Gets a value indicating if the game is still running. Returns `false` if game over. * Indicates if the game is still running. Returns `false` if the game is over or paused.
*/ */
//% weight=5 help=game/isrunning //% weight=5 help=game/is-running
//% blockId=game_isrunning block="is running?" blockGap=8 //% blockId=game_isrunning block="is running" blockGap=8
export function isRunning(): boolean { export function isRunning(): boolean {
let running: boolean; return !_isGameOver && !_paused && !!_img;
return !_isGameOver;
} }
/** /**
@ -271,10 +270,10 @@ namespace game {
} }
/** /**
* Indicates if the game is display the game over sequence. * Indicates if the game is over and displaying the game over sequence.
*/ */
//% weight=7 help=game/isgameover //% weight=7 help=game/is-game-over
//% blockId=game_isgameover block="is game over?" blockGap=8 //% blockId=game_isgameover block="is game over" blockGap=8
export function isGameOver(): boolean { export function isGameOver(): boolean {
return _isGameOver; return _isGameOver;
} }
@ -282,8 +281,8 @@ namespace game {
/** /**
* Indicates if the game rendering is paused to allow other animations * Indicates if the game rendering is paused to allow other animations
*/ */
//% weight=6 help=game/ispaused //% weight=6 help=game/is-paused
//% blockId=game_ispaused block="is paused?" blockGap=8 //% blockId=game_ispaused block="is paused" blockGap=8
export function isPaused(): boolean { export function isPaused(): boolean {
return _paused; return _paused;
} }