From f86c5a3da4db71469a15dea60bc9d817b61873e3 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Mon, 9 Sep 2013 20:03:53 +0200 Subject: [PATCH] parametrized number of card in hand --- INSTALL.sh | 17 +++++++++++++++-- web/briskin5/Obj/briskin5.phh | 29 +++++++++++++++-------------- web/briskin5/briskin5.js | 4 ++-- web/briskin5/dnd.js | 24 +++++++++++++----------- web/briskin5/index_wr.php | 8 ++++---- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/INSTALL.sh b/INSTALL.sh index b021de5..4f96382 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -6,6 +6,7 @@ CONFIG_FILE="$HOME/.brisk_install" apache_conf="/etc/apache2/sites-available/default" +card_hand=3 players_n=3 tables_n=44 tables_auth_n=12 @@ -29,12 +30,13 @@ function usage () { echo "$1 -h" echo "$1 chk - run lintian on all ph* files." echo "$1 pkg - build brisk packages." - echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T ] [-A ] [-a ] [-f ] [-p ] [-U ] [-u ] [-d ] [-w ] [-k ] [-l ] [-y ] [-P ]" + echo "$1 [-W] [-n 3|5] [-c 3|8] [-t <(n>=4)>] [-T ] [-A ] [-a ] [-f ] [-p ] [-U ] [-u ] [-d ] [-w ] [-k ] [-l ] [-y ] [-P ]" echo " -h this help" echo " -f use this config file" echo " -p save preferences in the file" echo " -W web files only" echo " -A apache_conf - def. $apache_conf" + echo " -c number cards in hand - def. $card_hand" echo " -n number of players - def. $players_n" echo " -t number of tables - def. $tables_n" echo " -T number of auth-only tables - def. $tables_auth_n" @@ -135,6 +137,7 @@ while [ $# -gt 0 ]; do -A*) apache_conf="$(get_param "-A" "$1" "$2")"; sh=$?;; -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;; -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;; + -c*) card_hand="$(get_param "-c" "$1" "$2")"; sh=$?;; -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;; -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;; -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;; @@ -168,8 +171,9 @@ done # echo " outconf: \"$outconf\"" echo " apache_conf:\"$apache_conf\"" +echo " card_hand: $card_hand" echo " players_n: $players_n" -echo " tables_n: $tables_n" +echo " tables_n: $tables_n" echo " tables_auth_n: $tables_auth_n" echo " brisk_auth_conf: \"$brisk_auth_conf\"" echo " brisk_debug:\"$brisk_debug\"" @@ -189,6 +193,7 @@ if [ ! -z "$outconf" ]; then echo "# Produced automatically by brisk::INSTALL.sh" echo "#" echo "apache_conf=$apache_conf" + echo "card_hand=$card_hand" echo "players_n=$players_n" echo "tables_n=$tables_n" echo "tables_auth_n=$tables_auth_n" @@ -249,6 +254,11 @@ IFS=' # ftokk_path="${ftok_path}k" +if [ $card_hand -lt 3 -o $card_hand -gt 8 ]; then + echo "card_hand ($card_hand) out of range (3 <= c <= 8)" + exit 1 +fi + if [ $players_n -ne 3 -a $players_n -ne 5 ]; then echo "players_n ($players_n) out of range (3|5)" exit 1 @@ -332,6 +342,7 @@ else fi # .js substitutions +sed -i "s/CARD_HAND *= *[0-9]\+/CARD_HAND = $card_hand/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l 'CARD_HAND *= *[0-9]\+' {} \;) sed -i "s/PLAYERS_N *= *[0-9]\+/PLAYERS_N = $players_n/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l 'PLAYERS_N *= *[0-9]\+' {} \;) sed -i "s/^var G_send_time *= *[0-9]\+/var G_send_time = $send_time/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l '^var G_send_time *= *[0-9]\+' {} \;) @@ -339,6 +350,8 @@ sed -i "s/^var G_send_time *= *[0-9]\+/var G_send_time = $send_time/g" $(find ${ # .ph[pho] substitutions sed -i "s/define *( *'PLAYERS_N', *[0-9]\+ *)/define('PLAYERS_N', $players_n)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'PLAYERS_N', *[0-9]\+ *)" {} \;) +sed -i "s/define *( *'BIN5_CARD_HAND', *[0-9]\+ *)/define('BIN5_CARD_HAND', $card_hand)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'BIN5_CARD_HAND', *[0-9]\+ *)" {} \;) + sed -i "s/define *( *'BIN5_PLAYERS_N', *[0-9]\+ *)/define('BIN5_PLAYERS_N', $players_n)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'BIN5_PLAYERS_N', *[0-9]\+ *)" {} \;) sed -i "s@define *( *'FTOK_PATH',[^)]*)@define('FTOK_PATH', \"$ftok_path\")@g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'FTOK_PATH',[^)]*)" {} \;) diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index e10cf82..12a5230 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -22,6 +22,7 @@ * */ define('BIN5_PLAYERS_N', 3); +define('BIN5_CARD_HAND', 3); // normal value 8 define('BIN5_MAX_PLAYERS', BIN5_PLAYERS_N); // define(BIN5_SHM_MIN', (50000 * BIN5_MAX_PLAYERS)); define('BIN5_SHM_MIN', 32768); @@ -308,8 +309,8 @@ class Bin5_table extends Table { // { // $ret = array(); // - // for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { - // // for ($i = 0 ; $i < 40 ; $i++) { + // for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { + // // for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { // $ret[$i] =& new Card($i, 'bunch', 'no_owner'); // } // @@ -321,7 +322,7 @@ class Bin5_table extends Table { { $ret = array(); - for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { + for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { $this->card[$i] = new Card($i, 'bunch', 'no_owner'); } } @@ -333,10 +334,10 @@ class Bin5_table extends Table { mt_srand(make_seed()); - for ($i = (BIN5_PLAYERS_N == 5 ? 40 : 24) - 1 ; $i >= 0 ; $i--) + for ($i = (BIN5_CARD_HAND * BIN5_PLAYERS_N) - 1 ; $i >= 0 ; $i--) $rest[$i] = $i; - for ($i = (BIN5_PLAYERS_N == 5 ? 40 : 24) - 1 ; $i >= 0 ; $i--) { + for ($i = (BIN5_CARD_HAND * BIN5_PLAYERS_N) - 1 ; $i >= 0 ; $i--) { $rn = rand(0, $i); if ($rn == 0) @@ -411,7 +412,7 @@ class Bin5_table extends Table { $tot = 0; - for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { + for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { // for ($i = 0 ; $i < 40 ; $i++) { if ($this->card[$i]->owner != $idx) continue; @@ -489,7 +490,7 @@ class Bin5_table extends Table { $this->old_reason = ""; // count points for the temporary 2 teams - for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { + for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { $ctt = $this->card[$i]->value % 10; $own = $this->card[$i]->owner; if ($own == $this->asta_win || $own == $this->friend) @@ -1462,7 +1463,7 @@ function calculate_points_old(&$table) $table->old_mult = $table->mult; // count points for the temporary 2 teams - for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { + for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { // for ($i = 0 ; $i < 40 ; $i++) { $ctt = $table->card[$i]->value % 10; $own = $table->card[$i]->owner; @@ -1583,10 +1584,10 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) if ($is_transition) { // && $user->subst == "asta" superfluo $ret .= "|"; - for ($i = 0 ; $i < 8 ; $i++) { + for ($i = 0 ; $i < BIN5_CARD_HAND ; $i++) { for ($e = 0 ; $e < BIN5_PLAYERS_N ; $e++) { $ct = 0; - for ($o = 0 ; $o < (BIN5_PLAYERS_N == 5 ? 40 : 24) && $ct < $i+1 ; $o++) { + for ($o = 0 ; $o < (BIN5_CARD_HAND * BIN5_PLAYERS_N) && $ct < $i+1 ; $o++) { // for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) { if ($table->card[$o]->owner == (($e + $table->gstart) % BIN5_PLAYERS_N)) { $ct++; @@ -1609,7 +1610,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) $ontabl = array(-1,-1,-1,-1,-1); $cards = array(); - for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { + for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { // for ($i = 0 ; $i < 40 ; $i++) { if ($table->card[$i]->stat == 'hand') { if ($table->card[$i]->owner == $table_pos) { @@ -1635,7 +1636,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) $oursarg = ""; for ($i = 0 ; $i < $inhand[$table_pos] ; $i++) $oursarg .= ($i == 0 ? "" : ", ").$cards[$i]; - for ($i = $inhand[$table_pos] ; $i < 8 ; $i++) + for ($i = $inhand[$table_pos] ; $i < BIN5_CARD_HAND ; $i++) $oursarg .= ($i == 0 ? "" : ", ")."-1"; $ret .= sprintf('card_setours(%s);', $oursarg); @@ -1643,7 +1644,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */ $ret .= sprintf('cards_dispose(%d,%d,%d);', $i, - ($inhand[$i] <= 8 ? $inhand[$i] : 8) , $taked[$i]); + ($inhand[$i] <= BIN5_CARD_HAND ? $inhand[$i] : BIN5_CARD_HAND), $taked[$i]); if ($ontabl[$i] != -1) { $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i], @@ -1721,7 +1722,7 @@ function calculate_winner(&$table) $cur_val = 100; $cur_seed = $table->briscola - ($table->briscola % 10); - for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { + for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) { // for ($i = 0 ; $i < 40 ; $i++) { if ($table->card[$i]->stat != "table") continue; diff --git a/web/briskin5/briskin5.js b/web/briskin5/briskin5.js index 32545f7..2e8d76c 100644 --- a/web/briskin5/briskin5.js +++ b/web/briskin5/briskin5.js @@ -210,7 +210,7 @@ function table_init() { show_astat(-2,-2,-2,-2,-2); set_iscalling(-1); - for (i=0 ; i < 8 ; i++) { + for (i=0 ; i < CARD_HAND ; i++) { Drag.init($("card" + i), card_mouseup_cb); for (e = 0 ; e < PLAYERS_N ; e++) $("card"+sux[e]+i).style.visibility = "hidden"; @@ -220,7 +220,7 @@ function table_init() { $("takes"+sux[i]).style.visibility = "hidden"; } - for (i = 0 ; i < 8 ; i++) { + for (i=0 ; i < CARD_HAND ; i++) { cards_pos[i] = i; cards_ea_pos[i] = i; cards_ne_pos[i] = i; diff --git a/web/briskin5/dnd.js b/web/briskin5/dnd.js index 1a5c6f5..76e4fab 100644 --- a/web/briskin5/dnd.js +++ b/web/briskin5/dnd.js @@ -20,8 +20,10 @@ * Suite 330, Boston, MA 02111-1307, USA. * */ - +/* number of players */ var PLAYERS_N = 3; +/* initial number of cards in hand */ +var CARD_HAND = 3; /* current manche */ var manche = 1; /* cards on hands */ @@ -65,16 +67,16 @@ var G_take_time = 500; /* suffix to add to images name */ var sux = new Array( "", "_ea", "", "", "_we"); -var cards_pos = new Array (8); -var cards_ea_pos = new Array (8); -var cards_ne_pos = new Array (8); -var cards_nw_pos = new Array (8); -var cards_we_pos = new Array (8); +var cards_pos = new Array (CARD_HAND); +var cards_ea_pos = new Array (CARD_HAND); +var cards_ne_pos = new Array (CARD_HAND); +var cards_nw_pos = new Array (CARD_HAND); +var cards_we_pos = new Array (CARD_HAND); var take_x = new Array(562, 745, 452, 30, 52); var take_y = new Array(545, 177, 70, 62,155); -for (i = 0 ; i < 8 ; i++) { +for (i = 0 ; i < CARD_HAND ; i++) { cards_pos[i] = i; cards_ea_pos[i] = i; cards_ne_pos[i] = i; @@ -110,7 +112,7 @@ function cards_dispose_so(car_n, tak_n) for (i = 0 ; i < car_n ; i++) { $("card" + cards_pos[i]).style.left = start + (i * inter); $("card" + cards_pos[i]).style.top = 475 + (125 - cards_height)/2; - $("card" + cards_pos[i]).style.zIndex = 8 - i; + $("card" + cards_pos[i]).style.zIndex = CARD_HAND - i; $("card" + cards_pos[i]).style.visibility = "visible"; } @@ -227,7 +229,7 @@ function cards_dispose_ea(car_n, tak_n) { for (i = 0 ; i < car_n ; i++) { $("card_ea" + cards_ea_pos[i]).style.left = 675 + (125 - cards_height)/2; $("card_ea" + cards_ea_pos[i]).style.top = start + (i * inter); - $("card_ea" + cards_ea_pos[i]).style.zIndex = 8 - i; + $("card_ea" + cards_ea_pos[i]).style.zIndex = CARD_HAND - i; $("card_ea" + cards_ea_pos[i]).style.visibility = "visible"; // alert("xx "+ (675 + (125 - cards_height)/2) +" yy " + start + (i * inter)); } @@ -273,7 +275,7 @@ function cards_dispose_we(car_n, tak_n) for (i = 0 ; i < car_n ; i++) { $("card_we" + cards_we_pos[i]).style.left = (125 - cards_height)/2; $("card_we" + cards_we_pos[i]).style.top = start - (i * inter); - $("card_we" + cards_we_pos[i]).style.zIndex = 8 - i; + $("card_we" + cards_we_pos[i]).style.zIndex = CARD_HAND - i; $("card_we" + cards_we_pos[i]).style.visibility = "visible"; } @@ -510,7 +512,7 @@ function card_setours(zer,uno,due,tre,qua,cin,sei,set) var i; var arg = new Array(zer,uno,due,tre,qua,cin,sei,set); - for (i = 0 ; i < 8 ; i++) { + for (i = 0 ; i < CARD_HAND ; i++) { $("card"+i).src = getcard(arg[i], 0); $("card"+i).briskid = arg[i]; } diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index 6fdf64d..91cf53c 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -438,7 +438,7 @@ function bin5_index_wr_main(&$bri, $remote_addr_full, $get, $post, $cookie) log_wr("CIC".$loggo); /* se era il suo turno e la carta era sua ed era in mano */ - if ($a_play >=0 && $a_play < (BIN5_PLAYERS_N == 5 ? 40 : 24) && + if ($a_play >=0 && $a_play < (BIN5_CARD_HAND * BIN5_PLAYERS_N) && ($user->table_pos == (($table->gstart + $table->turn) % BIN5_PLAYERS_N)) && $table->card[$a_play]->stat == 'hand' && $table->card[$a_play]->owner == $user->table_pos) { @@ -462,7 +462,7 @@ function bin5_index_wr_main(&$bri, $remote_addr_full, $get, $post, $cookie) $player_nex = $card_play . "is_my_time = true; remark_on();"; $player_oth = $card_play; } - else if ($table->turn <= (BIN5_PLAYERS_N * 8)) { /* manche finished */ + else if ($table->turn <= (BIN5_PLAYERS_N * BIN5_CARD_HAND)) { /* manche finished */ $winner = calculate_winner($table); log_wr("GSTART 3"); $table->gstart = $winner; @@ -475,7 +475,7 @@ function bin5_index_wr_main(&$bri, $remote_addr_full, $get, $post, $cookie) $player_nex = $card_play . $card_take; else $player_nex = ""; - if ($table->turn < (BIN5_PLAYERS_N * 8)) /* game NOT finished */ + if ($table->turn < (BIN5_PLAYERS_N * BIN5_CARD_HAND)) /* game NOT finished */ $player_nex .= "is_my_time = true; remark_on();"; $player_oth = $card_play . $card_take; } @@ -500,7 +500,7 @@ function bin5_index_wr_main(&$bri, $remote_addr_full, $get, $post, $cookie) $retar[$i] = $ret; } - if ($table->turn == (BIN5_PLAYERS_N * 8)) { /* game finished */ + if ($table->turn == (BIN5_PLAYERS_N * BIN5_CARD_HAND)) { /* game finished */ log_wr(sprintf("GIOCO FINITO !!!")); -- 2.17.1