Skip to content

Instantly share code, notes, and snippets.

@greggirwin
Created July 10, 2017 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greggirwin/6d3c3adc9525cd759258f85be817dc45 to your computer and use it in GitHub Desktop.
Save greggirwin/6d3c3adc9525cd759258f85be817dc45 to your computer and use it in GitHub Desktop.
Configurable Tile Game
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