4 * Copyright (C) 2006-2012 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program; if
19 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20 * Suite 330, Boston, MA 02111-1307, USA.
30 var is_my_time = false;
31 /* number of takes cards */
47 var cards_width = 55 + 2;
48 var cards_width_d2 = 27;
50 /* height of images */
51 var cards_height = 101 + 2;
52 var cards_height_d2 = 51;
54 /* width of hands area */
55 var hands_width = 400;
57 /* width of the border */
58 var border_width = 10;
60 /* time to send a card to the player 10 or 250 */
61 var G_send_time = 250;
62 var G_play_time = 500;
63 var G_take_time = 500;
65 /* suffix to add to images name */
66 var sux = new Array( "", "_ea", "", "", "_we");
68 var cards_pos = new Array (8);
69 var cards_ea_pos = new Array (8);
70 var cards_ne_pos = new Array (8);
71 var cards_nw_pos = new Array (8);
72 var cards_we_pos = new Array (8);
74 var take_x = new Array(562, 745, 452, 30, 52);
75 var take_y = new Array(545, 177, 70, 62,155);
77 for (i = 0 ; i < 8 ; i++) {
84 function $(id) { return document.getElementById(id); }
86 function cards_dispose_so(car_n, tak_n)
90 $("takes").style.left = 200 + 400 - 90 + ((90 - cards_width) / 2);
91 $("takes").style.top = 475 + (125 - cards_height)/2;
92 $("takes").style.zIndex = 1;
93 $("takes").style.visibility = "visible";
99 disp = 400 - delta - (2 * border_width);
101 inter = parseInt((disp - cards_width) / (car_n - 1));
102 if (inter > cards_width)
107 wcard = cards_width + inter * (car_n - 1);
108 start = 200 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
110 for (i = 0 ; i < car_n ; i++) {
111 $("card" + cards_pos[i]).style.left = start + (i * inter);
112 $("card" + cards_pos[i]).style.top = 475 + (125 - cards_height)/2;
113 $("card" + cards_pos[i]).style.zIndex = 8 - i;
114 $("card" + cards_pos[i]).style.visibility = "visible";
123 function cards_dispose_ne(car_n, tak_n) {
128 $("takes_ne").style.left = 800 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
129 $("takes_ne").style.top = (125 - cards_height)/2;
130 $("takes_ne").style.zIndex = 1;
131 $("takes_ne").style.visibility = "visible";
137 disp = 400 - delta - (2 * border_width);
139 inter = parseInt((disp - cards_width) / (car_n - 1));
140 if (inter > cards_width)
145 wcard = cards_width + inter * (car_n - 1);
146 start = 800 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
149 for (i = 0 ; i < car_n ; i++) {
150 $("card_ne" + cards_ne_pos[i]).style.left = start - ((car_n - i -1) * inter);
151 $("card_ne" + cards_ne_pos[i]).style.top = (125 - cards_height)/2;
152 $("card_ne" + cards_ne_pos[i]).style.zIndex = 8-i;
153 $("card_ne" + cards_ne_pos[i]).style.visibility = "visible";
162 function cards_dispose_nw(car_n, tak_n) {
167 $("takes_nw").style.left = 400 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
168 $("takes_nw").style.top = (125 - cards_height)/2;
169 $("takes_nw").style.zIndex = 1;
170 $("takes_nw").style.visibility = "visible";
176 disp = 400 - delta - (2 * border_width);
178 inter = parseInt((disp - cards_width) / (car_n - 1));
179 if (inter > cards_width)
184 wcard = cards_width + inter * (car_n - 1);
185 // start = 0 + delta + border_width + (400 - border_width - border_width - wcard - delta) / 2;
186 start = 400 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
189 for (i = 0 ; i < car_n ; i++) {
190 $("card_nw" + cards_nw_pos[i]).style.left = start - ((car_n-i-1) * inter);
191 $("card_nw" + cards_nw_pos[i]).style.top = (125 - cards_height)/2;
192 $("card_nw" + cards_nw_pos[i]).style.zIndex = (8-i);
193 $("card_nw" + cards_nw_pos[i]).style.visibility = "visible";
194 // alert("xx "+start + (i * inter)+" yy " + (125 - cards_height)/2);
203 function cards_dispose_ea(car_n, tak_n) {
206 $("takes_ea").style.left = 675 + (125 - cards_height)/2;
207 $("takes_ea").style.top = 125 + ((90 - cards_width) / 2);
208 $("takes_ea").style.zIndex = 1;
209 $("takes_ea").style.visibility = "visible";
214 disp = 400 - delta - (2 * border_width);
216 inter = parseInt((disp - cards_width) / (car_n - 1));
217 if (inter > cards_width)
222 wcard = cards_width + inter * (car_n - 1);
223 start = 125 + delta + border_width + (400 - border_width - border_width - wcard - delta) / 2;
226 // console.log(car_n);
227 for (i = 0 ; i < car_n ; i++) {
228 $("card_ea" + cards_ea_pos[i]).style.left = 675 + (125 - cards_height)/2;
229 $("card_ea" + cards_ea_pos[i]).style.top = start + (i * inter);
230 $("card_ea" + cards_ea_pos[i]).style.zIndex = 8 - i;
231 $("card_ea" + cards_ea_pos[i]).style.visibility = "visible";
232 // alert("xx "+ (675 + (125 - cards_height)/2) +" yy " + start + (i * inter));
241 function cards_dispose_we(car_n, tak_n)
245 $("takes_we").style.left = (125 - cards_height)/2;
246 // $("takes_we").style.top = 125 + 400 - 90 + ((90 - cards_width) / 2);
247 $("takes_we").style.top = 525 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
248 $("takes_we").style.zIndex = 1;
249 $("takes_we").style.visibility = "visible";
254 /* pixel a disposizione per mettere le carte: 400 - delta - 2 bordi */
255 disp = 400 - delta - (2 * border_width);
256 /* se c'e' piu' di una carta calcola di quanti pixel devono rimanere scoperte le carte dopo la prima */
258 inter = parseInt((disp - cards_width) / (car_n - 1));
259 if (inter > cards_width)
265 /* dopo avere fatto tutti i conti ricalcola quanti pixel effettivamente verranno occupati dalle carte */
266 wcard = cards_width + inter * (car_n - 1);
268 /* calcola il punto d'inizio da dove disporre le carte: DELTAY + lo spessore del bordo + la meta' di quello
269 che resta della larghezza totale meno tutti gli altri ingombri */
270 // start = 125 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
271 start = 525 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
273 for (i = 0 ; i < car_n ; i++) {
274 $("card_we" + cards_we_pos[i]).style.left = (125 - cards_height)/2;
275 $("card_we" + cards_we_pos[i]).style.top = start - (i * inter);
276 $("card_we" + cards_we_pos[i]).style.zIndex = 8 - i;
277 $("card_we" + cards_we_pos[i]).style.visibility = "visible";
286 var cards_dispose_arr = new Array(cards_dispose_so, cards_dispose_ea,
287 cards_dispose_ne, cards_dispose_nw,
290 function cards_dispose(player_pos, cards, takes)
292 var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
294 return (cards_dispose_arr[idx](cards,takes));
300 function card_mouseup_cb(o) {
301 var idx = o.id.substring(4);
302 var briskid = o.briskid;
308 /* case swap in the group */
311 if (parseInt(o.style.top) > 475 &&
312 parseInt(o.style.left) >= 200 && parseInt(o.style.left) < 600) {
313 /* Rearrange cards */
315 // $("sandbox3").innerHTML = "REARRANGE: "+idx;
322 /* found the associated index of the current card. */
323 for (i = 0 ; i < cards_n ; i++)
324 if (cards_pos[i] == idx)
328 disp = 400 - delta - (2 * border_width);
330 inter = parseInt((disp - cards_width) / (cards_n - 1));
331 if (inter > cards_width)
336 wcard = cards_width + inter * (cards_n - 1);
337 start = 200 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
339 for (i = 0 ; i < cards_n ; i++) {
340 /* $("sandbox").innerHTML = */
341 // alert( "LEFT: " + o.style.left + "VALUE " + (cards_width + start + (i * (cards_width / 2))));
342 // $("sandbox3").innerHTML += "<br>LEFT: "+parseInt(o.style.left)+" START["+i+"]: "+(start + ((i+1) * inter));
344 tst = (parseInt(o.style.left) < start + ((i+1) * inter));
346 tst = (parseInt(o.style.left) > start + (i * inter));
348 // $("sandbox2").innerHTML = "old: " +old_idx+ " i: " +i+ "left: " + parseInt(o.style.left) + "comp: " + (start + (cards_width / 2) + (i * (cards_width / 2)));
354 for (e = old_idx ; e < i ; e++)
355 cards_pos[e] = cards_pos[e+1];
359 for (e = old_idx ; e > i ; e--)
360 cards_pos[e] = cards_pos[e-1];
367 cards_dispose_so(cards_n,takes_n);
371 else if (is_my_time &&
372 parseInt(o.style.top) >= 250 &&
373 parseInt(o.style.top) + cards_height < 450 &&
374 parseInt(o.style.left) >= 300 &&
375 (parseInt(o.style.left) + cards_width) < 500) {
378 $("sandbox2").innerHTML = "PLAYED";
380 for (i = 0 ; i < cards_n ; i++) {
381 if (cards_pos[i] == idx) {
382 /* $("sandbox").innerHTML = "Pippo: "+ i; */
383 for (e = i ; e < cards_n-1 ; e++) {
384 cards_pos[e] = cards_pos[e+1];
386 cards_pos[cards_n-1] = idx;
388 cards_dispose_so(cards_n, takes_n);
391 act_play(briskid,o.style.left,o.style.top);
395 cards_dispose_so(cards_n, takes_n);
400 $("sandbox2").innerHTML = "TO ORIGINAL";
401 /* alert("out card " + parseInt(o.style.top)); */
402 /* return to the original position */
403 cards_dispose_so(cards_n, takes_n);
410 function card_send_so(id,card,free,ct)
412 var img = $("card"+id);
413 img.src = getcard(-1,0);
416 img.style.left = 400 - cards_width_d2;
417 img.style.top = 300 - cards_height_d2;
418 img.style.zIndex = 100;
420 var movimg = new slowimg(img,400 - cards_width / 2,475 + (125 - cards_height)/2,25,free,"cards_dispose_so("+ct+", 0)",getcard(card,0));
421 movimg.settime(G_send_time);
425 function card_send_ea(id,card,free,ct)
427 var img = $("card_ea"+id);
428 img.src = getcard(card,1);
431 img.style.left = 400 - cards_height_d2;
432 img.style.top = 300 - cards_width_d2;
433 img.style.zIndex = 100;
435 var movimg = new slowimg(img,686,296,25,free,"cards_dispose_ea("+ct+", 0);",getcard(card,1));
436 movimg.settime(G_send_time);
440 function card_send_ne(id,card,free,ct)
442 var img = $("card_ne"+id);
443 img.src = getcard(card,2);
446 img.style.left = 400 - cards_width_d2;
447 img.style.top = 300 - cards_height_d2;
448 img.style.zIndex = 100;
450 var movimg = new slowimg(img,571,11,25,free,"cards_dispose_ne("+ct+", 0);",getcard(card,2));
451 movimg.settime(G_send_time);
455 function card_send_nw(id,card,free,ct)
457 var img = $("card_nw"+id);
458 img.src = getcard(card,3);
461 img.style.left = 400 - cards_width_d2;
462 img.style.top = 300 - cards_height_d2;
463 img.style.zIndex = 100;
465 var movimg = new slowimg(img,171,11,25,free,"cards_dispose_nw("+ct+", 0);",getcard(card,3));
466 movimg.settime(G_send_time);
470 function card_send_we(id,card,free,ct)
472 var img = $("card_we"+id);
473 img.src = getcard(card,4);
476 if (id < 0 || id > 39)
477 alert("ID ERRATO"+id);
479 img.style.left = 400 - cards_height_d2;
480 img.style.top = 300 - cards_width_d2;
481 img.style.zIndex = 100;
482 var movimg = new slowimg(img,11,296,25,free,"cards_dispose_we("+ct+", 0);",getcard(card,4));
483 movimg.settime(G_send_time);
487 var card_send_arr = new Array(card_send_so, card_send_ea,
488 card_send_ne, card_send_nw,
491 function card_send(player_pos,id,card,free,ct)
493 var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
495 card_send_arr[idx](id,card,free,ct);
498 function getcard(card,pos_id)
501 return ("img/cover"+sux[pos_id]+".png");
503 return ("img/0"+card+sux[pos_id]+".png");
505 return ("img/"+card+sux[pos_id]+".png");
508 function card_setours(zer,uno,due,tre,qua,cin,sei,set)
511 var arg = new Array(zer,uno,due,tre,qua,cin,sei,set);
513 for (i = 0 ; i < 8 ; i++) {
514 $("card"+i).src = getcard(arg[i], 0);
515 $("card"+i).briskid = arg[i];
521 function card_play_so(card_idx, x, y)
523 alert("card_play_so: unreachable function.");
527 function card_postplay_ea(card_pos)
529 var img = $("card_ea"+card_pos);
532 for (i = 0 ; i < cards_ea_n ; i++) {
533 if (cards_ea_pos[i] == card_pos) {
534 for (e = i ; e < cards_ea_n-1 ; e++) {
535 cards_ea_pos[e] = cards_ea_pos[e+1];
537 cards_ea_pos[cards_ea_n-1] = card_pos;
539 cards_dispose_ea(cards_ea_n, takes_ea_n);
545 function card_play_ea(card_idx, x, y)
547 // var card_pos = RANGE 0 <= x < cards_ea_n
548 var card_pos = rnd_int(0,cards_ea_n-1);
549 var img = $("card_ea"+cards_ea_pos[card_pos]);
550 // alert("IMMO CON "+cards_ea_pos[card_pos]);
551 var newname = getcard(card_idx,1);
554 x1 = 500 + ((y-250) * (125 - cards_height) / (200 - cards_height));
555 y1 = 450 - cards_width - (x - 300);
557 var movimg = new slowimg(img, x1, y1, 25, 1, "card_postplay_ea("+cards_ea_pos[card_pos]+");", newname);
558 movimg.settime(G_play_time);
563 function card_postplay_ne(obj,card_pos)
565 var img = $("card_ne"+card_pos);
569 for (i = 0 ; i < cards_ne_n ; i++) {
570 if (cards_ne_pos[i] == card_pos) {
571 for (e = i ; e < cards_ne_n-1 ; e++) {
572 cards_ne_pos[e] = cards_ne_pos[e+1];
574 cards_ne_pos[cards_ne_n-1] = card_pos;
576 cards_dispose_ne(cards_ne_n, takes_ne_n);
582 function card_play_ne(card_idx, x, y)
584 var card_pos = rnd_int(0,cards_ne_n-1);
585 var img = $("card_ne"+cards_ne_pos[card_pos]);
586 var newname = getcard(card_idx,2);
589 x1 = 600 - cards_width - (x - 300);
590 y1 = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
592 var movimg = new slowimg(img, x1, y1, 25, 1, "card_postplay_ne(this,"+cards_ne_pos[card_pos]+");", newname);
593 movimg.settime(G_play_time);
598 function card_postplay_nw(card_pos)
600 var img = $("card_nw"+card_pos);
603 for (i = 0 ; i < cards_nw_n ; i++) {
604 if (cards_nw_pos[i] == card_pos) {
605 for (e = i ; e < cards_nw_n-1 ; e++) {
606 cards_nw_pos[e] = cards_nw_pos[e+1];
608 cards_nw_pos[cards_nw_n-1] = card_pos;
610 cards_dispose_nw(cards_nw_n, takes_nw_n);
616 function card_play_nw(card_idx, x, y)
618 var card_pos = rnd_int(0,cards_nw_n-1);
619 var img = $("card_nw"+cards_nw_pos[card_pos]);
620 var newname = getcard(card_idx,3);
623 x1 = 400 - cards_width - (x - 300);
624 y1 = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
626 var movimg = new slowimg(img, x1, y1, 25, 1, "card_postplay_nw("+cards_nw_pos[card_pos]+");", newname);
627 movimg.settime(G_play_time);
632 function card_postplay_we(card_pos)
634 var img = $("card_we"+card_pos);
637 for (i = 0 ; i < cards_we_n ; i++) {
638 if (cards_we_pos[i] == card_pos) {
639 for (e = i ; e < cards_we_n-1 ; e++) {
640 cards_we_pos[e] = cards_we_pos[e+1];
642 cards_we_pos[cards_we_n-1] = card_pos;
644 cards_dispose_we(cards_we_n, takes_we_n);
650 function card_play_we(card_idx, x, y)
652 var card_pos = rnd_int(0,cards_we_n-1);
653 var img = $("card_we"+cards_we_pos[card_pos]);
654 var newname = getcard(card_idx,4);
657 x1 = 300 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
660 var movimg = new slowimg(img, x1, y1, 25, 1, "card_postplay_we("+cards_we_pos[card_pos]+");", newname);
661 movimg.settime(G_play_time);
665 var card_play_arr = new Array( card_play_so, card_play_ea, card_play_ne, card_play_nw, card_play_we);
667 /* card_play(player_pos, card_pos, card_idx, x, y)
668 player_pos - position of the player on the table
669 card_pos - position of the card in the hand of the player
670 card_idx - id of the card (to show it after the move)
671 x, y - coordinates of the card on the original table
673 orig 200x200 dest 200x125
675 function card_play(player_pos, card_idx, x, y)
677 var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
679 card_play_arr[idx](card_idx, x, y);
684 function card_place_so(card_pos, card_idx, x, y)
686 var img = $("card"+card_pos);
688 // alert("card_place_so"+card_pos);
692 img.style.visibility = "visible";
693 img.src = getcard(card_idx,0);
697 function card_place_ea(card_pos, card_idx, x, y)
699 var img = $("card_ea"+card_pos);
701 // alert("card_place_ea");
703 img.style.left = 500 + ((y-250) * (125 - cards_height) / (200 - cards_height));
704 img.style.top = 450 - cards_width - (x - 300);
705 img.style.visibility = "visible";
706 img.src = getcard(card_idx,1);
710 function card_place_ne(card_pos, card_idx, x, y)
712 var img = $("card_ne"+card_pos);
714 // alert("card_place_ne");
716 img.style.left = 600 - cards_width - (x - 300);
717 img.style.top = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
718 img.style.visibility = "visible";
719 img.src = getcard(card_idx,2);
723 function card_place_nw(card_pos, card_idx, x, y)
725 var img = $("card_nw"+card_pos);
727 // alert("card_place_nw");
729 img.style.left = 400 - cards_width - (x - 300);
730 img.style.top = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
731 img.style.visibility = "visible";
732 img.src = getcard(card_idx,3);
736 function card_place_we(card_pos, card_idx, x, y)
738 var img = $("card_we"+card_pos);
740 // alert("card_place_we");
742 img.style.left = 300 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
743 img.style.top = 250 + x - 300;
744 img.style.visibility = "visible";
745 img.src = getcard(card_idx,4);
748 var card_place_arr = new Array( card_place_so, card_place_ea, card_place_ne, card_place_nw, card_place_we );
751 function card_place(player_pos, card_pos, card_idx, x, y)
753 var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
755 // alert("card_place"+idx);
757 card_place_arr[idx](card_pos, card_idx, x, y);
762 function card_post_take(card)
764 var img = $("card"+card);
765 img.style.visibility = "hidden";
766 cards_dispose_so(cards_n, takes_n);
769 function card_ea_post_take(card)
771 var img = $("card_ea"+card);
772 img.style.visibility = "hidden";
773 cards_dispose_ea(cards_ea_n, takes_ea_n);
776 function card_ne_post_take(card)
778 var img = $("card_ne"+card);
779 img.style.visibility = "hidden";
780 cards_dispose_ne(cards_ne_n, takes_ne_n);
783 function card_nw_post_take(card)
785 var img = $("card_nw"+card);
786 img.style.visibility = "hidden";
787 cards_dispose_nw(cards_nw_n, takes_nw_n);
790 function card_we_post_take(card)
792 var img = $("card_we"+card);
793 img.style.visibility = "hidden";
794 cards_dispose_we(cards_we_n, takes_we_n);
798 function cards_take(win)
800 var taker = (win - table_pos + PLAYERS_N) % PLAYERS_N;
802 // alert("cards_n: "+cards_n+"card: "+cards_pos[cards_n]+"cards_ea_n: "+cards_ea_n+"card_ea: "+cards_ea_pos[cards_ea_n]+"cards_ne_n: "+cards_ne_n+"card_ne: "+cards_ne_pos[cards_ne_n] + "taker:"+taker);
806 takes_n += PLAYERS_N; break;
808 takes_ea_n += PLAYERS_N; break;
810 takes_ne_n += PLAYERS_N; break;
812 takes_nw_n += PLAYERS_N; break;
814 takes_we_n += PLAYERS_N; break;
819 var img = $("card"+cards_pos[cards_n]);
820 var movimg = new slowimg(img,
821 take_x[taker] - cards_width_d2,
822 take_y[taker] - cards_height_d2,
823 25, 0, "card_post_take("+cards_pos[cards_n]+");", null);
824 movimg.settime(G_take_time);
827 var img = $("card_ea"+cards_ea_pos[cards_ea_n]);
828 var movimg = new slowimg(img,
829 take_x[taker] - cards_height_d2,
830 take_y[taker] - cards_width_d2,
831 25, 0, "card_ea_post_take("+cards_ea_pos[cards_ea_n]+");", null);
832 movimg.settime(G_take_time);
835 var img = $("card_ne"+cards_ne_pos[cards_ne_n]);
836 var movimg = new slowimg(img,
837 take_x[taker] - cards_width_d2,
838 take_y[taker] - cards_height_d2,
839 25, (PLAYERS_N == 3 ? 1 : 0), "card_ne_post_take("+cards_ne_pos[cards_ne_n]+");", null);
840 movimg.settime(G_take_time);
843 var img = $("card_nw"+cards_nw_pos[cards_nw_n]);
844 var movimg = new slowimg(img,
845 take_x[taker] - cards_width_d2,
846 take_y[taker] - cards_height_d2,
847 25, 0, "card_nw_post_take("+cards_nw_pos[cards_nw_n]+");", null);
848 movimg.settime(G_take_time);
851 var img = $("card_we"+cards_we_pos[cards_we_n]);
852 var movimg = new slowimg(img,
853 take_x[taker] - cards_height_d2,
854 take_y[taker] - cards_width_d2,
855 25, 1, "card_we_post_take("+cards_we_pos[cards_we_n]+");", null);
856 movimg.settime(G_take_time);