From 7167b4341ef290d56fb96e2af10883a4b925d83b Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 26 Mar 2026 19:27:18 +0100 Subject: I found my old code! --- .../all_versions/0.1/0.1 Alpha 1/src/Frame.java | 118 ++++++++++++ .../all_versions/0.1/0.1 Alpha 1/src/Main.java | 211 +++++++++++++++++++++ .../all_versions/0.1/0.1 Alpha 1/src/Pannello.java | 53 ++++++ 3 files changed, 382 insertions(+) create mode 100755 JBriscola/all_versions/0.1/0.1 Alpha 1/src/Frame.java create mode 100755 JBriscola/all_versions/0.1/0.1 Alpha 1/src/Main.java create mode 100755 JBriscola/all_versions/0.1/0.1 Alpha 1/src/Pannello.java (limited to 'JBriscola/all_versions/0.1/0.1 Alpha 1/src') 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 @@ +/* +Copyright 2009 Sebastiano Tronto + +This file is part of JBriscola. + + JBriscola is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + JBriscola is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with JBriscola; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class Frame extends JFrame { + public static boolean mazzo; + public static Main main; + public static Pannello pannello; + public static JButton button; + public static ImageIcon retro1, retro2, ultimaCarta; + public static ImageIcon[] giocata = new ImageIcon[2]; + public static ImageIcon[] carteInMano = new ImageIcon[3]; + public static ImageIcon[] carteCPU = new ImageIcon[3]; + public static ImageIcon[] arrayCarteMescolate = new ImageIcon[40]; + public static ImageIcon[][] arrayCarte = new ImageIcon[10][4]; + public Frame() { + super( "Tronto's JBriscola 0.1" ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + button = new JButton( "Prendi/Lascia carte" ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + else + JOptionPane.showMessageDialog( Frame.this, "Prima gioca!" ); + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Prima gioca!" ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, "Ultime 4 mani - occhio alla briscola!" ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) + 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." ); + } + } ); + retro1 = new ImageIcon( ClassLoader.getSystemResource( "img/retro1.jpg" ) ); + retro2 = new ImageIcon( ClassLoader.getSystemResource( "img/retro2.jpg" ) ); + for (int i = 0; i < 10; i++) + for (int j = 0; j < 4; j++) + arrayCarte[i][j] = new ImageIcon( ClassLoader.getSystemResource( "img/" + (i+1) + "-" + (j+1) + ".jpg" ) ); + main.mischia(); + carteInMano[0] = arrayCarteMescolate[0]; + carteInMano[1] = arrayCarteMescolate[1]; + carteInMano[2] = arrayCarteMescolate[2]; + carteCPU[0] = arrayCarteMescolate[3]; + carteCPU[1] = arrayCarteMescolate[4]; + carteCPU[2] = arrayCarteMescolate[5]; + ultimaCarta = arrayCarteMescolate[39]; + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( button, BorderLayout.SOUTH ); + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + } + public boolean mettiCarta( int x, int y ) { + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( x > 230 && x < 290 && y > 340 && y < 566 ) { + giocata[0] = carteInMano[0]; + carteInMano[0] = null; + pannello.repaint(); + return true; + } + if ( x > 300 && x < 360 && y > 340 && y < 566 ) { + giocata[0] = carteInMano[1]; + carteInMano[1] = null; + pannello.repaint(); + return true; + } + if ( x > 370 && x < 430 && y > 340 && y < 566 ) { + giocata[0] = carteInMano[2]; + carteInMano[2] = null; + pannello.repaint(); + return true; + } + } + return false; + } +} + + 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 @@ +/* +Copyright 2009 Sebastiano Tronto + +This file is part of JBriscola. + + JBriscola is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + JBriscola is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with JBriscola; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static Frame frame; + public static void main( String args[] ) { + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + frame.setVisible( true ); + frame.setResizable( false ); + frame.setSize( 600, 550 ); + } + public void mischia() { + mano = 0; + cartaDaPescare = 6; + ImageIcon aux; + for ( int i = 0, k = 0; i < 10; i++ ) + for ( int j = 0; j < 4; j++, k++ ) + frame.arrayCarteMescolate[k] = frame.arrayCarte[i][j]; + for ( int i = 0; i < 391; i++ ) { + double a = Math.random() * 40; + int x = (int) a; + double b = Math.random() * 40; + int y = (int) b; + aux = frame.arrayCarteMescolate[x]; + frame.arrayCarteMescolate[x] = frame.arrayCarteMescolate[y]; + frame.arrayCarteMescolate[y] = aux; + } + char auxChar[] = frame.arrayCarteMescolate[39].toString().toCharArray(); + semeBriscola = auxChar[auxChar.length-5] - 49; + } + public void giocaCPU() { + int cartaDaGiocare; + /*******************************************/ + if ( frame.carteCPU[0] != null ) + cartaDaGiocare = 0; + else if ( frame.carteCPU[1] != null ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + /*******************************************/ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + CPUHaGiocato = true; + if ( frame.giocata[0] == null ) + toccaAllaCPU = false; + } + public void chiPrende() { + char aux[], auxCPU[]; + aux = frame.giocata[0].toString().toCharArray(); + auxCPU = frame.giocata[1].toString().toCharArray(); + giocatorePrende( ( (aux[aux.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) ) + || ( (aux[aux.length-5] == auxCPU[auxCPU.length-5]) && laPrimaEPiuAlta( aux[aux.length-7] - 48, auxCPU[auxCPU.length-7] - 48 ) ) + || ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (aux[aux.length-5] != auxCPU[auxCPU.length-5]) && haGiocatoPrima ) ); + } + public boolean laPrimaEPiuAlta( int prima, int seconda ) { + int a, b; + switch ( prima ) { + case 0: + a = 10; + break; + case 1: + a = 12; + break; + case 3: + a = 11; + break; + default: + a = prima; + break; + } + switch ( seconda ) { + case 0: + b = 10; + break; + case 1: + b = 12; + break; + case 3: + b = 11; + break; + default: + b = seconda; + break; + } + return a > b; + } + public void giocatorePrende( boolean giocatore ) { + if ( giocatore ) { + toccaAllaCPU = CPUHaGiocato = false; + haGiocatoPrima = true; + } + else { + toccaAllaCPU = true; + CPUHaGiocato = haGiocatoPrima = false; + } + daiPunti( giocatore ); + if ( toccaAllaCPU ) + giocaCPU(); + } + public void daiPunti( boolean giocatore ) { + char aux[], auxCPU[]; + aux = frame.giocata[0].toString().toCharArray(); + auxCPU = frame.giocata[1].toString().toCharArray(); + int punti = 0; + switch( aux[aux.length-7] - 48 ) { + case 0: + punti += 4; + break; + case 1: + punti += 11; + break; + case 3: + punti += 10; + break; + case 8: + punti += 2; + break; + case 9: + punti += 3; + break; + default: + break; + } + switch( auxCPU[auxCPU.length-7] - 48 ) { + case 0: + punti += 4; + break; + case 1: + punti += 11; + break; + case 3: + punti += 10; + break; + case 8: + punti += 2; + break; + case 9: + punti += 3; + break; + default: + break; + } + frame.giocata[0] = frame.giocata[1] = null; + if ( giocatore ) { + punteggio += punti; + if ( mano < 18 ) { + if ( frame.carteInMano[0] == null ) + frame.carteInMano[0] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteInMano[1] == null ) + frame.carteInMano[1] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteInMano[2] == null ) + frame.carteInMano[2] = frame.arrayCarteMescolate[cartaDaPescare]; + cartaDaPescare++; + if ( frame.carteCPU[0] == null ) + frame.carteCPU[0] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteCPU[1] == null ) + frame.carteCPU[1] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteCPU[2] == null ) + frame.carteCPU[2] = frame.arrayCarteMescolate[cartaDaPescare]; + cartaDaPescare++; + } + } + else { + punteggioCPU += punti; + if ( mano < 18 ) { + if ( frame.carteCPU[0] == null ) + frame.carteCPU[0] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteCPU[1] == null ) + frame.carteCPU[1] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteCPU[2] == null ) + frame.carteCPU[2] = frame.arrayCarteMescolate[cartaDaPescare]; + cartaDaPescare++; + if ( frame.carteInMano[0] == null ) + frame.carteInMano[0] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteInMano[1] == null ) + frame.carteInMano[1] = frame.arrayCarteMescolate[cartaDaPescare]; + if ( frame.carteInMano[2] == null ) + frame.carteInMano[2] = frame.arrayCarteMescolate[cartaDaPescare]; + cartaDaPescare++; + } + } + frame.pannello.repaint(); + frame.repaint(); + } +} 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 @@ +/* +Copyright 2009 Sebastiano Tronto + +This file is part of JBriscola. + + JBriscola is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + JBriscola is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with JBriscola; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.*; +import java.awt.Graphics; + +public class Pannello extends JPanel { + public static Main main; + public Pannello() { + } + public void paint( Graphics g ) { + super.paint( g ); + if ( main.frame.ultimaCarta != null ) + main.frame.ultimaCarta.paintIcon( this, g, 50, 180 ); + if ( main.frame.mazzo ) + main.frame.retro2.paintIcon( this, g, 17, 256 ); + if ( main.frame.carteCPU[0] != null ) + main.frame.retro1.paintIcon( this, g, 230, 5 ); + if ( main.frame.carteCPU[1] != null ) + main.frame.retro1.paintIcon( this, g, 300, 5 ); + if ( main.frame.carteCPU[2] != null ) + main.frame.retro1.paintIcon( this, g, 370, 5 ); + if ( main.frame.carteInMano[0] != null ) + main.frame.carteInMano[0].paintIcon( this, g, 230, 340 ); + if ( main.frame.carteInMano[1] != null ) + main.frame.carteInMano[1].paintIcon( this, g, 300, 340 ); + if ( main.frame.carteInMano[2] != null ) + main.frame.carteInMano[2].paintIcon( this, g, 370, 340 ); + if ( main.frame.giocata[0] != null ) + main.frame.giocata[0].paintIcon( this, g, 250, 200 ); + if ( main.frame.giocata[1] != null ) + main.frame.giocata[1].paintIcon( this, g, 325, 150 ); + } +} + -- cgit v1.3