forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPS.js
127 lines (116 loc) · 2.29 KB
/
RPS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
@title: RPS
@author: Shahm Najeeb
@tags: ['endless']
@addedOn: 2024-08-23
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started
*/
const player = "p";
const rock = "r";
const paper = "f";
const scissors = "c";
const opponent = "o"; // Opponent could be another player or AI
setLegend(
[player, bitmap`
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222`],
[rock, bitmap`
................
................
................
................
................
................
................
......LL1.......
.....LLLLL......
....LL1LLL1.....
....1LLLLL......
.....LLL1.......
................
................
................
................`],
[scissors, bitmap`
................
................
................
................
................
......L.L.......
.....L.L.L......
......LLL.......
......1L1.......
.......1........
......1.1.......
......1.1.......
................
................
................
................`],
[paper, bitmap`
................
................
......6.........
.....6FFF.......
....6F222F......
.....F222F......
.....F222FF.....
.....FF222F.....
......F222F.....
......F222F6....
.......FFF6.....
.........6......
................
................
................
................`]
)
setSolids([])
let level = 0
const levels = [
map`
rfc`
]
setMap(levels[level])
function determineWinner(playerMove, opponentMove) {
if (playerMove === opponentMove) return "draw";
if ((playerMove === rock && opponentMove === scissors) ||
(playerMove === paper && opponentMove === rock) ||
(playerMove === scissors && opponentMove === paper)) {
return "player wins";
} else {
return "opponent wins";
}
}
onInput("a", () => {
playerMove = "r";
})
onInput("s", () => {
playerMove = "p";
})
onInput("d", () => {
playerMove = "s";
})
afterInput(() => {
clearText();
const opponentMoves = [rock, paper, scissors];
const opponentMove = opponentMoves[Math.floor(Math.random() * opponentMoves.length)];
const result = determineWinner(playerMove, opponentMove);
addText(result, { x: 0, y: 0 });
})