aboutsummaryrefslogtreecommitdiff
path: root/JBriscola/all_versions/0.1/0.1 Alpha 1/src
diff options
context:
space:
mode:
Diffstat (limited to 'JBriscola/all_versions/0.1/0.1 Alpha 1/src')
-rwxr-xr-xJBriscola/all_versions/0.1/0.1 Alpha 1/src/Frame.java118
-rwxr-xr-xJBriscola/all_versions/0.1/0.1 Alpha 1/src/Main.java211
-rwxr-xr-xJBriscola/all_versions/0.1/0.1 Alpha 1/src/Pannello.java53
3 files changed, 382 insertions, 0 deletions
diff --git a/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Frame.java b/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Frame.java
new file mode 100755
index 0000000..a372588
--- /dev/null
+++ b/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Frame.java
@@ -0,0 +1,118 @@
1/*
2Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org>
3
4This file is part of JBriscola.
5
6 JBriscola is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 JBriscola is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with JBriscola; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20*/
21
22import javax.swing.*;
23import java.awt.*;
24import java.awt.event.*;
25
26public class Frame extends JFrame {
27 public static boolean mazzo;
28 public static Main main;
29 public static Pannello pannello;
30 public static JButton button;
31 public static ImageIcon retro1, retro2, ultimaCarta;
32 public static ImageIcon[] giocata = new ImageIcon[2];
33 public static ImageIcon[] carteInMano = new ImageIcon[3];
34 public static ImageIcon[] carteCPU = new ImageIcon[3];
35 public static ImageIcon[] arrayCarteMescolate = new ImageIcon[40];
36 public static ImageIcon[][] arrayCarte = new ImageIcon[10][4];
37 public Frame() {
38 super( "Tronto's JBriscola 0.1" );
39 mazzo = true;
40 main = new Main();
41 pannello = new Pannello();
42 button = new JButton( "Prendi/Lascia carte" );
43 button.addActionListener( new ActionListener() {
44 public void actionPerformed( ActionEvent e ) {
45 if ( giocata[0] != null && giocata[1] != null )
46 main.mano++;
47 else
48 JOptionPane.showMessageDialog( Frame.this, "Prima gioca!" );
49 try {
50 main.chiPrende();
51 } catch ( Exception ex ) {
52 JOptionPane.showMessageDialog( Frame.this, "Prima gioca!" );
53 }
54 if ( main.mano == 16 )
55 JOptionPane.showMessageDialog( Frame.this, "Ultime 4 mani - occhio alla briscola!" );
56 if ( main.mano == 17 ) {
57 mazzo = false;
58 ultimaCarta = null;
59 pannello.repaint();
60 Frame.this.repaint();
61 }
62 if ( main.mano == 20 )
63 JOptionPane.showMessageDialog( Frame.this, "Giocatore: " + main.punteggio + "\nComputer: " + main.punteggioCPU + "\n\nMa grazie tante, il computer gioca a caso!\nNon serve che ti gasi tanto." );
64 }
65 } );
66 retro1 = new ImageIcon( ClassLoader.getSystemResource( "img/retro1.jpg" ) );
67 retro2 = new ImageIcon( ClassLoader.getSystemResource( "img/retro2.jpg" ) );
68 for (int i = 0; i < 10; i++)
69 for (int j = 0; j < 4; j++)
70 arrayCarte[i][j] = new ImageIcon( ClassLoader.getSystemResource( "img/" + (i+1) + "-" + (j+1) + ".jpg" ) );
71 main.mischia();
72 carteInMano[0] = arrayCarteMescolate[0];
73 carteInMano[1] = arrayCarteMescolate[1];
74 carteInMano[2] = arrayCarteMescolate[2];
75 carteCPU[0] = arrayCarteMescolate[3];
76 carteCPU[1] = arrayCarteMescolate[4];
77 carteCPU[2] = arrayCarteMescolate[5];
78 ultimaCarta = arrayCarteMescolate[39];
79 setLayout( new BorderLayout() );
80 add( pannello, BorderLayout.CENTER );
81 add( button, BorderLayout.SOUTH );
82 addMouseListener(
83 new MouseAdapter() {
84 public void mouseClicked ( MouseEvent e ) {
85 if ( mettiCarta( e.getX(), e.getY() ) ) {
86 if ( !main.CPUHaGiocato )
87 main.giocaCPU();
88 }
89 }
90 }
91 );
92 }
93 public boolean mettiCarta( int x, int y ) {
94 if ( !main.toccaAllaCPU && giocata[0] == null ) {
95 if ( x > 230 && x < 290 && y > 340 && y < 566 ) {
96 giocata[0] = carteInMano[0];
97 carteInMano[0] = null;
98 pannello.repaint();
99 return true;
100 }
101 if ( x > 300 && x < 360 && y > 340 && y < 566 ) {
102 giocata[0] = carteInMano[1];
103 carteInMano[1] = null;
104 pannello.repaint();
105 return true;
106 }
107 if ( x > 370 && x < 430 && y > 340 && y < 566 ) {
108 giocata[0] = carteInMano[2];
109 carteInMano[2] = null;
110 pannello.repaint();
111 return true;
112 }
113 }
114 return false;
115 }
116}
117
118
diff --git a/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Main.java b/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Main.java
new file mode 100755
index 0000000..22f6e47
--- /dev/null
+++ b/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Main.java
@@ -0,0 +1,211 @@
1/*
2Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org>
3
4This file is part of JBriscola.
5
6 JBriscola is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 JBriscola is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with JBriscola; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20*/
21
22import javax.swing.*;
23
24public class Main {
25 public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare;
26 public static boolean toccaAllaCPU = false;
27 public static boolean CPUHaGiocato = false;
28 public static boolean haGiocatoPrima = true;
29 public static Frame frame;
30 public static void main( String args[] ) {
31 frame = new Frame();
32 frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
33 frame.setVisible( true );
34 frame.setResizable( false );
35 frame.setSize( 600, 550 );
36 }
37 public void mischia() {
38 mano = 0;
39 cartaDaPescare = 6;
40 ImageIcon aux;
41 for ( int i = 0, k = 0; i < 10; i++ )
42 for ( int j = 0; j < 4; j++, k++ )
43 frame.arrayCarteMescolate[k] = frame.arrayCarte[i][j];
44 for ( int i = 0; i < 391; i++ ) {
45 double a = Math.random() * 40;
46 int x = (int) a;
47 double b = Math.random() * 40;
48 int y = (int) b;
49 aux = frame.arrayCarteMescolate[x];
50 frame.arrayCarteMescolate[x] = frame.arrayCarteMescolate[y];
51 frame.arrayCarteMescolate[y] = aux;
52 }
53 char auxChar[] = frame.arrayCarteMescolate[39].toString().toCharArray();
54 semeBriscola = auxChar[auxChar.length-5] - 49;
55 }
56 public void giocaCPU() {
57 int cartaDaGiocare;
58 /*******************************************/
59 if ( frame.carteCPU[0] != null )
60 cartaDaGiocare = 0;
61 else if ( frame.carteCPU[1] != null )
62 cartaDaGiocare = 1;
63 else
64 cartaDaGiocare = 2;
65 /*******************************************/
66 frame.giocata[1] = frame.carteCPU[cartaDaGiocare];
67 frame.carteCPU[cartaDaGiocare] = null;
68 frame.pannello.repaint();
69 CPUHaGiocato = true;
70 if ( frame.giocata[0] == null )
71 toccaAllaCPU = false;
72 }
73 public void chiPrende() {
74 char aux[], auxCPU[];
75 aux = frame.giocata[0].toString().toCharArray();
76 auxCPU = frame.giocata[1].toString().toCharArray();
77 giocatorePrende( ( (aux[aux.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) )
78 || ( (aux[aux.length-5] == auxCPU[auxCPU.length-5]) && laPrimaEPiuAlta( aux[aux.length-7] - 48, auxCPU[auxCPU.length-7] - 48 ) )
79 || ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (aux[aux.length-5] != auxCPU[auxCPU.length-5]) && haGiocatoPrima ) );
80 }
81 public boolean laPrimaEPiuAlta( int prima, int seconda ) {
82 int a, b;
83 switch ( prima ) {
84 case 0:
85 a = 10;
86 break;
87 case 1:
88 a = 12;
89 break;
90 case 3:
91 a = 11;
92 break;
93 default:
94 a = prima;
95 break;
96 }
97 switch ( seconda ) {
98 case 0:
99 b = 10;
100 break;
101 case 1:
102 b = 12;
103 break;
104 case 3:
105 b = 11;
106 break;
107 default:
108 b = seconda;
109 break;
110 }
111 return a > b;
112 }
113 public void giocatorePrende( boolean giocatore ) {
114 if ( giocatore ) {
115 toccaAllaCPU = CPUHaGiocato = false;
116 haGiocatoPrima = true;
117 }
118 else {
119 toccaAllaCPU = true;
120 CPUHaGiocato = haGiocatoPrima = false;
121 }
122 daiPunti( giocatore );
123 if ( toccaAllaCPU )
124 giocaCPU();
125 }
126 public void daiPunti( boolean giocatore ) {
127 char aux[], auxCPU[];
128 aux = frame.giocata[0].toString().toCharArray();
129 auxCPU = frame.giocata[1].toString().toCharArray();
130 int punti = 0;
131 switch( aux[aux.length-7] - 48 ) {
132 case 0:
133 punti += 4;
134 break;
135 case 1:
136 punti += 11;
137 break;
138 case 3:
139 punti += 10;
140 break;
141 case 8:
142 punti += 2;
143 break;
144 case 9:
145 punti += 3;
146 break;
147 default:
148 break;
149 }
150 switch( auxCPU[auxCPU.length-7] - 48 ) {
151 case 0:
152 punti += 4;
153 break;
154 case 1:
155 punti += 11;
156 break;
157 case 3:
158 punti += 10;
159 break;
160 case 8:
161 punti += 2;
162 break;
163 case 9:
164 punti += 3;
165 break;
166 default:
167 break;
168 }
169 frame.giocata[0] = frame.giocata[1] = null;
170 if ( giocatore ) {
171 punteggio += punti;
172 if ( mano < 18 ) {
173 if ( frame.carteInMano[0] == null )
174 frame.carteInMano[0] = frame.arrayCarteMescolate[cartaDaPescare];
175 if ( frame.carteInMano[1] == null )
176 frame.carteInMano[1] = frame.arrayCarteMescolate[cartaDaPescare];
177 if ( frame.carteInMano[2] == null )
178 frame.carteInMano[2] = frame.arrayCarteMescolate[cartaDaPescare];
179 cartaDaPescare++;
180 if ( frame.carteCPU[0] == null )
181 frame.carteCPU[0] = frame.arrayCarteMescolate[cartaDaPescare];
182 if ( frame.carteCPU[1] == null )
183 frame.carteCPU[1] = frame.arrayCarteMescolate[cartaDaPescare];
184 if ( frame.carteCPU[2] == null )
185 frame.carteCPU[2] = frame.arrayCarteMescolate[cartaDaPescare];
186 cartaDaPescare++;
187 }
188 }
189 else {
190 punteggioCPU += punti;
191 if ( mano < 18 ) {
192 if ( frame.carteCPU[0] == null )
193 frame.carteCPU[0] = frame.arrayCarteMescolate[cartaDaPescare];
194 if ( frame.carteCPU[1] == null )
195 frame.carteCPU[1] = frame.arrayCarteMescolate[cartaDaPescare];
196 if ( frame.carteCPU[2] == null )
197 frame.carteCPU[2] = frame.arrayCarteMescolate[cartaDaPescare];
198 cartaDaPescare++;
199 if ( frame.carteInMano[0] == null )
200 frame.carteInMano[0] = frame.arrayCarteMescolate[cartaDaPescare];
201 if ( frame.carteInMano[1] == null )
202 frame.carteInMano[1] = frame.arrayCarteMescolate[cartaDaPescare];
203 if ( frame.carteInMano[2] == null )
204 frame.carteInMano[2] = frame.arrayCarteMescolate[cartaDaPescare];
205 cartaDaPescare++;
206 }
207 }
208 frame.pannello.repaint();
209 frame.repaint();
210 }
211}
diff --git a/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Pannello.java b/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Pannello.java
new file mode 100755
index 0000000..9e73356
--- /dev/null
+++ b/JBriscola/all_versions/0.1/0.1 Alpha 1/src/Pannello.java
@@ -0,0 +1,53 @@
1/*
2Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org>
3
4This file is part of JBriscola.
5
6 JBriscola is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 JBriscola is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with JBriscola; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20*/
21
22import javax.swing.*;
23import java.awt.Graphics;
24
25public class Pannello extends JPanel {
26 public static Main main;
27 public Pannello() {
28 }
29 public void paint( Graphics g ) {
30 super.paint( g );
31 if ( main.frame.ultimaCarta != null )
32 main.frame.ultimaCarta.paintIcon( this, g, 50, 180 );
33 if ( main.frame.mazzo )
34 main.frame.retro2.paintIcon( this, g, 17, 256 );
35 if ( main.frame.carteCPU[0] != null )
36 main.frame.retro1.paintIcon( this, g, 230, 5 );
37 if ( main.frame.carteCPU[1] != null )
38 main.frame.retro1.paintIcon( this, g, 300, 5 );
39 if ( main.frame.carteCPU[2] != null )
40 main.frame.retro1.paintIcon( this, g, 370, 5 );
41 if ( main.frame.carteInMano[0] != null )
42 main.frame.carteInMano[0].paintIcon( this, g, 230, 340 );
43 if ( main.frame.carteInMano[1] != null )
44 main.frame.carteInMano[1].paintIcon( this, g, 300, 340 );
45 if ( main.frame.carteInMano[2] != null )
46 main.frame.carteInMano[2].paintIcon( this, g, 370, 340 );
47 if ( main.frame.giocata[0] != null )
48 main.frame.giocata[0].paintIcon( this, g, 250, 200 );
49 if ( main.frame.giocata[1] != null )
50 main.frame.giocata[1].paintIcon( this, g, 325, 150 );
51 }
52}
53

Generated with cgit - Back to sebastiano.tronto.net