( Check the function main for what actions are needed in this program. ) ( Attach them to a dartboard object and link them all to this program. ) ( It is likely that this program needs to be set WIZARD to work. ) () : say ( s -- ) me @ swap notify ; : all ( s -- ) loc @ contents begin dup while dup player? over "_darts" getpropstr and if dup 3 pick notify then next loop pop pop ; : not_all ( s d -- ) loc @ contents begin dup while dup player? over "_darts" getpropstr and over 4 pick dbcmp not and if dup 4 pick notify then next loop pop pop pop ; : tl ( -- d ) trigger @ location ; : prg ( -- d ) trigger @ getlink ; : is_turn? ( -- i ) tl "turn" getpropstr "player" swap strcat tl swap getpropstr atoi dbref me @ dbcmp not if 0 else 1 then ; : add_skill ( i -- ) prg me @ intostr getpropstr atoi swap + dup 20000 > if pop 20000 then dup 100 < if pop 100 then prg me @ intostr rot intostr 0 addprop ; : winner? ( -- i ) 0 0 tl "number" getpropstr atoi 1 swap 1 for tl "total" 3 pick intostr strcat getpropstr atoi dup 300 > swap 4 pick > and if swap pop swap pop dup tl "total" 3 pick intostr strcat getpropstr atoi -2 rotate pop else pop then loop pop ; : game_over? ( -- i ) tl "game_over" getpropstr "" stringcmp not if 0 else 1 then ; : remove_players ( i -- ) dup intostr "player" swap strcat tl swap getpropstr "" stringcmp not if pop exit then dup intostr "player" swap strcat tl swap remove_prop dup intostr "total" swap strcat tl swap remove_prop 1 + remove_players ; : players? ( -- i ) tl "number" getpropstr atoi ; : is_playing_loop ( i -- i ) dup intostr "player" swap strcat tl swap getpropstr dup "" stringcmp not if pop pop 0 exit then me @ intostr stringcmp not if pop 1 exit then 1 + is_playing_loop ; : is_playing? ( -- i ) 1 is_playing_loop ; : add_player prg me @ intostr getpropstr not if prg me @ intostr "100" 0 addprop then tl "number" getpropstr atoi 1 + dup intostr "player" swap strcat tl swap me @ intostr 0 addprop dup intostr "total" swap strcat tl swap "0" 0 addprop intostr tl "number" rot 0 addprop ; : is_started? ( -- i ) tl "turn" getpropstr atoi ; : do_join ( -- ) is_started? if "!> Game is already started!" say exit then is_playing? if "!> You are already playing!" say exit then add_player "!> You join the game." say "!> " me @ name strcat " (skill rating %s) joins the game." strcat prg me @ intostr getpropstr dup strlen 2 - strcut "." swap strcat strcat "%s" subst me @ not_all ; : do_status_loop ( i -- ) dup 0 = if pop exit then "player" over intostr strcat tl swap getpropstr "total" 3 pick intostr strcat tl swap getpropstr dup strlen " " swap strcut swap pop strcat swap atoi dbref name " " over strlen strcut swap pop strcat swap strcat "!> " swap strcat "player" 3 pick intostr strcat tl swap getpropstr prg swap getpropstr dup strlen 2 - strcut "." swap strcat strcat dup strlen " " swap strcut swap pop swap strcat strcat say 1 - do_status_loop ; : do_status ( -- ) "!> Player Score Skill" say "!>" say tl "number" getpropstr atoi do_status_loop "!>" say is_started? not if "!> Game has not yet begun." say exit then game_over? not if "!> Game is in progress." say "!> It is %p's turn." tl "turn" getpropstr "player" swap strcat tl swap getpropstr atoi dbref name "%p" subst say exit then "!> Game has ended." say exit ; : do_reset ( -- ) tl "number" remove_prop tl "players" remove_prop tl "turn" remove_prop tl "game_over" remove_prop tl "#_tosses" remove_prop tl "#_turns" remove_prop 1 remove_players "!> You reset the game." say "!> " me @ name strcat " resets the game." strcat me @ not_all ; : do_play ( -- ) players? not if "!> No players are joined!" say exit then is_started? if "!> Game is already started!" say exit then tl "number" getpropstr atoi random swap % 1 + tl "turn" 3 pick intostr 0 addprop tl "player" rot intostr strcat getpropstr "!> " me @ name strcat " begins the game." strcat all tl "player" rot atoi dbref name "!> " swap strcat " gets the first tosses." strcat all ; : fix_turn ( -- ) tl "turn" getpropstr atoi 1 + tl "number" getpropstr atoi over swap > if pop 1 then tl "turn" rot intostr 0 addprop ; : parse_# ( -- s ) tl "#_tosses" getpropstr atoi dup 1 = if pop "first" exit then dup 2 = if pop "second" exit then dup 3 = if pop "third" exit then ; : parse_multiples ( i -- i s ) dup 1 = if pop "single " exit then dup 2 = if pop "double " exit then dup 3 = if pop "triple " exit then ; : get_toss ( -- i i ) dup if dup 1 strcut pop "bsdt" swap instr if 1 strcut over "b" 1 strncmp not over atoi dup 20 <= swap 1 >= and or if prg me @ intostr getpropstr atoi random 26667 % 1 + swap <= if over "b" 1 strncmp not if pop pop 22 1 players? 2 > if 6 add_skill then exit then over "s" 1 strncmp not if swap pop atoi 1 exit then over "d" 1 strncmp not if swap pop atoi 2 players? 2 > if 3 add_skill then exit then over "t" 1 strncmp not if swap pop atoi 3 players? 2 > if 4 add_skill then exit then else pop pop players? 2 > if -3 add_skill then then else pop pop then else pop then else pop then random 27 % 4 - prg me @ intostr getpropstr atoi 1250 / + dup 22 > if pop 22 then dup 22 = players? 2 > and if 5 add_skill 0 exit then dup 21 = players? 2 > and if 4 add_skill 0 exit then dup 1 < if 0 exit then random 100 % 1 + prg me @ intostr getpropstr atoi 300 / + dup 70 <= if pop 1 exit then dup dup 70 > swap 91 < and if pop 2 players? 2 > if 2 add_skill then exit then pop 3 players? 2 > if 3 add_skill then ; : do_toss ( -- ) is_started? not if pop "!> Game has not yet begun!" say exit then game_over? if pop "!> Game is over!" say exit then is_turn? not if pop "!> It's not your turn!" say exit then tl "#_tosses" getpropstr atoi 1 + intostr tl "#_tosses" rot 0 addprop me @ name " throws %p " strcat parse_# strcat " dart" strcat over if ", aiming for the %m%n." strcat over 1 strcut over "b" 1 strncmp not if rot "" "%m" subst "bullseye" "%n" subst -3 rotate then over "s" 1 strncmp not if rot "single " "%m" subst over "%n" subst -3 rotate then over "d" 1 strncmp not if rot "double " "%m" subst over "%n" subst -3 rotate then over "t" 1 strncmp not if rot "triple " "%m" subst over "%n" subst -3 rotate then pop pop else "." strcat then me @ swap pronoun_sub "!> " swap strcat all get_toss me @ name " hits the " strcat "!> " swap strcat -3 rotate swap "" over 21 = if pop pop pop 1 25 "outer bullseye ring" then over 22 = if pop pop pop 1 50 "bullseye" then over 1 < if pop pop pop 0 0 "wall (?!)" then dup "" stringcmp not if pop over parse_multiples over intostr strcat then 4 rotate swap strcat " for a total of %t." strcat swap rot * tl "turn" getpropstr "total" swap strcat tl swap getpropstr atoi + intostr tl "turn" getpropstr "total" swap strcat tl swap 3 pick 0 addprop "%t" subst all tl "#_tosses" getpropstr atoi 3 = if tl "#_tosses" remove_prop tl "#_turns" getpropstr atoi 1 + intostr tl "#_turns" rot 0 addprop fix_turn tl "#_turns" getpropstr atoi tl "number" getpropstr atoi % not if winner? dup if "player" swap intostr strcat tl swap getpropstr atoi dbref name "!> " swap strcat " has won the game!" strcat all tl "game_over" "yes" 0 addprop exit else pop then then tl "turn" getpropstr "player" swap strcat tl swap getpropstr atoi dbref name "!> It is now " swap strcat "'s turn." strcat all then ; : do_rules ( -- ) "!> +---------------------------------------------------+" say "!> | Darts 3.0, written by Sjade |" say "!> +----------+----------------------------------------+" say "!> | join | Join in a game, no player limit |" say "!> | reset | Reset the game |" say "!> | play | Begin a game when all have joined |" say "!> | rules | Show this rules screen |" say "!> | toss | Throw a dart |" say "!> | status | Show current players, scores & skills |" say "!> | skill | Show skill rating of specified player |" say "!> +----------+------------+---------------------------+" say "!> | bulls eye = +.05(.06) | To aim do: toss |" say "!> | outer eye = +.04(n/a) | = s1 through s20 |" say "!> | triple = +.03(.04) | or d1 through d20 |" say "!> | double = +.02(.03) | or t1 through t20 |" say "!> | () is bonus if aiming | or bullseye |" say "!> +-----------------------+---------------------------+" say "!> | A 'skill' match involves three or more players |" say "!> | Maximum possible skill rating is exactly 200.00 |" say "!> | Game play ends after one rotation over 300 points |" say "!> +---------------------------------------------------+" say ; : do_skill ( s -- ) .pmatch dup #-1 dbcmp if pop "!> Don't recognize that player." say exit then "!> " over name strcat "'s current skill score is " strcat prg rot intostr getpropstr dup not if pop "100" then dup strlen 2 - strcut "." swap strcat strcat strcat " (out of 200)." strcat say ; : main ( s -- ) .sstrip trigger @ name "play" stringcmp not if pop do_play exit then trigger @ name "toss" stringcmp not if do_toss exit then trigger @ name "join" stringcmp not if pop do_join exit then trigger @ name "reset" stringcmp not if pop do_reset exit then trigger @ name "status" stringcmp not if pop do_status exit then trigger @ name "rules" stringcmp not if pop do_rules exit then trigger @ name "skill" stringcmp not if do_skill exit then pop "!> Command not understood." say ;