PageRenderTime 26ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/casket/valentine-bingo.rx

https://github.com/crcx/retro-language
Forth | 84 lines | 65 code | 14 blank | 5 comment | 1 complexity | 5df6121c4e220003b439b68a105be0af MD5 | raw file
  1. ( Port of http://groups.google.com/group/comp.lang.forth/browse_frm/thread/f37aff28d9a3102e )
  2. ( This is a pretty simple Bingo card generator using an array of words/phrases. )
  3. ( We start by setting up an array of strings, then randomly sort this into a secondary )
  4. ( array. The "free space" location is manually patched, and then the resulting array is )
  5. ( rendered as HTML. )
  6. needs casket'
  7. needs array'
  8. [ "Be Mine"
  9. "Love"
  10. "It's Love"
  11. "All Mine"
  12. "Kiss Me"
  13. "You & Me"
  14. "Awesome"
  15. "My Baby"
  16. "Love Me"
  17. "All Star"
  18. "My Way"
  19. "Love You"
  20. "For You"
  21. "Cool"
  22. "I Hope"
  23. "Love Life"
  24. "Angel"
  25. "Sweet Talk"
  26. "True Love"
  27. "Be Good"
  28. "How Nice"
  29. "Let's Kiss"
  30. "#1 Fan"
  31. "Be True"
  32. "Love Her" ] ^array'fromQuote constant WORDS
  33. WORDS ^array'length constant #WORDS
  34. create CARD
  35. #WORDS dup , allot
  36. : nth ( na-$ )
  37. 1+ + @ ;
  38. : rnd ( -n )
  39. random #WORDS mod ;
  40. : obtain ( -$ )
  41. 0 [ drop rnd WORDS nth dup CARD ^array'stringIn? ] while ;
  42. : populate ( - )
  43. CARD 1+ #WORDS [ obtain swap !+ ] times drop "Free Square" CARD 13 + ! ;
  44. : card ( - )
  45. populate CARD 1+
  46. 5 [ "<tr align='center'>" puts 5 [ @+ "<td>%s</td>" puts cr ] times "</td>" puts ] times cr ;
  47. : header ( - )
  48. "\n<html>\n" puts
  49. "<body>\n" puts
  50. "<table border=1 height=500 width=500>\n" puts
  51. "<tr style='color: red'>\n" puts
  52. "<th width='20\%'>B</th>\n" puts
  53. "<th width='20\%'>I</th>\n" puts
  54. "<th width='20\%'>N</th>\n" puts
  55. "<th width='20\%'>G</th>\n" puts
  56. "<th width='20\%'>O</th>\n" puts
  57. "</tr>\n" puts ;
  58. : footer ( - )
  59. "</table>\n" puts
  60. "</body>\n" puts
  61. "</html>\n" puts ;
  62. with casket'
  63. : /bingo ( - )
  64. Content-type: text/html
  65. header card footer ;
  66. [ ( -$ ) "/home/crc/apps/bingo/" ] is casket:root
  67. [ ( -$ ) "http://rx-core.org/dev/bingo" ] is casket:url
  68. &/bingo is /
  69. &dispatch is boot
  70. save bye