forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add files via upload * Add files via upload * Fixing metadata * Update slot_machine.js --------- Co-authored-by: graham <graham@hackclub.com>
- Loading branch information
1 parent
5df20bd
commit d08edf2
Showing
2 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
@title: Slot Machine | ||
@author: Alexander Li | ||
@discord: thefaix. | ||
@tags: ["classic", "tool"] | ||
@img: "" | ||
@addedOn: 2024-05-23 | ||
*/ | ||
|
||
const slot = "s" | ||
const symbol7 = "7" | ||
const symbolC = "C" | ||
const symbolB = "B" | ||
const symbolX = "X" | ||
const winSign = "W" | ||
|
||
const symbols = [symbol7, symbolC, symbolB, symbolX] | ||
|
||
setLegend( | ||
[ slot, bitmap` | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................` ], | ||
[ symbol7, bitmap` | ||
................ | ||
..444........... | ||
..44444444...... | ||
..4444444444.... | ||
.....4444..44... | ||
........44.4.... | ||
.........444.... | ||
...4444.444..44. | ||
...444444444444. | ||
...444444444444. | ||
......4444...... | ||
......444....... | ||
.....444........ | ||
....4444........ | ||
....444......... | ||
................` ], | ||
[ symbolC, bitmap` | ||
................ | ||
.......33....... | ||
......3333...... | ||
.....333333..... | ||
....333...33.... | ||
...3333....33... | ||
....33333333.... | ||
.....333333..... | ||
....3333...3.... | ||
...333333..33... | ||
..333333333333.. | ||
...3333333333... | ||
....33333333.... | ||
.....333333..... | ||
......3333...... | ||
................` ], | ||
[ symbolB, bitmap` | ||
................ | ||
.........9...... | ||
.......999...... | ||
.......9........ | ||
.....999999..... | ||
...999999.999... | ||
...999999...9... | ||
..99999999...9.. | ||
..999999999.99.. | ||
..999999999999.. | ||
..999999999999.. | ||
...9999999999... | ||
...9999999999... | ||
.....9999999.... | ||
.......9999..... | ||
................` ], | ||
[ symbolX, bitmap` | ||
................ | ||
................ | ||
.......C........ | ||
.....CCCCCC..... | ||
...CCC....CC.... | ||
...C......CC.... | ||
..CCCCCCCC.CC... | ||
..CC......C.CCC. | ||
..C...........CC | ||
.CCCCCCCCCCCC..C | ||
.C...........CCC | ||
.CC.........CCC. | ||
..CCCCCCCCCCC... | ||
................ | ||
................ | ||
................` ] | ||
) | ||
|
||
setSolids([]) | ||
|
||
const level = 0 | ||
const levels = [ | ||
map` | ||
.s.s.s.` | ||
] | ||
|
||
setMap(levels[level]) | ||
|
||
function getRandomSymbol() { | ||
return symbols[Math.floor(Math.random() * symbols.length)] | ||
} | ||
|
||
function spinSlots() { | ||
clearBoard() | ||
const slotPositions = getAll(slot) | ||
const results = [] | ||
slotPositions.forEach(pos => { | ||
const symbol = getRandomSymbol() | ||
addSprite(pos.x, pos.y, symbol) | ||
results.push(symbol) | ||
}) | ||
checkWin(results) | ||
} | ||
|
||
function clearBoard() { | ||
const slotPositions = getAll(slot) | ||
slotPositions.forEach(pos => { | ||
clearTile(pos.x, pos.y) | ||
addSprite(pos.x, pos.y, slot) | ||
}) | ||
clearText() | ||
} | ||
|
||
function checkWin(results) { | ||
if (results.every(symbol => symbol === results[0])) { | ||
displayWin() | ||
} | ||
} | ||
|
||
function displayWin() { | ||
// Display "You Win!" message | ||
clearText() | ||
addText("YOU WIN!", { | ||
x: 2, | ||
y: 5, | ||
color: color`3` | ||
}) | ||
} | ||
|
||
onInput("s", () => { | ||
spinSlots() | ||
}) | ||
|
||
afterInput(() => { | ||
// No additional actions needed after input | ||
}) |