#! /usr/bin/env sh # Fri Aug 20 20:47:59 EDT 2004 # NAME: y2 # Copyright 2004, Chris F.A. Johnson # Released under the terms of the GNU General Public License #type standard-vars >/dev/null 2>&1 && . y2-funcs-sh [ -z "$awk" ] && set_awk help() { :; } description="The Game of Yahtzee" verbose=0 longusage=0 version="1.0" copyright=2004 author="Chris F.A. Johnson" progname=${0##*/} while getopts vVhH-: var do case $var in -) case $OPTARG in help) usage; exit ;; help_long) longusage=1; usage; exit ;; version) version; exit ;; esac ;; h) usage; exit ;; H) longusage=1; usage; exit ;; v) verbose=$(( $verbose + 1 )) ;; V) version; exit ;; esac done $(( $OPTIND - 1 )) clear init while : do loop=$(( ($loop + 1) % 3 )) printat $status_row 1 printf " Round: %d.%d" $round $(( ($loop + 2) % 3 + 1 )) roll_dice [ $loop -eq 0 ] && unkeep show_dice evaluate $d_1 $d_2 $d_3 $d_4 $d_5 show_scores printf "$main_attr" selection= while : do show_dice show_scores [ $loop -eq 0 ] && { printat $select_row $select_col "$select_attr $select_button " } || printat $select_row $select_col "$NA$cle" get_key c printat 1 $(( $COLUMNS / 2 )); printf "$NA%s\n" "$c" case $c in ""|"$NL"|"$CR") [ -n "$selection" ] && loop=0 break ;; " ") reload; init ;; Q) exit ;; q) verify "Really quit?" && { printf "$NA" exit break 2 } printf "$NA" ;; C) var_toggle configure ;; [a-m]) eval score=\$_$c [ -z "$score" ] && selection=$c || selection= ;; [1-5]) selection= [ $loop -ne 0 ] && var_toggle k_$c ##|| unkeep ;; \?) help ;; *) selection= ;; esac done case $loop in 0) printat 1 1 "\$selection = $selection" case $selection in a) [ -n "$_a" ] || _a=${#ones} ;; b) [ -n "$_b" ] || _b=$(( 2 * ${#twos} )) ;; c) [ -n "$_c" ] || _c=$(( 3 * ${#threes} )) ;; d) [ -n "$_d" ] || _d=$(( 4 * ${#fours} )) ;; e) [ -n "$_e" ] || _e=$(( 5 * ${#fives} )) ;; f) [ -n "$_f" ] || _f=$(( 6 * ${#sixes} )) ;; g) [ -n "$_g" ] || _g=$k3 ;; h) [ -n "$_h" ] || _h=$k4 ;; i) [ -n "$_i" ] || _i=$full_house ;; j) [ -n "$_j" ] || _j=$sm_straight ;; k) [ -n "$_k" ] || _k=$lg_straight ;; l) [ -n "$_l" ] || _l=$yahtzee ;; m) [ -n "$_m" ] || _m=$chance ;; esac round=$(( $round + 1 )) unkeep ;; *) kd ;; esac [ $round -gt 13 ] && { printf "$NA"; clear; show_scores; break; } done printat $LINES 1 "$NA" [ -t 0 ] && stty sane