4 * Copyright (C) 2006-2008 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.
32 var is_my_time = false;
33 /* number of takes cards */
49 var cards_width = 55 + 2;
50 var cards_width_d2 = 27;
52 /* height of images */
53 var cards_height = 101 + 2;
54 var cards_height_d2 = 51;
56 /* width of hands area */
57 var hands_width = 400;
59 /* width of the border */
60 var border_width = 10;
62 /* time to send a card to the player 10 or 250 */
63 var G_send_time = 250;
64 var G_play_time = 500;
65 var G_take_time = 500;
67 /* suffix to add to images name */
68 var sux = new Array( "", "_ea", "", "", "_we");
70 var cards_pos = new Array (8);
71 var cards_ea_pos = new Array (8);
72 var cards_ne_pos = new Array (8);
73 var cards_nw_pos = new Array (8);
74 var cards_we_pos = new Array (8);
76 var take_x = new Array(562, 745, 452, 30, 52);
77 var take_y = new Array(545, 177, 70, 62,155);
79 for (i = 0 ; i < 8 ; i++) {
86 function $(id) { return document.getElementById(id); }
88 function cards_dispose_so(car_n, tak_n)
92 $("takes").style.left = 200 + 400 - 90 + ((90 - cards_width) / 2);
93 $("takes").style.top = 475 + (125 - cards_height)/2;
94 $("takes").style.zIndex = 1;
95 $("takes").style.visibility = "visible";
101 disp = 400 - delta - (2 * border_width);
103 inter = parseInt((disp - cards_width) / (car_n - 1));
104 if (inter > cards_width)
109 wcard = cards_width + inter * (car_n - 1);
110 start = 200 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
112 for (i = 0 ; i < car_n ; i++) {
113 $("card" + cards_pos[i]).style.left = start + (i * inter);
114 $("card" + cards_pos[i]).style.top = 475 + (125 - cards_height)/2;
115 $("card" + cards_pos[i]).style.zIndex = 8 - i;
116 $("card" + cards_pos[i]).style.visibility = "visible";
125 function cards_dispose_ne(car_n, tak_n) {
130 $("takes_ne").style.left = 800 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
131 $("takes_ne").style.top = (125 - cards_height)/2;
132 $("takes_ne").style.zIndex = 1;
133 $("takes_ne").style.visibility = "visible";
139 disp = 400 - delta - (2 * border_width);
141 inter = parseInt((disp - cards_width) / (car_n - 1));
142 if (inter > cards_width)
147 wcard = cards_width + inter * (car_n - 1);
148 start = 800 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
151 for (i = 0 ; i < car_n ; i++) {
152 $("card_ne" + cards_ne_pos[i]).style.left = start - ((car_n - i -1) * inter);
153 $("card_ne" + cards_ne_pos[i]).style.top = (125 - cards_height)/2;
154 $("card_ne" + cards_ne_pos[i]).style.zIndex = 8-i;
155 $("card_ne" + cards_ne_pos[i]).style.visibility = "visible";
164 function cards_dispose_nw(car_n, tak_n) {
169 $("takes_nw").style.left = 400 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
170 $("takes_nw").style.top = (125 - cards_height)/2;
171 $("takes_nw").style.zIndex = 1;
172 $("takes_nw").style.visibility = "visible";
178 disp = 400 - delta - (2 * border_width);
180 inter = parseInt((disp - cards_width) / (car_n - 1));
181 if (inter > cards_width)
186 wcard = cards_width + inter * (car_n - 1);
187 // start = 0 + delta + border_width + (400 - border_width - border_width - wcard - delta) / 2;
188 start = 400 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
191 for (i = 0 ; i < car_n ; i++) {
192 $("card_nw" + cards_nw_pos[i]).style.left = start - ((car_n-i-1) * inter);
193 $("card_nw" + cards_nw_pos[i]).style.top = (125 - cards_height)/2;
194 $("card_nw" + cards_nw_pos[i]).style.zIndex = (8-i);
195 $("card_nw" + cards_nw_pos[i]).style.visibility = "visible";
196 // alert("xx "+start + (i * inter)+" yy " + (125 - cards_height)/2);
205 function cards_dispose_ea(car_n, tak_n) {
208 $("takes_ea").style.left = 675 + (125 - cards_height)/2;
209 $("takes_ea").style.top = 125 + ((90 - cards_width) / 2);
210 $("takes_ea").style.zIndex = 1;
211 $("takes_ea").style.visibility = "visible";
216 disp = 400 - delta - (2 * border_width);
218 inter = parseInt((disp - cards_width) / (car_n - 1));
219 if (inter > cards_width)
224 wcard = cards_width + inter * (car_n - 1);
225 start = 125 + delta + border_width + (400 - border_width - border_width - wcard - delta) / 2;
228 for (i = 0 ; i < car_n ; i++) {
229 $("card_ea" + cards_ea_pos[i]).style.left = 675 + (125 - cards_height)/2;
230 $("card_ea" + cards_ea_pos[i]).style.top = start + (i * inter);
231 $("card_ea" + cards_ea_pos[i]).style.zIndex = 8 - i;
232 $("card_ea" + cards_ea_pos[i]).style.visibility = "visible";
233 // alert("xx "+ (675 + (125 - cards_height)/2) +" yy " + start + (i * inter));
242 function cards_dispose_we(car_n, tak_n)
246 $("takes_we").style.left = (125 - cards_height)/2;
247 // $("takes_we").style.top = 125 + 400 - 90 + ((90 - cards_width) / 2);
248 $("takes_we").style.top = 525 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
249 $("takes_we").style.zIndex = 1;
250 $("takes_we").style.visibility = "visible";
255 /* pixel a disposizione per mettere le carte: 400 - delta - 2 bordi */
256 disp = 400 - delta - (2 * border_width);
257 /* se c'e' piu' di una carta calcola di quanti pixel devono rimanere scoperte le carte dopo la prima */
259 inter = parseInt((disp - cards_width) / (car_n - 1));
260 if (inter > cards_width)
266 /* dopo avere fatto tutti i conti ricalcola quanti pixel effettivamente verranno occupati dalle carte */
267 wcard = cards_width + inter * (car_n - 1);
269 /* calcola il punto d'inizio da dove disporre le carte: DELTAY + lo spessore del bordo + la meta' di quello
270 che resta della larghezza totale meno tutti gli altri ingombri */
271 // start = 125 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
272 start = 525 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
274 for (i = 0 ; i < car_n ; i++) {
275 $("card_we" + cards_we_pos[i]).style.left = (125 - cards_height)/2;
276 $("card_we" + cards_we_pos[i]).style.top = start - (i * inter);
277 $("card_we" + cards_we_pos[i]).style.zIndex = 8 - i;
278 $("card_we" + cards_we_pos[i]).style.visibility = "visible";
287 var cards_dispose_arr = new Array(cards_dispose_so, cards_dispose_ea,
288 cards_dispose_ne, cards_dispose_nw,
291 function cards_dispose(player_pos, cards, takes)
293 var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
295 return (cards_dispose_arr[idx](cards,takes));
301 function card_mouseup_cb(o) {
302 var idx = o.id.substring(4);
303 var briskid = o.briskid;
309 /* case swap in the group */
312 if (parseInt(o.style.top) > 475 &&
313 parseInt(o.style.left) >= 200 && parseInt(o.style.left) < 600) {
314 /* Rearrange cards */
316 // $("sandbox3").innerHTML = "REARRANGE: "+idx;
323 /* found the associated index of the current card. */
324 for (i = 0 ; i < cards_n ; i++)
325 if (cards_pos[i] == idx)
329 disp = 400 - delta - (2 * border_width);
331 inter = parseInt((disp - cards_width) / (cards_n - 1));
332 if (inter > cards_width)
337 wcard = cards_width + inter * (cards_n - 1);
338 start = 200 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
340 for (i = 0 ; i < cards_n ; i++) {
341 /* $("sandbox").innerHTML = */
342 // alert( "LEFT: " + o.style.left + "VALUE " + (cards_width + start + (i * (cards_width / 2))));
343 // $("sandbox3").innerHTML += "<br>LEFT: "+parseInt(o.style.left)+" START["+i+"]: "+(start + ((i+1) * inter));
345 tst = (parseInt(o.style.left) < start + ((i+1) * inter));
347 tst = (parseInt(o.style.left) > start + (i * inter));
349 // $("sandbox2").innerHTML = "old: " +old_idx+ " i: " +i+ "left: " + parseInt(o.style.left) + "comp: " + (start + (cards_width / 2) + (i * (cards_width / 2)));
355 for (e = old_idx ; e < i ; e++)
356 cards_pos[e] = cards_pos[e+1];
360 for (e = old_idx ; e > i ; e--)
361 cards_pos[e] = cards_pos[e-1];
368 cards_dispose_so(cards_n,takes_n);
372 else if (is_my_time &&
373 parseInt(o.style.top) >= 250 &&
374 parseInt(o.style.top) + cards_height < 450 &&
375 parseInt(o.style.left) >= 300 &&
376 (parseInt(o.style.left) + cards_width) < 500) {
379 $("sandbox2").innerHTML = "PLAYED";
381 for (i = 0 ; i < cards_n ; i++) {
382 if (cards_pos[i] == idx) {
383 /* $("sandbox").innerHTML = "Pippo: "+ i; */
384 for (e = i ; e < cards_n-1 ; e++) {
385 cards_pos[e] = cards_pos[e+1];
387 cards_pos[cards_n-1] = idx;
389 cards_dispose_so(cards_n, takes_n);
392 act_play(briskid,o.style.left,o.style.top);
396 cards_dispose_so(cards_n, takes_n);
401 $("sandbox2").innerHTML = "TO ORIGINAL";
402 /* alert("out card " + parseInt(o.style.top)); */
403 /* return to the original position */
404 cards_dispose_so(cards_n, takes_n);
411 function card_send_so(id,card,free,ct)
413 var img = $("card"+id);
414 img.src = getcard(-1,0);
417 img.style.left = 400 - cards_width_d2;
418 img.style.top = 300 - cards_height_d2;
419 img.style.zIndex = 100;
421 var movimg = new slowimg(img,400 - cards_width / 2,475 + (125 - cards_height)/2,25,free,"cards_dispose_so("+ct+", 0)",getcard(card,0));
422 movimg.settime(G_send_time);
426 function card_send_ea(id,card,free,ct)
428 var img = $("card_ea"+id);
429 img.src = getcard(card,1);
432 img.style.left = 400 - cards_height_d2;
433 img.style.top = 300 - cards_width_d2;
434 img.style.zIndex = 100;
436 var movimg = new slowimg(img,686,296,25,free,"cards_dispose_ea("+ct+", 0);",getcard(card,1));
437 movimg.settime(G_send_time);
441 function card_send_ne(id,card,free,ct)
443 var img = $("card_ne"+id);
444 img.src = getcard(card,2);
447 img.style.left = 400 - cards_width_d2;
448 img.style.top = 300 - cards_height_d2;
449 img.style.zIndex = 100;
451 var movimg = new slowimg(img,571,11,25,free,"cards_dispose_ne("+ct+", 0);",getcard(card,2));
452 movimg.settime(G_send_time);
456 function card_send_nw(id,card,free,ct)
458 var img = $("card_nw"+id);
459 img.src = getcard(card,3);
462 img.style.left = 400 - cards_width_d2;
463 img.style.top = 300 - cards_height_d2;
464 img.style.zIndex = 100;
466 var movimg = new slowimg(img,171,11,25,free,"cards_dispose_nw("+ct+", 0);",getcard(card,3));
467 movimg.settime(G_send_time);
471 function card_send_we(id,card,free,ct)
473 var img = $("card_we"+id);
474 img.src = getcard(card,4);
477 if (id < 0 || id > 39)
478 alert("ID ERRATO"+id);
480 img.style.left = 400 - cards_height_d2;
481 img.style.top = 300 - cards_width_d2;
482 img.style.zIndex = 100;
483 var movimg = new slowimg(img,11,296,25,free,"cards_dispose_we("+ct+", 0);",getcard(card,4));
484 movimg.settime(G_send_time);
488 var card_send_arr = new Array(card_send_so, card_send_ea,
489 card_send_ne, card_send_nw,
492 function card_send(player_pos,id,card,free,ct)
494 var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
496 card_send_arr[idx](id,card,free,ct);
499 function getcard(card,pos_id)
502 return ("img/cover"+sux[pos_id]+".png");
504 return ("img/0"+card+sux[pos_id]+".png");
506 return ("img/"+card+sux[pos_id]+".png");
509 function card_setours(zer,uno,due,tre,qua,cin,sei,set)
512 var arg = new Array(zer,uno,due,tre,qua,cin,sei,set);
514 for (i = 0 ; i < 8 ; i++) {
515 $("card"+i).src = getcard(arg[i], 0);
516 $("card"+i).briskid = arg[i];
522 function card_play_so(card_idx, x, y)
524 alert("card_play_so: unreachable function.");
528 function card_postplay_ea(card_pos)
530 var img = $("card_ea"+card_pos);
533 for (i = 0 ; i < cards_ea_n ; i++) {
534 if (cards_ea_pos[i] == card_pos) {
535 for (e = i ; e < cards_ea_n-1 ; e++) {
536 cards_ea_pos[e] = cards_ea_pos[e+1];
538 cards_ea_pos[cards_ea_n-1] = card_pos;
540 cards_dispose_ea(cards_ea_n, takes_ea_n);
546 function card_play_ea(card_idx, x, y)
548 // var card_pos = RANGE 0 <= x < cards_ea_n
549 var card_pos = rnd_int(0,cards_ea_n-1);
550 var img = $("card_ea"+cards_ea_pos[card_pos]);
551 // alert("IMMO CON "+cards_ea_pos[card_pos]);
552 var newname = getcard(card_idx,1);
555 x1 = 500 + ((y-250) * (125 - cards_height) / (200 - cards_height));
556 y1 = 450 - cards_width - (x - 300);
558 var movimg = new slowimg(img, x1, y1, 25, 1, "card_postplay_ea("+cards_ea_pos[card_pos]+");", newname);
559 movimg.settime(G_play_time);
564 function card_postplay_ne(card_pos)
566 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("+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);