/examples/casket/valentine-bingo.rx
Forth | 84 lines | 65 code | 14 blank | 5 comment | 1 complexity | 5df6121c4e220003b439b68a105be0af MD5 | raw file
- ( Port of http://groups.google.com/group/comp.lang.forth/browse_frm/thread/f37aff28d9a3102e )
- ( This is a pretty simple Bingo card generator using an array of words/phrases. )
- ( We start by setting up an array of strings, then randomly sort this into a secondary )
- ( array. The "free space" location is manually patched, and then the resulting array is )
- ( rendered as HTML. )
- needs casket'
- needs array'
- [ "Be Mine"
- "Love"
- "It's Love"
- "All Mine"
- "Kiss Me"
- "You & Me"
- "Awesome"
- "My Baby"
- "Love Me"
- "All Star"
- "My Way"
- "Love You"
- "For You"
- "Cool"
- "I Hope"
- "Love Life"
- "Angel"
- "Sweet Talk"
- "True Love"
- "Be Good"
- "How Nice"
- "Let's Kiss"
- "#1 Fan"
- "Be True"
- "Love Her" ] ^array'fromQuote constant WORDS
- WORDS ^array'length constant #WORDS
- create CARD
- #WORDS dup , allot
- : nth ( na-$ )
- 1+ + @ ;
- : rnd ( -n )
- random #WORDS mod ;
- : obtain ( -$ )
- 0 [ drop rnd WORDS nth dup CARD ^array'stringIn? ] while ;
- : populate ( - )
- CARD 1+ #WORDS [ obtain swap !+ ] times drop "Free Square" CARD 13 + ! ;
- : card ( - )
- populate CARD 1+
- 5 [ "<tr align='center'>" puts 5 [ @+ "<td>%s</td>" puts cr ] times "</td>" puts ] times cr ;
- : header ( - )
- "\n<html>\n" puts
- "<body>\n" puts
- "<table border=1 height=500 width=500>\n" puts
- "<tr style='color: red'>\n" puts
- "<th width='20\%'>B</th>\n" puts
- "<th width='20\%'>I</th>\n" puts
- "<th width='20\%'>N</th>\n" puts
- "<th width='20\%'>G</th>\n" puts
- "<th width='20\%'>O</th>\n" puts
- "</tr>\n" puts ;
- : footer ( - )
- "</table>\n" puts
- "</body>\n" puts
- "</html>\n" puts ;
- with casket'
- : /bingo ( - )
- Content-type: text/html
- header card footer ;
- [ ( -$ ) "/home/crc/apps/bingo/" ] is casket:root
- [ ( -$ ) "http://rx-core.org/dev/bingo" ] is casket:url
- &/bingo is /
- &dispatch is boot
- save bye