-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory-game.red
140 lines (123 loc) · 4.57 KB
/
memory-game.red
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
Red [
Title: "memory-game.red"
Needs: 'View
Iteration: 0.0.1.1
Purpose: {
FIX: *** Script Error: img-none has no value
set clicked of previous-face-clicked to true
to previous-face from flipping
}
Code: {
if img-clicked = previous-image-clicked [
previous-face-clicked/image: img-clicked
previous-face-clicked/extra: update-readable previous-face-clicked/extra 'clicked true
exit
]
}
References: [
https://www.packtpub.com/mapt/book/all_books/9781789130706/9/ch09lvl1sec79/a-faces-walkthrough
http://www.rebol.com/how-to/btns-cust.html
]
Credits: [
https://www.iconfinder.com/icons/2730389/brain_divide_inkcontober_sains_icon
]
Free-icons: [
https://www.iconfinder.com/icons/2308049/application_friends_photos_publications_snapchat_snaps_icon
https://www.iconfinder.com/icons/2308040/logo_videos_watch_wbesite_youtube_youtube2_icon
]
Free-images: [
https://www.freepik.com/free-vector/funny-animals-collection_765907.htm
https://www.freepik.com/free-vector/set-of-funny-cartoon-animals_683237.htm
https://image.freepik.com/free-vector/funny-animals-collection_23-2147505702.jpg
https://www.sketchappsources.com/free-source/3073-crypto-currency-alt-coins-vector-logo-sketch-freebie-resource.html
]
]
do read http://redlang.red/range
do read http://redlang.red/crud-readable.red
cell-size: 128x128
img-back: load http://miniapps.red/images/brain_128.png
base-img-url: http://miniapps.red/images/
icons-list: [
%google_128.png %twitter_128.png %facebook_128.png %youtube_128.png
%winword_128.png %excel_128.png %powerpoint_128.png %onenote_128.png
%google_128.png %twitter_128.png %facebook_128.png %youtube_128.png
%winword_128.png %excel_128.png %powerpoint_128.png %onenote_128.png
]
img-1: load http://miniapps.red/images/google_128.png
img-2: load http://miniapps.red/images/twitter_128.png
img-3: load http://miniapps.red/images/facebook_128.png
img-4: load http://miniapps.red/images/youtube_128.png
img-5: load http://miniapps.red/images/winword_128.png
img-6: load http://miniapps.red/images/excel_128.png
img-7: load http://miniapps.red/images/powerpoint_128.png
img-8: load http://miniapps.red/images/onenote_128.png
img-9: load http://miniapps.red/images/google_128.png
img-10: load http://miniapps.red/images/twitter_128.png
img-11: load http://miniapps.red/images/facebook_128.png
img-12: load http://miniapps.red/images/youtube_128.png
img-13: load http://miniapps.red/images/winword_128.png
img-14: load http://miniapps.red/images/excel_128.png
img-15: load http://miniapps.red/images/powerpoint_128.png
img-16: load http://miniapps.red/images/onenote_128.png
i: 1
random/seed now
shuffled-img: random .range 1 16
previous-image-clicked: none
img-clicked: none
previous-id-clicked: none
id-clicked: none
previous-face-clicked: none
face-clicked: none
view layout compose [
title "Memory Game"
backdrop white
style cell: image (cell-size) (img-back) on-over [
clicked: select face/extra 'clicked
if clicked = true [
previous-image-clicked: img-clicked
img-clicked: face/image
previous-id-clicked: id-clicked
id-clicked: select face/extra 'id
previous-face-clicked: face-clicked
face-clicked: face
if img-clicked = previous-image-clicked [
previous-face-clicked/image: img-clicked
previous-face-clicked/extra: update-readable previous-face-clicked/extra 'clicked true
exit
]
]
img: face/image
either img = (img-back) [
img-number: select face/extra 'img-number ; set in on-create
img-id: to-word rejoin ["img-" img-number]
face/image: get img-id
][
face/image: (img-back)
]
]
on-down [
face/extra: update-readable face/extra 'clicked true
]
extra 0 on-create [
i: 1 + i
face/extra: copy []
append face/extra compose [(to-set-word "id") (i)]
append face/extra compose [(to-set-word "img-number") (shuffled-img/:i)]
append face/extra compose [(to-set-word "clicked") false]
]
panel [
cell cell cell cell return
cell cell cell cell return
cell cell cell cell return
cell cell cell cell
]
return
panel 400x40 [
button "Play" [
Play-Status: true
]
]
do [
Play-Status: False
]
]