Skip to content

Commit 9579ba6

Browse files
committed
Can interact with the game and draw it to a conclusion. needs work on the game end part
1 parent cf3c046 commit 9579ba6

File tree

5 files changed

+453
-64
lines changed

5 files changed

+453
-64
lines changed

resources/web/index.css

+5
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ body {
5252
width: 98vw;
5353
background: #cfc;
5454
}
55+
56+
.cardspan {
57+
margin-left: 0.5em;
58+
border: 1px solid black;
59+
}

resources/web/index.js

+78
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
let all_selected_cards = [{}, {}];
2+
3+
function set_card_properties(who, collection) {
4+
for (let i = 0; i < 8; i++) {
5+
let label = `${who}_card${i}`;
6+
let card = document.getElementById(label);
7+
if (!card) {
8+
continue;
9+
}
10+
let n_string = `_${i}`;
11+
if (collection[n_string]) {
12+
card.style.background = 'green';
13+
} else {
14+
card.style.background = 'white';
15+
}
16+
}
17+
}
18+
119
function check() {
220
return fetch("idle.json", {
321
"method": "POST"
@@ -17,10 +35,70 @@ function check() {
1735
p2.innerHTML = json.p2;
1836
}
1937

38+
set_card_properties('alice', all_selected_cards[0]);
39+
set_card_properties('bob', all_selected_cards[1]);
40+
2041
setTimeout(check, 500);
2142
});
2243
}
2344

45+
function send_alice_word() {
46+
let word = Math.random().toString();
47+
return fetch(`alice_word_hash?word=${word}`, {
48+
"method": "POST"
49+
});
50+
}
51+
52+
function send_bob_word() {
53+
let word = Math.random().toString();
54+
return fetch(`bob_word?word=${word}`, {
55+
"method": "POST"
56+
});
57+
}
58+
59+
function toggle_card(label, selected_cards, n) {
60+
let n_string = `_${n}`;
61+
let card = document.getElementById(label);
62+
if (!card) {
63+
return;
64+
}
65+
if (selected_cards[n_string]) {
66+
card.style.background = 'white';
67+
delete selected_cards[n_string];
68+
} else {
69+
card.style.background = 'green';
70+
selected_cards[n_string] = true;
71+
}
72+
console.log(selected_cards);
73+
}
74+
75+
function alice_toggle(n) {
76+
toggle_card(`alice_card${n}`, all_selected_cards[0], n);
77+
}
78+
79+
function bob_toggle(n) {
80+
toggle_card(`bob_card${n}`, all_selected_cards[1], n);
81+
}
82+
83+
function set_picks(who, id) {
84+
let picks = '';
85+
for (let i = 0; i < 8; i++) {
86+
let n_string = `_${i}`;
87+
picks += (all_selected_cards[id][n_string]) ? '1' : '0';
88+
}
89+
return fetch(`${who}_picks?cards=${picks}`, {
90+
"method": "POST"
91+
});
92+
}
93+
94+
function set_alice_picks() {
95+
set_picks('alice', 0);
96+
}
97+
98+
function set_bob_picks() {
99+
set_picks('bob', 1);
100+
}
101+
24102
function exitapp() {
25103
return fetch("exit", {"method": "POST"}).then((response) => {
26104
console.log("exiting...");

src/channel_handler/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ impl ReadableMove {
283283
pub fn from_nodeptr(n: NodePtr) -> Self {
284284
ReadableMove(n)
285285
}
286+
287+
pub fn to_nodeptr(&self) -> NodePtr {
288+
self.0
289+
}
286290
}
287291

288292
impl ToClvm<NodePtr> for ReadableMove {

0 commit comments

Comments
 (0)