Overview
| SHA1 Hash: | 53759181d15d04de917ccaf6b5a4da3af2753dea |
|---|---|
| Date: | 2011-10-24 11:36:24 |
| User: | crc |
| Comment: | move hangman to games directory |
| Timelines: | family | ancestors | descendants | both | trunk |
| Other Links: | files | manifest |
Tags And Properties
- branch=trunk inherited from [dc67bca1f3]
- sym-trunk inherited from [dc67bca1f3]
Changes
[hide diffs]
[patch]Execute permission cleared for games/hangman/dict.retro
Execute permission cleared for games/hangman/graphics.retro
Execute permission set for games/hangman/hangman
Execute permission cleared for games/hangman/hangman.retro
Deleted hangman/dict.retro version [6b17b48456cd9893]
@@ -1,49 +0,0 @@ -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) -( Hangman for Retro Console ) -( * System dictionary access. ) -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) -( Copyright [c] 2010-11, Marc Simpson ) -( License: ISC ) -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) - -( --[ Variables ]--------------------------------------------- ) - -: sys-dict "wordlist.txt" ^files':R ; - -variable dict -create dict-word 80 allot -variable dict-size - -( --[ Access ]------------------------------------------------ ) - -: open-dict ( -h ) sys-dict ^files'open dup 0 < - [ "\nError: can't open dictionary." puts ] ifTrue ; - -: init ( -h ) open-dict dup 0 < if; - dup dup !dict ^files'size !dict-size ; - -: initialise ( - ) @dict 0 = [ init 0 > - [ "\nInitialisation successful." puts ] - [ "\nInitialisation failed." puts ] if - ] ifTrue ; - -: toRandom ( n-n ) ^math'random swap /mod drop ; -: rand-off ( -n ) @dict-size toRandom ; -: rand-pos ( -n ) rand-off @dict ^files'seek drop ; - -: >line ( - ) repeat @dict ^files'read 10 = if; again ; -: fread! ( ha-f ) swap ^files'read dup rot ! ; -: (readline) ( - ) dict-word repeat @dict over fread! drop - dup @ 10 = if; 1+ again ; -: readline ( a- ) (readline) 0 swap ! ; - -: rand-word ( - ) rand-pos >line readline ; -: close-dict ( - ) @dict ^files'close 0 <> - [ "Error: Can't close dictionary." puts ] ifTrue ; - -( --[ Retrieval ]--------------------------------------------- ) - -: get-word ( -$ ) - rand-word dict-word dup ^strings'toLower over withLength copy ; - -( ============================================================ )
Deleted hangman/graphics.retro version [6e7f65e6b35a0862]
@@ -1,41 +0,0 @@ -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) -( Hangman for Retro Console ) -( * Drawing routines. ) -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) -( Copyright [c] 2010-11, Marc Simpson ) -( License: ISC ) -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) - -needs console' - -( --[ Drawing Routines ]-------------------------------------- ) - -: bar ( xyn- ) [ ^console'at-xy ] dip [ '- putc ] times ; -: col ( xyn- ) [ 2over ^console'at-xy '| putc 1+ ] times 2drop ; - -( --[ Stages ]------------------------------------------------ ) - -( NOTE: 13 is FIXED unless we add more drawing XTs ) - -13 constant stages - -create graphics stages allot -graphics variable: current-graphic - -: graphic, @current-graphic ! current-graphic ++ ; - -[ 20 15 15 bar ] graphic, -[ 20 5 10 col ] graphic, -[ 20 5 15 bar ] graphic, -[ 21 6 ^console'at-xy '/ putc ] graphic, -[ 30 6 2 col ] graphic, -[ 30 8 ^console'at-xy '@ putc ] graphic, -[ 30 9 1 col ] graphic, -[ 29 9 ^console'at-xy '/ putc ] graphic, -[ 31 9 ^console'at-xy '\ putc ] graphic, -[ 30 9 1 col ] graphic, -[ 30 10 1 col ] graphic, -[ 29 11 ^console'at-xy '/ putc ] graphic, -[ 31 11 ^console'at-xy '\ putc ] graphic, - -( ============================================================ )
Deleted hangman/hangman version [af5cb5a3d6e9d0dd]
@@ -1,10 +0,0 @@ -#! /bin/sh - -if [ ! -f "wordlist.txt" ]; then - if [ -f "/usr/share/dict/words" ]; then - echo "Wordlist missing -- symlinking the system dictionary." - ln -s /usr/share/dict/words wordlist.txt - fi -fi - -../retro --image ../retroImage --with hangman.retro
Deleted hangman/hangman.retro version [445abd42a07a88af]
@@ -1,110 +0,0 @@ -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) -( Hangman for Retro Console ) -( * Main game logic. ) -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) -( Copyright [c] 2010-11, Marc Simpson ) -( License: ISC ) -( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) - -needs console' - -( File inclusion will only work if you're running retro from ) -( the same directory as hangman. ) - -include graphics.retro -include dict.retro - -( --[ Variables ]--------------------------------------------- ) - -5 elements target guessed lifeline this-char foul-count -stages constant lives ( see graphics.retro ) -create foul-addr lives allot - -( --[ Offset Calculation ]------------------------------------ ) - -( Build an array with offsets for a given character in string ) - -: offsets, ( c$- ) - withLength [ [ 2over @ = ] dip swap &, &drop if 1+ ] iter - 2drop ; - -: offsets ( $c-an ) here 2rot swap offsets, here over - ; - -( --[ Allocation ]-------------------------------------------- ) - -: unallot ( n- ) negate allot ; -: unarray ( an- ) nip unallot ; - -( --[ Masking ]----------------------------------------------- ) - -( The array contains offset information; set the guess string ) - -: update-guessed ( $ offsets len - ) - [ 2over @ + @this-char swap ! 1+ ] times 2drop ; - -: toGuess ( guessed target c - ) - dup !this-char offsets ( guessed offsets length ) - 2over [ &update-guessed dip ] dip unarray ; - -: guessChar ( c- ) @guessed @target rot toGuess ; - -( --[ Printing ]---------------------------------------------- ) - -: .target ( - ) @target puts ; -: .guessed ( - ) @guessed puts ; -: .input ( - ) @lifeline "Tries: (%d): " puts ; -: .fouls ( - ) "Fouls: " puts foul-addr puts ; -: .prompt ( - ) 0 0 ^console'at-xy .guessed cr .fouls cr .input ; -: .already ( - ) " [already guessed]" puts ; -: .correct ( - ) " [correct guess] " puts ; -: .graphic ( - ) lives @lifeline - 1- graphics + @ do ; -: .wrong ( - ) " [not present] " puts .graphic ; - -( --[ Guessing ]---------------------------------------------- ) - -: 0<> ( x-f ) 0 = not ; -: has ( $c-f ) ^strings'findChar 0<> ; - -: foul+ ( c- ) foul-addr @foul-count + ! foul-count ++ ; - -: (guess) ( c- ) - @guessed over has - [ .already ] - [ @target over has - [ dup guessChar .correct ] - [ foul-addr over has - [ .already ] - [ dup foul+ lifeline -- .wrong ] if ] if ] if drop ; - -: guess ( - ) .prompt getc &putc &(guess) bi ; - -( --[ Game Logic ]-------------------------------------------- ) - -: _string ( n-$ ) here swap [ '_ , ] times 0 , ; - -: >target ( $- ) withLength swap !target _string !guessed ; - -: 0fouls ( - ) 0 !foul-count - foul-addr lives [ 0 over ! 1+ ] times drop ; - -: revive ( - ) lives !lifeline 0fouls ; -: remaining ( -f ) guessed @ '_ has ; -: alive ( -f ) remaining lifeline @ 0<> and ; -: dead? ( -f ) alive not ; -: foot ( - ) 0 20 ^console'at-xy ; -: .lose ( - ) foot "You LOSE; the word was: " puts .target ; -: .win ( - ) foot .target "\nYou WIN!" puts ; -: endgame ( - ) @lifeline &.win &.lose if ; - -: (hangman) ( - ) clear repeat dead? if; guess again ; -: hangman ( $- ) >target revive (hangman) endgame ; - -( --[ Main Game ]--------------------------------------------- ) - -: y-or-n ( -f ) getc [ 'y = ] [ 'Y = ] bi or ; -: .again? ( -f ) "\n\nPlay again? [Y/N] " puts y-or-n ; -: play ( - ) - initialise @dict 0; drop - repeat get-word hangman .again? [ close-dict bye ] ifFalse again ; -( ============================================================ ) -play