Last active
September 24, 2021 03:28
-
-
Save toomasv/db152840afa1d7639975c24f0ed2996c to your computer and use it in GitHub Desktop.
TIc-Tac-Toe
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
Red [ | |
Description: "Tic-Tac-Toe" | |
Date: 2021-02-26 | |
] | |
wins: [[1 2 3][4 5 6][7 8 9][1 4 7][2 5 8][3 6 9][1 5 9][3 5 7]] | |
check: func [move][ | |
foreach win wins [ | |
if 3 = length? intersect win state/:move [return win] | |
] | |
false | |
] | |
init: does [ | |
cross?: yes | |
end?: no | |
state: reduce [true clear [] false clear []] | |
] | |
init | |
fnt: make font! [size: 46 name: system/view/fonts/fixed style: 'bold color: crimson] | |
view [ | |
title "Tic-Tac-Toe" | |
size 630x630 origin 25x25 space 6x6 | |
style cell: box 190x190 snow | |
draw [line-cap round line-width 5 pen pink] | |
on-down [ | |
either end? [ | |
append fin/draw [font fnt text 80x220 {Game is over!^/ Restart?}] | |
fin/color: 128.128.128.128 | |
][ | |
if none? face/data [ | |
append face/draw either cross?: not cross? [ | |
[line 35x35 155x155 line 155x35 35x155] | |
][ | |
[circle 95x95 60] | |
] | |
face/data: cross? | |
append state/(cross?) face/extra | |
if w: check cross? [ | |
append fin/draw compose [ | |
line ( | |
switch w/3 - w/1 [ | |
2 [reduce [as-pair 10 y: (to-integer w/1 - 1 / 3) * 196 + 96 as-pair 572 y]] | |
6 [reduce [as-pair x: w/1 - 1 % 3 * 196 + 96 10 as-pair x 572]] | |
8 [[10x10 572x572]] | |
4 [[572x10 10x572]] | |
] | |
) | |
] | |
end?: yes | |
] | |
] | |
] | |
] | |
on-created [face/extra: -1 + index? find face/parent/pane face] | |
at 25x25 box silver 582x582 | |
cell cell cell return | |
cell cell cell return | |
cell cell cell | |
at 25x25 fin: box 582x582 draw [line-cap round line-width 15 pen 0.128.0.64] | |
on-down [ | |
init | |
foreach-face/with face/parent [ | |
clear at face/draw 7 | |
face/data: none | |
][face/draw] | |
face/color: none | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment