Created
July 10, 2017 16:56
-
-
Save greggirwin/6d3c3adc9525cd759258f85be817dc45 to your computer and use it in GitHub Desktop.
Configurable Tile Game
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 [ | |
Purpose: "Simple tile game where you can set the the board and button size." | |
Author: "Gregg Irwin" | |
Notes: { | |
Based on https://github.com/red/code/blob/master/Showcase/tile-game.red | |
Shows how to dynamically generate a VID GUI, including static elements. | |
} | |
] | |
; Defaults | |
board-size: 4 | |
button-size: 60 | |
view [ | |
text "Board Size:" f-board-size: field data (form board-size) return | |
text "Button Size:" f-button-size: field data (form button-size) return | |
button "Go!" [ | |
board-size: to integer! f-board-size/data | |
button-size: to pair! to integer! f-button-size/data | |
max-delta: to integer! button-size/x * 1.5 | |
unview | |
] | |
] | |
; Start with the static prologue of your layout | |
board: [ | |
title "Tile game" | |
style tile: button button-size font-size 12 bold [ | |
delta: absolute face/offset - empty/offset | |
if delta/x + delta/y > max-delta [exit] | |
pos: face/offset face/offset: empty/offset empty/offset: pos | |
] | |
] | |
; Add the dynamic buttons | |
repeat n subtract round (board-size ** 2) 1 [ | |
repend board ['tile form n] | |
if zero? n // board-size [append board 'return] | |
] | |
; Add the static epilogue | |
append board [empty: tile ""] | |
; See if it worked | |
view/tight board | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment