commit 7167b4341ef290d56fb96e2af10883a4b925d83b Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Thu, 26 Mar 2026 19:27:18 +0100 I found my old code! Diffstat:
737 files changed, 28144 insertions(+), 0 deletions(-)
diff --git a/GiocoUno/GiocoUno.BAT b/GiocoUno/GiocoUno.BAT @@ -0,0 +1 @@ +java GiocoUno diff --git a/GiocoUno/GiocoUno.class b/GiocoUno/GiocoUno.class Binary files differ. diff --git a/GiocoUno/GiocoUno.java b/GiocoUno/GiocoUno.java @@ -0,0 +1,241 @@ +import javax.swing.JOptionPane; +public class GiocoUno { + public static void main(String args[]) { + int grpas = 0, + grpbs = 0, + grpcs = 0, + grpds = 0, + grpes = 0, + A = 2, + B = 1, + C = 16, + D = 8, + E = 4; + String grpa = "", + grpb = "", + grpc = "", + grpd = "", + grpe = ""; + JOptionPane.showMessageDialog(null,"Con questo giochetto vi stupirò (forse)\n\nPremi OK per continuare","Gioco numero uno",1); + JOptionPane.showMessageDialog(null,"Scegli un numero da 1 a 30...\n\nE premi OK per continuare","Gioco numero uno",1); + JOptionPane.showMessageDialog(null,"In quali di questi 5 gruppi appare il vostro numero?\n\nGruppo A: 2; 27; 14; 15; 18; 10; 22; 7; 19; 26; 23; 6; 3; 11; 30\nGruppo B: 1; 5; 17; 11; 9; 21; 3; 29; 19; 7; 15; 25; 23; 13; 27\nGruppo C: 16; 24; 28; 17; 30; 21; 18; 22; 23; 19; 26; 27; 25; 20; 29\nGruppo D: 8; 9; 30; 10; 27; 14; 26; 28; 13; 11; 29; 24; 12; 15; 25\nGruppo E: 4; 23; 20; 7; 12; 15; 6; 30; 5; 21; 14; 22; 13; 29; 28","Gioco numero uno",1); + grpa=JOptionPane.showInputDialog("Il numero appariva nel gruppo A?\n(1 per sì o qualunque altro numero per no)"); + grpas=Integer.parseInt(grpa); + if (grpas == 1) { + grpb=JOptionPane.showInputDialog("Il numero appariva nel gruppo B?\n(1 per sì o qualunque altro numero per no)"); + grpbs=Integer.parseInt(grpb); + if (grpbs == 1) { + grpc=JOptionPane.showInputDialog("Il numero appariva nel gruppo C?\n(1 per sì o qualunque altro numero per no)"); + grpcs=Integer.parseInt(grpc); + if (grpcs == 1) { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B + C + D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B + C + D)); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B + C + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B + C)); + } + } + } + else { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B + D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B + D)); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + B)); + } + } + } + } + else { + grpc=JOptionPane.showInputDialog("Il numero appariva nel gruppo C?\n(1 per sì o qualunque altro numero per no)"); + grpcs=Integer.parseInt(grpc); + if (grpcs == 1) { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + C + D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + C + D)); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + C + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + C)); + } + } + } + else { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + D)); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (A + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + A); + } + } + } + } + } + else { + grpb=JOptionPane.showInputDialog("Il numero appariva nel gruppo B?\n(1 per sì o qualunque altro numero per no)"); + grpbs=Integer.parseInt(grpb); + if (grpbs == 1) { + grpc=JOptionPane.showInputDialog("Il numero appariva nel gruppo C?\n(1 per sì o qualunque altro numero per no)"); + grpcs=Integer.parseInt(grpc); + if (grpcs == 1) { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (B + C + D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (B + C + D)); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (B + C + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (B + C)); + } + } + } + else { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (B + D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (B + D)); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (B + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + B); + } + } + } + } + else { + grpc=JOptionPane.showInputDialog("Il numero appariva nel gruppo C?\n(1 per sì o qualunque altro numero per no)"); + grpcs=Integer.parseInt(grpc); + if (grpcs == 1) { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (C + D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (C + D)); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (C + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + C); + } + } + } + else { + grpd=JOptionPane.showInputDialog("Il numero appariva nel gruppo D?\n(1 per sì o qualunque altro numero per no)"); + grpds=Integer.parseInt(grpd); + if (grpds == 1) { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + (D + E)); + } + else { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + D); + } + } + else { + grpe=JOptionPane.showInputDialog("Il numero appariva nel gruppo E?\n(1 per sì o qualunque altro numero per no)"); + grpes=Integer.parseInt(grpe); + if (grpes == 1) { + JOptionPane.showMessageDialog(null,"Il numero che hai pensato è " + E); + } + else { + JOptionPane.showMessageDialog(null,"Errore! Deve pur eesere da qualche parte!"); + } + } + } + } + } + } +} +\ No newline at end of file diff --git a/GiocoUno/GiocoUno.sh b/GiocoUno/GiocoUno.sh @@ -0,0 +1 @@ +java GiocoUno diff --git a/GiocoUno/Readme.txt b/GiocoUno/Readme.txt @@ -0,0 +1,3 @@ +Ecco il gioco che vi legge nel pensiero! +Non mi credete? provatelo! +Se usate windows aprite il file GiocoUno.BAT, se usate linux GiocoUno.sh +\ No newline at end of file diff --git a/JBriscola/JBriscola.jar b/JBriscola/JBriscola.jar Binary files differ. 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 @@ -0,0 +1,118 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 @@ -0,0 +1,211 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 @@ -0,0 +1,53 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 ); + } +} + diff --git a/JBriscola/all_versions/0.1/0.1 Beta 1/src/Frame.java b/JBriscola/all_versions/0.1/0.1 Beta 1/src/Frame.java @@ -0,0 +1,159 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 JMenuBar barraMenu; + public static JMenu file; + public static JMenuItem nuovaPartita, esci; + 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++; + 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 ) { + String titolo = "Hai vinto!"; + if ( main.punteggio < main.punteggioCPU ) + titolo = "Hai perso"; + if ( main.punteggio == main.punteggioCPU ) + titolo = "Pareggio!"; + JOptionPane.showMessageDialog( Frame.this, "Giocatore: " + main.punteggio + "\nComputer: " + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( "Nuova Partita" ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, "Vuoi davvero iniziare una nuova partita?", "JBriscola 0.1", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + esci = new JMenuItem( "Esci" ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, "Vuoi davvero uscire?", "JBriscola 0.1", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( esci ); + barraMenu.add( file ); + setJMenuBar( barraMenu ); + 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(); + 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(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, "Vuoi davvero uscire?", "JBriscola 0.1", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + 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 Beta 1/src/Main.java b/JBriscola/all_versions/0.1/0.1 Beta 1/src/Main.java @@ -0,0 +1,399 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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, cartaDaGiocare; + 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.DO_NOTHING_ON_CLOSE ); + frame.setVisible( true ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( frame.giocata[0] == null ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiBriscola() ); + else if ( vaiCarico() ); + else; + } + else { + if ( haLisciato() || haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiBriscola() ); + else if ( vaiCarico() ); + else System.out.println("Ha lisciato e non so cosa fare"); + } else if ( haMessoBriscola() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiBriscola() ); + else if ( vaiCarico() ); + else System.out.println("Ha messo una briscola e non so cosa fare"); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiBriscola() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + else System.out.println("Ha caricato e non so cosa fare"); + } else System.out.println("Non so cosa ha fatto"); + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haMessoBriscola() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscola() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + } + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else cartaDaGiocare = 55; + return true; + } +} diff --git a/JBriscola/all_versions/0.1/0.1 Beta 1/src/Pannello.java b/JBriscola/all_versions/0.1/0.1 Beta 1/src/Pannello.java @@ -0,0 +1,53 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 ); + } +} + diff --git a/JBriscola/all_versions/0.1/0.1 Beta 2/src/Frame.java b/JBriscola/all_versions/0.1/0.1 Beta 2/src/Frame.java @@ -0,0 +1,174 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 JMenuBar barraMenu; + public static JMenu file; + public static JMenuItem nuovaPartita, opzioni, esci; + 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 Beta 2" ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola 0.1", JOptionPane.WARNING_MESSAGE ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) { + String titolo = main.stringaVinto; + if ( main.punteggio < main.punteggioCPU ) + titolo = main.stringaPerso; + if ( main.punteggio == main.punteggioCPU ) + titolo = main.stringaPareggio; + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola 0.1", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 150 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola 0.1", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + barraMenu.add( file ); + setJMenuBar( barraMenu ); + 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(); + 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(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola 0.1", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + 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 Beta 2/src/Main.java b/JBriscola/all_versions/0.1/0.1 Beta 2/src/Main.java @@ -0,0 +1,492 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static Frame frame; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultime 4 mani - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore"; + public static String stringaComputer = "\nComputer"; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua.\nAlcune parti saranno comunque tradotte prima."; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static void main( String args[] ) { + settaOpzioni(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + + frame.setVisible( true ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( frame.giocata[0] == null ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiBriscola() ); + else if ( vaiCarico() ); + else; + } + else { + if ( haLisciato() || haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiBriscola() ); + else if ( vaiCarico() ); + else System.out.println("Ha lisciato e non so cosa fare"); + } else if ( haMessoBriscola() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiBriscola() ); + else if ( vaiCarico() ); + else System.out.println("Ha messo una briscola e non so cosa fare"); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiBriscola() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + else System.out.println("Ha caricato e non so cosa fare"); + } else System.out.println("Non so cosa ha fatto"); + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haMessoBriscola() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscola() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + } + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else cartaDaGiocare = 55; + return true; + } + public static void settaOpzioni() { + String lang; + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { + lang = "it"; + } + lang = scanner.next(); + } + else { + lang = "it"; + } + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultime 4 mani - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore"; + stringaComputer = "\nComputer"; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero dscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua\nAlcune parti saranno comunque tradotte prima."; + stringaModificaOpzioni = "Modifica Opzioni"; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "IV MANVS POSTREMAS - INTVERE BRISCOLAM!"; + stringaVinto = "VINXISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICE"; + stringaLa = "LATINE"; + stringaNecessarioRiavviare = "JBRISCOLAM RVRSVS INCIPERE NECESSE EST\nSI LINGVA PRAELATIONES NOVATAE SUNT.\nALIQVAE ANTE ID VERSA ERVNT"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + } + } +} diff --git a/JBriscola/all_versions/0.1/0.1 Beta 2/src/OptionFrame.java b/JBriscola/all_versions/0.1/0.1 Beta 2/src/OptionFrame.java @@ -0,0 +1,83 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla; + public static JLabel lingua; + public static JComboBox selezionaLingua; + public static JPanel pannello1, pannello2; + public OptionFrame() { + super( "JBriscola - " + main.stringaModificaOpzioni ); + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex ); + } + String lang; + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + default: + lang = "it"; + break; + } + formatter.format( lang ); + formatter.close(); + main.settaOpzioni(); + main.frame.pannello.repaint(); + main.frame.repaint(); + OptionFrame.this.dispose(); + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + } + }); + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + lingua = new JLabel( main.stringaLingua ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + pannello1 = new JPanel( new FlowLayout() ); + pannello1.add( lingua ); + pannello1.add( selezionaLingua ); + pannello2 = new JPanel( new FlowLayout() ); + pannello2.add( ok ); + pannello2.add( annulla ); + add( pannello1, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.1/0.1 Beta 2/src/Pannello.java b/JBriscola/all_versions/0.1/0.1 Beta 2/src/Pannello.java @@ -0,0 +1,53 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 ); + } +} + diff --git a/JBriscola/all_versions/0.1/0.1.1/src/Frame.java b/JBriscola/all_versions/0.1/0.1.1/src/Frame.java @@ -0,0 +1,186 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, opzioni, esci, informazioni; + 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 " + main.version ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) { + String titolo = main.stringaVinto; + if ( main.punteggio < main.punteggioCPU ) + titolo = main.stringaPerso; + if ( main.punteggio == main.punteggioCPU ) + titolo = main.stringaPareggio; + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 150 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + puntoInterrogativo = new JMenu( "?" ); + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + puntoInterrogativo.add( informazioni ); + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + setJMenuBar( barraMenu ); + 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(); + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + 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.1/src/Main.java b/JBriscola/all_versions/0.1/0.1.1/src/Main.java @@ -0,0 +1,708 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static Frame frame; + public static String version = "0.1.1"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua.\nAlcune parti saranno comunque tradotte prima."; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static void main( String args[] ) { + settaOpzioni(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + + frame.setVisible( true ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( frame.giocata[0] == null ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscolaAlta() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + return true; + } + public static void settaOpzioni() { + String lang; + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { + lang = "it"; + } + lang = scanner.next(); + } + else { + lang = "it"; + } + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua\nAlcune parti saranno comunque tradotte prima."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaNecessarioRiavviare = "JBRISCOLAM RVRSVS INCIPERE NECESSE EST\nSI LINGVA PRAELATIONES NOVATAE SVNT.\nALIQVAE ANTE ID VERSA ERVNT"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + } + if ( lang.equals( "bl" ) ) { + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaNecessarioRiavviare = "Se te ha cambia' la lengua te toca\nstusar su e impizar de novo al dugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + } + if ( lang.equals( "bv" ) ) { + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaNecessarioRiavviare = "Se ti ga cambia' la lengua te toca\nstusar su e impizar de novo al zugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + } + } +} diff --git a/JBriscola/all_versions/0.1/0.1.1/src/OptionFrame.java b/JBriscola/all_versions/0.1/0.1.1/src/OptionFrame.java @@ -0,0 +1,87 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla; + public static JLabel lingua; + public static JComboBox selezionaLingua; + public static JPanel pannello1, pannello2; + public OptionFrame() { + super( "JBriscola - " + main.stringaModificaOpzioni ); + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex ); + } + String lang; + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + default: + lang = "it"; + break; + } + formatter.format( lang ); + formatter.close(); + main.settaOpzioni(); + OptionFrame.this.dispose(); + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + } + }); + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + lingua = new JLabel( main.stringaLingua ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + pannello1 = new JPanel( new FlowLayout() ); + pannello1.add( lingua ); + pannello1.add( selezionaLingua ); + pannello2 = new JPanel( new FlowLayout() ); + pannello2.add( ok ); + pannello2.add( annulla ); + add( pannello1, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.1/0.1.1/src/Pannello.java b/JBriscola/all_versions/0.1/0.1.1/src/Pannello.java @@ -0,0 +1,53 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 ); + } +} + diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/1-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/1-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/1-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/1-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/10-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/10-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/10-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/10-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/2-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/2-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/2-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/2-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/3-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/3-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/3-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/3-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/4-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/4-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/4-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/4-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/5-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/5-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/5-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/5-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/6-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/6-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/6-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/6-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/7-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/7-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/7-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/7-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/8-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/8-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/8-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/8-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/9-1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/9-2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/9-3.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/9-4.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/carte.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/retro1.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.1/0.1.1/src/img/retro2.jpg b/JBriscola/all_versions/0.1/0.1.1/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/Frame.java b/JBriscola/all_versions/0.2/0.2 Beta 1/src/Frame.java @@ -0,0 +1,242 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +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 JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, opzioni, esci, informazioni, punti; + 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 " + main.version ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) { + String titolo = ""; + String suonoFinale = ""; + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + if ( main.sound ) { + try { + File suono = new File( ClassLoader.getSystemResource( suonoFinale ).toURI() ); + AudioFileFormat aff = AudioSystem.getAudioFileFormat( suono ); + AudioInputStream ais = AudioSystem.getAudioInputStream( suono ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 150 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + puntoInterrogativo = new JMenu( "?" ); + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + } + } ); + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( informazioni ); + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + setJMenuBar( barraMenu ); + 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(); + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + public boolean mettiCarta( int x, int y ) { + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound ) { + try { + double a = Math.random() * 6; + int i = (int) a; + File suono = new File( ClassLoader.getSystemResource( "sounds/" + i + ".wav" ).toURI() ); + AudioFileFormat aff = AudioSystem.getAudioFileFormat( suono ); + AudioInputStream ais = AudioSystem.getAudioInputStream( suono ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception e ) { + System.err.println( e ); + } + } + 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.2/0.2 Beta 1/src/Main.java b/JBriscola/all_versions/0.2/0.2 Beta 1/src/Main.java @@ -0,0 +1,1068 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean sound = true; + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String version = "0.2 beta 1"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua.\nAlcune parti saranno comunque tradotte prima."; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String lang, soundString; + public static void main( String args[] ) { + settaOpzioni(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + + frame.setVisible( true ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( mano < 16 ) { + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + else if ( mano == 16 ) { + if ( frame.giocata[0] == null ) { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + else { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + } else if ( mano == 17 ) { + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else if ( mano == 18 ) { + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscolaAlta() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + return true; + } + public boolean hoCarico() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + return true; + } + } + } + return false; + } + public boolean hoTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + return true; + } + } + } + return false; + } + public boolean hoBriscolaAlta() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 < 8 ) && (auxCPU[auxCPU.length-7] - 48 != 3 ) + && (auxCPU[auxCPU.length-7] - 48 != 1 ) && (auxCPU[auxCPU.length-7] - 48 != 0 ) ) { + return true; + } + } + } + return false; + } + public static void settaOpzioni() { + lang = "it"; + soundString = "suono=si"; + int r = 0; + int g = 150; + int b = 0; + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + else { + lang = "it"; + soundString = "suono=si"; + r = 0; + g = 150; + b = 0; + } + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua\nAlcune parti saranno comunque tradotte prima."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaNecessarioRiavviare = "JBRISCOLAM RVRSVS INCIPERE NECESSE EST\nSI LINGVA PRAELATIONES NOVATAE SVNT.\nALIQVAE ANTE ID VERSA ERVNT"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONUS"; + stringaPunteggio = "NUMERI"; + stringaSfondo = "COLOR"; + } + if ( lang.equals( "bl" ) ) { + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaNecessarioRiavviare = "Se te ha cambia' la lengua te toca\nstusar su e impizar de novo al dugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + } + if ( lang.equals( "bv" ) ) { + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaNecessarioRiavviare = "Se ti ga cambia' la lengua te toca\nstusar su e impizar de novo al zugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + } + sound = ( soundString.equals( "suono=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/OptionFrame.java b/JBriscola/all_versions/0.2/0.2 Beta 1/src/OptionFrame.java @@ -0,0 +1,129 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono; + public static JPanel[] pannello = new JPanel[5]; + public OptionFrame() { + super( "JBriscola - " + main.stringaModificaOpzioni ); + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex ); + } + String lang; + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + default: + lang = "it"; + break; + } + String suonosiono; + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + main.settaOpzioni(); + OptionFrame.this.dispose(); + //JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + } + }); + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + pannello[0] = new JPanel( new GridLayout( 3, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[4].add( ok ); + pannello[4].add( annulla ); + pannello[3].add( sfondo ); + pannello[3].add( scegliColore ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[4], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/Pannello.java b/JBriscola/all_versions/0.2/0.2 Beta 1/src/Pannello.java @@ -0,0 +1,54 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +public class Pannello extends JPanel { + public static Main main; + public static Color color; + public Pannello() { } + public void paint( Graphics g ) { + super.paint( g ); + setBackground( main.color ); + 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 ); + } +} + diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/carte.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/retro1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/retro2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 1/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/0.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/1.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/2.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/3.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/4.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/5.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/pareggio.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/perso.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/vinto.wav b/JBriscola/all_versions/0.2/0.2 Beta 1/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/Frame.java b/JBriscola/all_versions/0.2/0.2 Beta 2/src/Frame.java @@ -0,0 +1,243 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +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 JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, opzioni, esci, informazioni, punti; + 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 " + main.version ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) { + String titolo = ""; + String suonoFinale = ""; + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 150 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + puntoInterrogativo = new JMenu( "?" ); + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + } + } ); + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( informazioni ); + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + setJMenuBar( barraMenu ); + 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(); + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + public boolean mettiCarta( int x, int y ) { + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 ) || + ( x > 300 && x < 360 && y > 340 && y < 566 ) || + ( x > 370 && x < 430 && y > 340 && y < 566 ) ) ) { + try { + double a = Math.random() * 6; + int i = (int) a; + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception e ) { + System.err.println( e ); + } + } + 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.2/0.2 Beta 2/src/Main.java b/JBriscola/all_versions/0.2/0.2 Beta 2/src/Main.java @@ -0,0 +1,1069 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean sound = true; + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String version = "0.2 Beta 2"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua.\nAlcune parti saranno comunque tradotte prima."; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String lang, soundString; + public static File[] suoni = new File[6]; + public static File suonoVinto, suonoPerso, suonoPareggio; + public static void main( String args[] ) { + settaOpzioni(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( mano < 16 ) { + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + else if ( mano == 16 ) { + if ( frame.giocata[0] == null ) { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + else { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + } else if ( mano == 17 ) { + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else if ( mano == 18 ) { + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscolaAlta() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + return true; + } + public boolean hoCarico() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + return true; + } + } + } + return false; + } + public boolean hoTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + return true; + } + } + } + return false; + } + public boolean hoBriscolaAlta() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 < 8 ) && (auxCPU[auxCPU.length-7] - 48 != 3 ) + && (auxCPU[auxCPU.length-7] - 48 != 1 ) && (auxCPU[auxCPU.length-7] - 48 != 0 ) ) { + return true; + } + } + } + return false; + } + public static void settaOpzioni() { + lang = "it"; + soundString = "suono=si"; + int r = 0; + int g = 150; + int b = 0; + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + else { + lang = "it"; + soundString = "suono=si"; + r = 0; + g = 150; + b = 0; + } + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua\nAlcune parti saranno comunque tradotte prima."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaNecessarioRiavviare = "JBRISCOLAM RVRSVS INCIPERE NECESSE EST\nSI LINGVA PRAELATIONES NOVATAE SVNT.\nALIQVAE ANTE ID VERSA ERVNT"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONUS"; + stringaPunteggio = "NUMERI"; + stringaSfondo = "COLOR"; + } + if ( lang.equals( "bl" ) ) { + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaNecessarioRiavviare = "Se te ha cambia' la lengua te toca\nstusar su e impizar de novo al dugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + } + if ( lang.equals( "bv" ) ) { + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaNecessarioRiavviare = "Se ti ga cambia' la lengua te toca\nstusar su e impizar de novo al zugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + } + sound = ( soundString.equals( "suono=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/OptionFrame.java b/JBriscola/all_versions/0.2/0.2 Beta 2/src/OptionFrame.java @@ -0,0 +1,129 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono; + public static JPanel[] pannello = new JPanel[5]; + public OptionFrame() { + super( "JBriscola - " + main.stringaModificaOpzioni ); + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex ); + } + String lang; + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + default: + lang = "it"; + break; + } + String suonosiono; + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + main.settaOpzioni(); + OptionFrame.this.dispose(); + //JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + } + }); + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + pannello[0] = new JPanel( new GridLayout( 3, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[4].add( ok ); + pannello[4].add( annulla ); + pannello[3].add( sfondo ); + pannello[3].add( scegliColore ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[4], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/Pannello.java b/JBriscola/all_versions/0.2/0.2 Beta 2/src/Pannello.java @@ -0,0 +1,54 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +public class Pannello extends JPanel { + public static Main main; + public static Color color; + public Pannello() { } + public void paint( Graphics g ) { + super.paint( g ); + setBackground( main.color ); + 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 ); + } +} + diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/carte.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/retro1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/retro2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 2/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/0.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/1.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/2.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/3.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/4.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/5.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/pareggio.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/perso.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/vinto.wav b/JBriscola/all_versions/0.2/0.2 Beta 2/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/Frame.java b/JBriscola/all_versions/0.2/0.2 Beta 3/src/Frame.java @@ -0,0 +1,306 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +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 JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, opzioni, esci, informazioni, punti; + 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 " + main.version ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) { + String titolo = ""; + String suonoFinale = ""; + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + button.addKeyListener( new KeyAdapter() { + public void keyReleased( KeyEvent key ) { + switch ( key.getKeyCode() ) { + case KeyEvent.VK_1: + if ( mettiCarta( 231, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_2: + if ( mettiCarta( 301, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_3: + if ( mettiCarta( 371, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_F1: + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.stringaTasti, JOptionPane.INFORMATION_MESSAGE ); + break; + case KeyEvent.VK_F2: + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + case KeyEvent.VK_F3: + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 150 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + break; + case KeyEvent.VK_F4: + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_F5: + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_Q: + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + break; + } + } + }); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 150 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + puntoInterrogativo = new JMenu( "?" ); + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + } + } ); + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( informazioni ); + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + setJMenuBar( barraMenu ); + 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(); + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + public boolean mettiCarta( int x, int y ) { + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) || + ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) || + ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) ) ) { + try { + double a = Math.random() * 6; + int i = (int) a; + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception e ) { + System.err.println( e ); + } + } + 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.2/0.2 Beta 3/src/Main.java b/JBriscola/all_versions/0.2/0.2 Beta 3/src/Main.java @@ -0,0 +1,1080 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean sound = true; + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String version = "0.2 Beta 3"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua.\nAlcune parti saranno comunque tradotte prima."; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String stringaTasti = "Tasti rapidi"; + public static String stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 Nuova partita\nF3 Opzioni\nF4 Visualizza Punteggio\nF5 Informazioni\nq Esci"; + public static String lang, soundString; + public static File[] suoni = new File[6]; + public static File suonoVinto, suonoPerso, suonoPareggio; + public static void main( String args[] ) { + settaOpzioni(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( mano < 16 ) { + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + else if ( mano == 16 ) { + if ( frame.giocata[0] == null ) { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + else { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + } else if ( mano == 17 ) { + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else if ( mano == 18 ) { + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscolaAlta() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + return true; + } + public boolean hoCarico() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + return true; + } + } + } + return false; + } + public boolean hoTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + return true; + } + } + } + return false; + } + public boolean hoBriscolaAlta() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 < 8 ) && (auxCPU[auxCPU.length-7] - 48 != 3 ) + && (auxCPU[auxCPU.length-7] - 48 != 1 ) && (auxCPU[auxCPU.length-7] - 48 != 0 ) ) { + return true; + } + } + } + return false; + } + public static void settaOpzioni() { + lang = "it"; + soundString = "suono=si"; + int r = 0; + int g = 150; + int b = 0; + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + else { + lang = "it"; + soundString = "suono=si"; + r = 0; + g = 150; + b = 0; + } + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua\nAlcune parti saranno comunque tradotte prima."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 Nuova partita\nF3 Opzioni\nF4 Visualizza Punteggio\nF5 Informazioni\nq Esci"; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaNecessarioRiavviare = "JBRISCOLAM RVRSVS INCIPERE NECESSE EST\nSI LINGVA PRAELATIONES NOVATAE SVNT.\nALIQVAE ANTE ID VERSA ERVNT"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONVS"; + stringaPunteggio = "NVMERI"; + stringaSfondo = "COLOR"; + stringaTasti = "TASTI RAPIDI"; + stringaTasti2 = "1 PONE CHARTAM PRIMAM\n2 PONE CHARTAM SECUNDAM\n3 PONE CHARTAM TERTIAM\nF1 HEAC INFORMATIONES\nF2 NOVA LVSO\nF3 OPTIONES\nF4 NVMERI\nF5 INFORMATIONES\nq EXIRE"; + } + if ( lang.equals( "bl" ) ) { + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaNecessarioRiavviare = "Se te ha cambia' la lengua te toca\nstusar su e impizar de novo al dugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaTasti2 = "1 Duga la prima carta\n2 Duga la seconda carta\n3 Duga la terza carta\nF1 Tasti rapidi\nF2 Taca n'altra partida\nF3 Opzioni\nF4 Varda i punti\nF5 Informazioni\nq Stusa su"; + } + if ( lang.equals( "bv" ) ) { + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaNecessarioRiavviare = "Se ti ga cambia' la lengua te toca\nstusar su e impizar de novo al zugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaTasti2 = "1 Zuga la prima carta\n2 Zuga la seconda carta\n3 Zuga la terza carta\nF1 Tasti rapidi\nF2 N'altra partida\nF3 Opzioni\nF4 Varda i punti\nF5 Informazioni\nq Stusa su"; + + } + sound = ( soundString.equals( "suono=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/OptionFrame.java b/JBriscola/all_versions/0.2/0.2 Beta 3/src/OptionFrame.java @@ -0,0 +1,129 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono; + public static JPanel[] pannello = new JPanel[5]; + public OptionFrame() { + super( "JBriscola - " + main.stringaModificaOpzioni ); + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex ); + } + String lang; + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + default: + lang = "it"; + break; + } + String suonosiono; + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + main.settaOpzioni(); + OptionFrame.this.dispose(); + //JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + } + }); + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + pannello[0] = new JPanel( new GridLayout( 3, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[4].add( ok ); + pannello[4].add( annulla ); + pannello[3].add( sfondo ); + pannello[3].add( scegliColore ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[4], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/Pannello.java b/JBriscola/all_versions/0.2/0.2 Beta 3/src/Pannello.java @@ -0,0 +1,54 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +public class Pannello extends JPanel { + public static Main main; + public static Color color; + public Pannello() { } + public void paint( Graphics g ) { + super.paint( g ); + setBackground( main.color ); + 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 ); + } +} + diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-3.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-4.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/carte.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/retro1.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/retro2.jpg b/JBriscola/all_versions/0.2/0.2 Beta 3/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/0.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/1.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/2.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/3.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/4.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/5.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/pareggio.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/perso.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/vinto.wav b/JBriscola/all_versions/0.2/0.2 Beta 3/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/Frame.java b/JBriscola/all_versions/0.2/0.2.1/src/Frame.java @@ -0,0 +1,348 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +import java.net.*; +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 JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, opzioni, esci, informazioni, punti, aggiornamenti, tastiRapidi; + 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 " + main.version ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) { + String titolo = ""; + String suonoFinale = ""; + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + button.addKeyListener( new KeyAdapter() { + public void keyReleased( KeyEvent key ) { + if ( main.keys ) { + switch ( key.getKeyCode() ) { + case KeyEvent.VK_1: + if ( mettiCarta( 231, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_2: + if ( mettiCarta( 301, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_3: + if ( mettiCarta( 371, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_F1: + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + case KeyEvent.VK_F2: + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + case KeyEvent.VK_F3: + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + break; + case KeyEvent.VK_F4: + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_F5: + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_F6: + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + case KeyEvent.VK_Q: + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + break; + } + } + } + } ); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + puntoInterrogativo = new JMenu( "?" ); + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + tastiRapidi = new JMenuItem( main.stringaTasti ); + tastiRapidi.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + } + } ); + aggiornamenti = new JMenuItem( main.stringaAggiornamenti ); + aggiornamenti.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( tastiRapidi ); + puntoInterrogativo.add( informazioni ); + puntoInterrogativo.add( aggiornamenti ); + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + setJMenuBar( barraMenu ); + 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(); + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + public boolean mettiCarta( int x, int y ) { + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) || + ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) || + ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) ) ) { + try { + double a = Math.random() * 6; + int i = (int) a; + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception e ) { + System.err.println( e ); + } + } + if ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) { + giocata[0] = carteInMano[0]; + carteInMano[0] = null; + pannello.repaint(); + return true; + } + if ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) { + giocata[0] = carteInMano[1]; + carteInMano[1] = null; + pannello.repaint(); + return true; + } + if ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) { + giocata[0] = carteInMano[2]; + carteInMano[2] = null; + pannello.repaint(); + return true; + } + } + return false; + } +} + + diff --git a/JBriscola/all_versions/0.2/0.2.1/src/Main.java b/JBriscola/all_versions/0.2/0.2.1/src/Main.java @@ -0,0 +1,1101 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean sound = true; + public static boolean keys = true; + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String version = "0.2.1"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua.\nAlcune parti saranno comunque tradotte prima."; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String stringaTasti = "Tasti rapidi"; + public static String stringaAggiornamenti = "Cerca aggiornamenti"; + public static String stringaAggiornamentiSi = "Aggiornamento disponibile: "; + public static String stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + public static String stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + public static String stringaNoInternet = "Errore: nessuna connessione internet"; + public static String stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + public static String lang, soundString, keysString; + public static File[] suoni = new File[6]; + public static File suonoVinto, suonoPerso, suonoPareggio; + public static void main( String args[] ) { + settaOpzioni(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( mano < 16 ) { + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + else if ( mano == 16 ) { + if ( frame.giocata[0] == null ) { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + else { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + } else if ( mano == 17 ) { + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else if ( mano == 18 ) { + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscolaAlta() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + return true; + } + public boolean hoCarico() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + return true; + } + } + } + return false; + } + public boolean hoTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + return true; + } + } + } + return false; + } + public boolean hoBriscolaAlta() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 < 8 ) && (auxCPU[auxCPU.length-7] - 48 != 3 ) + && (auxCPU[auxCPU.length-7] - 48 != 1 ) && (auxCPU[auxCPU.length-7] - 48 != 0 ) ) { + return true; + } + } + } + return false; + } + public static void settaOpzioni() { + lang = "it"; + soundString = "suono=si"; + keysString = "tasti=si"; + int r = 0; + int g = 150; + int b = 0; + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + keysString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua\nAlcune parti saranno comunque tradotte prima."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Cerca aggiornamenti"; + stringaAggiornamentiSi = "Aggiornamento disponibile: "; + stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Errore: nessuna connessione internet"; + stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaNecessarioRiavviare = "JBRISCOLAM RVRSVS INCIPERE NECESSE EST\nSI LINGVA PRAELATIONES NOVATAE SVNT.\nALIQVAE ANTE ID VERSA ERVNT"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONVS"; + stringaPunteggio = "NVMERI"; + stringaSfondo = "COLOR"; + stringaTasti = "TASTI RAPIDI"; + stringaAggiornamenti = "VERSIONEM RECENTIOREM QVAERERE"; + stringaNoInternet = "ERROR: INTERNETIS CONIVCTIO NON EST"; + stringaAggiornamentiSi = "VERSIO RECENTIOR EST: "; + stringaAggiornamentiNo = "VERSIO RECENTIOR NON EST"; + stringaScarica = "VERSIONEM RECENTIOREM CEPTA ESSE POTEST:\nhttp://porkynator.altervista.org/programmi.html"; + stringaTasti2 = "1 PONE CHARTAM PRIMAM\n2 PONE CHARTAM SECUNDAM\n3 PONE CHARTAM TERTIAM\nF1 HEAC INFORMATIONES\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + if ( lang.equals( "bl" ) ) { + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaNecessarioRiavviare = "Se te ha cambia' la lengua te toca\nstusar su e impizar de novo al dugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe ne' na version pi nova"; + stringaAggiornamentiSi = "Ghe ne' na version pi nova: "; + stringaAggiornamentiNo = "No ghe ne na version pi nova"; + stringaScarica = "Te pol scaricar le version pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no te se su internet"; + stringaTasti2 = "1 Duga la prima carta\n2 Duga la seconda carta\n3 Duga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + if ( lang.equals( "bv" ) ) { + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaNecessarioRiavviare = "Se ti ga cambia' la lengua te toca\nstusar su e impizar de novo al zugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se xe ne' na versione pi nova"; + stringaAggiornamentiSi = "Ghe xe na versione pi nova: "; + stringaAggiornamentiNo = "No ghe xe na versione pi nova"; + stringaScarica = "Te pol scaricar le versione pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no ti xe su internet"; + stringaTasti2 = "1 Zuga la prima carta\n2 Zuga la seconda carta\n3 Zuga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + sound = ( soundString.equals( "suono=si" ) ); + keys = ( keysString.equals( "tasti=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.2/0.2.1/src/OptionFrame.java b/JBriscola/all_versions/0.2/0.2.1/src/OptionFrame.java @@ -0,0 +1,140 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono, tastiRapidi; + public static JPanel[] pannello = new JPanel[6]; + public OptionFrame() { + super( "JBriscola - " + main.stringaModificaOpzioni ); + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + String lang; + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + default: + lang = "it"; + break; + } + String suonosiono, tastisiono; + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + if ( tastiRapidi.isSelected() ) + tastisiono = "tasti=si"; + else + tastisiono = "tasti=no"; + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( tastisiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + main.settaOpzioni(); + OptionFrame.this.dispose(); + //JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + } + }); + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + tastiRapidi = new JCheckBox( main.stringaTasti ); + tastiRapidi.setSelected( main.keys ); + pannello[0] = new JPanel( new GridLayout( 4, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[5] = new JPanel( new FlowLayout() ); + pannello[5].add( ok ); + pannello[5].add( annulla ); + pannello[4].add( sfondo ); + pannello[4].add( scegliColore ); + pannello[3].add( tastiRapidi ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + pannello[0].add( pannello[4] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[5], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.2/0.2.1/src/Pannello.java b/JBriscola/all_versions/0.2/0.2.1/src/Pannello.java @@ -0,0 +1,54 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +public class Pannello extends JPanel { + public static Main main; + public static Color color; + public Pannello() { } + public void paint( Graphics g ) { + super.paint( g ); + setBackground( main.color ); + 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 ); + } +} + diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/1-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/1-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/1-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/1-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/10-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/10-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/10-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/10-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/2-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/2-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/2-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/2-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/3-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/3-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/3-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/3-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/4-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/4-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/4-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/4-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/5-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/5-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/5-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/5-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/6-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/6-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/6-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/6-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/7-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/7-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/7-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/7-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/8-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/8-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/8-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/8-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/9-1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/9-2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/9-3.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/9-4.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/carte.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/retro1.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/img/retro2.jpg b/JBriscola/all_versions/0.2/0.2.1/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/0.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/1.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/2.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/3.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/4.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/5.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/pareggio.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/perso.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.1/src/sounds/vinto.wav b/JBriscola/all_versions/0.2/0.2.1/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/Frame.java b/JBriscola/all_versions/0.2/0.2.2/src/Frame.java @@ -0,0 +1,432 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +import java.net.*; +import java.awt.*; +import java.awt.event.*; + +public class Frame extends JFrame { + + /* Booleana per determinare se disegnare il mazzo di carte o no (se + * è l'ultima mano). */ + public static boolean mazzo; + + public static Main main; + + /* Menu, bottoni, pannelli e componenti vari. */ + public static Pannello pannello; + public static JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, opzioni, esci, informazioni, punti, aggiornamenti, tastiRapidi; + + /* Immagini delle carte. */ + 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 " + main.version ); + + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + + /* Quando viene premuto il bottone per prendere/lasciare le carte, + * valuta innanzitutto se il giocatore ha giocato, e poi a chi + * darle ed eventualmente, se è finita la partita, a caricare + * il suono adatto. */ + public void actionPerformed( ActionEvent e ) { + + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + + try { + main.chiPrende(); + } catch ( Exception ex ) { + /* Avvisa di giocare una carta. */ + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + + if ( main.mano == 16 ) + /* Avvisa che si è arrivati alla quartultima mano. */ + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + + /* Non disegna più la briscola e il mazzo se sono già state + * pescate tutte le carte. */ + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + + /* Mostra il punteggio e carica i suoni se è finita la partita. */ + if ( main.mano == 20 ) { + + String titolo = ""; + String suonoFinale = ""; + + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + button.addKeyListener( new KeyAdapter() { + /* Aggiunge il keyListener per le scorciatoie da tastiera. Dato + * che il bottone prendi/lascia è l'unico componente effettivo + * della finestra, avrà obbligatoriamente il focus ed è necessario + * che sia lui a gestire gli eventi della tastiera. */ + public void keyReleased( KeyEvent key ) { + + if ( main.keys ) { + switch ( key.getKeyCode() ) { + case KeyEvent.VK_1: + if ( mettiCarta( 231, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + + case KeyEvent.VK_2: + if ( mettiCarta( 301, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + + case KeyEvent.VK_3: + if ( mettiCarta( 371, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + + case KeyEvent.VK_F1: + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F2: + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + + case KeyEvent.VK_F3: + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + break; + case KeyEvent.VK_F4: + + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_F5: + + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_F6: + + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + case KeyEvent.VK_Q: + + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + break; + } + } + } + } ); + + barraMenu = new JMenuBar(); + + file = new JMenu( "File" ); + + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + /* Avvia una nuova partita, chiedendo prima conferma se ce n'è + * già una in corso. */ + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + /* Apre una OptionFrame per modificare le opzioni. */ + public void actionPerformed( ActionEvent e ) { + + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + /* Ciede conferma prima di uscire. */ + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + + puntoInterrogativo = new JMenu( "?" ); + + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + /* Visualizza le informazioni. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + + tastiRapidi = new JMenuItem( main.stringaTasti ); + tastiRapidi.addActionListener( new ActionListener() { + /* Visualizza i tasti rapidi. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + /* Visualizza il punteggio. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + } + } ); + + aggiornamenti = new JMenuItem( main.stringaAggiornamenti ); + aggiornamenti.addActionListener( new ActionListener() { + /* Cerca aggiornamenti sul sito http://porkynator.altervista.org, + * confrontando la versione del programma con quella scritta nel + * file jbriscola-latest.is (online). */ + public void actionPerformed( ActionEvent e ) { + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( tastiRapidi ); + puntoInterrogativo.add( informazioni ); + puntoInterrogativo.add( aggiornamenti ); + + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + + setJMenuBar( barraMenu ); + + /* Inizializza le immagini del retro delle carte. */ + retro1 = new ImageIcon( ClassLoader.getSystemResource( "img/retro1.jpg" ) ); + retro2 = new ImageIcon( ClassLoader.getSystemResource( "img/retro2.jpg" ) ); + + /* Inizializza tutte le immagini delle carte scorrendo l'array bidimensionale. */ + 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" ) ); + + /* Mischia le carte. */ + main.mischia(); + + /* Aggiunge i vari componenti. */ + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + + /* Chiama il metodo mettiCarta se l'utente clicca. */ + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + + /* Chiede conferma prima di uscire quando viene chiusa la finestra. */ + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + + /* Se il giocatore ha cliccato su una carta la gioca e riproduce un suono casuale. */ + public boolean mettiCarta( int x, int y ) { + + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) || + ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) || + ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) ) ) { + try { + + double a = Math.random() * 6; + int i = (int) a; + + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + + ol.open(ais); + ol.loop( 0 ); + + } catch ( Exception e ) { + System.err.println( e ); + } + } + + if ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) { + giocata[0] = carteInMano[0]; + carteInMano[0] = null; + pannello.repaint(); + return true; + } + + if ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) { + giocata[0] = carteInMano[1]; + carteInMano[1] = null; + pannello.repaint(); + return true; + } + + if ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) { + giocata[0] = carteInMano[2]; + carteInMano[2] = null; + pannello.repaint(); + return true; + } + } + + return false; + } +} + + diff --git a/JBriscola/all_versions/0.2/0.2.2/src/Main.java b/JBriscola/all_versions/0.2/0.2.2/src/Main.java @@ -0,0 +1,1317 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + + /* semeBriscola serve a determinare quale il seme di briscola (0 coppe, + * 1 bastoni, 2 denari, 3 spade). + * punteggio è il punteggio del giocatore, punteggioCPU quello della CPU + * mano tiene il conto della mano a cui si è arrivati. + * cartaDaPescare è la carta che la CPU deve raccogliere dal mazzo + * cartaDaGiocare (può assumere valore compraso tra 0 e 2) è la carta + * che la cpu deve giocare. */ + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + + /* toccaAllaCPU determina se è il turno del computer o del giocatore, + * CPUHaGiocato se il computer ha già giocato in questo turno e + * haGiocatoPrima se la prima mossa del turno è stata del giocatore + * (true) o della CPU (false). + * sound e keys riguardano le opzioni (souno si o no, tasti rapidi si + * o no) salvate nel file di configurazione. */ + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean sound = true; + public static boolean keys = true; + + /* frame è la finestra principale del gioco, color il colore dello sfondo. + * lang, soundString e keysString servono a leggere le opzioni dal file + * di configurazione. */ + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String lang, soundString, keysString; + + /* Tutte le stringhe che vengono utilizzate durante il gioco sono + * inizializzate qui, per poter essere tradotte in altre lingue. */ + public static String version = "0.2.2"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaEN = "Inglese"; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String stringaTasti = "Tasti rapidi"; + public static String stringaAggiornamenti = "Cerca aggiornamenti"; + public static String stringaAggiornamentiSi = "Aggiornamento disponibile: "; + public static String stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + public static String stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + public static String stringaNoInternet = "Errore: nessuna connessione internet"; + public static String stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + + public static void main( String args[] ) { + + /* Chiama il metodo settaOpzioni per leggere le impostazioni + * dell'utente da un eventuale file di configurazione */ + settaOpzioni(); + + /* Crea la finestra principale del gioco e la posiziona al centro + * dello schermo. */ + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + + /* Algoritmo per mischiare il mazzo: prende due carte a caso e le + * inverte di posto, utilizzando una variabile aux. Ripete il procedimento + * per 391 volte. */ + public void mischia() { + + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + + /* Inizializza l'array di carte mescolate ordinato */ + for ( int i = 0, k = 0; i < 10; i++ ) + for ( int j = 0; j < 4; j++, k++ ) + frame.arrayCarteMescolate[k] = frame.arrayCarte[i][j]; + + /* Mescola le carte utilizzando il metodo sopra citato */ + 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; + } + + /* Imposta il seme della briscola leggendo il nome dell'ultima carta + * utilizzando un array ausiliare */ + char auxChar[] = frame.arrayCarteMescolate[39].toString().toCharArray(); + semeBriscola = auxChar[auxChar.length-5] - 49; + + /* Distribuisce le carte */ + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + + /* Fa giocare la CPU. Questo metodo contiene l'iuntelligenza artificiale + * del gioco. Ho preferito non commentare il corpo del metodo per due + * motivi; il primo è che abbastanza intuitivo: basta sapere che i vari + * metodi vaiLiscio(), vaiTaglio() ecc... tentano di fare ciò che + * ovviamente dice il loro nome, se ci riescono restituiscono true, + * in caso contrario false.*/ + public void giocaCPU() { + + if ( mano < 16 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + else if ( mano == 16 ) { + if ( frame.giocata[0] == null ) { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + else { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + } else if ( mano == 17 ) { + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else if ( mano == 18 ) { + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + + /* Gioca la carta e aggiorna la finestra con il metodo repaint() */ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + + CPUHaGiocato = true; + + if ( frame.giocata[0] == null ) + toccaAllaCPU = false; + } + + /* Determina se ha preso la CPU o il giocatore */ + public void chiPrende() { + char aux[], auxCPU[]; + aux = frame.giocata[0].toString().toCharArray(); + auxCPU = frame.giocata[1].toString().toCharArray(); + + /* Chiama il metodo giocatorePrende( boolean giocatore ) con parametro + * true se ha preso il giocatore, false se ha preso la CPU */ + 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 ) ); + } + + /* Confronta due carte per decidere quale ha più valore di presa. + * Restituisce true se è la prima, false se è la seconda */ + 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; + } + + /* Viene chiamato con parametro true se ha preso il giocatore, false se + * ha preso la CPU */ + public void giocatorePrende( boolean giocatore ) { + if ( giocatore ) { + toccaAllaCPU = CPUHaGiocato = false; + haGiocatoPrima = true; + } + else { + toccaAllaCPU = true; + CPUHaGiocato = haGiocatoPrima = false; + } + daiPunti( giocatore ); + if ( toccaAllaCPU ) + giocaCPU(); + } + + /* Da i punti (true al giocatore, false alla CPU) e fa pescare le carte*/ + 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++; + } + } + + /* Aggiorna la finestra */ + frame.pannello.repaint(); + frame.repaint(); + } + + /* Vari metodi che determinano che tipo di carta ha giocato il giocatore. + * Per farlo leggono il nome dell'immagine dal file. Dato che ogni carta + * a un nome del tipo 1-1.jpg (asso di coppe) o 10-3 (re di denari) e + * così via, è facile riconoscerle. */ + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + + /* I metodi seguenti cercano di andare liscio - dare punti - mettere + * un taglio - ecc... e restituiscono true se hanno avuto successo, + * false altrimenti. */ + public boolean vaiLiscio() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiPunti() { + /* Cerca di dare punti, cercando di darne il meno possibile (meglio + * un fante di re). */ + + char[] auxCPU; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiTaglio() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiBriscolaAlta() { + + char[] auxCPU; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiTre() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiAsso() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiCarico() { + + char[] auxCPU; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiSopra() { + /* Innanzitutto controlla se il giocatore ha giocato (non dovrebbe + * essere possibile, in quanto quando questo metodo viene chiamato + * tale condizione è già stata verificata, ma è sempre meglio un + * controllo in più che uno in meno) e restituisce false in caso + * contrario */ + if ( frame.giocata[0] == null ) + return false; + + /* Tre variabili intere che serviranno a valutare quali delle tre + * carte è meglio giocare, se più di una può andare sopra. */ + int a = -1; + int b = -1; + int c = -1; + + /* Tre booleane che verificano quali delle tre carte possono + * andare sopra. */ + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + + /* E tre array di caratteri ausiliari per leggere il nome delle + * carte, più quello per la carta giocata dal giocatore.*/ + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + + /* Se il giocatore ha giocato un asso, restituisce direttamente false. */ + if ( aux[aux.length-7] - 48 == 1 ) + return false; + + /* Valuta quali delle tre carte possono andare sopra, dopo essersi + * accertato di averle: nelle ultime mani non si hanno tutte le carte + * in mano, e noi non vogliamo una NullPointerException sul più bello + * di una partita, vero?! */ + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + + /* Se nessuna carta può andare sopra, restituisce false. Se una + * sola delle tre può andare sopra la imposta come carta da giocare. */ + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + + /* Se più di una carta può andare sopra, valuta quale è più alta. */ + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + + /* Controlla che la carta con cui sta cercando di andare sopra + * sia una figura o un carico. Non vogliamo mica prendere delle + * scartelle con delle scartelle, giusto?! */ + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + + return true; + } + + /* I metodi seguenti valutano le carte che la CPU ha in mano. */ + public boolean hoCarico() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoAsso() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTre() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + return true; + } + } + } + + return false; + } + public boolean hoBriscolaAlta() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTaglio() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 < 8 ) && (auxCPU[auxCPU.length-7] - 48 != 3 ) + && (auxCPU[auxCPU.length-7] - 48 != 1 ) && (auxCPU[auxCPU.length-7] - 48 != 0 ) ) { + return true; + } + } + } + + return false; + } + + /* Imposta le opzioni dell'utente cercando di leggerle dal file di configurazione. */ + public static void settaOpzioni() { + + /* Impostazioni predefinite. */ + lang = "it"; + soundString = "suono=si"; + keysString = "tasti=si"; + int r = 0; + int g = 150; + int b = 0; + + /* Cerca di leggere il file per impostare le opzioni. */ + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + keysString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + + /* Modifica le opzioni. */ + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Cerca aggiornamenti"; + stringaAggiornamentiSi = "Aggiornamento disponibile: "; + stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Errore: nessuna connessione internet"; + stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaEN = "ANGLICVS"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONVS"; + stringaPunteggio = "NVMERI"; + stringaSfondo = "COLOR"; + stringaTasti = "TASTI RAPIDI"; + stringaAggiornamenti = "VERSIONEM RECENTIOREM QVAERERE"; + stringaNoInternet = "ERROR: INTERNETIS CONIVCTIO NON EST"; + stringaAggiornamentiSi = "VERSIO RECENTIOR EST: "; + stringaAggiornamentiNo = "VERSIO RECENTIOR NON EST"; + stringaScarica = "VERSIONEM RECENTIOREM CEPTA ESSE POTEST:\nhttp://porkynator.altervista.org/programmi.html"; + stringaTasti2 = "1 PONE CHARTAM PRIMAM\n2 PONE CHARTAM SECUNDAM\n3 PONE CHARTAM TERTIAM\nF1 HEAC INFORMATIONES\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + if ( lang.equals( "bl" ) ) { + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe ne' na version pi nova"; + stringaAggiornamentiSi = "Ghe ne' na version pi nova: "; + stringaAggiornamentiNo = "No ghe ne na version pi nova"; + stringaScarica = "Te pol scaricar le version pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no te se su internet"; + stringaTasti2 = "1 Duga la prima carta\n2 Duga la seconda carta\n3 Duga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + if ( lang.equals( "bv" ) ) { + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se xe ne' na versione pi nova"; + stringaAggiornamentiSi = "Ghe xe na versione pi nova: "; + stringaAggiornamentiNo = "No ghe xe na versione pi nova"; + stringaScarica = "Te pol scaricar le versione pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no ti xe su internet"; + stringaTasti2 = "1 Zuga la prima carta\n2 Zuga la seconda carta\n3 Zuga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + if ( lang.equals( "en" ) ) { + stringaBottonePrendi = "Take/leave cards"; + stringaPrimaGioca = "Play your card before!"; + stringaUltime4 = "Last card - keep your eye on the briscola!"; + stringaVinto = "You won!"; + stringaPerso = "You lost"; + stringaPareggio = "Sixty - sixty!"; + stringaGiocatore = "Palyer: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "New Game"; + stringaVuoiDavveroIniziare = "Do you really want to start a new game?"; + stringaVuoiDavveroUscire = "Do you really want to exit?"; + stringaSi = "Yes"; + stringaNo = "No"; + stringaOpzioni = "Options..."; + stringaEsci = "Exit"; + stringaImpossibileConfigurare = "Couldn't write to the configuration file.\nPlease report the bug to: sebastiano@luganega.org\n\nException:\n"; + stringaLingua = "Lang"; + stringaAnnulla = "Cancel"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Belluno dialect"; + stringaBV = "Venice dialect"; + stringaEN = "English"; + stringaModificaOpzioni = "Change options"; + stringaInformazioni = "Information"; + stringaInformazioni2 = "JBriscola is a briscola pc game written in java, meant\nand made by Sebastiano Tronto. The game is protected by the GNU/General public licence version 2 or later.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Sound"; + stringaPunteggio = "Score"; + stringaSfondo = "Background"; + stringaTasti = "Hot keys"; + stringaAggiornamenti = "Check updates"; + stringaAggiornamentiSi = "Update available: "; + stringaAggiornamentiNo = "No updates available"; + stringaScarica = "You can get the latest version from the site\nhttp://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Error: no internet connection"; + stringaTasti2 = "1 Play the first card\n2 Play the second card\n3 Play the third card\nF1 Get this message\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nq " + stringaEsci; + } + sound = ( soundString.equals( "suono=si" ) ); + keys = ( keysString.equals( "tasti=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.2/0.2.2/src/OptionFrame.java b/JBriscola/all_versions/0.2/0.2.2/src/OptionFrame.java @@ -0,0 +1,169 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono, tastiRapidi; + public static JPanel[] pannello = new JPanel[6]; + + public OptionFrame() { + + super( "JBriscola - " + main.stringaModificaOpzioni ); + + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + + /* Quando le modifiche vengono confermate premendo ok, viene scritto + * il file di configurazione (o aggiornato) se possibile, e modificate + * le impostazioni attuali. */ + public void actionPerformed( ActionEvent e ) { + + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + + String lang; + + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + case 4: + lang = "en"; + break; + default: + lang = "it"; + break; + } + + String suonosiono, tastisiono; + + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + if ( tastiRapidi.isSelected() ) + tastisiono = "tasti=si"; + else + tastisiono = "tasti=no"; + + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( tastisiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + + main.settaOpzioni(); + + OptionFrame.this.dispose(); + } + }); + + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + /* Se l'utente annulla viene chiusa la finestra senza fare nulla. */ + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + /* Permette di scegliere il colore dello sfondo. */ + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + + /* Vengono impostati e disegnati i vari componenti. */ + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV, main.stringaEN }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + else if ( main.lang.equals( "en" ) ) + linguaPreselezionata = 4; + + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + tastiRapidi = new JCheckBox( main.stringaTasti ); + tastiRapidi.setSelected( main.keys ); + + pannello[0] = new JPanel( new GridLayout( 4, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[5] = new JPanel( new FlowLayout() ); + pannello[5].add( ok ); + pannello[5].add( annulla ); + pannello[4].add( sfondo ); + pannello[4].add( scegliColore ); + pannello[3].add( tastiRapidi ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + pannello[0].add( pannello[4] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[5], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.2/0.2.2/src/Pannello.java b/JBriscola/all_versions/0.2/0.2.2/src/Pannello.java @@ -0,0 +1,56 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +/* Questa classe dispone semplicemente le carte + * sulla finestra e imposta la sfondo. */ +public class Pannello extends JPanel { + public static Main main; + public static Color color; + public Pannello() { } + public void paint( Graphics g ) { + super.paint( g ); + setBackground( main.color ); + 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 ); + } +} + diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/1-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/1-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/1-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/1-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/10-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/10-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/10-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/10-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/2-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/2-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/2-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/2-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/3-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/3-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/3-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/3-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/4-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/4-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/4-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/4-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/5-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/5-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/5-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/5-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/6-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/6-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/6-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/6-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/7-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/7-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/7-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/7-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/8-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/8-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/8-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/8-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/9-1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/9-2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/9-3.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/9-4.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/carte.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/retro1.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/img/retro2.jpg b/JBriscola/all_versions/0.2/0.2.2/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/0.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/1.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/2.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/3.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/4.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/5.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/pareggio.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/perso.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2.2/src/sounds/vinto.wav b/JBriscola/all_versions/0.2/0.2.2/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/Frame.java b/JBriscola/all_versions/0.2/0.2/src/Frame.java @@ -0,0 +1,308 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +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 JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, opzioni, esci, informazioni, punti; + 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 " + main.version ); + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + try { + main.chiPrende(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + if ( main.mano == 20 ) { + String titolo = ""; + String suonoFinale = ""; + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.PLAIN_MESSAGE ); + } + } + } ); + button.addKeyListener( new KeyAdapter() { + public void keyReleased( KeyEvent key ) { + if ( main.keys ) { + switch ( key.getKeyCode() ) { + case KeyEvent.VK_1: + if ( mettiCarta( 231, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_2: + if ( mettiCarta( 301, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_3: + if ( mettiCarta( 371, 500 ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + break; + case KeyEvent.VK_F1: + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.stringaTasti, JOptionPane.INFORMATION_MESSAGE ); + break; + case KeyEvent.VK_F2: + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + case KeyEvent.VK_F3: + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + break; + case KeyEvent.VK_F4: + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_F5: + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + break; + case KeyEvent.VK_Q: + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + break; + } + } + } + } ); + barraMenu = new JMenuBar(); + file = new JMenu( "File" ); + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + file.add( nuovaPartita ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + puntoInterrogativo = new JMenu( "?" ); + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + "\n" + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.PLAIN_MESSAGE ); + } + } ); + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( informazioni ); + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + setJMenuBar( barraMenu ); + 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(); + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + main.giocaCPU(); + } + } + } + ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + public boolean mettiCarta( int x, int y ) { + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) || + ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) || + ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) ) ) { + try { + double a = Math.random() * 6; + int i = (int) a; + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( + Clip.class, + ais.getFormat(), + ( (int) ais.getFrameLength() * + af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception e ) { + System.err.println( e ); + } + } + 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.2/0.2/src/Main.java b/JBriscola/all_versions/0.2/0.2/src/Main.java @@ -0,0 +1,1077 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean sound = true; + public static boolean keys = true; + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String version = "0.2"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua.\nAlcune parti saranno comunque tradotte prima."; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String stringaTasti = "Tasti rapidi"; + public static String stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 Nuova partita\nF3 Opzioni\nF4 Visualizza Punteggio\nF5 Informazioni\nq Esci"; + public static String lang, soundString, keysString; + public static File[] suoni = new File[6]; + public static File suonoVinto, suonoPerso, suonoPareggio; + public static void main( String args[] ) { + settaOpzioni(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + public void mischia() { + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + ImageIcon aux; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + 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; + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + public void giocaCPU() { + if ( mano < 16 ) { + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + else if ( mano == 16 ) { + if ( frame.giocata[0] == null ) { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + else { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + } else if ( mano == 17 ) { + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else if ( mano == 18 ) { + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + 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(); + } + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + public boolean vaiLiscio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiPunti() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiBriscolaAlta() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiCarico() { + char[] auxCPU; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + return false; + } + public boolean vaiSopra() { + if ( frame.giocata[0] == null ) + return false; + int a = -1; + int b = -1; + int c = -1; + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 1 ) + return false; + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + return true; + } + public boolean hoCarico() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoAsso() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + return true; + } + } + } + return false; + } + public boolean hoTre() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + return true; + } + } + } + return false; + } + public boolean hoBriscolaAlta() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + return true; + } + } + } + return false; + } + public boolean hoTaglio() { + char auxCPU[]; + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 < 8 ) && (auxCPU[auxCPU.length-7] - 48 != 3 ) + && (auxCPU[auxCPU.length-7] - 48 != 1 ) && (auxCPU[auxCPU.length-7] - 48 != 0 ) ) { + return true; + } + } + } + return false; + } + public static void settaOpzioni() { + lang = "it"; + soundString = "suono=si"; + keysString = "tasti=si"; + int r = 0; + int g = 150; + int b = 0; + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + keysString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + if ( lang.equals( "it" ) ) { + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaNecessarioRiavviare = "E' necessario riavviare JBriscola se sono state\nmodificate impostazioni riguardanti la lingua\nAlcune parti saranno comunque tradotte prima."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 Nuova partita\nF3 Opzioni\nF4 Visualizza Punteggio\nF5 Informazioni\nq Esci"; + } + else if ( lang.equals( "la" ) ) { + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaNecessarioRiavviare = "JBRISCOLAM RVRSVS INCIPERE NECESSE EST\nSI LINGVA PRAELATIONES NOVATAE SVNT.\nALIQVAE ANTE ID VERSA ERVNT"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONVS"; + stringaPunteggio = "NVMERI"; + stringaSfondo = "COLOR"; + stringaTasti = "TASTI RAPIDI"; + stringaTasti2 = "1 PONE CHARTAM PRIMAM\n2 PONE CHARTAM SECUNDAM\n3 PONE CHARTAM TERTIAM\nF1 HEAC INFORMATIONES\nF2 NOVA LVSO\nF3 OPTIONES\nF4 NVMERI\nF5 INFORMATIONES\nq EXIRE"; + } + if ( lang.equals( "bl" ) ) { + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaNecessarioRiavviare = "Se te ha cambia' la lengua te toca\nstusar su e impizar de novo al dugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaTasti2 = "1 Duga la prima carta\n2 Duga la seconda carta\n3 Duga la terza carta\nF1 Tasti rapidi\nF2 Taca n'altra partida\nF3 Opzioni\nF4 Varda i punti\nF5 Informazioni\nq Stusa su"; + } + if ( lang.equals( "bv" ) ) { + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaNecessarioRiavviare = "Se ti ga cambia' la lengua te toca\nstusar su e impizar de novo al zugo\nPero' zerte robe le e' belche tradote."; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaTasti2 = "1 Zuga la prima carta\n2 Zuga la seconda carta\n3 Zuga la terza carta\nF1 Tasti rapidi\nF2 N'altra partida\nF3 Opzioni\nF4 Varda i punti\nF5 Informazioni\nq Stusa su"; + + } + sound = ( soundString.equals( "suono=si" ) ); + keys = ( keysString.equals( "tasti=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.2/0.2/src/OptionFrame.java b/JBriscola/all_versions/0.2/0.2/src/OptionFrame.java @@ -0,0 +1,140 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono, tastiRapidi; + public static JPanel[] pannello = new JPanel[6]; + public OptionFrame() { + super( "JBriscola - " + main.stringaModificaOpzioni ); + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex ); + } + String lang; + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + default: + lang = "it"; + break; + } + String suonosiono, tastisiono; + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + if ( tastiRapidi.isSelected() ) + tastisiono = "tasti=si"; + else + tastisiono = "tasti=no"; + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( tastisiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + main.settaOpzioni(); + OptionFrame.this.dispose(); + //JOptionPane.showMessageDialog( OptionFrame.this, main.stringaNecessarioRiavviare, "JBriscola 0.1", JOptionPane.INFORMATION_MESSAGE ); + } + }); + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + tastiRapidi = new JCheckBox( main.stringaTasti ); + tastiRapidi.setSelected( main.keys ); + pannello[0] = new JPanel( new GridLayout( 4, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[5] = new JPanel( new FlowLayout() ); + pannello[5].add( ok ); + pannello[5].add( annulla ); + pannello[4].add( sfondo ); + pannello[4].add( scegliColore ); + pannello[3].add( tastiRapidi ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + pannello[0].add( pannello[4] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[5], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.2/0.2/src/Pannello.java b/JBriscola/all_versions/0.2/0.2/src/Pannello.java @@ -0,0 +1,54 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +public class Pannello extends JPanel { + public static Main main; + public static Color color; + public Pannello() { } + public void paint( Graphics g ) { + super.paint( g ); + setBackground( main.color ); + 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 ); + } +} + diff --git a/JBriscola/all_versions/0.2/0.2/src/img/1-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/1-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/1-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/1-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/10-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/10-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/10-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/10-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/2-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/2-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/2-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/2-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/3-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/3-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/3-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/3-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/4-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/4-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/4-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/4-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/5-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/5-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/5-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/5-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/6-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/6-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/6-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/6-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/7-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/7-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/7-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/7-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/8-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/8-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/8-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/8-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/9-1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/9-2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/9-3.jpg b/JBriscola/all_versions/0.2/0.2/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/9-4.jpg b/JBriscola/all_versions/0.2/0.2/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/carte.jpg b/JBriscola/all_versions/0.2/0.2/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/retro1.jpg b/JBriscola/all_versions/0.2/0.2/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/img/retro2.jpg b/JBriscola/all_versions/0.2/0.2/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/0.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/1.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/2.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/3.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/4.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/5.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/pareggio.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/perso.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.2/0.2/src/sounds/vinto.wav b/JBriscola/all_versions/0.2/0.2/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/Frame.java b/JBriscola/all_versions/0.3/0.3.1/src/Frame.java @@ -0,0 +1,523 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +import java.net.*; +import java.awt.*; +import java.awt.event.*; + +public class Frame extends JFrame { + + /* Booleana per determinare se disegnare il mazzo di carte o no (se + * è l'ultima mano). */ + public static boolean mazzo; + + public static Main main; + + /* Menu, bottoni, pannelli e componenti vari. */ + public static Pannello pannello; + public static JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, nuovaPartitaAiTrenta, opzioni, esci, informazioni, punti, aggiornamenti, trucchi, tastiRapidi, briscola; + + /* Immagini delle carte. */ + 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 " + main.version ); + + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + + /* Quando viene premuto il bottone per prendere/lasciare le carte, + * valuta innanzitutto se il giocatore ha giocato, poi a chi + * darle ed eventualmente, se è finita la partita, a caricare + * il suono adatto. */ + public void actionPerformed( ActionEvent e ) { + + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + + try { + main.chiPrende(); + } catch ( Exception ex ) { + /* Avvisa di giocare una carta. */ + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + + /* Avvisa che si è arrivati alla quartultima mano. */ + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + + /* Non disegna più la briscola e il mazzo se sono già state + * pescate tutte le carte. */ + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + + /* Mostra il punteggio e carica i suoni se è finita la partita. */ + if ( main.mano == 20 || + ( main.aiTrenta && + ( ( main.punteggio >= 30 || main.punteggioCPU >= 30 ) ) ) ) { + + String titolo = ""; + String suonoFinale = ""; + + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.INFORMATION_MESSAGE ); + + main.pulisciTavolo(); + + } + if ( main.toccaAllaCPU ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + } ); + button.addKeyListener( new KeyAdapter() { + /* Aggiunge il keyListener per le scorciatoie da tastiera. Dato + * che il bottone prendi/lascia è l'unico componente effettivo + * della finestra, avrà obbligatoriamente il focus ed è necessario + * che sia lui a gestire gli eventi della tastiera. */ + public void keyReleased( KeyEvent key ) { + + if ( main.keys ) { + switch ( key.getKeyCode() ) { + case KeyEvent.VK_1: + if ( mettiCarta( 231, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_2: + if ( mettiCarta( 301, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_3: + if ( mettiCarta( 371, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_F1: + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F2: + if ( main.mano == 20 ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + + case KeyEvent.VK_F3: + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + break; + + case KeyEvent.VK_F4: + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F5: + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + break; + + case KeyEvent.VK_F6: + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F7: + if ( main.mano == 20 ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + + case KeyEvent.VK_F8: + main.trucco( JOptionPane.showInputDialog( Frame.this, main.stringaInserisciCodice, "JBriscola - " + main.version, JOptionPane.PLAIN_MESSAGE ) ); + break; + + case KeyEvent.VK_Q: + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + break; + } + } + } + } ); + + barraMenu = new JMenuBar(); + + file = new JMenu( "File" ); + + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + /* Avvia una nuova partita, chiedendo prima conferma se ce n'è + * già una in corso. */ + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + + nuovaPartitaAiTrenta = new JMenuItem( main.stringaNuovaPartitaAiTrenta ); + nuovaPartitaAiTrenta.addActionListener( new ActionListener() { + /* Avvia una nuova partita ai 30, chiedendo prima conferma se + * ce n'è già una in corso. */ + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + + trucchi = new JMenuItem( main.stringaTrucchi ); + trucchi.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + /* Esegue il trucco */ + main.trucco( JOptionPane.showInputDialog( Frame.this, main.stringaInserisciCodice, "JBriscola - " + main.version, JOptionPane.PLAIN_MESSAGE ) ); + } + } ); + + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + /* Apre una OptionFrame per modificare le opzioni. */ + public void actionPerformed( ActionEvent e ) { + + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + /* Ciede conferma prima di uscire. */ + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + + file.add( nuovaPartita ); + file.add( nuovaPartitaAiTrenta ); + file.add( trucchi ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + + puntoInterrogativo = new JMenu( "?" ); + + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + /* Visualizza le informazioni. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + + tastiRapidi = new JMenuItem( main.stringaTasti ); + tastiRapidi.addActionListener( new ActionListener() { + /* Visualizza i tasti rapidi. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + briscola = new JMenuItem( main.stringaBriscola ); + briscola.addActionListener( new ActionListener() { + /* Visualizza il seme di briscola corrente. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaBriscola + ": " + main.semi[main.semeBriscola], "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + }); + + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + /* Visualizza il punteggio. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + aggiornamenti = new JMenuItem( main.stringaAggiornamenti ); + aggiornamenti.addActionListener( new ActionListener() { + /* Cerca aggiornamenti sul sito http://porkynator.altervista.org, + * confrontando la versione del programma con quella scritta nel + * file jbriscola-latest.is (online). */ + public void actionPerformed( ActionEvent e ) { + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( briscola ); + puntoInterrogativo.add( tastiRapidi ); + puntoInterrogativo.add( informazioni ); + puntoInterrogativo.add( aggiornamenti ); + + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + + setJMenuBar( barraMenu ); + + /* Inizializza le immagini del retro delle carte. */ + retro1 = new ImageIcon( ClassLoader.getSystemResource( "img/retro1.jpg" ) ); + retro2 = new ImageIcon( ClassLoader.getSystemResource( "img/retro2.jpg" ) ); + + /* Inizializza tutte le immagini delle carte scorrendo l'array bidimensionale. */ + 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" ) ); + + /* Mischia le carte. */ + main.mischia(); + + /* Aggiunge i vari componenti. */ + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + + /* Chiama il metodo mettiCarta se l'utente clicca. */ + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + } + } + ); + + /* Chiede conferma prima di uscire quando viene chiusa la finestra. */ + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + + /* Se il giocatore ha cliccato su una carta la gioca e riproduce un suono casuale. */ + public boolean mettiCarta( int x, int y ) { + + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) || + ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) || + ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) ) ) { + try { + + double a = Math.random() * 6; + int i = (int) a; + + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + + ol.open(ais); + ol.loop( 0 ); + + } catch ( Exception e ) { + System.err.println( e ); + } + } + + if ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) { + giocata[0] = carteInMano[0]; + carteInMano[0] = null; + pannello.repaint(); + return true; + } + + if ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) { + giocata[0] = carteInMano[1]; + carteInMano[1] = null; + pannello.repaint(); + return true; + } + + if ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) { + giocata[0] = carteInMano[2]; + carteInMano[2] = null; + pannello.repaint(); + return true; + } + } + + return false; + } +} + + diff --git a/JBriscola/all_versions/0.3/0.3.1/src/Main.java b/JBriscola/all_versions/0.3/0.3.1/src/Main.java @@ -0,0 +1,1637 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + + /*Costanti per i semi e i valori delle carte*/ + public static final int COPPE = 0; + public static final int BASTONI = 1; + public static final int DENARI = 2; + public static final int SPADE = 3; + public static final int RE = 0; + public static final int ASSO = 1; + public static final int DUE = 2; + public static final int TRE = 3; + public static final int QUATTRO = 4; + public static final int CINQUE = 5; + public static final int SEI = 6; + public static final int SETTE = 7; + public static final int FANTE = 8; + public static final int CAVALLO = 9; + + /* semeBriscola serve a determinare quale il seme di briscola (0 coppe, + * 1 bastoni, 2 denari, 3 spade). + * punteggio è il punteggio del giocatore, punteggioCPU quello della CPU + * mano tiene il conto della mano a cui si è arrivati. + * cartaDaPescare è la carta che la CPU deve raccogliere dal mazzo + * cartaDaGiocare (può assumere valore compraso tra 0 e 2) è la carta + * che la cpu deve giocare. */ + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + + /* toccaAllaCPU determina se è il turno del computer o del giocatore, + * CPUHaGiocato se il computer ha già giocato in questo turno e + * haGiocatoPrima se la prima mossa del turno è stata del giocatore + * (true) o della CPU (false). + * aiTrenta serve per determinare se la partida che si sta giocando è + * normale o ai 30. + * carteScoperte serve se viene attivato il trucco per mostrare le + * carte della CPU. + * sound e keys riguardano le opzioni (souno si o no, tasti rapidi si + * o no) salvate nel file di configurazione. */ + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean aiTrenta = false; + public static boolean carteScoperte = false; + public static boolean sound = true; + public static boolean keys = true; + + /* frame è la finestra principale del gioco, color il colore dello sfondo. + * lang, soundString e keysString servono a leggere le opzioni dal file + * di configurazione. */ + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String lang, soundString, keysString; + + /* Tutte le stringhe che vengono utilizzate durante il gioco sono + * inizializzate qui, per poter essere tradotte in altre lingue. */ + public static String version = "0.3.1"; + public static String semi[] = { "Bastoni", "Coppe", "Denari", "Spade" }; + public static String stringaBriscola = "Briscola"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaNuovaPartitaAiTrenta = "Nuova Partita Ai 30"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaEN = "Inglese"; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String stringaTasti = "Tasti rapidi"; + public static String stringaAggiornamenti = "Cerca aggiornamenti"; + public static String stringaTrucchi = "Trucchi"; + public static String stringaInserisciCodice = "Inserisci il codice:"; + public static String stringaTruccoAttivato = "Trucco attivato!"; + public static String stringaTruccoSbagliato = "Trucco non valido"; + public static String stringaCheCartaVuoi = "E allora che carta vuoi?"; + public static String stringaAggiornamentiSi = "Aggiornamento disponibile: "; + public static String stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + public static String stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + public static String stringaNoInternet = "Errore: nessuna connessione internet"; + public static String stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + + public static void main( String args[] ) { + + /* Chiama il metodo settaOpzioni per leggere le impostazioni + * dell'utente da un eventuale file di configurazione */ + settaOpzioni(); + + /* Crea la finestra principale del gioco e la posiziona al centro + * dello schermo. */ + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + + /* Algoritmo per mischiare il mazzo: prende due carte a caso e le + * inverte di posto, utilizzando una variabile aux. Ripete il procedimento + * per 391 volte. */ + public void mischia() { + + ImageIcon aux; + + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + frame.mazzo = true; + + /* Inizializza l'array di carte mescolate ordinato */ + for ( int i = 0, k = 0; i < 10; i++ ) + for ( int j = 0; j < 4; j++, k++ ) + frame.arrayCarteMescolate[k] = frame.arrayCarte[i][j]; + + /* Mescola le carte utilizzando il metodo sopra citato */ + 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; + } + + /* Imposta il seme della briscola */ + semeBriscola = seme( frame.arrayCarteMescolate[39] ); + + /* Distribuisce le carte */ + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + + /* Viene chiamato a fine partita. */ + public void pulisciTavolo() { + + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + + frame.mazzo = false; + frame.ultimaCarta = null; + for ( int i = 0; i < 3; i++ ) { + frame.carteCPU[i] = null; + frame.carteInMano[i] = null; + } + + frame.pannello.repaint(); + frame.repaint(); + + } + + /* Fa giocare la CPU. Questo metodo contiene l'intelligenza artificiale + * del gioco. Ho preferito non commentare molto il corpo del metodo per + * due motivi; il primo è che abbastanza intuitivo: basta sapere che i + * vari metodi vaiLiscio(), vaiTaglio() ecc... tentano di fare ciò che + * ovviamente dice il loro nome, se ci riescono restituiscono true, + * in caso contrario false.*/ + public void giocaCPU() { + + /* Nelle prime 16 mani ragiona in maniera diversa*/ + if ( mano < 16 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + /* Nella penultima mano (prima di pescare l'ultima carta) */ + else if ( mano == 16 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( valore( frame.ultimaCarta ) == TRE || valore( frame.ultimaCarta ) == ASSO ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( valore( frame.ultimaCarta ) == TRE || valore( frame.ultimaCarta ) == ASSO ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + } else if ( mano == 17 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + + } else if ( mano == 18 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + + /* All'ultima mano è inutile ragionare, dato che ha una sola carta */ + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + + /* Gioca la carta e aggiorna la finestra con il metodo repaint() */ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + + CPUHaGiocato = true; + + if ( frame.giocata[0] == null ) + toccaAllaCPU = false; + } + + /* Fa giocare una partita ai 30. È analogo al metodo precedente, cambia + * solo la tecnica di gioco, quindi non è commentato. */ + public void giocaCPUAiTrenta() { + + if ( punteggio <= 20 ) { + + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + else { + + if ( frame.giocata[0] == null ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTre() ); + else if ( vaiCarico() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + /* Gioca la carta e aggiorna la finestra con il metodo repaint() */ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + + CPUHaGiocato = true; + + if ( frame.giocata[0] == null ) + toccaAllaCPU = false; + } + + /* Determina se ha preso la CPU o il giocatore */ + public void chiPrende() { + + /* Chiama il metodo giocatorePrende( boolean giocatore ) con parametro + * true se ha preso il giocatore, false se ha preso la CPU */ + giocatorePrende( ( (seme( frame.giocata[0] ) == semeBriscola) && (seme( frame.giocata[1] ) != semeBriscola) ) + || ( (seme( frame.giocata[0] ) == seme( frame.giocata[1] )) && laPrimaEPiuAlta( valore( frame.giocata[0] ), valore( frame.giocata[1] )) ) + || ( (seme( frame.giocata[1] ) != semeBriscola) && (seme( frame.giocata[0] ) != seme( frame.giocata[1] )) && haGiocatoPrima ) ); + } + + /* Confronta due carte per decidere quale ha più valore di presa. + * Restituisce true se è la prima, false se è la seconda */ + 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; + } + + /* Viene chiamato con parametro true se ha preso il giocatore, false se + * ha preso la CPU */ + public void giocatorePrende( boolean giocatore ) { + if ( giocatore ) { + toccaAllaCPU = CPUHaGiocato = false; + haGiocatoPrima = true; + } + else { + toccaAllaCPU = true; + CPUHaGiocato = haGiocatoPrima = false; + } + daiPunti( giocatore ); + } + + /* Da i punti (true al giocatore, false alla CPU) e fa pescare le carte*/ + public void daiPunti( boolean giocatore ) { + + int punti = 0; + + switch( valore( frame.giocata[0] ) ) { + 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( valore( frame.giocata[1] ) ) { + 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++; + } + } + + /* Aggiorna la finestra */ + frame.pannello.repaint(); + frame.repaint(); + } + + /* Vari metodi che determinano che tipo di carta ha giocato il giocatore.*/ + public boolean haLisciato() { + return ( (frame.giocata[0] != null) && (seme( frame.giocata[0] ) != semeBriscola) && + (valore( frame.giocata[0] ) != RE ) && (valore( frame.giocata[0] ) != ASSO ) && + (valore( frame.giocata[0] ) != TRE ) && (valore( frame.giocata[0] ) < FANTE ) ); + } + + public boolean haMessoPunti() { + return ( (frame.giocata[0] != null) && (seme( frame.giocata[0] ) != semeBriscola) && + ( (valore( frame.giocata[0] ) == RE ) || (valore( frame.giocata[0] ) == FANTE ) || + (valore( frame.giocata[0] ) == CAVALLO ) ) ); + } + + public boolean haTagliato() { + return ( (frame.giocata[0] != null) && (seme( frame.giocata[0] ) == semeBriscola) && + (valore( frame.giocata[0] ) == RE) && (valore( frame.giocata[0] ) != ASSO) && + (valore( frame.giocata[0] ) == TRE) && (valore( frame.giocata[0] ) <= SETTE) ); + } + + public boolean haMessoBriscolaAlta() { + return ( (frame.giocata[0] != null) && (seme( frame.giocata[0] ) == semeBriscola) && + ( (valore( frame.giocata[0] ) == RE ) || (valore( frame.giocata[0] ) == FANTE ) || + (valore( frame.giocata[0] ) == CAVALLO ) ) ); + } + + public boolean haMessoTre() { + return ( (frame.giocata[0] != null) && (seme( frame.giocata[0] ) == semeBriscola) && + (valore( frame.giocata[0] ) == TRE) ); + } + + public boolean haMessoAsso() { + return ( (frame.giocata[0] != null) && (seme( frame.giocata[0] ) == semeBriscola) && + (valore( frame.giocata[0] ) == ASSO) ); + } + + public boolean haCaricato() { + return ( (frame.giocata[0] != null) && (seme( frame.giocata[0] ) != semeBriscola) && + ( (valore( frame.giocata[0] ) == ASSO) || (valore( frame.giocata[0] ) == TRE) ) ); + } + + /* I metodi seguenti cercano di andare liscio - dare punti - mettere + * un taglio - ecc... e restituiscono true se hanno avuto successo, + * false altrimenti. */ + public boolean vaiLiscio() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiPunti() { + /* Cerca di dare punti, cercando di darne il meno possibile (meglio + * un fante di re). */ + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiTaglio() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( seme( frame.carteCPU[i] ) == semeBriscola && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiBriscolaAlta() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == RE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiTre() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( seme( frame.carteCPU[i] ) == semeBriscola && (valore( frame.carteCPU[i] ) == TRE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiAsso() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( seme( frame.carteCPU[i] ) == semeBriscola && (valore( frame.carteCPU[i] ) == ASSO) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiCarico() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == TRE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == ASSO) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiSopra() { + /* Innanzitutto controlla se il giocatore ha giocato (non dovrebbe + * essere possibile, in quanto quando questo metodo viene chiamato + * tale condizione è già stata verificata, ma è sempre meglio un + * controllo in più che uno in meno) e restituisce false in caso + * contrario */ + if ( frame.giocata[0] == null ) + return false; + + /* Tre variabili intere che serviranno a valutare quali delle tre + * carte è meglio giocare, se più di una può andare sopra. */ + int a = -1; + int b = -1; + int c = -1; + + /* Tre booleane che verificano quali delle tre carte possono + * andare sopra. */ + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + + /* Se il giocatore ha giocato un asso, restituisce direttamente false. */ + if ( valore( frame.giocata[0] ) == ASSO ) + return false; + + /* Valuta quali delle tre carte possono andare sopra, dopo essersi + * accertato di averle: nelle ultime mani non si hanno tutte le carte + * in mano, e noi non vogliamo una NullPointerException sul più bello + * di una partita, vero?! */ + if ( frame.carteCPU[0] != null ) { + a = valore( frame.carteCPU[0] ); + if ( (seme( frame.carteCPU[0] ) == seme( frame.giocata[0] )) && laPrimaEPiuAlta( a, valore( frame.giocata[0] ) ) ) + laPrimaPuoAndareSopra = true; + } + + if ( frame.carteCPU[1] != null ) { + b = valore( frame.carteCPU[1] ); + if ( (seme( frame.carteCPU[1] ) == seme( frame.giocata[0] )) && laPrimaEPiuAlta( b, valore( frame.giocata[0] ) ) ) + laSecondaPuoAndareSopra = true; + } + + if ( frame.carteCPU[2] != null ) { + c = valore( frame.carteCPU[2] ); + if ( (seme( frame.carteCPU[2] ) == seme( frame.giocata[0] )) && laPrimaEPiuAlta( c, valore( frame.giocata[0] ) ) ) + laTerzaPuoAndareSopra = true; + } + + /* Se nessuna carta può andare sopra, restituisce false. Se una + * sola delle tre può andare sopra la imposta come carta da giocare. */ + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + + /* Se più di una carta può andare sopra, valuta quale è più alta. */ + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + + /* Controlla che la carta con cui sta cercando di andare sopra + * sia una figura o un carico. Non vogliamo mica prendere delle + * scartelle con delle scartelle, giusto?! */ + if ( ( valore( frame.carteCPU[cartaDaGiocare] ) != RE ) && ( valore( frame.carteCPU[cartaDaGiocare] ) != ASSO ) && + ( valore( frame.carteCPU[cartaDaGiocare] ) != TRE ) && ( valore( frame.carteCPU[cartaDaGiocare] ) <= SETTE ) ) + return false; + + return true; + } + + /* I metodi seguenti valutano le carte che la CPU ha in mano. */ + public boolean hoCarico() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + ( ( valore( frame.carteCPU[i] ) == ASSO ) || ( valore( frame.carteCPU[i] ) == TRE ) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoAsso() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == ASSO ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTre() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == TRE ) ) { + return true; + } + } + } + + return false; + } + public boolean hoBriscolaAlta() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && + ( (valore( frame.carteCPU[i] ) == RE) || (valore( frame.carteCPU[i] ) == FANTE) || (valore( frame.carteCPU[i] ) == CAVALLO) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTaglio() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && + (valore( frame.carteCPU[i] ) < FANTE ) && (valore( frame.carteCPU[i] ) != TRE ) + && (valore( frame.carteCPU[i] ) != ASSO ) && (valore( frame.carteCPU[i] ) != RE ) ) { + return true; + } + } + } + + return false; + } + + /* Restituisce il seme della carta passata come parametro */ + public static int seme( ImageIcon carta ) { + char aux[] = carta.toString().toCharArray(); + return aux[aux.length-5] - 49; + } + + /* Restituisce il valore della carta */ + public static int valore( ImageIcon carta ) { + char aux[] = carta.toString().toCharArray(); + return aux[aux.length-7] - 48; + } + + /* I vari trucchi del gioco. */ + public static void trucco( String trucco ) { + + byte[] truccoByte = trucco.getBytes(); + char[] truccoChar = new char[ truccoByte.length ]; + for ( int i = 0; i < truccoChar.length; i++ ) + truccoChar[i] = (char)truccoByte[i]; + + String attivato = stringaTruccoSbagliato; + + /* Carta che vuoi dove vuoi. Esempio: x251 sostituisce + * la terza carta (2) con il 6 (5) di coppe (1). */ + if ( truccoChar[0] == 'x' && truccoChar.length == 4 ) { + + attivato = stringaTruccoAttivato; + + String aS = "" + truccoChar[1]; + String xS = "" + truccoChar[2]; + String yS = "" + truccoChar[3]; + + int a, x, y; + + try { + + a = Integer.parseInt( aS ); + x = Integer.parseInt( xS ); + y = Integer.parseInt( yS ); + + frame.carteInMano[a] = frame.arrayCarte[x][y]; + + } catch ( Exception e ) { + attivato = stringaTruccoSbagliato; + } + } + + /* Mostra le carte del computer. */ + if ( trucco.equalsIgnoreCase( "Kill Devil Hill" ) ) { + + attivato = stringaTruccoAttivato; + + carteScoperte = true; + + } + + /* Scambia le carte con il computer. */ + if ( trucco.equalsIgnoreCase( "Darkside of Aquarius" ) ) { + + attivato = stringaTruccoAttivato; + + ImageIcon aux = null; + + for ( int i = 0; i < 3; i++ ) { + + aux = frame.carteInMano[i]; + frame.carteInMano[i] = frame.carteCPU[i]; + frame.carteCPU[i] = aux; + + } + } + + /* Cambia il seme di briscola con uno a caso, senza dire quale. + * L'ultima carta non cambia. È possibile comunque capire + * qual'è la briscola dal menu ?->Briscola*/ + if ( trucco.equalsIgnoreCase( "Change of Heart" ) ) { + + attivato = stringaTruccoAttivato; + + semeBriscola = (int) ( Math.random() * 4 ); + + } + + /* Asso Tre e Re di Briscola tutti in mano (anche in caso di doppioni). */ + if ( trucco.equalsIgnoreCase( "Tears of The Dragon" ) ) { + + attivato = stringaTruccoAttivato; + + frame.carteInMano[0] = frame.arrayCarte[9][semeBriscola]; + frame.carteInMano[1] = frame.arrayCarte[2][semeBriscola]; + frame.carteInMano[2] = frame.arrayCarte[0][semeBriscola]; + + } + + /* Tre assi di briscola. */ + if ( trucco.equalsIgnoreCase( "Navigate The Seas of The Sun" ) ) { + + attivato = stringaTruccoAttivato; + + frame.carteInMano[0] = frame.arrayCarte[0][semeBriscola]; + frame.carteInMano[1] = frame.arrayCarte[0][semeBriscola]; + frame.carteInMano[2] = frame.arrayCarte[0][semeBriscola]; + + } + + /* Fa finire la partita al prossimo piglio. */ + if ( trucco.equalsIgnoreCase( "Omega" ) ) { + + attivato = stringaTruccoAttivato; + + mano = 19; + + } + + JOptionPane.showMessageDialog( frame, attivato, "JBriscola - " + version, JOptionPane.INFORMATION_MESSAGE ); + frame.pannello.repaint(); + frame.repaint(); + + } + + /* Imposta le opzioni dell'utente cercando di leggerle dal file di configurazione. */ + public static void settaOpzioni() { + + /* Impostazioni predefinite. */ + lang = "it"; + soundString = "suono=si"; + keysString = "tasti=si"; + int r = 0; + int g = 150; + int b = 0; + + /* Cerca di leggere il file per impostare le opzioni. */ + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + keysString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + + /* Modifica le opzioni. */ + if ( lang.equals( "it" ) ) { + semi[0] = "Bastoni"; + semi[1] = "Coppe"; + semi[2] = "Denari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaNuovaPartitaAiTrenta = "Nuova Partita Ai 30"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Cerca aggiornamenti"; + stringaTrucchi = "Trucchi"; + stringaInserisciCodice = "Inserisci il codice:"; + stringaTruccoAttivato = "Trucco attivato!"; + stringaTruccoSbagliato = "Trucco non valido"; + stringaCheCartaVuoi = "E allora che carta vuoi?"; + stringaAggiornamentiSi = "Aggiornamento disponibile: "; + stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Errore: nessuna connessione internet"; + stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + else if ( lang.equals( "la" ) ) { + semi[0] = "BACULI"; + semi[1] = "CALICES"; + semi[2] = "DENARII"; + semi[3] = "GLADII"; + stringaBriscola = "BRISCOLA"; + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaNuovaPartitaAiTrenta = "NOVA LVSO XXX"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaEN = "ANGLICVS"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONVS"; + stringaPunteggio = "NVMERI"; + stringaSfondo = "COLOR"; + stringaTasti = "TASTI RAPIDI"; + stringaAggiornamenti = "VERSIONEM RECENTIOREM QVAERERE"; + stringaTrucchi = "CODICES"; + stringaInserisciCodice = "CODICEM INSCRIBE:"; + stringaTruccoAttivato = "CODEX INCIPIVIT!"; + stringaTruccoSbagliato = "ERROR CODICIS"; + stringaCheCartaVuoi = "QUAM CHARTAM VOLIS?"; + stringaNoInternet = "ERROR: INTERNETIS CONIVCTIO NON EST"; + stringaAggiornamentiSi = "VERSIO RECENTIOR EST: "; + stringaAggiornamentiNo = "VERSIO RECENTIOR NON EST"; + stringaScarica = "VERSIONEM RECENTIOREM CEPTA ESSE POTEST:\nhttp://porkynator.altervista.org/programmi.html"; + stringaTasti2 = "1 PONE CHARTAM PRIMAM\n2 PONE CHARTAM SECUNDAM\n3 PONE CHARTAM TERTIAM\nF1 HEAC INFORMATIONES\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "bl" ) ) { + semi[0] = "Bastoi"; + semi[1] = "Coppe"; + semi[2] = "Danari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaNuovaPartitaAiTrenta = "Taca na partida ai 30"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe ne' na version pi nova"; + stringaTrucchi = "Truchi"; + stringaInserisciCodice = "Scrivi al codice:"; + stringaTruccoAttivato = "Truco ativa'!"; + stringaTruccoSbagliato = "Truco sbaia'"; + stringaCheCartaVuoi = "Che carta utu alora?"; + stringaAggiornamentiSi = "Ghe ne' na version pi nova: "; + stringaAggiornamentiNo = "No ghe ne na version pi nova"; + stringaScarica = "Te pol scaricar le version pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no te se su internet"; + stringaTasti2 = "1 Duga la prima carta\n2 Duga la seconda carta\n3 Duga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "bv" ) ) { + semi[0] = "Bastoni"; + semi[1] = "Coppe"; + semi[2] = "Danari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaNuovaPartitaAiTrenta = "Na Partida ai 30"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe xe na versione pi nova"; + stringaTrucchi = "Truchi"; + stringaInserisciCodice = "Scrivi al codice:"; + stringaTruccoAttivato = "Truco ativa'!"; + stringaTruccoSbagliato = "Truco sbaia'"; + stringaCheCartaVuoi = "Che carta utu alora?"; + stringaAggiornamentiSi = "Ghe xe na versione pi nova: "; + stringaAggiornamentiNo = "No ghe xe na versione pi nova"; + stringaScarica = "Te pol scaricar le versione pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no ti xe su internet"; + stringaTasti2 = "1 Zuga la prima carta\n2 Zuga la seconda carta\n3 Zuga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "en" ) ) { + semi[0] = "Sticks"; + semi[1] = "Cups"; + semi[2] = "Golds"; + semi[3] = "Swords"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Take/leave cards"; + stringaPrimaGioca = "Play your card before!"; + stringaUltime4 = "Last card - keep your eye on the briscola!"; + stringaVinto = "You won!"; + stringaPerso = "You lost"; + stringaPareggio = "Sixty - sixty!"; + stringaGiocatore = "Palyer: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "New Game"; + stringaNuovaPartitaAiTrenta = "New Game - 30 Points"; + stringaVuoiDavveroIniziare = "Do you really want to start a new game?"; + stringaVuoiDavveroUscire = "Do you really want to exit?"; + stringaSi = "Yes"; + stringaNo = "No"; + stringaOpzioni = "Options..."; + stringaEsci = "Exit"; + stringaImpossibileConfigurare = "Couldn't write to the configuration file.\nPlease report the bug to: sebastiano@luganega.org\n\nException:\n"; + stringaLingua = "Lang"; + stringaAnnulla = "Cancel"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Belluno dialect"; + stringaBV = "Venice dialect"; + stringaEN = "English"; + stringaModificaOpzioni = "Change options"; + stringaInformazioni = "Information"; + stringaInformazioni2 = "JBriscola is a briscola pc game written in java, meant\nand made by Sebastiano Tronto. The game is protected by the GNU/General public licence version 2 or later.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Sound"; + stringaPunteggio = "Score"; + stringaSfondo = "Background"; + stringaTasti = "Hot keys"; + stringaAggiornamenti = "Check updates"; + stringaTrucchi = "Cheats"; + stringaInserisciCodice = "Insert cheat:"; + stringaTruccoAttivato = "Cheat actived!"; + stringaTruccoSbagliato = "Wrong cheat"; + stringaCheCartaVuoi = "So what card do you want?"; + stringaAggiornamentiSi = "Update available: "; + stringaAggiornamentiNo = "No updates available"; + stringaScarica = "You can get the latest version from the site\nhttp://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Error: no internet connection"; + stringaTasti2 = "1 Play the first card\n2 Play the second card\n3 Play the third card\nF1 Get this message\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + sound = ( soundString.equals( "suono=si" ) ); + keys = ( keysString.equals( "tasti=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.3/0.3.1/src/OptionFrame.java b/JBriscola/all_versions/0.3/0.3.1/src/OptionFrame.java @@ -0,0 +1,169 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono, tastiRapidi; + public static JPanel[] pannello = new JPanel[6]; + + public OptionFrame() { + + super( "JBriscola - " + main.stringaModificaOpzioni ); + + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + + /* Quando le modifiche vengono confermate premendo ok, viene scritto + * il file di configurazione (o aggiornato) se possibile, e modificate + * le impostazioni attuali. */ + public void actionPerformed( ActionEvent e ) { + + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + + String lang; + + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + case 4: + lang = "en"; + break; + default: + lang = "it"; + break; + } + + String suonosiono, tastisiono; + + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + if ( tastiRapidi.isSelected() ) + tastisiono = "tasti=si"; + else + tastisiono = "tasti=no"; + + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( tastisiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + + main.settaOpzioni(); + + OptionFrame.this.dispose(); + } + }); + + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + /* Se l'utente annulla viene chiusa la finestra senza fare nulla. */ + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + /* Permette di scegliere il colore dello sfondo. */ + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + + /* Vengono impostati e disegnati i vari componenti. */ + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV, main.stringaEN }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + else if ( main.lang.equals( "en" ) ) + linguaPreselezionata = 4; + + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + tastiRapidi = new JCheckBox( main.stringaTasti ); + tastiRapidi.setSelected( main.keys ); + + pannello[0] = new JPanel( new GridLayout( 4, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[5] = new JPanel( new FlowLayout() ); + pannello[5].add( ok ); + pannello[5].add( annulla ); + pannello[4].add( sfondo ); + pannello[4].add( scegliColore ); + pannello[3].add( tastiRapidi ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + pannello[0].add( pannello[4] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[5], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.3/0.3.1/src/Pannello.java b/JBriscola/all_versions/0.3/0.3.1/src/Pannello.java @@ -0,0 +1,88 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +/* Questa classe dispone semplicemente le carte + * sulla finestra e imposta la sfondo. */ +public class Pannello extends JPanel { + + public static Main main; + + public static Color color; + + public Pannello() { } + + public void paint( Graphics g ) { + + super.paint( g ); + + setBackground( main.color ); + + 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.carteScoperte ) { + + if ( main.frame.carteCPU[0] != null ) + main.frame.carteCPU[0].paintIcon( this, g, 230, 5 ); + + if ( main.frame.carteCPU[1] != null ) + main.frame.carteCPU[1].paintIcon( this, g, 300, 5 ); + + if ( main.frame.carteCPU[2] != null ) + main.frame.carteCPU[2].paintIcon( this, g, 370, 5 ); + + } else { + + 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 ); + + } +} + diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/1-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/1-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/1-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/1-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/10-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/10-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/10-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/10-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/2-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/2-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/2-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/2-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/3-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/3-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/3-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/3-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/4-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/4-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/4-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/4-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/5-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/5-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/5-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/5-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/6-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/6-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/6-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/6-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/7-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/7-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/7-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/7-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/8-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/8-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/8-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/8-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/9-1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/9-2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/9-3.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/9-4.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/Thumbs.db b/JBriscola/all_versions/0.3/0.3.1/src/img/Thumbs.db Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/carte.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/retro1.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/img/retro2.jpg b/JBriscola/all_versions/0.3/0.3.1/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/0.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/1.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/2.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/3.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/4.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/5.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/pareggio.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/perso.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.1/src/sounds/vinto.wav b/JBriscola/all_versions/0.3/0.3.1/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/CartePassateFrame.java b/JBriscola/all_versions/0.3/0.3.2/src/CartePassateFrame.java @@ -0,0 +1,39 @@ +/* +Copyright 2009-2010 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +public class CartePassateFrame extends JFrame { + + public static Main main = new Main(); + public static PannelloCartePassate pannelloCP = new PannelloCartePassate(); + + CartePassateFrame() { + super( "JBriscola - " + main.stringaCartePassate ); + pannelloCP.repaint(); + add( pannelloCP ); + } + +} + + + diff --git a/JBriscola/all_versions/0.3/0.3.2/src/Frame.java b/JBriscola/all_versions/0.3/0.3.2/src/Frame.java @@ -0,0 +1,552 @@ +/* +Copyright 2009-2010 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +import java.net.*; +import java.awt.*; +import java.awt.event.*; + +public class Frame extends JFrame { + + /* Booleana per determinare se disegnare il mazzo di carte o no (se + * è l'ultima mano). */ + public static boolean mazzo; + + public static Main main; + + /* Menu, bottoni, pannelli e componenti vari. */ + public static Pannello pannello; + public static JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, nuovaPartitaAiTrenta, opzioni, esci, informazioni, punti, cartePassate, aggiornamenti, trucchi, tastiRapidi, briscola; + + /* Immagini delle carte. */ + 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[] arrayCartePassate = new ImageIcon[40]; + public static ImageIcon[][] arrayCarte = new ImageIcon[10][4]; + + public Frame() { + + super( "Tronto's JBriscola " + main.version ); + + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + + /* Quando viene premuto il bottone per prendere/lasciare le carte, + * valuta innanzitutto se il giocatore ha giocato, poi a chi + * darle ed eventualmente, se è finita la partita, a caricare + * il suono adatto. */ + public void actionPerformed( ActionEvent e ) { + + arrayCartePassate[main.mano*2] = giocata[0]; + arrayCartePassate[main.mano*2+1] = giocata[1]; + + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + + try { + main.chiPrende(); + } catch ( Exception ex ) { + /* Avvisa di giocare una carta. */ + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + + /* Avvisa che si è arrivati alla quartultima mano. */ + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + + /* Non disegna più la briscola e il mazzo se sono già state + * pescate tutte le carte. */ + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + + /* Mostra il punteggio e carica i suoni se è finita la partita. */ + if ( main.mano == 20 || + ( main.aiTrenta && + ( ( main.punteggio >= 30 || main.punteggioCPU >= 30 ) ) ) ) { + + String titolo = ""; + String suonoFinale = ""; + + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.INFORMATION_MESSAGE ); + + main.pulisciTavolo(); + + } + if ( main.toccaAllaCPU ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + } ); + button.addKeyListener( new KeyAdapter() { + /* Aggiunge il keyListener per le scorciatoie da tastiera. Dato + * che il bottone prendi/lascia è l'unico componente effettivo + * della finestra, avrà obbligatoriamente il focus ed è necessario + * che sia lui a gestire gli eventi della tastiera. */ + public void keyReleased( KeyEvent key ) { + + if ( main.keys ) { + switch ( key.getKeyCode() ) { + case KeyEvent.VK_1: + if ( mettiCarta( 231, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_2: + if ( mettiCarta( 301, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_3: + if ( mettiCarta( 371, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_F1: + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F2: + if ( main.mano == 20 ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + + case KeyEvent.VK_F3: + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + break; + + case KeyEvent.VK_F4: + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F5: + CartePassateFrame cartePassateFrame = new CartePassateFrame(); + cartePassateFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + cartePassateFrame.setResizable( false ); + cartePassateFrame.setAlwaysOnTop( true ); + cartePassateFrame.setSize( 700, 560 ); + cartePassateFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 700) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 560) / 2); + cartePassateFrame.setVisible( true ); + break; + + case KeyEvent.VK_F6: + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + break; + + case KeyEvent.VK_F7: + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F8: + if ( main.mano == 20 ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + + case KeyEvent.VK_F9: + main.trucco( JOptionPane.showInputDialog( Frame.this, main.stringaInserisciCodice, "JBriscola - " + main.version, JOptionPane.PLAIN_MESSAGE ) ); + break; + + case KeyEvent.VK_Q: + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + break; + } + } + } + } ); + + barraMenu = new JMenuBar(); + + file = new JMenu( "File" ); + + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + /* Avvia una nuova partita, chiedendo prima conferma se ce n'è + * già una in corso. */ + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + + nuovaPartitaAiTrenta = new JMenuItem( main.stringaNuovaPartitaAiTrenta ); + nuovaPartitaAiTrenta.addActionListener( new ActionListener() { + /* Avvia una nuova partita ai 30, chiedendo prima conferma se + * ce n'è già una in corso. */ + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + + trucchi = new JMenuItem( main.stringaTrucchi ); + trucchi.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + /* Esegue il trucco */ + main.trucco( JOptionPane.showInputDialog( Frame.this, main.stringaInserisciCodice, "JBriscola - " + main.version, JOptionPane.PLAIN_MESSAGE ) ); + } + } ); + + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + /* Apre una OptionFrame per modificare le opzioni. */ + public void actionPerformed( ActionEvent e ) { + + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + /* Ciede conferma prima di uscire. */ + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + + file.add( nuovaPartita ); + file.add( nuovaPartitaAiTrenta ); + file.add( trucchi ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + + puntoInterrogativo = new JMenu( "?" ); + + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + /* Visualizza le informazioni. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + + tastiRapidi = new JMenuItem( main.stringaTasti ); + tastiRapidi.addActionListener( new ActionListener() { + /* Visualizza i tasti rapidi. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + briscola = new JMenuItem( main.stringaBriscola ); + briscola.addActionListener( new ActionListener() { + /* Visualizza il seme di briscola corrente. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaBriscola + ": " + main.semi[main.semeBriscola], "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + }); + + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + /* Visualizza il punteggio. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + cartePassate = new JMenuItem( main.stringaCartePassate ); + cartePassate.addActionListener( new ActionListener() { + /*Visualizza le carte passate*/ + public void actionPerformed( ActionEvent e ) { + CartePassateFrame cartePassateFrame = new CartePassateFrame(); + cartePassateFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + cartePassateFrame.setResizable( false ); + cartePassateFrame.setAlwaysOnTop( true ); + cartePassateFrame.setSize( 700, 560 ); + cartePassateFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 700) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 560) / 2); + cartePassateFrame.setVisible( true ); + } + } ); + + aggiornamenti = new JMenuItem( main.stringaAggiornamenti ); + aggiornamenti.addActionListener( new ActionListener() { + /* Cerca aggiornamenti sul sito http://porkynator.altervista.org, + * confrontando la versione del programma con quella scritta nel + * file jbriscola-latest.is (online). */ + public void actionPerformed( ActionEvent e ) { + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( cartePassate ); + puntoInterrogativo.add( briscola ); + puntoInterrogativo.add( tastiRapidi ); + puntoInterrogativo.add( informazioni ); + puntoInterrogativo.add( aggiornamenti ); + + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + + setJMenuBar( barraMenu ); + + /* Inizializza le immagini del retro delle carte. */ + retro1 = new ImageIcon( ClassLoader.getSystemResource( "img/retro1.jpg" ) ); + retro2 = new ImageIcon( ClassLoader.getSystemResource( "img/retro2.jpg" ) ); + + /* Inizializza tutte le immagini delle carte scorrendo l'array bidimensionale. */ + 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" ) ); + + /* Mischia le carte. */ + main.mischia(); + + /* Aggiunge i vari componenti. */ + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + + /* Chiama il metodo mettiCarta se l'utente clicca. */ + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + } + } + ); + + /* Chiede conferma prima di uscire quando viene chiusa la finestra. */ + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + + /* Se il giocatore ha cliccato su una carta la gioca e riproduce un suono casuale. */ + public boolean mettiCarta( int x, int y ) { + + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) || + ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) || + ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) ) ) { + try { + + double a = Math.random() * 6; + int i = (int) a; + + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + + ol.open(ais); + ol.loop( 0 ); + + } catch ( Exception e ) { + System.err.println( e ); + } + } + + if ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) { + giocata[0] = carteInMano[0]; + carteInMano[0] = null; + pannello.repaint(); + return true; + } + + if ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) { + giocata[0] = carteInMano[1]; + carteInMano[1] = null; + pannello.repaint(); + return true; + } + + if ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) { + giocata[0] = carteInMano[2]; + carteInMano[2] = null; + pannello.repaint(); + return true; + } + } + + return false; + } +} + + diff --git a/JBriscola/all_versions/0.3/0.3.2/src/Main.java b/JBriscola/all_versions/0.3/0.3.2/src/Main.java @@ -0,0 +1,2086 @@ +/* +Copyright 2009-2010 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + + /*Costanti per i semi e i valori delle carte*/ + public static final int COPPE = 0; + public static final int BASTONI = 1; + public static final int DENARI = 2; + public static final int SPADE = 3; + public static final int RE = 0; + public static final int ASSO = 1; + public static final int DUE = 2; + public static final int TRE = 3; + public static final int QUATTRO = 4; + public static final int CINQUE = 5; + public static final int SEI = 6; + public static final int SETTE = 7; + public static final int FANTE = 8; + public static final int CAVALLO = 9; + + /* semeBriscola serve a determinare quale il seme di briscola (0 coppe, + * 1 bastoni, 2 denari, 3 spade). + * punteggio è il punteggio del giocatore, punteggioCPU quello della CPU + * mano tiene il conto della mano a cui si è arrivati. + * cartaDaPescare è la carta che la CPU deve raccogliere dal mazzo + * cartaDaGiocare (può assumere valore compraso tra 0 e 2) è la carta + * che la cpu deve giocare. */ + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + + /* toccaAllaCPU determina se è il turno del computer o del giocatore, + * CPUHaGiocato se il computer ha già giocato in questo turno e + * haGiocatoPrima se la prima mossa del turno è stata del giocatore + * (true) o della CPU (false). + * aiTrenta serve per determinare se la partida che si sta giocando è + * normale o ai 30. + * carteScoperte serve se viene attivato il trucco per mostrare le + * carte della CPU. + * sound e keys riguardano le opzioni (souno si o no, tasti rapidi si + * o no) salvate nel file di configurazione. */ + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean aiTrenta = false; + public static boolean carteScoperte = false; + public static boolean sound = true; + public static boolean keys = true; + + /* frame è la finestra principale del gioco, color il colore dello sfondo. + * lang, soundString e keysString servono a leggere le opzioni dal file + * di configurazione. */ + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String lang, soundString, keysString; + + /* Tutte le stringhe che vengono utilizzate durante il gioco sono + * inizializzate qui, per poter essere tradotte in altre lingue. */ + public static String version = "0.3.2"; + public static String semi[] = { "Bastoni", "Coppe", "Denari", "Spade" }; + public static String stringaBriscola = "Briscola"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaNuovaPartitaAiTrenta = "Nuova Partita Ai 30"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaEN = "Inglese"; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaCartePassate = "Carte Passate"; + public static String stringaSfondo = "Sfondo"; + public static String stringaTasti = "Tasti rapidi"; + public static String stringaAggiornamenti = "Cerca aggiornamenti"; + public static String stringaTrucchi = "Trucchi"; + public static String stringaInserisciCodice = "Inserisci il codice:"; + public static String stringaTruccoAttivato = "Trucco attivato!"; + public static String stringaTruccoSbagliato = "Trucco non valido"; + public static String stringaCheCartaVuoi = "E allora che carta vuoi?"; + public static String stringaAggiornamentiSi = "Aggiornamento disponibile: "; + public static String stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + public static String stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + public static String stringaNoInternet = "Errore: nessuna connessione internet"; + public static String stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaCartePassate + "\nF6 " + stringaInformazioni + "\nF7 " + stringaAggiornamenti + "\nF8 " + stringaNuovaPartitaAiTrenta + "\nF9 " + stringaTrucchi + "\nq " + stringaEsci; + + public static void main( String args[] ) { + + /* Chiama il metodo settaOpzioni per leggere le impostazioni + * dell'utente da un eventuale file di configurazione */ + settaOpzioni(); + + /* Crea la finestra principale del gioco e la posiziona al centro + * dello schermo. */ + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + + /* Algoritmo per mischiare il mazzo: prende due carte a caso e le + * inverte di posto, utilizzando una variabile aux. Ripete il procedimento + * per 391 volte. */ + public void mischia() { + + ImageIcon aux; + + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + frame.mazzo = true; + + /* Inizializza l'array di carte mescolate ordinato */ + for ( int i = 0, k = 0; i < 10; i++ ) + for ( int j = 0; j < 4; j++, k++ ) + frame.arrayCarteMescolate[k] = frame.arrayCarte[i][j]; + + /* Mescola le carte utilizzando il metodo sopra citato */ + 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; + } + + /* Imposta il seme della briscola */ + semeBriscola = seme( frame.arrayCarteMescolate[39] ); + + /* Distribuisce le carte */ + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + + /* Viene chiamato a fine partita. */ + public void pulisciTavolo() { + + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + + frame.mazzo = false; + frame.ultimaCarta = null; + for ( int i = 0; i < 3; i++ ) { + frame.carteCPU[i] = null; + frame.carteInMano[i] = null; + } + + for ( int i = 0; i < 40; i++ ) + frame.arrayCartePassate[i] = null; + + frame.pannello.repaint(); + frame.repaint(); + + } + + /* Fa giocare la CPU. Questo metodo contiene l'intelligenza artificiale + * del gioco. Ho preferito non commentare molto il corpo del metodo per + * due motivi; il primo è che abbastanza intuitivo: basta sapere che i + * vari metodi vaiLiscio(), vaiTaglio() ecc... tentano di fare ciò che + * ovviamente dice il loro nome, se ci riescono restituiscono true, + * in caso contrario false.*/ + public void giocaCPU() { + + /* Nelle prime 16 mani ragiona in maniera diversa*/ + if ( mano < 16 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( !haGiocato() ) { + if ( vaiPuntiConCarichiPassati() ); + else if ( vaiLiscioConCarichiPassati() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + /* Nella penultima mano (prima di pescare l'ultima carta) */ + else if ( mano == 16 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( !haGiocato() ) { + if ( valore( frame.ultimaCarta ) == TRE || valore( frame.ultimaCarta ) == ASSO ) { + + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPuntiConCarichiPassati() ); + else if ( vaiLiscioConCarichiPassati() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( valore( frame.ultimaCarta ) == TRE || valore( frame.ultimaCarta ) == ASSO ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + } else if ( mano == 17 ) { + /* AVVISO: nelle ultime 3 mani, la CPU "guarda" le carte al giocatore; + * Questa non è una scorrettezza, ma semplicemente un metodo per sem- + * plificare i passaggi: il computer potrebbe comunque dedurre le carte + * che ha in mano il giocatore controllando le proprie carte e quelle + * che sono già passate. */ + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( !haGiocato() ) { + if ( hoLaBriscolaPiuAltaInGioco() && hoLaSecondaBriscolaPiuAltaInGioco() ) + vaiSecondaBriscolaPiuAltaInGioco(); + else { + if ( vaiLiscioConCarichiPassati() ); + else if ( vaiPuntiConCarichiPassati() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( piuAltaInGioco() == ASSO && luiHaLaBriscolaPiuAltaInGioco() && hoTre() ) + vaiTre(); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( piuAltaInGioco() == ASSO && !luiHaLaSecondaBriscolaPiuAltaInGioco() && hoAsso() ) + vaiAsso(); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + + } else if ( mano == 18 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( !haGiocato() ) { + if ( hoLaBriscolaPiuAltaInGioco() ) + vaiBriscolaPiuAltaInGioco(); + else + if ( hoLaSecondaBriscolaPiuAltaInGioco() ) + vaiNon( secondaPiuAltaInGioco(), semeBriscola ); + else + if ( luiHaTutteBriscole() ) + vaiPrima(); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiLiscioConCarichiPassati() ); + else if ( vaiPuntiConCarichiPassati() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( luiHaLaBriscolaPiuAltaInGioco() && hoLaSecondaBriscolaPiuAltaInGioco() ) + vaiSecondaBriscolaPiuAltaInGioco(); + else if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( luiHaLaBriscolaPiuAltaInGioco() && hoLaSecondaBriscolaPiuAltaInGioco() ) + vaiSecondaBriscolaPiuAltaInGioco(); + else if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( luiHaLaBriscolaPiuAltaInGioco() && hoLaSecondaBriscolaPiuAltaInGioco() ) + vaiSecondaBriscolaPiuAltaInGioco(); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( luiHaLaBriscolaPiuAltaInGioco() && hoLaSecondaBriscolaPiuAltaInGioco() ) + vaiSecondaBriscolaPiuAltaInGioco(); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiSopra() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( luiHaLaBriscolaPiuAltaInGioco() && hoLaSecondaBriscolaPiuAltaInGioco() ) + vaiSecondaBriscolaPiuAltaInGioco(); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + + /* All'ultima mano è inutile ragionare, dato che ha una sola carta */ + } else vaiPrima(); + + /* Gioca la carta e aggiorna la finestra con il metodo repaint() */ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + + CPUHaGiocato = true; + + if ( !haGiocato() ) + toccaAllaCPU = false; + } + + /* Fa giocare una partita ai 30. È analogo al metodo precedente, cambia + * solo la tecnica di gioco, quindi non è commentato. */ + public void giocaCPUAiTrenta() { + + if ( punteggio <= 20 ) { + + if ( !haGiocato() ) { + if ( vaiPuntiConCarichiPassati() ); + else if ( vaiPunti() ); + else if ( vaiLiscioConCarichiPassati() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haTagliato() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + else { + + if ( !haGiocato() ) { + if ( vaiLiscioConCarichiPassati() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiPassati() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haTagliato() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscioConCarichiInGioco() ); + else if ( vaiLiscio() ); + else if ( vaiPuntiConCarichiInGioco() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + /* Gioca la carta e aggiorna la finestra con il metodo repaint() */ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + + CPUHaGiocato = true; + + if ( !haGiocato() ) + toccaAllaCPU = false; + } + + /* Determina se ha preso la CPU o il giocatore*/ + public void chiPrende() { + + /* Chiama il metodo giocatorePrende( boolean giocatore ) con parametro + * true se ha preso il giocatore, false se ha preso la CPU */ + giocatorePrende( ( (seme( frame.giocata[0] ) == semeBriscola) && (seme( frame.giocata[1] ) != semeBriscola) ) + || ( (seme( frame.giocata[0] ) == seme( frame.giocata[1] )) && laPrimaEPiuAlta( valore( frame.giocata[0] ), valore( frame.giocata[1] )) ) + || ( (seme( frame.giocata[1] ) != semeBriscola) && (seme( frame.giocata[0] ) != seme( frame.giocata[1] )) && haGiocatoPrima ) ); + } + + /* Confronta due carte per decidere quale ha più valore di presa. + * Restituisce true se è la prima, false se è la seconda */ + 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; + } + + /* Viene chiamato con parametro true se ha preso il giocatore, false se + * ha preso la CPU */ + public void giocatorePrende( boolean giocatore ) { + if ( giocatore ) { + toccaAllaCPU = CPUHaGiocato = false; + haGiocatoPrima = true; + } + else { + toccaAllaCPU = true; + CPUHaGiocato = haGiocatoPrima = false; + } + daiPunti( giocatore ); + } + + /* Da i punti (true al giocatore, false alla CPU) e fa pescare le carte*/ + public void daiPunti( boolean giocatore ) { + + int punti = 0; + + switch( valore( frame.giocata[0] ) ) { + 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( valore( frame.giocata[1] ) ) { + 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++; + } + } + + /* Aggiorna la finestra */ + frame.pannello.repaint(); + frame.repaint(); + } + + /* Ritorna true se il giocatore ha giocato */ + public boolean haGiocato() { + return frame.giocata[0] != null; + } + + /* Vari metodi che determinano che tipo di carta ha giocato il giocatore.*/ + public boolean haLisciato() { + return ( (haGiocato()) && (seme( frame.giocata[0] ) != semeBriscola) && + (valore( frame.giocata[0] ) != RE ) && (valore( frame.giocata[0] ) != ASSO ) && + (valore( frame.giocata[0] ) != TRE ) && (valore( frame.giocata[0] ) < FANTE ) ); + } + + public boolean haMessoPunti() { + return ( (haGiocato()) && (seme( frame.giocata[0] ) != semeBriscola) && + ( (valore( frame.giocata[0] ) == RE ) || (valore( frame.giocata[0] ) == FANTE ) || + (valore( frame.giocata[0] ) == CAVALLO ) ) ); + } + + public boolean haTagliato() { + return ( (haGiocato()) && (seme( frame.giocata[0] ) == semeBriscola) && + (valore( frame.giocata[0] ) == RE) && (valore( frame.giocata[0] ) != ASSO) && + (valore( frame.giocata[0] ) == TRE) && (valore( frame.giocata[0] ) <= SETTE) ); + } + + public boolean haMessoBriscolaAlta() { + return ( (haGiocato()) && (seme( frame.giocata[0] ) == semeBriscola) && + ( (valore( frame.giocata[0] ) == RE ) || (valore( frame.giocata[0] ) == FANTE ) || + (valore( frame.giocata[0] ) == CAVALLO ) ) ); + } + + public boolean haMessoTre() { + return ( (haGiocato()) && (seme( frame.giocata[0] ) == semeBriscola) && + (valore( frame.giocata[0] ) == TRE) ); + } + + public boolean haMessoAsso() { + return ( (haGiocato()) && (seme( frame.giocata[0] ) == semeBriscola) && + (valore( frame.giocata[0] ) == ASSO) ); + } + + public boolean haCaricato() { + return ( (haGiocato()) && (seme( frame.giocata[0] ) != semeBriscola) && + ( (valore( frame.giocata[0] ) == ASSO) || (valore( frame.giocata[0] ) == TRE) ) ); + } + + /* I metodi seguenti cercano di andare liscio - dare punti - mettere + * un taglio - ecc... e restituiscono true se hanno avuto successo, + * false altrimenti. Le varianti -ConCarichiPassati e -ConCarichiInGioco + * cercano, rispettivamente, di giocare un seme i cui carichi siano già + * passati o ancora in gioco.*/ + public boolean vaiLiscio() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiLiscioConCarichiPassati() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) + && sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) + && ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) + && ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiLiscioConCarichiInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) + && !sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) + && !ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) + && !ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiPunti() { + /* Cerca di dare punti, cercando di darne il meno possibile (meglio + * un fante di re). */ + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiPuntiConCarichiPassati() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) + && sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) + && ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) + && ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) + && sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) + && ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) + && ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) + && sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) + && ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) + && ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiPuntiConCarichiInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) + && !sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) + && !ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE ) + && !ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) + && !sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) + && !ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO ) + && !ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) + && !sonoPassatiICarichi( seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) + && !ePassato( ASSO, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } else if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == RE ) + && !ePassato( TRE, seme( frame.carteCPU[i] ) ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiTaglio() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( seme( frame.carteCPU[i] ) == semeBriscola && + (valore( frame.carteCPU[i] ) != RE) && (valore( frame.carteCPU[i] ) != ASSO) && + (valore( frame.carteCPU[i] ) != TRE) && (valore( frame.carteCPU[i] ) < FANTE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiBriscolaAlta() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == FANTE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == CAVALLO) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == RE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiTre() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( seme( frame.carteCPU[i] ) == semeBriscola && (valore( frame.carteCPU[i] ) == TRE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiAsso() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( seme( frame.carteCPU[i] ) == semeBriscola && (valore( frame.carteCPU[i] ) == ASSO) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiCarico() { + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == ASSO) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && (valore( frame.carteCPU[i] ) == TRE) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + /* Gioca una carta diversa da quella passata come parametro */ + public boolean vaiNon( int valore, int seme ) { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( seme( frame.carteCPU[i] ) != seme && valore( frame.carteCPU[i] ) != valore ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + /* Gioca la prima carta che trova */ + public boolean vaiPrima() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + cartaDaGiocare = i; + return true; + } + } + + return false; + } + + /* Metodi per l'ultima mano */ + public boolean vaiBriscolaPiuAltaInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == piuAltaInGioco()) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiSecondaBriscolaPiuAltaInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == secondaPiuAltaInGioco()) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiSopra() { + /* Innanzitutto controlla se il giocatore ha giocato (non dovrebbe + * essere possibile, in quanto quando questo metodo viene chiamato + * tale condizione è già stata verificata, ma è sempre meglio un + * controllo in più che uno in meno) e restituisce false in caso + * contrario */ + if ( !haGiocato() ) + return false; + + /* Tre variabili intere che serviranno a valutare quali delle tre + * carte è meglio giocare, se più di una può andare sopra. */ + int a = -1; + int b = -1; + int c = -1; + + /* Tre booleane che verificano quali delle tre carte possono + * andare sopra. */ + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + + /* Se il giocatore ha giocato un asso, restituisce direttamente false. */ + if ( valore( frame.giocata[0] ) == ASSO ) + return false; + + /* Valuta quali delle tre carte possono andare sopra, dopo essersi + * accertato di averle: nelle ultime mani non si hanno tutte le carte + * in mano, e noi non vogliamo una NullPointerException sul più bello + * di una partita, vero?! */ + if ( frame.carteCPU[0] != null ) { + a = valore( frame.carteCPU[0] ); + if ( (seme( frame.carteCPU[0] ) == seme( frame.giocata[0] )) && laPrimaEPiuAlta( a, valore( frame.giocata[0] ) ) ) + laPrimaPuoAndareSopra = true; + } + + if ( frame.carteCPU[1] != null ) { + b = valore( frame.carteCPU[1] ); + if ( (seme( frame.carteCPU[1] ) == seme( frame.giocata[0] )) && laPrimaEPiuAlta( b, valore( frame.giocata[0] ) ) ) + laSecondaPuoAndareSopra = true; + } + + if ( frame.carteCPU[2] != null ) { + c = valore( frame.carteCPU[2] ); + if ( (seme( frame.carteCPU[2] ) == seme( frame.giocata[0] )) && laPrimaEPiuAlta( c, valore( frame.giocata[0] ) ) ) + laTerzaPuoAndareSopra = true; + } + + /* Se nessuna carta può andare sopra, restituisce false. Se una + * sola delle tre può andare sopra la imposta come carta da giocare. */ + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + + /* Se più di una carta può andare sopra, valuta quale è più alta. */ + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + + /* Controlla che la carta con cui sta cercando di andare sopra + * sia una figura o un carico. Non vogliamo mica prendere delle + * scartelle con delle scartelle, giusto?! */ + if ( ( valore( frame.carteCPU[cartaDaGiocare] ) != RE ) && ( valore( frame.carteCPU[cartaDaGiocare] ) != ASSO ) && + ( valore( frame.carteCPU[cartaDaGiocare] ) != TRE ) && ( valore( frame.carteCPU[cartaDaGiocare] ) <= SETTE ) ) + return false; + + return true; + } + + /* I metodi seguenti valutano le carte che la CPU ha in mano. */ + public boolean hoCarico() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) != semeBriscola) && + ( ( valore( frame.carteCPU[i] ) == ASSO ) || ( valore( frame.carteCPU[i] ) == TRE ) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoAsso() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == ASSO ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTre() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == TRE ) ) { + return true; + } + } + } + + return false; + } + public boolean hoBriscolaAlta() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && + ( (valore( frame.carteCPU[i] ) == RE) || (valore( frame.carteCPU[i] ) == FANTE) || (valore( frame.carteCPU[i] ) == CAVALLO) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTaglio() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && + (valore( frame.carteCPU[i] ) < FANTE ) && (valore( frame.carteCPU[i] ) != TRE ) + && (valore( frame.carteCPU[i] ) != ASSO ) && (valore( frame.carteCPU[i] ) != RE ) ) { + return true; + } + } + } + + return false; + } + + /* Metodi per l'ultima mano */ + public boolean hoLaBriscolaPiuAltaInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == piuAltaInGioco()) ) + return true; + } + } + + return false; + } + public boolean hoLaSecondaBriscolaPiuAltaInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + if ( (seme( frame.carteCPU[i] ) == semeBriscola) && (valore( frame.carteCPU[i] ) == secondaPiuAltaInGioco()) ) + return true; + } + } + + return false; + } + public boolean luiHaLaBriscolaPiuAltaInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteInMano[i] != null ) { + if ( (seme( frame.carteInMano[i] ) == semeBriscola) && (valore( frame.carteInMano[i] ) == piuAltaInGioco()) ) + return true; + } + } + + return false; + } + public boolean luiHaLaSecondaBriscolaPiuAltaInGioco() { + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteInMano[i] != null ) { + if ( (seme( frame.carteInMano[i] ) == semeBriscola) && (valore( frame.carteInMano[i] ) == secondaPiuAltaInGioco()) ) + return true; + } + } + + return false; + } + public boolean luiHaTutteBriscole() { + if ( frame.carteInMano[0] != null && seme( frame.carteInMano[0] ) != semeBriscola ) return false; + else if ( frame.carteInMano[1] != null && seme( frame.carteInMano[1] ) != semeBriscola ) return false; + else if ( frame.carteInMano[2] != null && seme( frame.carteInMano[2] ) != semeBriscola ) return false; + else return true; + } + + /* Restituisce il seme della carta passata come parametro */ + public static int seme( ImageIcon carta ) { + char aux[] = carta.toString().toCharArray(); + return aux[aux.length-5] - 49; + } + + /* Restituisce il valore della carta */ + public static int valore( ImageIcon carta ) { + char aux[] = carta.toString().toCharArray(); + return aux[aux.length-7] - 48; + } + + /* Controlla se una carta è già passata */ + public static boolean ePassato( int valore, int seme ) { + for ( int i = 0; ; i++ ) { + if ( frame.arrayCartePassate[i] == null ) { + for ( int j = 0; j < 3; j++ ) + if ( frame.carteCPU[j] != null && valore( frame.carteCPU[j] ) == valore && seme( frame.carteCPU[j] ) == seme ) return true; + return false; + } + else if ( valore( frame.arrayCartePassate[i] ) == valore && seme( frame.arrayCartePassate[i] ) == seme ) return true; + } + } + + /* Controlla se sono passati i carichi di un determinato seme */ + public static boolean sonoPassatiICarichi( int seme ) { + return ePassato( TRE, seme ) && ePassato( ASSO, seme ); + } + + /* Restituisce il valore della briscola più alta in gioco*/ + public static int piuAltaInGioco() { + if ( !ePassato( ASSO, semeBriscola ) ) return ASSO; + else if ( !ePassato( TRE, semeBriscola ) ) return TRE; + else if ( !ePassato( RE, semeBriscola ) ) return RE; + else if ( !ePassato( CAVALLO, semeBriscola ) ) return CAVALLO; + else if ( !ePassato( FANTE, semeBriscola ) ) return FANTE; + else if ( !ePassato( SETTE, semeBriscola ) ) return SETTE; + else if ( !ePassato( SEI, semeBriscola ) ) return SEI; + else if ( !ePassato( CINQUE, semeBriscola ) ) return CINQUE; + else if ( !ePassato( QUATTRO, semeBriscola ) ) return QUATTRO; + else if ( !ePassato( DUE, semeBriscola ) ) return DUE; + else return -1; + } + + /* Restituisce il valore della seconda briscola più alta in gioco*/ + public static int secondaPiuAltaInGioco() { + if ( !ePassato( ASSO, semeBriscola ) && piuAltaInGioco() != ASSO ) return ASSO; + else if ( !ePassato( TRE, semeBriscola ) && piuAltaInGioco() != TRE ) return TRE; + else if ( !ePassato( RE, semeBriscola ) && piuAltaInGioco() != RE ) return RE; + else if ( !ePassato( CAVALLO, semeBriscola ) && piuAltaInGioco() != CAVALLO ) return CAVALLO; + else if ( !ePassato( FANTE, semeBriscola ) && piuAltaInGioco() != FANTE ) return FANTE; + else if ( !ePassato( SETTE, semeBriscola ) && piuAltaInGioco() != SETTE ) return SETTE; + else if ( !ePassato( SEI, semeBriscola ) && piuAltaInGioco() != SEI ) return SEI; + else if ( !ePassato( CINQUE, semeBriscola ) && piuAltaInGioco() != CINQUE ) return CINQUE; + else if ( !ePassato( QUATTRO, semeBriscola ) && piuAltaInGioco() != QUATTRO ) return QUATTRO; + else if ( !ePassato( DUE, semeBriscola ) && piuAltaInGioco() != DUE ) return DUE; + else return -1; + } + + /* I vari trucchi del gioco. */ + public static void trucco( String trucco ) { + + byte[] truccoByte = trucco.getBytes(); + char[] truccoChar = new char[ truccoByte.length ]; + for ( int i = 0; i < truccoChar.length; i++ ) + truccoChar[i] = (char)truccoByte[i]; + + String attivato = stringaTruccoSbagliato; + + /* Carta che vuoi dove vuoi. Esempio: x251 sostituisce + * la terza carta (2) con il 6 (5) di coppe (1). */ + if ( truccoChar[0] == 'x' && truccoChar.length == 4 ) { + + attivato = stringaTruccoAttivato; + + String aS = "" + truccoChar[1]; + String xS = "" + truccoChar[2]; + String yS = "" + truccoChar[3]; + + int a, x, y; + + try { + + a = Integer.parseInt( aS ); + x = Integer.parseInt( xS ); + y = Integer.parseInt( yS ); + + frame.carteInMano[a] = frame.arrayCarte[x][y]; + + } catch ( Exception e ) { + attivato = stringaTruccoSbagliato; + } + } + + /* Mostra le carte del computer. */ + if ( trucco.equalsIgnoreCase( "Kill Devil Hill" ) ) { + + attivato = stringaTruccoAttivato; + + carteScoperte = true; + + } + + /* Scambia le carte con il computer. */ + if ( trucco.equalsIgnoreCase( "Darkside of Aquarius" ) ) { + + attivato = stringaTruccoAttivato; + + ImageIcon aux = null; + + for ( int i = 0; i < 3; i++ ) { + + aux = frame.carteInMano[i]; + frame.carteInMano[i] = frame.carteCPU[i]; + frame.carteCPU[i] = aux; + + } + } + + /* Cambia il seme di briscola con uno a caso, senza dire quale. + * L'ultima carta non cambia. È possibile comunque capire + * qual'è la briscola dal menu ?->Briscola*/ + if ( trucco.equalsIgnoreCase( "Change of Heart" ) ) { + + attivato = stringaTruccoAttivato; + + semeBriscola = (int) ( Math.random() * 4 ); + + } + + /* Asso Tre e Re di Briscola tutti in mano (anche in caso di doppioni). */ + if ( trucco.equalsIgnoreCase( "Tears of The Dragon" ) ) { + + attivato = stringaTruccoAttivato; + + frame.carteInMano[0] = frame.arrayCarte[9][semeBriscola]; + frame.carteInMano[1] = frame.arrayCarte[2][semeBriscola]; + frame.carteInMano[2] = frame.arrayCarte[0][semeBriscola]; + + } + + /* Tre assi di briscola. */ + if ( trucco.equalsIgnoreCase( "Navigate The Seas of The Sun" ) ) { + + attivato = stringaTruccoAttivato; + + frame.carteInMano[0] = frame.arrayCarte[0][semeBriscola]; + frame.carteInMano[1] = frame.arrayCarte[0][semeBriscola]; + frame.carteInMano[2] = frame.arrayCarte[0][semeBriscola]; + + } + + /* Fa finire la partita al prossimo piglio. */ + if ( trucco.equalsIgnoreCase( "Omega" ) ) { + + attivato = stringaTruccoAttivato; + + mano = 19; + + } + + JOptionPane.showMessageDialog( frame, attivato, "JBriscola - " + version, JOptionPane.INFORMATION_MESSAGE ); + frame.pannello.repaint(); + frame.repaint(); + + } + + /* Imposta le opzioni dell'utente cercando di leggerle dal file di configurazione. */ + public static void settaOpzioni() { + + /* Impostazioni predefinite. */ + lang = "it"; + soundString = "suono=si"; + keysString = "tasti=si"; + int r = 0; + int g = 150; + int b = 0; + + /* Cerca di leggere il file per impostare le opzioni. */ + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + keysString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + + /* Modifica le opzioni. */ + if ( lang.equals( "it" ) ) { + semi[0] = "Bastoni"; + semi[1] = "Coppe"; + semi[2] = "Denari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaNuovaPartitaAiTrenta = "Nuova Partita Ai 30"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaCartePassate = "Carte Passate"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Cerca aggiornamenti"; + stringaTrucchi = "Trucchi"; + stringaInserisciCodice = "Inserisci il codice:"; + stringaTruccoAttivato = "Trucco attivato!"; + stringaTruccoSbagliato = "Trucco non valido"; + stringaCheCartaVuoi = "E allora che carta vuoi?"; + stringaAggiornamentiSi = "Aggiornamento disponibile: "; + stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Errore: nessuna connessione internet"; + stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaCartePassate + "\nF6 " + stringaInformazioni + "\nF7 " + stringaAggiornamenti + "\nF8 " + stringaNuovaPartitaAiTrenta + "\nF9 " + stringaTrucchi + "\nq " + stringaEsci; + } + else if ( lang.equals( "la" ) ) { + semi[0] = "BACULI"; + semi[1] = "CALICES"; + semi[2] = "DENARII"; + semi[3] = "GLADII"; + stringaBriscola = "BRISCOLA"; + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaNuovaPartitaAiTrenta = "NOVA LVSO XXX"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaEN = "ANGLICVS"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONVS"; + stringaPunteggio = "NVMERI"; + stringaCartePassate = "CHARTAS ITAS"; + stringaSfondo = "COLOR"; + stringaTasti = "TASTI RAPIDI"; + stringaAggiornamenti = "VERSIONEM RECENTIOREM QVAERERE"; + stringaTrucchi = "CODICES"; + stringaInserisciCodice = "CODICEM INSCRIBE:"; + stringaTruccoAttivato = "CODEX INCIPIVIT!"; + stringaTruccoSbagliato = "ERROR CODICIS"; + stringaCheCartaVuoi = "QUAM CHARTAM VOLIS?"; + stringaNoInternet = "ERROR: INTERNETIS CONIVCTIO NON EST"; + stringaAggiornamentiSi = "VERSIO RECENTIOR EST: "; + stringaAggiornamentiNo = "VERSIO RECENTIOR NON EST"; + stringaScarica = "VERSIONEM RECENTIOREM CEPTA ESSE POTEST:\nhttp://porkynator.altervista.org/programmi.html"; + stringaTasti2 = "1 PONE CHARTAM PRIMAM\n2 PONE CHARTAM SECUNDAM\n3 PONE CHARTAM TERTIAM\nF1 HEAC INFORMATIONES\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaCartePassate + "\nF6 " + stringaInformazioni + "\nF7 " + stringaAggiornamenti + "\nF8 " + stringaNuovaPartitaAiTrenta + "\nF9 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "bl" ) ) { + semi[0] = "Bastoi"; + semi[1] = "Coppe"; + semi[2] = "Danari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaNuovaPartitaAiTrenta = "Taca na partida ai 30"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaCartePassate = "Carte pasade"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe ne' na version pi nova"; + stringaTrucchi = "Truchi"; + stringaInserisciCodice = "Scrivi al codice:"; + stringaTruccoAttivato = "Truco ativa'!"; + stringaTruccoSbagliato = "Truco sbaia'"; + stringaCheCartaVuoi = "Che carta utu alora?"; + stringaAggiornamentiSi = "Ghe ne' na version pi nova: "; + stringaAggiornamentiNo = "No ghe ne na version pi nova"; + stringaScarica = "Te pol scaricar le version pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no te se su internet"; + stringaTasti2 = "1 Duga la prima carta\n2 Duga la seconda carta\n3 Duga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaCartePassate + "\nF6 " + stringaInformazioni + "\nF7 " + stringaAggiornamenti + "\nF8 " + stringaNuovaPartitaAiTrenta + "\nF9 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "bv" ) ) { + semi[0] = "Bastoni"; + semi[1] = "Coppe"; + semi[2] = "Danari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaNuovaPartitaAiTrenta = "Na Partida ai 30"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaCartePassate = "Carte pasade"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe xe na versione pi nova"; + stringaTrucchi = "Truchi"; + stringaInserisciCodice = "Scrivi al codice:"; + stringaTruccoAttivato = "Truco ativa'!"; + stringaTruccoSbagliato = "Truco sbaia'"; + stringaCheCartaVuoi = "Che carta utu alora?"; + stringaAggiornamentiSi = "Ghe xe na versione pi nova: "; + stringaAggiornamentiNo = "No ghe xe na versione pi nova"; + stringaScarica = "Te pol scaricar le versione pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no ti xe su internet"; + stringaTasti2 = "1 Zuga la prima carta\n2 Zuga la seconda carta\n3 Zuga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaCartePassate + "\nF6 " + stringaInformazioni + "\nF7 " + stringaAggiornamenti + "\nF8 " + stringaNuovaPartitaAiTrenta + "\nF9 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "en" ) ) { + semi[0] = "Sticks"; + semi[1] = "Cups"; + semi[2] = "Golds"; + semi[3] = "Swords"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Take/leave cards"; + stringaPrimaGioca = "Play your card before!"; + stringaUltime4 = "Last card - keep your eye on the briscola!"; + stringaVinto = "You won!"; + stringaPerso = "You lost"; + stringaPareggio = "Sixty - sixty!"; + stringaGiocatore = "Palyer: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "New Game"; + stringaNuovaPartitaAiTrenta = "New Game - 30 Points"; + stringaVuoiDavveroIniziare = "Do you really want to start a new game?"; + stringaVuoiDavveroUscire = "Do you really want to exit?"; + stringaSi = "Yes"; + stringaNo = "No"; + stringaOpzioni = "Options..."; + stringaEsci = "Exit"; + stringaImpossibileConfigurare = "Couldn't write to the configuration file.\nPlease report the bug to: sebastiano@luganega.org\n\nException:\n"; + stringaLingua = "Lang"; + stringaAnnulla = "Cancel"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Belluno dialect"; + stringaBV = "Venice dialect"; + stringaEN = "English"; + stringaModificaOpzioni = "Change options"; + stringaInformazioni = "Information"; + stringaInformazioni2 = "JBriscola is a briscola pc game written in java, meant\nand made by Sebastiano Tronto. The game is protected by the GNU/General public licence version 2 or later.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Sound"; + stringaPunteggio = "Score"; + stringaCartePassate = "Played cards"; + stringaSfondo = "Background"; + stringaTasti = "Hot keys"; + stringaAggiornamenti = "Check updates"; + stringaTrucchi = "Cheats"; + stringaInserisciCodice = "Insert cheat:"; + stringaTruccoAttivato = "Cheat actived!"; + stringaTruccoSbagliato = "Wrong cheat"; + stringaCheCartaVuoi = "So what card do you want?"; + stringaAggiornamentiSi = "Update available: "; + stringaAggiornamentiNo = "No updates available"; + stringaScarica = "You can get the latest version from the site\nhttp://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Error: no internet connection"; + stringaTasti2 = "1 Play the first card\n2 Play the second card\n3 Play the third card\nF1 Get this message\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaCartePassate + "\nF6 " + stringaInformazioni + "\nF7 " + stringaAggiornamenti + "\nF8 " + stringaNuovaPartitaAiTrenta + "\nF9 " + stringaTrucchi + "\nq " + stringaEsci; + } + sound = ( soundString.equals( "suono=si" ) ); + keys = ( keysString.equals( "tasti=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.3/0.3.2/src/OptionFrame.java b/JBriscola/all_versions/0.3/0.3.2/src/OptionFrame.java @@ -0,0 +1,169 @@ +/* +Copyright 2009-2010 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono, tastiRapidi; + public static JPanel[] pannello = new JPanel[6]; + + public OptionFrame() { + + super( "JBriscola - " + main.stringaModificaOpzioni ); + + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + + /* Quando le modifiche vengono confermate premendo ok, viene scritto + * il file di configurazione (o aggiornato) se possibile, e modificate + * le impostazioni attuali. */ + public void actionPerformed( ActionEvent e ) { + + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + + String lang; + + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + case 4: + lang = "en"; + break; + default: + lang = "it"; + break; + } + + String suonosiono, tastisiono; + + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + if ( tastiRapidi.isSelected() ) + tastisiono = "tasti=si"; + else + tastisiono = "tasti=no"; + + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( tastisiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + + main.settaOpzioni(); + + OptionFrame.this.dispose(); + } + }); + + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + /* Se l'utente annulla viene chiusa la finestra senza fare nulla. */ + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + /* Permette di scegliere il colore dello sfondo. */ + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + + /* Vengono impostati e disegnati i vari componenti. */ + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV, main.stringaEN }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + else if ( main.lang.equals( "en" ) ) + linguaPreselezionata = 4; + + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + tastiRapidi = new JCheckBox( main.stringaTasti ); + tastiRapidi.setSelected( main.keys ); + + pannello[0] = new JPanel( new GridLayout( 4, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[5] = new JPanel( new FlowLayout() ); + pannello[5].add( ok ); + pannello[5].add( annulla ); + pannello[4].add( sfondo ); + pannello[4].add( scegliColore ); + pannello[3].add( tastiRapidi ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + pannello[0].add( pannello[4] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[5], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.3/0.3.2/src/Pannello.java b/JBriscola/all_versions/0.3/0.3.2/src/Pannello.java @@ -0,0 +1,88 @@ +/* +Copyright 2009-2010 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +/* Questa classe dispone semplicemente le carte + * sulla finestra e imposta la sfondo. */ +public class Pannello extends JPanel { + + public static Main main; + + public static Color color; + + public Pannello() { } + + public void paint( Graphics g ) { + + super.paint( g ); + + setBackground( main.color ); + + 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.carteScoperte ) { + + if ( main.frame.carteCPU[0] != null ) + main.frame.carteCPU[0].paintIcon( this, g, 230, 5 ); + + if ( main.frame.carteCPU[1] != null ) + main.frame.carteCPU[1].paintIcon( this, g, 300, 5 ); + + if ( main.frame.carteCPU[2] != null ) + main.frame.carteCPU[2].paintIcon( this, g, 370, 5 ); + + } else { + + 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 ); + + } +} + diff --git a/JBriscola/all_versions/0.3/0.3.2/src/PannelloCartePassate.java b/JBriscola/all_versions/0.3/0.3.2/src/PannelloCartePassate.java @@ -0,0 +1,49 @@ +/* +Copyright 2009-2010 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +public class PannelloCartePassate extends JPanel { + + public static int posto[][] = new int[40][2]; + + public static Main main; + + public PannelloCartePassate() { } + + public void paint( Graphics g ) { + + super.paint( g ); + + for( int i = 0; i < 40; i++ ) { + posto[i][0] = ( i % 10 ) * 70; + posto[i][1] = ( i / 10 ) * 136; + } + + for ( int i = 0; i < main.mano*2; i++ ) + if ( main.frame.arrayCartePassate[i] != null ) + main.frame.arrayCartePassate[i].paintIcon( this, g, posto[i][0], posto[i][1] ); + + + } + +} diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/1-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/1-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/1-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/1-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/10-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/10-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/10-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/10-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/2-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/2-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/2-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/2-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/3-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/3-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/3-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/3-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/4-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/4-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/4-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/4-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/5-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/5-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/5-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/5-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/6-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/6-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/6-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/6-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/7-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/7-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/7-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/7-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/8-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/8-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/8-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/8-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/9-1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/9-2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/9-3.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/9-4.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/Thumbs.db b/JBriscola/all_versions/0.3/0.3.2/src/img/Thumbs.db Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/carte.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/retro1.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3.2/src/img/retro2.jpg b/JBriscola/all_versions/0.3/0.3.2/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/Frame.java b/JBriscola/all_versions/0.3/0.3/src/Frame.java @@ -0,0 +1,523 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 javax.sound.sampled.*; +import java.io.*; +import java.net.*; +import java.awt.*; +import java.awt.event.*; + +public class Frame extends JFrame { + + /* Booleana per determinare se disegnare il mazzo di carte o no (se + * è l'ultima mano). */ + public static boolean mazzo; + + public static Main main; + + /* Menu, bottoni, pannelli e componenti vari. */ + public static Pannello pannello; + public static JPanel pannello2; + public static JButton button; + public static JMenuBar barraMenu; + public static JMenu file, puntoInterrogativo; + public static JMenuItem nuovaPartita, nuovaPartitaAiTrenta, opzioni, esci, informazioni, punti, aggiornamenti, trucchi, tastiRapidi, briscola; + + /* Immagini delle carte. */ + 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 " + main.version ); + + mazzo = true; + main = new Main(); + pannello = new Pannello(); + pannello2 = new JPanel( new FlowLayout() ); + + button = new JButton( main.stringaBottonePrendi ); + button.addActionListener( new ActionListener() { + + /* Quando viene premuto il bottone per prendere/lasciare le carte, + * valuta innanzitutto se il giocatore ha giocato, poi a chi + * darle ed eventualmente, se è finita la partita, a caricare + * il suono adatto. */ + public void actionPerformed( ActionEvent e ) { + + if ( giocata[0] != null && giocata[1] != null ) + main.mano++; + + try { + main.chiPrende(); + } catch ( Exception ex ) { + /* Avvisa di giocare una carta. */ + JOptionPane.showMessageDialog( Frame.this, main.stringaPrimaGioca, "JBriscola " + main.version, JOptionPane.WARNING_MESSAGE ); + } + + /* Avvisa che si è arrivati alla quartultima mano. */ + if ( main.mano == 16 ) + JOptionPane.showMessageDialog( Frame.this, main.stringaUltime4, "JBriscola " + main.version, JOptionPane.INFORMATION_MESSAGE ); + + /* Non disegna più la briscola e il mazzo se sono già state + * pescate tutte le carte. */ + if ( main.mano == 17 ) { + mazzo = false; + ultimaCarta = null; + pannello.repaint(); + Frame.this.repaint(); + } + + /* Mostra il punteggio e carica i suoni se è finita la partita. */ + if ( main.mano == 20 || + ( main.aiTrenta && + ( ( main.punteggio >= 30 || main.punteggioCPU >= 30 ) ) ) ) { + + String titolo = ""; + String suonoFinale = ""; + + if ( main.punteggio > main.punteggioCPU ) { + titolo = main.stringaVinto; + suonoFinale = "sounds/perso.wav"; + } + if ( main.punteggio < main.punteggioCPU ) { + titolo = main.stringaPerso; + suonoFinale = "sounds/vinto.wav"; + } + if ( main.punteggio == main.punteggioCPU ) { + titolo = main.stringaPareggio; + suonoFinale = "sounds/pareggio.wav"; + } + + if ( main.sound ) { + try { + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource( suonoFinale ) ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource( suonoFinale ) ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + ol.open(ais); + ol.loop( 0 ); + } catch ( Exception ex ) { + System.err.println( e ); + } + } + + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, titolo, JOptionPane.INFORMATION_MESSAGE ); + + main.pulisciTavolo(); + + } + if ( main.toccaAllaCPU ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + } ); + button.addKeyListener( new KeyAdapter() { + /* Aggiunge il keyListener per le scorciatoie da tastiera. Dato + * che il bottone prendi/lascia è l'unico componente effettivo + * della finestra, avrà obbligatoriamente il focus ed è necessario + * che sia lui a gestire gli eventi della tastiera. */ + public void keyReleased( KeyEvent key ) { + + if ( main.keys ) { + switch ( key.getKeyCode() ) { + case KeyEvent.VK_1: + if ( mettiCarta( 231, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_2: + if ( mettiCarta( 301, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_3: + if ( mettiCarta( 371, 500 ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + break; + + case KeyEvent.VK_F1: + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F2: + if ( main.mano == 20 ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + + case KeyEvent.VK_F3: + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + break; + + case KeyEvent.VK_F4: + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F5: + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + break; + + case KeyEvent.VK_F6: + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + break; + + case KeyEvent.VK_F7: + if ( main.mano == 20 ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + break; + + case KeyEvent.VK_F8: + main.trucco( JOptionPane.showInputDialog( Frame.this, main.stringaInserisciCodice, "JBriscola - " + main.version, JOptionPane.PLAIN_MESSAGE ) ); + break; + + case KeyEvent.VK_Q: + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + break; + } + } + } + } ); + + barraMenu = new JMenuBar(); + + file = new JMenu( "File" ); + + nuovaPartita = new JMenuItem( main.stringaNuovaPartita ); + nuovaPartita.addActionListener( new ActionListener() { + /* Avvia una nuova partita, chiedendo prima conferma se ce n'è + * già una in corso. */ + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = false; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + + nuovaPartitaAiTrenta = new JMenuItem( main.stringaNuovaPartitaAiTrenta ); + nuovaPartitaAiTrenta.addActionListener( new ActionListener() { + /* Avvia una nuova partita ai 30, chiedendo prima conferma se + * ce n'è già una in corso. */ + public void actionPerformed( ActionEvent e ) { + if ( main.mano == 20 ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + + else { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroIniziare, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.aiTrenta = true; + main.mischia(); + pannello.repaint(); + repaint(); + } + } + } + }); + + trucchi = new JMenuItem( main.stringaTrucchi ); + trucchi.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + /* Esegue il trucco */ + main.trucco( JOptionPane.showInputDialog( Frame.this, main.stringaInserisciCodice, "JBriscola - " + main.version, JOptionPane.PLAIN_MESSAGE ) ); + } + } ); + + opzioni = new JMenuItem( main.stringaOpzioni ); + opzioni.addActionListener( new ActionListener() { + /* Apre una OptionFrame per modificare le opzioni. */ + public void actionPerformed( ActionEvent e ) { + + OptionFrame optionFrame = new OptionFrame(); + optionFrame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + optionFrame.setResizable( false ); + optionFrame.setAlwaysOnTop( true ); + optionFrame.setSize( 300, 200 ); + optionFrame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 300) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 150) / 2); + optionFrame.setVisible( true ); + } + }); + + esci = new JMenuItem( main.stringaEsci ); + esci.addActionListener( new ActionListener() { + /* Ciede conferma prima di uscire. */ + public void actionPerformed( ActionEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + Frame.this.dispose(); + } + }); + + file.add( nuovaPartita ); + file.add( nuovaPartitaAiTrenta ); + file.add( trucchi ); + file.add( opzioni ); + file.addSeparator(); + file.add( esci ); + + puntoInterrogativo = new JMenu( "?" ); + + informazioni = new JMenuItem( main.stringaInformazioni ); + informazioni.addActionListener( new ActionListener() { + /* Visualizza le informazioni. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaInformazioni2, main.stringaInformazioni, JOptionPane.PLAIN_MESSAGE ); + } + } ); + + tastiRapidi = new JMenuItem( main.stringaTasti ); + tastiRapidi.addActionListener( new ActionListener() { + /* Visualizza i tasti rapidi. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaTasti2, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + briscola = new JMenuItem( main.stringaBriscola ); + briscola.addActionListener( new ActionListener() { + /* Visualizza il seme di briscola corrente. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaBriscola + ": " + main.semi[main.semeBriscola], "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + }); + + punti = new JMenuItem( main.stringaPunteggio ); + punti.addActionListener( new ActionListener() { + /* Visualizza il punteggio. */ + public void actionPerformed( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaGiocatore + main.punteggio + main.stringaComputer + main.punteggioCPU, main.stringaPunteggio, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + aggiornamenti = new JMenuItem( main.stringaAggiornamenti ); + aggiornamenti.addActionListener( new ActionListener() { + /* Cerca aggiornamenti sul sito http://porkynator.altervista.org, + * confrontando la versione del programma con quella scritta nel + * file jbriscola-latest.is (online). */ + public void actionPerformed( ActionEvent e ) { + String latest = main.version; + try { + URL latestIs = new URL( "http://porkynator.altervista.org/jbriscola-latest.is" ); + BufferedReader latestIsReader = new BufferedReader( new InputStreamReader( latestIs.openStream() ) ); + latest = latestIsReader.readLine(); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, main.stringaNoInternet, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + if ( latest.equals( main.version ) ) + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiNo, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + else + JOptionPane.showMessageDialog( Frame.this, main.stringaAggiornamentiSi + "\n" + main.version + " ==> " + latest + "\n\n" + main.stringaScarica, "JBriscola - " + main.version, JOptionPane.INFORMATION_MESSAGE ); + } + } ); + + puntoInterrogativo.add( punti ); + puntoInterrogativo.add( briscola ); + puntoInterrogativo.add( tastiRapidi ); + puntoInterrogativo.add( informazioni ); + puntoInterrogativo.add( aggiornamenti ); + + barraMenu.add( file ); + barraMenu.add( puntoInterrogativo ); + + setJMenuBar( barraMenu ); + + /* Inizializza le immagini del retro delle carte. */ + retro1 = new ImageIcon( ClassLoader.getSystemResource( "img/retro1.jpg" ) ); + retro2 = new ImageIcon( ClassLoader.getSystemResource( "img/retro2.jpg" ) ); + + /* Inizializza tutte le immagini delle carte scorrendo l'array bidimensionale. */ + 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" ) ); + + /* Mischia le carte. */ + main.mischia(); + + /* Aggiunge i vari componenti. */ + pannello2.add( button ); + setLayout( new BorderLayout() ); + add( pannello, BorderLayout.CENTER ); + add( pannello2, BorderLayout.SOUTH ); + + /* Chiama il metodo mettiCarta se l'utente clicca. */ + addMouseListener( + new MouseAdapter() { + public void mouseClicked ( MouseEvent e ) { + if ( mettiCarta( e.getX(), e.getY() ) ) { + if ( !main.CPUHaGiocato ) + if ( main.aiTrenta ) + main.giocaCPUAiTrenta(); + else + main.giocaCPU(); + } + } + } + ); + + /* Chiede conferma prima di uscire quando viene chiusa la finestra. */ + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, main.stringaVuoiDavveroUscire, "JBriscola " + main.version, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { main.stringaSi, main.stringaNo }, main.stringaNo ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + + /* Se il giocatore ha cliccato su una carta la gioca e riproduce un suono casuale. */ + public boolean mettiCarta( int x, int y ) { + + if ( !main.toccaAllaCPU && giocata[0] == null ) { + if ( main.sound && + ( ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) || + ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) || + ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) ) ) { + try { + + double a = Math.random() * 6; + int i = (int) a; + + AudioFileFormat aff = AudioSystem.getAudioFileFormat( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioInputStream ais = AudioSystem.getAudioInputStream( ClassLoader.getSystemResource("sounds/" + i + ".wav") ); + AudioFormat af = aff.getFormat(); + DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ( (int) ais.getFrameLength() * af.getFrameSize() ) ); + Clip ol = ( Clip ) AudioSystem.getLine( info ); + + ol.open(ais); + ol.loop( 0 ); + + } catch ( Exception e ) { + System.err.println( e ); + } + } + + if ( x > 230 && x < 290 && y > 340 && y < 566 && carteInMano[0] != null ) { + giocata[0] = carteInMano[0]; + carteInMano[0] = null; + pannello.repaint(); + return true; + } + + if ( x > 300 && x < 360 && y > 340 && y < 566 && carteInMano[1] != null ) { + giocata[0] = carteInMano[1]; + carteInMano[1] = null; + pannello.repaint(); + return true; + } + + if ( x > 370 && x < 430 && y > 340 && y < 566 && carteInMano[2] != null ) { + giocata[0] = carteInMano[2]; + carteInMano[2] = null; + pannello.repaint(); + return true; + } + } + + return false; + } +} + + diff --git a/JBriscola/all_versions/0.3/0.3/src/Main.java b/JBriscola/all_versions/0.3/0.3/src/Main.java @@ -0,0 +1,1702 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.io.*; +import java.util.*; +import javax.swing.*; +import java.awt.*; + +public class Main { + + /* semeBriscola serve a determinare quale il seme di briscola (0 coppe, + * 1 bastoni, 2 denari, 3 spade). + * punteggio è il punteggio del giocatore, punteggioCPU quello della CPU + * mano tiene il conto della mano a cui si è arrivati. + * cartaDaPescare è la carta che la CPU deve raccogliere dal mazzo + * cartaDaGiocare (può assumere valore compraso tra 0 e 2) è la carta + * che la cpu deve giocare. */ + public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare, cartaDaGiocare; + + /* toccaAllaCPU determina se è il turno del computer o del giocatore, + * CPUHaGiocato se il computer ha già giocato in questo turno e + * haGiocatoPrima se la prima mossa del turno è stata del giocatore + * (true) o della CPU (false). + * aiTrenta serve per determinare se la partida che si sta giocando è + * normale o ai 30. + * carteScoperte serve se viene attivato il trucco per mostrare le + * carte della CPU. + * sound e keys riguardano le opzioni (souno si o no, tasti rapidi si + * o no) salvate nel file di configurazione. */ + public static boolean toccaAllaCPU = false; + public static boolean CPUHaGiocato = false; + public static boolean haGiocatoPrima = true; + public static boolean aiTrenta = false; + public static boolean carteScoperte = false; + public static boolean sound = true; + public static boolean keys = true; + + /* frame è la finestra principale del gioco, color il colore dello sfondo. + * lang, soundString e keysString servono a leggere le opzioni dal file + * di configurazione. */ + public static Frame frame; + public static Color color = new Color( 0, 150, 0 ); + public static String lang, soundString, keysString; + + /* Tutte le stringhe che vengono utilizzate durante il gioco sono + * inizializzate qui, per poter essere tradotte in altre lingue. */ + public static String version = "0.3"; + public static String semi[] = { "Bastoni", "Coppe", "Denari", "Spade" }; + public static String stringaBriscola = "Briscola"; + public static String stringaBottonePrendi = "Prendi/Lascia carte"; + public static String stringaPrimaGioca = "Prima Gioca!"; + public static String stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + public static String stringaVinto = "Hai Vinto!"; + public static String stringaPerso = "Hai Perso"; + public static String stringaPareggio = "Pareggio"; + public static String stringaGiocatore = "Giocatore: "; + public static String stringaComputer = "\nComputer: "; + public static String stringaNuovaPartita = "Nuova Partita"; + public static String stringaNuovaPartitaAiTrenta = "Nuova Partita Ai 30"; + public static String stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + public static String stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + public static String stringaSi = "Si"; + public static String stringaNo = "No"; + public static String stringaOpzioni = "Opzioni..."; + public static String stringaEsci = "Esci"; + public static String stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + public static String stringaLingua = "Lingua"; + public static String stringaAnnulla = "Annulla"; + public static String stringaIt = "Italiano"; + public static String stringaLa = "Latino"; + public static String stringaBL = "Dialetto Bellunese"; + public static String stringaBV = "Dialetto Basso Veneto"; + public static String stringaEN = "Inglese"; + public static String stringaModificaOpzioni = "Modifica Opzioni"; + public static String stringaInformazioni = "Informazioni"; + public static String stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + public static String stringaSuono = "Effetti Sonori"; + public static String stringaPunteggio = "Punteggio"; + public static String stringaSfondo = "Sfondo"; + public static String stringaTasti = "Tasti rapidi"; + public static String stringaAggiornamenti = "Cerca aggiornamenti"; + public static String stringaTrucchi = "Trucchi"; + public static String stringaInserisciCodice = "Inserisci il codice:"; + public static String stringaTruccoAttivato = "Trucco attivato!"; + public static String stringaTruccoSbagliato = "Trucco non valido"; + public static String stringaCheCartaVuoi = "E allora che carta vuoi?"; + public static String stringaAggiornamentiSi = "Aggiornamento disponibile: "; + public static String stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + public static String stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + public static String stringaNoInternet = "Errore: nessuna connessione internet"; + public static String stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + + public static void main( String args[] ) { + + /* Chiama il metodo settaOpzioni per leggere le impostazioni + * dell'utente da un eventuale file di configurazione */ + settaOpzioni(); + + /* Crea la finestra principale del gioco e la posiziona al centro + * dello schermo. */ + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setResizable( false ); + frame.setSize( 600, 600 ); + frame.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width - 600) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - 600) / 2); + frame.setVisible( true ); + } + + /* Algoritmo per mischiare il mazzo: prende due carte a caso e le + * inverte di posto, utilizzando una variabile aux. Ripete il procedimento + * per 391 volte. */ + public void mischia() { + + ImageIcon aux; + + mano = 0; + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + frame.mazzo = true; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + frame.mazzo = true; + + /* Inizializza l'array di carte mescolate ordinato */ + for ( int i = 0, k = 0; i < 10; i++ ) + for ( int j = 0; j < 4; j++, k++ ) + frame.arrayCarteMescolate[k] = frame.arrayCarte[i][j]; + + /* Mescola le carte utilizzando il metodo sopra citato */ + 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; + } + + /* Imposta il seme della briscola leggendo il nome dell'ultima carta + * utilizzando un array ausiliare */ + char auxChar[] = frame.arrayCarteMescolate[39].toString().toCharArray(); + semeBriscola = auxChar[auxChar.length-5] - 49; + + /* Distribuisce le carte */ + frame.carteInMano[0] = frame.arrayCarteMescolate[0]; + frame.carteInMano[1] = frame.arrayCarteMescolate[1]; + frame.carteInMano[2] = frame.arrayCarteMescolate[2]; + frame.carteCPU[0] = frame.arrayCarteMescolate[3]; + frame.carteCPU[1] = frame.arrayCarteMescolate[4]; + frame.carteCPU[2] = frame.arrayCarteMescolate[5]; + frame.ultimaCarta = frame.arrayCarteMescolate[39]; + frame.giocata[0] = null; + frame.giocata[1] = null; + } + + /* Viene chiamato a fine partita. */ + public void pulisciTavolo() { + + punteggio = 0; + punteggioCPU = 0; + cartaDaPescare = 6; + toccaAllaCPU = false; + CPUHaGiocato = false; + haGiocatoPrima = true; + + frame.mazzo = false; + frame.ultimaCarta = null; + for ( int i = 0; i < 3; i++ ) { + frame.carteCPU[i] = null; + frame.carteInMano[i] = null; + } + + frame.pannello.repaint(); + frame.repaint(); + + } + + /* Fa giocare la CPU. Questo metodo contiene l'intelligenza artificiale + * del gioco. Ho preferito non commentare molto il corpo del metodo per + * due motivi; il primo è che abbastanza intuitivo: basta sapere che i + * vari metodi vaiLiscio(), vaiTaglio() ecc... tentano di fare ciò che + * ovviamente dice il loro nome, se ci riescono restituiscono true, + * in caso contrario false.*/ + public void giocaCPU() { + + /* Nelle prime 16 mani ragiona in maniera diversa*/ + if ( mano < 16 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + /* Nella penultima mano (prima di pescare l'ultima carta) */ + else if ( mano == 16 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( vaiCarico() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } else { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + char aux[]; + aux = frame.ultimaCarta.toString().toCharArray(); + if ( aux[aux.length-7] - 48 == 3 || aux[aux.length-7] - 48 == 1 ) { + if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } + } else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + } else if ( mano == 17 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( hoAsso() ) { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + + } else if ( mano == 18 ) { + + /* Valuta cosa fare se il giocatore non ha ancora giocato. */ + if ( frame.giocata[0] == null ) { + if ( vaiAsso() ); + else if ( vaiCarico() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiAsso() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + + /* All'ultima mano è inutile ragionare, dato che ha una sola carta */ + } else { + if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + + /* Gioca la carta e aggiorna la finestra con il metodo repaint() */ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + + CPUHaGiocato = true; + + if ( frame.giocata[0] == null ) + toccaAllaCPU = false; + } + + /* Fa giocare una partita ai 30. È analogo al metodo precedente, cambia + * solo la tecnica di gioco, quindi non è commentato. */ + public void giocaCPUAiTrenta() { + + if ( punteggio <= 20 ) { + + if ( frame.giocata[0] == null ) { + if ( vaiPunti() ); + else if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + else if ( vaiAsso() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiCarico() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + else { + + if ( frame.giocata[0] == null ) { + if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiTre() ); + else if ( vaiCarico() ); + else; + } + + /* Valuta cosa fare quando invece il giocatore ha giocato */ + else { + if ( haLisciato() ) { + if ( vaiSopra() ); + else if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoPunti() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haTagliato() ) { + if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiAsso() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoBriscolaAlta() ) { + if ( vaiLiscio() ); + else if ( vaiTre() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } else if ( haMessoTre() ) { + if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiTaglio() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + } else if ( haMessoAsso() ) { + if ( vaiLiscio() ); + else if ( vaiTaglio() ); + else if ( vaiPunti() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiCarico() ); + else if ( vaiTre() ); + } else if ( haCaricato() ) { + if ( vaiSopra() ); + else if ( vaiTre() ); + else if ( vaiBriscolaAlta() ); + else if ( vaiTaglio() ); + else if ( vaiAsso() ); + else if ( vaiLiscio() ); + else if ( vaiPunti() ); + else if ( vaiCarico() ); + } + } + } + + /* Gioca la carta e aggiorna la finestra con il metodo repaint() */ + frame.giocata[1] = frame.carteCPU[cartaDaGiocare]; + frame.carteCPU[cartaDaGiocare] = null; + frame.pannello.repaint(); + + CPUHaGiocato = true; + + if ( frame.giocata[0] == null ) + toccaAllaCPU = false; + } + + /* Determina se ha preso la CPU o il giocatore */ + public void chiPrende() { + char aux[], auxCPU[]; + aux = frame.giocata[0].toString().toCharArray(); + auxCPU = frame.giocata[1].toString().toCharArray(); + + /* Chiama il metodo giocatorePrende( boolean giocatore ) con parametro + * true se ha preso il giocatore, false se ha preso la CPU */ + 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 ) ); + } + + /* Confronta due carte per decidere quale ha più valore di presa. + * Restituisce true se è la prima, false se è la seconda */ + 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; + } + + /* Viene chiamato con parametro true se ha preso il giocatore, false se + * ha preso la CPU */ + public void giocatorePrende( boolean giocatore ) { + if ( giocatore ) { + toccaAllaCPU = CPUHaGiocato = false; + haGiocatoPrima = true; + } + else { + toccaAllaCPU = true; + CPUHaGiocato = haGiocatoPrima = false; + } + daiPunti( giocatore ); + } + + /* Da i punti (true al giocatore, false alla CPU) e fa pescare le carte*/ + 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++; + } + } + + /* Aggiorna la finestra */ + frame.pannello.repaint(); + frame.repaint(); + } + + /* Vari metodi che determinano che tipo di carta ha giocato il giocatore. + * Per farlo leggono il nome dell'immagine dal file. Dato che ogni carta + * a un nome del tipo 1-1.jpg (asso di coppe) o 10-3 (re di denari) e + * così via, è facile riconoscerle. */ + public boolean haLisciato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ); + } + + public boolean haMessoPunti() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || + (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ); + } + + public boolean haTagliato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ); + } + + public boolean haMessoBriscolaAlta() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0) || (auxCPU[auxCPU.length-7] - 48 == 8) || + (auxCPU[auxCPU.length-7] - 48 == 9) ) ); + } + + public boolean haMessoTre() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 3) ); + } + + public boolean haMessoAsso() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 == 1) ); + } + + public boolean haCaricato() { + char auxCPU[]; + auxCPU = frame.giocata[0].toString().toCharArray(); + return ( (frame.giocata[0] != null) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ); + } + + /* I metodi seguenti cercano di andare liscio - dare punti - mettere + * un taglio - ecc... e restituiscono true se hanno avuto successo, + * false altrimenti. */ + public boolean vaiLiscio() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 != 0 ) && (auxCPU[auxCPU.length-7] - 48 != 1 ) && + (auxCPU[auxCPU.length-7] - 48 != 3 ) && (auxCPU[auxCPU.length-7] - 48 < 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + + public boolean vaiPunti() { + /* Cerca di dare punti, cercando di darne il meno possibile (meglio + * un fante di re). */ + + char[] auxCPU; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiTaglio() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && + (auxCPU[auxCPU.length-7] - 48 != 0) && (auxCPU[auxCPU.length-7] - 48 != 1) && + (auxCPU[auxCPU.length-7] - 48 != 3) && (auxCPU[auxCPU.length-7] - 48 <= 7) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiBriscolaAlta() { + + char[] auxCPU; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 8 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 9 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 0 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiTre() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 3) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiAsso() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( auxCPU[auxCPU.length-5] - 49 == semeBriscola && (auxCPU[auxCPU.length-7] - 48 == 1) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiCarico() { + + char[] auxCPU; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + cartaDaGiocare = i; + return true; + } + } + } + + return false; + } + public boolean vaiSopra() { + /* Innanzitutto controlla se il giocatore ha giocato (non dovrebbe + * essere possibile, in quanto quando questo metodo viene chiamato + * tale condizione è già stata verificata, ma è sempre meglio un + * controllo in più che uno in meno) e restituisce false in caso + * contrario */ + if ( frame.giocata[0] == null ) + return false; + + /* Tre variabili intere che serviranno a valutare quali delle tre + * carte è meglio giocare, se più di una può andare sopra. */ + int a = -1; + int b = -1; + int c = -1; + + /* Tre booleane che verificano quali delle tre carte possono + * andare sopra. */ + boolean laPrimaPuoAndareSopra = false; + boolean laSecondaPuoAndareSopra = false; + boolean laTerzaPuoAndareSopra = false; + + /* E tre array di caratteri ausiliari per leggere il nome delle + * carte, più quello per la carta giocata dal giocatore.*/ + char[] auxCPU1 = new char[1024]; + char[] auxCPU2 = new char[1024]; + char[] auxCPU3 = new char[1024]; + char[] aux = frame.giocata[0].toString().toCharArray(); + + /* Se il giocatore ha giocato un asso, restituisce direttamente false. */ + if ( aux[aux.length-7] - 48 == 1 ) + return false; + + /* Valuta quali delle tre carte possono andare sopra, dopo essersi + * accertato di averle: nelle ultime mani non si hanno tutte le carte + * in mano, e noi non vogliamo una NullPointerException sul più bello + * di una partita, vero?! */ + if ( frame.carteCPU[0] != null ) { + auxCPU1 = frame.carteCPU[0].toString().toCharArray(); + a = auxCPU1[auxCPU1.length-7] - 48; + if ( (auxCPU1[auxCPU1.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( a, aux[aux.length-7] - 48 ) ) + laPrimaPuoAndareSopra = true; + } + + if ( frame.carteCPU[1] != null ) { + auxCPU2 = frame.carteCPU[1].toString().toCharArray(); + b = auxCPU2[auxCPU2.length-7] - 48; + if ( (auxCPU2[auxCPU2.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( b, aux[aux.length-7] - 48 ) ) + laSecondaPuoAndareSopra = true; + } + + if ( frame.carteCPU[2] != null ) { + auxCPU3 = frame.carteCPU[2].toString().toCharArray(); + c = auxCPU3[auxCPU3.length-7] - 48; + if ( (auxCPU3[auxCPU3.length-5] - 49 == aux[aux.length-5] - 49) && laPrimaEPiuAlta( c, aux[aux.length-7] - 48 ) ) + laTerzaPuoAndareSopra = true; + } + + /* Se nessuna carta può andare sopra, restituisce false. Se una + * sola delle tre può andare sopra la imposta come carta da giocare. */ + if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + return false; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 0; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + cartaDaGiocare = 2; + + /* Se più di una carta può andare sopra, valuta quale è più alta. */ + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && !laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 1; + else if ( !laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && !laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else if ( laPrimaPuoAndareSopra && laSecondaPuoAndareSopra && laTerzaPuoAndareSopra ) + if ( laPrimaEPiuAlta( a, b ) ) + if ( laPrimaEPiuAlta( a, c ) ) + cartaDaGiocare = 0; + else + cartaDaGiocare = 2; + else + if ( laPrimaEPiuAlta( b, c ) ) + cartaDaGiocare = 1; + else + cartaDaGiocare = 2; + + /* Controlla che la carta con cui sta cercando di andare sopra + * sia una figura o un carico. Non vogliamo mica prendere delle + * scartelle con delle scartelle, giusto?! */ + aux = frame.carteCPU[cartaDaGiocare].toString().toCharArray(); + if ( (aux[aux.length-7] - 48 != 0) && (aux[aux.length-7] - 48 != 1) && + (aux[aux.length-7] - 48 != 3) && (aux[aux.length-7] - 48 <= 7) ) + return false; + + return true; + } + + /* I metodi seguenti valutano le carte che la CPU ha in mano. */ + public boolean hoCarico() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 1 ) || (auxCPU[auxCPU.length-7] - 48 == 3 ) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoAsso() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 1 ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTre() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-7] - 48 == 3 ) ) { + return true; + } + } + } + + return false; + } + public boolean hoBriscolaAlta() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + ( (auxCPU[auxCPU.length-7] - 48 == 0 ) || (auxCPU[auxCPU.length-7] - 48 == 8 ) || (auxCPU[auxCPU.length-7] - 48 == 9 ) ) ) { + return true; + } + } + } + + return false; + } + public boolean hoTaglio() { + + char auxCPU[]; + + for ( int i = 0; i < 3; i++ ) { + if ( frame.carteCPU[i] != null ) { + auxCPU = frame.carteCPU[i].toString().toCharArray(); + if ( (auxCPU[auxCPU.length-5] - 49 == semeBriscola) && + (auxCPU[auxCPU.length-7] - 48 < 8 ) && (auxCPU[auxCPU.length-7] - 48 != 3 ) + && (auxCPU[auxCPU.length-7] - 48 != 1 ) && (auxCPU[auxCPU.length-7] - 48 != 0 ) ) { + return true; + } + } + } + + return false; + } + + /* I vari trucchi del gioco. */ + public static void trucco( String trucco ) { + + byte[] truccoByte = trucco.getBytes(); + char[] truccoChar = new char[ truccoByte.length ]; + for ( int i = 0; i < truccoChar.length; i++ ) + truccoChar[i] = (char)truccoByte[i]; + + String attivato = stringaTruccoSbagliato; + + /* Carta che vuoi dove vuoi. Esempio: x251 sostituisce + * la terza carta (2) con il 6 (5) di coppe (1). */ + if ( truccoChar[0] == 'x' && truccoChar.length == 4 ) { + + attivato = stringaTruccoAttivato; + + String aS = "" + truccoChar[1]; + String xS = "" + truccoChar[2]; + String yS = "" + truccoChar[3]; + + int a, x, y; + + try { + + a = Integer.parseInt( aS ); + x = Integer.parseInt( xS ); + y = Integer.parseInt( yS ); + + frame.carteInMano[a] = frame.arrayCarte[x][y]; + + } catch ( Exception e ) { + attivato = stringaTruccoSbagliato; + } + } + + /* Mostra le carte del computer. */ + if ( trucco.equalsIgnoreCase( "Kill Devil Hill" ) ) { + + attivato = stringaTruccoAttivato; + + carteScoperte = true; + + } + + /* Scambia le carte con il computer. */ + if ( trucco.equalsIgnoreCase( "Darkside of Aquarius" ) ) { + + attivato = stringaTruccoAttivato; + + ImageIcon aux = null; + + for ( int i = 0; i < 3; i++ ) { + + aux = frame.carteInMano[i]; + frame.carteInMano[i] = frame.carteCPU[i]; + frame.carteCPU[i] = aux; + + } + } + + /* Cambia il seme di briscola con uno a caso, senza dire quale. + * L'ultima carta non cambia. È possibile comunque capire + * qual'è la briscola dal menu ?->Briscola*/ + if ( trucco.equalsIgnoreCase( "Change of Heart" ) ) { + + attivato = stringaTruccoAttivato; + + semeBriscola = (int) ( Math.random() * 4 ); + + } + + /* Asso Tre e Re di Briscola tutti in mano (anche in caso di doppioni). */ + if ( trucco.equalsIgnoreCase( "Tears of The Dragon" ) ) { + + attivato = stringaTruccoAttivato; + + frame.carteInMano[0] = frame.arrayCarte[9][semeBriscola]; + frame.carteInMano[1] = frame.arrayCarte[2][semeBriscola]; + frame.carteInMano[2] = frame.arrayCarte[0][semeBriscola]; + + } + + /* Tre assi di briscola. */ + if ( trucco.equalsIgnoreCase( "Navigate The Seas of The Sun" ) ) { + + attivato = stringaTruccoAttivato; + + frame.carteInMano[0] = frame.arrayCarte[0][semeBriscola]; + frame.carteInMano[1] = frame.arrayCarte[0][semeBriscola]; + frame.carteInMano[2] = frame.arrayCarte[0][semeBriscola]; + + } + + /* Fa finire la partita al prossimo piglio. */ + if ( trucco.equalsIgnoreCase( "Omega" ) ) { + + attivato = stringaTruccoAttivato; + + mano = 19; + + } + + JOptionPane.showMessageDialog( frame, attivato, "JBriscola - " + version, JOptionPane.INFORMATION_MESSAGE ); + frame.pannello.repaint(); + frame.repaint(); + + } + + /* Imposta le opzioni dell'utente cercando di leggerle dal file di configurazione. */ + public static void settaOpzioni() { + + /* Impostazioni predefinite. */ + lang = "it"; + soundString = "suono=si"; + keysString = "tasti=si"; + int r = 0; + int g = 150; + int b = 0; + + /* Cerca di leggere il file per impostare le opzioni. */ + Scanner scanner = null; + File file = new File( "JBriscolaConfig.txt" ); + if ( file.exists() ) { + try { + scanner = new Scanner( file ); + } catch ( FileNotFoundException e ) { } + try { + lang = scanner.next(); + soundString = scanner.next(); + keysString = scanner.next(); + r = scanner.nextInt(); + g = scanner.nextInt(); + b = scanner.nextInt(); + } catch ( NoSuchElementException e ) { } + } + + /* Modifica le opzioni. */ + if ( lang.equals( "it" ) ) { + semi[0] = "Bastoni"; + semi[1] = "Coppe"; + semi[2] = "Denari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Prendi/Lascia carte"; + stringaPrimaGioca = "Prima Gioca!"; + stringaUltime4 = "Ultima carta - Occhio alla briscola!"; + stringaVinto = "Hai Vinto!"; + stringaPerso = "Hai Perso"; + stringaPareggio = "Pareggio"; + stringaGiocatore = "Giocatore: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Nuova Partita"; + stringaNuovaPartitaAiTrenta = "Nuova Partita Ai 30"; + stringaVuoiDavveroIniziare = "Vuoi davvero iniziare una nuova partita?"; + stringaVuoiDavveroUscire = "Vuoi davvero uscire?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Esci"; + stringaImpossibileConfigurare = "Impossibile modificare il file di configurazione.\nSegnalare il bug a: sebastiano@luganega.org\n\nEccezione:\n"; + stringaLingua = "Lingua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italiano"; + stringaLa = "Latino"; + stringaBL = "Dialetto Bellunese"; + stringaBV = "Dialetto Basso Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola e' un gioco di briscola per pc scritto in java ideato\ne realizzato da Sebastiano Tronto. Il gioco viene rilasciato sotto licenza GNU/Gpl versione 2 o successive; questo permette\npotenzialmente a chiunque di modificare il gioco partendo dal codice sorgente del programma. Se non avete ricevuto i sorgenti\nassieme al gioco, potete richiedermeli con un'e-mail a sebastiano@luganega.org.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Effetti sonori"; + stringaPunteggio = "Punteggio"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Cerca aggiornamenti"; + stringaTrucchi = "Trucchi"; + stringaInserisciCodice = "Inserisci il codice:"; + stringaTruccoAttivato = "Trucco attivato!"; + stringaTruccoSbagliato = "Trucco non valido"; + stringaCheCartaVuoi = "E allora che carta vuoi?"; + stringaAggiornamentiSi = "Aggiornamento disponibile: "; + stringaAggiornamentiNo = "Nessun aggiornamento disponibile"; + stringaScarica = "E' possibile scaricare la versione più recente\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Errore: nessuna connessione internet"; + stringaTasti2 = "1 Gioca la prima carta\n2 Gioca la seconda carta\n3 Gioca la terza carta\nF1 Visualizza questo messaggio\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + else if ( lang.equals( "la" ) ) { + semi[0] = "BACULI"; + semi[1] = "CALICES"; + semi[2] = "DENARII"; + semi[3] = "GLADII"; + stringaBriscola = "BRISCOLA"; + stringaBottonePrendi = "CAPIS/RELINQVIS CHARTAS"; + stringaPrimaGioca = "ANTE CHARTAM PONE!"; + stringaUltime4 = "CHARTA POSTREMA - INTVERE BRISCOLAM!"; + stringaVinto = "VICISTI!"; + stringaPerso = "PERDIDISTI"; + stringaPareggio = "AEQVATIO!"; + stringaGiocatore = "LVSOR: "; + stringaComputer = "\nCOMPVTER: "; + stringaNuovaPartita = "NOVA LVSO"; + stringaNuovaPartitaAiTrenta = "NOVA LVSO XXX"; + stringaVuoiDavveroIniziare = "NOVAM LVSIONEM INCIPERE?"; + stringaVuoiDavveroUscire = "EXIRE?"; + stringaSi = "ID VOLO"; + stringaNo = "NOLO"; + stringaOpzioni = "OPTIONES..."; + stringaEsci = "EXIRE"; + stringaImpossibileConfigurare = "CONFIGVRATIONIS FILE SCRIBERE NON POTVI.\nERROREM ME CERTIOREM FACITE: sebastiano@luganega.org\n\nEXCEPTIO:\n"; + stringaLingua = "LINGVA"; + stringaAnnulla = "ABROGA"; + stringaIt = "ITALICA"; + stringaLa = "LATINA"; + stringaBL = "BELLUNI"; + stringaBV = "VENETIAE"; + stringaEN = "ANGLICVS"; + stringaModificaOpzioni = "OPTIONES NOVARE"; + stringaInformazioni = "INFORMATIONES"; + stringaInformazioni2 = "JBriscola EST LVDVM BRISCOLAE COMPVTERI, JAVA SCRIPTVM, EXCOGITATVM\nFACTVMQUE A SEBASTIANO TRONTO. IPSVM LUDVM REICITUR LICENTIA GNU/Gpl VERSIONE 2 AVT POSTERIORIBUS; ID\nOMNIBVS LVDVM MUTARE CODICE IPSIVS INCIPIENDO LICET. SI CODICES CUM\nLVDO NON PERVENIT, EOS POSCERE POTESTIS E-MAILE sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "SONVS"; + stringaPunteggio = "NVMERI"; + stringaSfondo = "COLOR"; + stringaTasti = "TASTI RAPIDI"; + stringaAggiornamenti = "VERSIONEM RECENTIOREM QVAERERE"; + stringaTrucchi = "CODICES"; + stringaInserisciCodice = "CODICEM INSCRIBE:"; + stringaTruccoAttivato = "CODEX INCIPIVIT!"; + stringaTruccoSbagliato = "ERROR CODICIS"; + stringaCheCartaVuoi = "QUAM CHARTAM VOLIS?"; + stringaNoInternet = "ERROR: INTERNETIS CONIVCTIO NON EST"; + stringaAggiornamentiSi = "VERSIO RECENTIOR EST: "; + stringaAggiornamentiNo = "VERSIO RECENTIOR NON EST"; + stringaScarica = "VERSIONEM RECENTIOREM CEPTA ESSE POTEST:\nhttp://porkynator.altervista.org/programmi.html"; + stringaTasti2 = "1 PONE CHARTAM PRIMAM\n2 PONE CHARTAM SECUNDAM\n3 PONE CHARTAM TERTIAM\nF1 HEAC INFORMATIONES\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "bl" ) ) { + semi[0] = "Bastoi"; + semi[1] = "Coppe"; + semi[2] = "Danari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Cio' su/lasa le carte"; + stringaPrimaGioca = "Prima Duga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Te ha vint!"; + stringaPerso = "Te ha pers"; + stringaPareggio = "Pari"; + stringaGiocatore = "Dugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "Taca n'altra partida"; + stringaNuovaPartitaAiTrenta = "Taca na partida ai 30"; + stringaVuoiDavveroIniziare = "Utu sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Utu sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe ho riva' a scrivere al file de configurazion.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto de Belun"; + stringaBV = "Dialeto de la basa"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informazioni"; + stringaInformazioni2 = "JBriscola le' an dugo de briscola par computer scrit in java, pensa' e realiza'\n da Sebastiano Tronto. Al dugo l'e' sotto licenza GNU/Gpl versione 2 o sucesive; questo ol dir che chi che ol\n(se l'e' bon) al pol modificar al dugo coi codici sorgenti del programa. Se no i ve ha dat i sorgenti\nasieme al dugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe ne' na version pi nova"; + stringaTrucchi = "Truchi"; + stringaInserisciCodice = "Scrivi al codice:"; + stringaTruccoAttivato = "Truco ativa'!"; + stringaTruccoSbagliato = "Truco sbaia'"; + stringaCheCartaVuoi = "Che carta utu alora?"; + stringaAggiornamentiSi = "Ghe ne' na version pi nova: "; + stringaAggiornamentiNo = "No ghe ne na version pi nova"; + stringaScarica = "Te pol scaricar le version pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no te se su internet"; + stringaTasti2 = "1 Duga la prima carta\n2 Duga la seconda carta\n3 Duga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "bv" ) ) { + semi[0] = "Bastoni"; + semi[1] = "Coppe"; + semi[2] = "Danari"; + semi[3] = "Spade"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Ciapa su/lasa e carte"; + stringaPrimaGioca = "Prima Zuga!"; + stringaUltime4 = "Ultima carta - Ocio a la briscola!"; + stringaVinto = "Ti ga vinto!"; + stringaPerso = "Ti ga perso"; + stringaPareggio = "Pari"; + stringaGiocatore = "Zugador: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "N'altra Partida"; + stringaNuovaPartitaAiTrenta = "Na Partida ai 30"; + stringaVuoiDavveroIniziare = "Ti vol sul serio scuminziar n'altra partida?"; + stringaVuoiDavveroUscire = "Ti vol sul serio stusar su?"; + stringaSi = "Si"; + stringaNo = "No"; + stringaOpzioni = "Opzioni..."; + stringaEsci = "Stusa su"; + stringaImpossibileConfigurare = "No ghe son riusito a scrivere al file de configurazione.\nMandeme na mail a: sebastiano@luganega.org\n\nEcezion:\n"; + stringaLingua = "Lengua"; + stringaAnnulla = "Annulla"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Dialeto Belumat"; + stringaBV = "Dialeto Veneto"; + stringaEN = "Inglese"; + stringaModificaOpzioni = "Modifica Opzioni"; + stringaInformazioni = "Informasioni"; + stringaInformazioni2 = "JBriscola xe an zugo de briscola par computer scrito in java, pensato e realisato\n da Sebastiano Tronto. Al zugo xe sotto licenza GNU/Gpl versione 2 o sucesive; questo vol dire che chi che\nvol (se xe bono) al pol modificare al zugo coi codici sorgenti del programa. Se no i ve ha dato i sorgenti\nasieme al zugo, pote' domandarmeli co na e-mail a sebastiano@luganega.org.\n\nJBriscola version " + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Efeti sonori"; + stringaPunteggio = "Varda i punti"; + stringaSfondo = "Sfondo"; + stringaTasti = "Tasti rapidi"; + stringaAggiornamenti = "Varda se ghe xe na versione pi nova"; + stringaTrucchi = "Truchi"; + stringaInserisciCodice = "Scrivi al codice:"; + stringaTruccoAttivato = "Truco ativa'!"; + stringaTruccoSbagliato = "Truco sbaia'"; + stringaCheCartaVuoi = "Che carta utu alora?"; + stringaAggiornamentiSi = "Ghe xe na versione pi nova: "; + stringaAggiornamentiNo = "No ghe xe na versione pi nova"; + stringaScarica = "Te pol scaricar le versione pi nova\ndal sito http://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Erore: no ti xe su internet"; + stringaTasti2 = "1 Zuga la prima carta\n2 Zuga la seconda carta\n3 Zuga la terza carta\nF1 Tasti rapidi\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + if ( lang.equals( "en" ) ) { + semi[0] = "Sticks"; + semi[1] = "Cups"; + semi[2] = "Golds"; + semi[3] = "Swords"; + stringaBriscola = "Briscola"; + stringaBottonePrendi = "Take/leave cards"; + stringaPrimaGioca = "Play your card before!"; + stringaUltime4 = "Last card - keep your eye on the briscola!"; + stringaVinto = "You won!"; + stringaPerso = "You lost"; + stringaPareggio = "Sixty - sixty!"; + stringaGiocatore = "Palyer: "; + stringaComputer = "\nComputer: "; + stringaNuovaPartita = "New Game"; + stringaNuovaPartitaAiTrenta = "New Game - 30 Points"; + stringaVuoiDavveroIniziare = "Do you really want to start a new game?"; + stringaVuoiDavveroUscire = "Do you really want to exit?"; + stringaSi = "Yes"; + stringaNo = "No"; + stringaOpzioni = "Options..."; + stringaEsci = "Exit"; + stringaImpossibileConfigurare = "Couldn't write to the configuration file.\nPlease report the bug to: sebastiano@luganega.org\n\nException:\n"; + stringaLingua = "Lang"; + stringaAnnulla = "Cancel"; + stringaIt = "Italian"; + stringaLa = "Latin"; + stringaBL = "Belluno dialect"; + stringaBV = "Venice dialect"; + stringaEN = "English"; + stringaModificaOpzioni = "Change options"; + stringaInformazioni = "Information"; + stringaInformazioni2 = "JBriscola is a briscola pc game written in java, meant\nand made by Sebastiano Tronto. The game is protected by the GNU/General public licence version 2 or later.\n\nJBriscola version" + version + "\nCopyright 2009 Sebastiano Tronto, license GNU/Gpl 2.0 or later\nE-mail: sebastiano@luganega.org"; + stringaSuono = "Sound"; + stringaPunteggio = "Score"; + stringaSfondo = "Background"; + stringaTasti = "Hot keys"; + stringaAggiornamenti = "Check updates"; + stringaTrucchi = "Cheats"; + stringaInserisciCodice = "Insert cheat:"; + stringaTruccoAttivato = "Cheat actived!"; + stringaTruccoSbagliato = "Wrong cheat"; + stringaCheCartaVuoi = "So what card do you want?"; + stringaAggiornamentiSi = "Update available: "; + stringaAggiornamentiNo = "No updates available"; + stringaScarica = "You can get the latest version from the site\nhttp://porkynator.altervista.org/programmi.html"; + stringaNoInternet = "Error: no internet connection"; + stringaTasti2 = "1 Play the first card\n2 Play the second card\n3 Play the third card\nF1 Get this message\nF2 " + stringaNuovaPartita + "\nF3 " + stringaOpzioni + "\nF4 " + stringaPunteggio + "\nF5 " + stringaInformazioni + "\nF6 " + stringaAggiornamenti + "\nF7 " + stringaNuovaPartitaAiTrenta + "\nF8 " + stringaTrucchi + "\nq " + stringaEsci; + } + sound = ( soundString.equals( "suono=si" ) ); + keys = ( keysString.equals( "tasti=si" ) ); + color = new Color( r, g, b ); + if ( frame != null ) { + frame.pannello.repaint(); + frame.pannello2.repaint(); + frame.repaint(); + } + } +} diff --git a/JBriscola/all_versions/0.3/0.3/src/OptionFrame.java b/JBriscola/all_versions/0.3/0.3/src/OptionFrame.java @@ -0,0 +1,169 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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 java.util.Formatter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class OptionFrame extends JFrame { + + public static Main main = new Main(); + public static Formatter formatter; + public static JButton ok, annulla, scegliColore; + public static JLabel lingua, sfondo; + public static JComboBox selezionaLingua; + public static JCheckBox suono, tastiRapidi; + public static JPanel[] pannello = new JPanel[6]; + + public OptionFrame() { + + super( "JBriscola - " + main.stringaModificaOpzioni ); + + ok = new JButton( "OK" ); + ok.addActionListener( new ActionListener() { + + /* Quando le modifiche vengono confermate premendo ok, viene scritto + * il file di configurazione (o aggiornato) se possibile, e modificate + * le impostazioni attuali. */ + public void actionPerformed( ActionEvent e ) { + + try { + formatter = new Formatter( "JBriscolaConfig.txt" ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE ); + } + + String lang; + + switch ( selezionaLingua.getSelectedIndex() ) { + case 0: + lang = "it"; + break; + case 1: + lang = "la"; + break; + case 2: + lang = "bl"; + break; + case 3: + lang = "bv"; + break; + case 4: + lang = "en"; + break; + default: + lang = "it"; + break; + } + + String suonosiono, tastisiono; + + if ( suono.isSelected() ) + suonosiono = "suono=si"; + else + suonosiono = "suono=no"; + if ( tastiRapidi.isSelected() ) + tastisiono = "tasti=si"; + else + tastisiono = "tasti=no"; + + formatter.format( lang ); + formatter.format( "\n" ); + formatter.format( suonosiono ); + formatter.format( "\n" ); + formatter.format( tastisiono ); + formatter.format( "\n" ); + formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() ); + formatter.close(); + + main.settaOpzioni(); + + OptionFrame.this.dispose(); + } + }); + + annulla = new JButton( main.stringaAnnulla ); + annulla.addActionListener( new ActionListener() { + /* Se l'utente annulla viene chiusa la finestra senza fare nulla. */ + public void actionPerformed( ActionEvent e ) { + OptionFrame.this.dispose(); + } + }); + + scegliColore = new JButton( " " ); + scegliColore.setBackground( main.color ); + scegliColore.addActionListener( new ActionListener() { + /* Permette di scegliere il colore dello sfondo. */ + public void actionPerformed( ActionEvent e ) { + Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color ); + if ( colore != null ) + main.color = colore; + OptionFrame.scegliColore.setBackground( main.color ); + } + } ); + + /* Vengono impostati e disegnati i vari componenti. */ + lingua = new JLabel( main.stringaLingua ); + sfondo = new JLabel( main.stringaSfondo ); + String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV, main.stringaEN }; + selezionaLingua = new JComboBox( lingueDaSelezionare ); + int linguaPreselezionata = 0; + + if ( main.lang.equals( "it" ) ) + linguaPreselezionata = 0; + else if ( main.lang.equals( "la" ) ) + linguaPreselezionata = 1; + else if ( main.lang.equals( "bl" ) ) + linguaPreselezionata = 2; + else if ( main.lang.equals( "bv" ) ) + linguaPreselezionata = 3; + else if ( main.lang.equals( "en" ) ) + linguaPreselezionata = 4; + + selezionaLingua.setSelectedIndex( linguaPreselezionata ); + suono = new JCheckBox( main.stringaSuono ); + suono.setSelected( main.sound ); + tastiRapidi = new JCheckBox( main.stringaTasti ); + tastiRapidi.setSelected( main.keys ); + + pannello[0] = new JPanel( new GridLayout( 4, 1 ) ); + pannello[1] = new JPanel( new FlowLayout() ); + pannello[2] = new JPanel( new FlowLayout() ); + pannello[3] = new JPanel( new FlowLayout() ); + pannello[4] = new JPanel( new FlowLayout() ); + pannello[5] = new JPanel( new FlowLayout() ); + pannello[5].add( ok ); + pannello[5].add( annulla ); + pannello[4].add( sfondo ); + pannello[4].add( scegliColore ); + pannello[3].add( tastiRapidi ); + pannello[2].add( suono ); + pannello[1].add( lingua ); + pannello[1].add( selezionaLingua ); + pannello[0].add( pannello[1] ); + pannello[0].add( pannello[2] ); + pannello[0].add( pannello[3] ); + pannello[0].add( pannello[4] ); + add( pannello[0], BorderLayout.CENTER ); + add( pannello[5], BorderLayout.SOUTH ); + } +} diff --git a/JBriscola/all_versions/0.3/0.3/src/Pannello.java b/JBriscola/all_versions/0.3/0.3/src/Pannello.java @@ -0,0 +1,88 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +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.*; + +/* Questa classe dispone semplicemente le carte + * sulla finestra e imposta la sfondo. */ +public class Pannello extends JPanel { + + public static Main main; + + public static Color color; + + public Pannello() { } + + public void paint( Graphics g ) { + + super.paint( g ); + + setBackground( main.color ); + + 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.carteScoperte ) { + + if ( main.frame.carteCPU[0] != null ) + main.frame.carteCPU[0].paintIcon( this, g, 230, 5 ); + + if ( main.frame.carteCPU[1] != null ) + main.frame.carteCPU[1].paintIcon( this, g, 300, 5 ); + + if ( main.frame.carteCPU[2] != null ) + main.frame.carteCPU[2].paintIcon( this, g, 370, 5 ); + + } else { + + 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 ); + + } +} + diff --git a/JBriscola/all_versions/0.3/0.3/src/img/1-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/1-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/1-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/1-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/1-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/1-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/1-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/1-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/10-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/10-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/10-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/10-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/10-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/10-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/10-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/10-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/2-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/2-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/2-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/2-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/2-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/2-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/2-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/2-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/3-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/3-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/3-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/3-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/3-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/3-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/3-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/3-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/4-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/4-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/4-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/4-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/4-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/4-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/4-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/4-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/5-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/5-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/5-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/5-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/5-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/5-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/5-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/5-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/6-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/6-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/6-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/6-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/6-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/6-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/6-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/6-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/7-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/7-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/7-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/7-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/7-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/7-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/7-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/7-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/8-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/8-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/8-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/8-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/8-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/8-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/8-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/8-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/9-1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/9-1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/9-2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/9-2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/9-3.jpg b/JBriscola/all_versions/0.3/0.3/src/img/9-3.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/9-4.jpg b/JBriscola/all_versions/0.3/0.3/src/img/9-4.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/Thumbs.db b/JBriscola/all_versions/0.3/0.3/src/img/Thumbs.db Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/carte.jpg b/JBriscola/all_versions/0.3/0.3/src/img/carte.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/retro1.jpg b/JBriscola/all_versions/0.3/0.3/src/img/retro1.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/img/retro2.jpg b/JBriscola/all_versions/0.3/0.3/src/img/retro2.jpg Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/0.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/0.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/1.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/1.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/2.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/2.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/3.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/3.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/4.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/4.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/5.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/5.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/pareggio.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/pareggio.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/perso.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/perso.wav Binary files differ. diff --git a/JBriscola/all_versions/0.3/0.3/src/sounds/vinto.wav b/JBriscola/all_versions/0.3/0.3/src/sounds/vinto.wav Binary files differ. diff --git a/JBriscola/trucchi.txt b/JBriscola/trucchi.txt @@ -0,0 +1,18 @@ +Tutti i trucchi vanno inseriti (dal menu file->trucchi) senza virgolette e con gli spazi. Il programma non distingue tra lettere maiuscole e minuscole. + +"Kill Devil Hill" - La CPU gioca a carte scoperte + +"Darkside of Aquarius" - Scambia le proprie carte con quelle della CPU + +"Change of Heart" - Cambia il seme di briscola con uno a caso, senza dire quale. L'ultima carta non cambia. È possibile comunque capire qual'è la briscola dal menu ?->Briscola + +"Tears of The Dragon" - Asso Tre e Re di Briscola tutti in mano (anche in caso di doppioni). + +"Navigate The Seas of The Sun" - Tre assi di briscola in mano + +"Omega" - Fa finire la partita al prossimo piglio + +P.S.: Sì, sono tutti titoli di canzoni di Bruce Dickinson. +P.P.S.: Se c'è qualche trucco che vi picerebbe avere, chiedete pure, e vedrò di implementarlo nella prossima versione :) + +per contattarmi: <i>sebastiano@luganega.org</i> +\ No newline at end of file diff --git a/PagaLavoro/PagaLavoro.bat b/PagaLavoro/PagaLavoro.bat @@ -0,0 +1 @@ +java PagaLavoro diff --git a/PagaLavoro/PagaLavoro.class b/PagaLavoro/PagaLavoro.class Binary files differ. diff --git a/PagaLavoro/PagaLavoro.java b/PagaLavoro/PagaLavoro.java @@ -0,0 +1,55 @@ +/******Programma per calcolare i soldini che ti devono dare******/ +/******quei rompiscatole dei tuoi superiori a fine giornata******/ +/************************Tecnoteam Zonto*************************/ + +/*cazzate iniziali...*/ +import java.util.Scanner; +class PagaLavoro { + public static void main (String args[]) { + + /*inizializziamo lo "scanner", per l'input di dati*/ + Scanner in = new Scanner(System.in); + + /*richiediamo i dati*/ + System.out.println ("Lavoratore: "); + String nome = in.nextLine(); + System.out.println ("Data (gg/mm/aaaa): "); + String data = in.nextLine(); + System.out.println ("Paga (€/Ora): "); + double pagaOra = in.nextDouble(); + System.out.println ("Ore di lavoro (numero intero): "); + int oreLavoro = in.nextInt(); + System.out.println ("Minuti di lavoro (numero intero): "); + int minutiLavoro = in.nextInt(); + + /*Scriviamo il resoconto, con tanto di calcolo ipergalattico per l'approssimazione dal centesimo*/ + System.out.println ("Il giorno " + data + ", " + nome + " ha lavorato " + oreLavoro + ":" + minutiLavoro + " ore, guadagnando " + (((double)((int)((pagaOra * oreLavoro + pagaOra / 60 * minutiLavoro)*100+0.5)))/100) + " €"); + + /*il try serve in caso di errore*/ + try { + /*scriviamo un file .txt con il resoconto*/ + FileOutputStream file = new FileOutputStream("Resoconto_lavoro_" + nome + ".txt"); + PrintStream Output = new PrintStream(file); + Output.println ("***************************************"); + Output.println ("**************Paga-Lavoro**************"); + Output.println ("***************************************"); + Output.println ("************Tecnoteam Zonto************"); + Output.println ("***************************************"); + Output.println (); + Output.println ("Resoconto del lavoro di " + nome); + Output.println ("Data: " + data); + Output.println ("Tempo di lavoro: " + oreLavoro + ":" + minutiLavoro + " ore"); + Output.println ("Paga per ora: " + pagaOra + " €"); + Output.println ("Paga totale: " + (((double)((int)((pagaOra * oreLavoro + pagaOra / 60 * minutiLavoro)*100+0.5)))/100) + " €"); + Output.println (); + Output.println ("Resoconto giornaliero: "); + Output.println ("Il giorno " + data + ", " + nome + " ha lavorato " + oreLavoro + ":" + minutiLavoro + " ore, guadagnando " + (((double)((int)((pagaOra * oreLavoro + pagaOra / 60 * minutiLavoro)*100+0.5)))/100) + " €"); + + /*anche il catch serve in caso di errore*/ + } catch (IOException e) { + System.out.println("Errore: " + e); + System.exit(1); + } + + } +} diff --git a/PagaLavoro/PagaLavoro.sh b/PagaLavoro/PagaLavoro.sh @@ -0,0 +1 @@ +java PagaLavoro diff --git a/PagaLavoro/Readme.txt b/PagaLavoro/Readme.txt @@ -0,0 +1,2 @@ +Il vostro capo vi fa sgobbare e vi obbliga anche a farvi i conti della paga? se lavorate part-time potete usare questo comodo programma che calcolerà per voi quanti soldi vi spettano! +Se usate windows aprite il file PagaLavoro.BAT, se usate linux PagaLavoro.sh +\ No newline at end of file diff --git a/README.md b/README.md @@ -0,0 +1,60 @@ +# Some of my earliest programs (2006-2010) + +In this repository you can find some of my earliest programs. +All of them are written in Java - although I had previously written some +[DarkBASIC](https://en.wikipedia.org/wiki/The_Game_Creators#DarkBASIC) +code, I could not find the sources in my backup folders. + +For some of the programs you can find multiple versions of the source +code, in separate folders. I did not use a version control system at +the time. Binaries (`.class` files) are also in provided in this repo. + +If you want to check them out, do start from JBriscola, +which is actually fun to play. It is an single-player game of +[briscola](https://en.wikipedia.org/wiki/Briscola) with a decent AI +and some fun extras (you can turn the sound effects off if you find +them annoying). + +The code, comments and the readme files are all in Italian. + +## JBriscola + +A single-player game of +[briscola](https://en.wikipedia.org/wiki/Briscola) with a decent AI. +It supports the classic variant as well as 30-points games. + +Available in 5 languages (Italian, English, Latin, +[Northern-Venetian](https://en.wikipedia.org/wiki/Venetian_language#Regional_variants) +and Central-Venetian). Keyboard shortcuts, persistent settings, +sound effects, you name it. And cheat codes too! + +## GiocoUno + +My first "game" (*GiocoUno* translates to *GameOne*), made with +[Swing](https://en.wikipedia.org/wiki/Swing_(Java)) +`JOptionPane`s. Honestly it's pretty bad. It is only notable because +it is my first GUI application, and possible the earliest piece of code +of mine that I have not lost. + +## Robottino + +A more complex GUI application with a menu bar, +images and animations. You can give commands to a +[robot](https://en.wikipedia.org/wiki/Bender_(Futurama)) and change its +position. This was the most complex application I wrote before JBriscola. + +## PagaLavoro + +Very simple wage calculator. I used this when helping my dad preparing firewood for the winter. +But don't worry, I did not start doing lumberjack work when I was 12. + +I started when I was 6. + +## pbfi + +A [brainfuck](https://en.wikipedia.org/wiki/Brainfuck) interpreter. + +## SlackYouInterpreter + +An interpreter for an esoteric programming language inspirid by brainfuck. +The syntax is explained in the README.txt. diff --git a/SlackYouInterpreter/README.txt b/SlackYouInterpreter/README.txt @@ -0,0 +1,29 @@ +SlackYou è un linguaggio di programmazione esoterico, ispirato al famoso BrainFuck, ma con molte funzionalità in più. +Innanzitutto in SlackYou l'array di byte è bidimensionale. +Il linguaggio è case-sensitive. Ogni carattere che non è valido come comando può essere usato come commento, +inclusi i caratteri-comando scritti in maiuscolo. Tutti gli altri comandi sono spiegati nella lista seguente: + +. Incrementa di 1 il byte al puntatore. Corrisponde al + in BF. +, Decrementa di 1 il byte al puntatore. Corrisponde al - in BF. +> Incrementa il puntatore orizzontale, come in BF. +< Decrementa il puntatore orizzontale, come in BF. +v Incrementa il puntatore verticale. +^ Decrementa il puntatore verticale. ++ Somma il byte al puntatore con il byte alla sua destra. Il risultato viene memorizzato nel byte al puntatore. +- Come sopra, ma sottrae. +* Come sopra, ma moltiplica. +/ Come sopra, ma esegue una divisione euclidea (senza virgola e senza resto). +% Come sopra, ma esegue l'operatore modulo (restituisce il resto della divisione euclidea). +j Copia il byte al puntatore nel byte a destra e incrementa il puntatore orizzontale. +g Copia il byte al puntatore nel byte a sinistra e decrementa il puntatore orizzontale. +y Copia il byte al puntatore nel byte sopra e decrementa il puntatore verticale. +h Copia il byte al puntatore nel byte sotto e incrementa il puntatore verticale. +=xy Se x e y sono cifre esadecimali (da '0' a '9' e da 'a' a 'f') il byte al puntatore assume il valore esadecimale xy. +r Memorizza nel byte al puntatore il codice ASCII del carattere digitato in input. +w Scrive in output il byte al puntatore tradotto in carattere ASCII. +? Se il byte al puntatore è 0, salta avanti fino all'istruzione dopo il corrispondente comando ; o :. +! Se il byte al puntatore non è 0, salta avanti fino all'istruzione dopo il corrispondente comando : o ;. +; Se il byte al puntatore non è 0, salta indietro fino all'istruzione dopo il corrispondente comando ? o !. +: Se il byte al puntatore è 0, salta indietro fino all'istruzione dopo il corrispondedente comando ! o ?. + +Nella cartella src trovate alcuni esempi di programmi in questo linguaggio. +\ No newline at end of file diff --git a/SlackYouInterpreter/SlackYouInterpreter-1.1/src/Frame.java b/SlackYouInterpreter/SlackYouInterpreter-1.1/src/Frame.java @@ -0,0 +1,209 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of SlackYouInterpreter. + + SlackYouInterpreter 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. + + SlackYouInterpreter 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 SlackYouInterpreter; 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.BorderLayout; +import java.awt.event.*; +import java.io.*; + +public class Frame extends JFrame { + public static int valoreChooser; + public static boolean firstSave; + public static String defaultSave; + public static Main main; + public static JTextArea textArea; + public static JButton runButton; + public static JMenuBar bar; + public static JMenu menuFile, menuAiuto; + public static JMenuItem esci, esegui, salva, salvaConNome, apri, info; + public static JFileChooser chooser; + public static FileInputStream in; + public static FileOutputStream out; + public Frame() { + super( "Porky's SlackYouInterpreter - v1.1" ); + firstSave = true; + main = new Main(); + defaultSave = ""; + chooser = new JFileChooser(); + textArea = new JTextArea( "Digitare qui il codice SlackYou", 15, 15 ); + bar = new JMenuBar(); + menuFile = new JMenu( "File" ); + menuAiuto = new JMenu( "?" ); + esci = new JMenuItem( "Esci" ); + esegui = new JMenuItem( "Esegui" ); + salva = new JMenuItem( "Salva" ); + salvaConNome = new JMenuItem( "Salva con nome" ); + apri = new JMenuItem( "Apri" ); + info = new JMenuItem( "Aiuto" ); + menuFile.setMnemonic( 'F' ); + menuAiuto.setMnemonic( '?' ); + esci.setMnemonic( 'E' ); + esegui.setMnemonic( 's' ); + salva.setMnemonic( 'a' ); + salvaConNome.setMnemonic( 'n' ); + apri.setMnemonic( 'p' ); + info.setMnemonic( 'i' ); + esci.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + System.exit( 0 ); + } + } + ); + esegui.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + salva.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + if ( firstSave ) { + valoreChooser = chooser.showSaveDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + out = new FileOutputStream( chooser.getSelectedFile().getPath() ); + defaultSave = chooser.getSelectedFile().getPath(); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "SlackYou - Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "SlackYou - Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + firstSave = false; + } else { + try { + out = new FileOutputStream( defaultSave ); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "SlackYou - Errore", JOptionPane.ERROR_MESSAGE ); + } + } + } + } + ); + salvaConNome.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + valoreChooser = chooser.showSaveDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + out = new FileOutputStream( chooser.getSelectedFile().getPath() ); + defaultSave = chooser.getSelectedFile().getPath(); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "SlackYou - Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "SlackYou - Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + firstSave = false; + } + } + ); + apri.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + valoreChooser = chooser.showOpenDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + String stringa; + byte bytes[]; + char caratteri[]; + in = new FileInputStream( chooser.getSelectedFile().getPath() ); + bytes = new byte[in.available()]; + caratteri = new char[in.available()]; + in.read( bytes ); + for ( int i = 0; i < bytes.length; i++ ) + caratteri[i] = ( char ) bytes[i]; + stringa = new String( caratteri ); + textArea.setText( stringa ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "SlackYou - Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "SlackYou - Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + } + } + ); + info.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, "SlackYou è un linguaggio di programmazione esoterico,\n ispirato al famoso BrainFuck, ma con molte funzionalità in più.\nInnanzitutto in SlackYou l'array di byte è bidimensionale.\nIl linguaggio è case-sensitive. Ogni carattere che non è valido\ncome comando può essere usato come commento,\ninclusi i caratteri-comando scritti in maiuscolo.\nTutti gli altri comandi sono spiegati nella lista seguente:\n\n. Incrementa di 1 il byte al puntatore. Corrisponde al + in BF.\n, Decrementa di 1 il byte al puntatore. Corrisponde al - in BF.\n> Incrementa il puntatore orizzontale, come in BF.\n< Decrementa il puntatore orizzontale, come in BF.\nv Incrementa il puntatore verticale.\n^ Decrementa il puntatore verticale.\n+ Somma il byte al puntatore con il byte alla sua destra. Il risultato viene memorizzato nel byte al puntatore.\n- Come sopra, ma sottrae.\n* Come sopra, ma moltiplica.\n/ Come sopra, ma esegue una divisione euclidea (senza virgola e senza resto).\n% Come sopra, ma esegue l'operatore modulo (restituisce il resto della divisione euclidea).\nj Copia il byte al puntatore nel byte a destra e incrementa il puntatore orizzontale.\ng Copia il byte al puntatore nel byte a sinistra e decrementa il puntatore orizzontale.\ny Copia il byte al puntatore nel byte sopra e decrementa il puntatore verticale.\nh Copia il byte al puntatore nel byte sotto e incrementa il puntatore verticale.\n=xy Se x e y sono cifre esadecimali (da '0' a '9' e da 'a' a 'f') il byte al puntatore assume il valore esadecimale xy.\nr Memorizza nel byte al puntatore il codice ASCII del carattere digitato in input.\nw Scrive in output il byte al puntatore tradotto in carattere ASCII.\n? Se il byte al puntatore è 0, salta avanti fino all'istruzione dopo il corrispondente comando ; o :.\n! Se il byte al puntatore non è 0, salta avanti fino all'istruzione dopo il corrispondente comando : o ;.\n; Se il byte al puntatore non è 0, salta indietro fino all'istruzione dopo il corrispondente comando ? o !.\n: Se il byte al puntatore è 0, salta indietro fino all'istruzione dopo il corrispondente comando ! o ?.\n\nNella cartella src trovate un esempio di Hello World in questo linguaggio.\n\nPer maggiori informazioni visitate la pagina:\nhttp://porkynator.altervista.org/SlackYou.html\no contattatemi al mio indirizzo e-mail:\nsebastiano@luganega.org", "SlackYou - informazioni", JOptionPane.INFORMATION_MESSAGE ); + } + } + ); + menuFile.add( esegui ); + menuFile.add( salva ); + menuFile.add( salvaConNome ); + menuFile.add( apri ); + menuFile.add( esci ); + menuAiuto.add( info ); + bar.add( menuFile ); + bar.add( menuAiuto ); + runButton = new JButton( "Esegui" ); + runButton.addActionListener( + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + setLayout( new BorderLayout() ); + setJMenuBar( bar ); + add( new JScrollPane( textArea ), BorderLayout.CENTER ); + add( runButton, BorderLayout.SOUTH ); + } +} +\ No newline at end of file diff --git a/SlackYouInterpreter/SlackYouInterpreter-1.1/src/HelloWorld.sky b/SlackYouInterpreter/SlackYouInterpreter-1.1/src/HelloWorld.sky @@ -0,0 +1,12 @@ +QUESTO È UN ESEMPIO DI HELLO WORLD IN SLACKYOU +=48w +=65w +=6cww +...w +=20w +=57w +=6fw +...w +,,,,,,w +=64w +=21w +\ No newline at end of file diff --git a/SlackYouInterpreter/SlackYouInterpreter-1.1/src/Main.java b/SlackYouInterpreter/SlackYouInterpreter-1.1/src/Main.java @@ -0,0 +1,325 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of SlackYouInterpreter. + + SlackYouInterpreter 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. + + SlackYouInterpreter 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 SlackYouInterpreter; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; +import java.util.Scanner; +public class Main { + public static Scanner scanner; + public static char totalCode[], charCodeAux[], charCode[], chars; + public static int i, j; + public static byte a[][]; + public static void main( String args[] ) { + System.out.println(""); + Frame frame = new Frame(); + frame.setSize( 200, 300 ); + frame.setVisible( true ); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + } + public static void run( String code ) { + scanner = new Scanner( System.in ); + a = new byte[1024][1024]; + for ( int countX = 0; countX < a[0].length; countX++ ) + for ( int countY = 0; countY < a.length; countY++ ) + a[countX][countY] = 0; + chars = 'A'; + int z = 0; + totalCode = code.toCharArray(); + charCodeAux = new char[totalCode.length*2]; + for ( int k = 0; k < totalCode.length; k++ ) { + switch ( totalCode[k] ) { + case '>': + case '<': + case '+': + case '-': + case '.': + case ',': + case '^': + case 'v': + case 'y': + case 'g': + case 'h': + case 'j': + case '*': + case '/': + case '%': + case '=': + case 'r': + case 'w': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + charCodeAux[z] = totalCode[k]; + z++; + break; + case '?': + case '!': + charCodeAux[z] = totalCode[k]; + z++; + charCodeAux[z] = chars; + chars++; + z++; + break; + case ';': + case ':': + chars--; + charCodeAux[z] = chars; + z++; + charCodeAux[z] = totalCode[k]; + z++; + break; + } + } + charCode = new char[z]; + for ( int k = 0; k < charCode.length; k++ ) + charCode[k] = charCodeAux[k]; + i = 0; + j = 0; + execute( scanner, charCode, a, i, j, 0, charCode.length ); + } + public static void execute( Scanner scanner, char charCode[], byte a[][], int i, int j, int start, int stop ) { + + for (int count = start; count < stop; count++ ) { + switch ( charCode[count] ) { + case '>': + i++; + break; + case '<': + i--; + break; + case 'v': + j++; + break; + case '^': + j--; + break; + case '.': + a[j][i]++; + break; + case ',': + a[j][i]--; + break; + case 'y': + a[j-1][i] = a[j][i]; + j--; + break; + case 'h': + a[j+1][i] = a[j][i]; + j++; + break; + case 'g': + a[j][i-1] = a[j][i]; + i--; + break; + case 'j': + a[j][i+1] = a[j][i]; + i++; + break; + case '+': + a[j][i] += a[j][i+1]; + break; + case '-': + a[j][i] -= a[j][i+1]; + break; + case '*': + a[j][i] *= a[j][i+1]; + break; + case '/': + a[j][i] /= a[j][i+1]; + break; + case '%': + a[j][i] %= a[j][i+1]; + break; + case 'w': + System.out.print( (char) a[j][i] ); + break; + case 'r': + String stringa = scanner.nextLine(); + char character[] = stringa.toCharArray(); + switch ( character.length ) { + case 1: + a[j][i] = (byte) character[0]; + break; + default: + count --; + break; + } + break; + case '=': + if ( (charCode[count+1] == '0' || charCode[count+1] == '1' || charCode[count+1] == '2' || charCode[count+1] == '3' || + charCode[count+1] == '4' || charCode[count+1] == '5' || charCode[count+1] == '6' || charCode[count+1] == '7' || + charCode[count+1] == '8' || charCode[count+1] == '9' || charCode[count+1] == 'a' || charCode[count+1] == 'b' || + charCode[count+1] == 'c' || charCode[count+1] == 'd' || charCode[count+1] == 'e' || charCode[count+1] == 'f' ) && + (charCode[count+2] == '0' || charCode[count+2] == '1' || charCode[count+2] == '2' || charCode[count+2] == '3' || + charCode[count+2] == '4' || charCode[count+2] == '5' || charCode[count+2] == '6' || charCode[count+2] == '7' || + charCode[count+2] == '8' || charCode[count+2] == '9' || charCode[count+2] == 'a' || charCode[count+2] == 'b' || + charCode[count+2] == 'c' || charCode[count+2] == 'd' || charCode[count+2] == 'e' || charCode[count+2] == 'f' ) ) { + a[j][i] = 0; + switch ( charCode[count+1] ) { + case '0': + break; + case '1': + a[j][i] += 1 * 16; + break; + case '2': + a[j][i] += 2 * 16; + break; + case '3': + a[j][i] += 3 * 16; + break; + case '4': + a[j][i] += 4 * 16; + break; + case '5': + a[j][i] += 5 * 16; + break; + case '6': + a[j][i] += 6 * 16; + break; + case '7': + a[j][i] += 7 * 16; + break; + case '8': + a[j][i] += 8 * 16; + break; + case '9': + a[j][i] += 9 * 16; + break; + case 'a': + a[j][i] += 10 * 16; + break; + case 'b': + a[j][i] += 11 * 16; + break; + case 'c': + a[j][i] += 12 * 16; + break; + case 'd': + a[j][i] += 13 * 16; + break; + case 'e': + a[j][i] += 14 * 16; + break; + case 'f': + a[j][i] += 15 * 16; + break; + } + switch ( charCode[count+2] ) { + case '0': + break; + case '1': + a[j][i] += 1; + break; + case '2': + a[j][i] += 2; + break; + case '3': + a[j][i] += 3; + break; + case '4': + a[j][i] += 4; + break; + case '5': + a[j][i] += 5; + break; + case '6': + a[j][i] += 6; + break; + case '7': + a[j][i] += 7; + break; + case '8': + a[j][i] += 8; + break; + case '9': + a[j][i] += 9; + break; + case 'a': + a[j][i] += 10; + break; + case 'b': + a[j][i] += 11; + break; + case 'c': + a[j][i] += 12; + break; + case 'd': + a[j][i] += 13; + break; + case 'e': + a[j][i] += 14; + break; + case 'f': + a[j][i] += 15; + break; + } + } + break; + case '?': + if ( a[j][i] == 0 ) { + count++; + char key = charCode[count]; + count++; + for ( ; charCode[count] != key; count++ ) ; + count++; + } + break; + case '!': + if ( a[j][i] != 0 ) { + count ++; + char key = charCode[count]; + count ++; + for ( ; charCode[count] != key; count++ ) ; + count++; + } + break; + case ';': + if ( a[j][i] != 0 ) { + count --; + char key = charCode[count]; + count --; + for ( ; charCode[count] != key; count-- ) ; + } + break; + case ':': + if ( a[j][i] == 0 ) { + count --; + char key = charCode[count]; + count --; + for ( ; charCode[count] != key; count-- ) ; + } + break; + } + } + } +} +\ No newline at end of file diff --git a/SlackYouInterpreter/SlackYouInterpreter.jar b/SlackYouInterpreter/SlackYouInterpreter.jar Binary files differ. diff --git a/pbfi/PBFI.jar b/pbfi/PBFI.jar Binary files differ. diff --git a/pbfi/pbfi-1.0/src/Frame.java b/pbfi/pbfi-1.0/src/Frame.java @@ -0,0 +1,49 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JTextArea; +import javax.swing.JScrollPane; +import java.awt.BorderLayout; +import java.awt.event.*; + +public class Frame extends JFrame { + public static Main main; + public static JTextArea textArea; + public static JButton runButton; + public Frame() { + super( "Porky's Brain F*** Interpreter - v1.0" ); + main = new Main(); + textArea = new JTextArea( "Brain F*** source code here", 15, 15 ); + runButton = new JButton( "Run" ); + runButton.addActionListener( + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + setLayout( new BorderLayout() ); + add( new JScrollPane( textArea ), BorderLayout.CENTER ); + add( runButton, BorderLayout.SOUTH ); + } +} +\ No newline at end of file diff --git a/pbfi/pbfi-1.0/src/Main.java b/pbfi/pbfi-1.0/src/Main.java @@ -0,0 +1,119 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; +import java.util.Scanner; +public class Main { + public static Scanner scanner; + public static char totalCode[], charCodeAux[], charCode[], chars; + public static byte a[]; + public static int i; + public static void main( String args[] ) { + Frame frame = new Frame(); + frame.setSize( 200, 300 ); + frame.setVisible( true ); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + } + public static void run( String code ) { + chars = 'a'; + int j = 0; + totalCode = code.toCharArray(); + charCodeAux = new char[totalCode.length*2]; + for ( int k = 0; k < totalCode.length; k++ ) { + switch ( totalCode[k] ) { + case '>': + case '<': + case '+': + case '-': + case '.': + case ',': + charCodeAux[j] = totalCode[k]; + j++; + break; + case '[': + charCodeAux[j] = totalCode[k]; + j++; + charCodeAux[j] = chars; + j++; + chars++; + break; + case ']': + chars--; + charCodeAux[j] = chars; + j++; + charCodeAux[j] = totalCode[k]; + j++; + break; + } + } + charCode = new char[j]; + for ( int k = 0; k < charCode.length; k++ ) + charCode[k] = charCodeAux[k]; + scanner = new Scanner( System.in ); + a = new byte[30000]; + for ( int count = 0; count < a.length; count++ ) + a[count] = 0; + i = 0; + execute( scanner, charCode, a, i, 0, charCode.length ); + } + public static void execute( Scanner scanner, char charCode[], byte a[], int i, int start, int stop ) { + for (int count = start; count < stop; count++ ) { + switch ( charCode[count] ) { + case '>': + i++; + break; + case '<': + i--; + break; + case '+': + a[i]++; + break; + case '-': + a[i]--; + break; + case '.': + System.out.print( (char) a[i] ); + break; + case ',': + String stringa = scanner.nextLine(); + a[i] = (byte) ( ( stringa.toCharArray() )[0] ); + break; + case '[': + if ( a[i] == 0 ) { + count++; + char key = charCode[count]; + count++; + for ( ; charCode[count] != key; count++ ) ; + count++; + } + break; + case ']': + if ( a[i] != 0 ) { + count --; + char key = charCode[count]; + count --; + for ( ; charCode[count] != key; count-- ) ; + } + break; + } + } + } +} +\ No newline at end of file diff --git a/pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk b/pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk @@ -0,0 +1,249 @@ +Programma che stampa il testo completo della canzone 99 bottles of beer + +########################## +### +### Severely updated version! +### (now says "1 bottle" and +### contains no extra "0" verse) +### +########################## +### 99 Bottles of Beer ### +### coded in Brainfuck ### +### with explanations ### +########################## +# +# This Bottles of Beer program +# was written by Andrew Paczkowski +# Coder Alias: thepacz +# three_halves_plus_one at yahoo dot com +##### + +> 0 in the zeroth cell ++++++++>++++++++++[<+++++>-] 57 in the first cell or "9" ++++++++>++++++++++[<+++++>-] 57 in second cell or "9" +++++++++++ 10 in third cell +>+++++++++ 9 in fourth cell + +########################################## +### create ASCII chars in higher cells ### +########################################## + +>>++++++++[<++++>-] " " +>++++++++++++++[<+++++++>-] b ++>+++++++++++[<++++++++++>-] o +++>+++++++++++++++++++[<++++++>-] t +++>+++++++++++++++++++[<++++++>-] t +>++++++++++++[<+++++++++>-] l ++>++++++++++[<++++++++++>-] e ++>+++++++++++++++++++[<++++++>-] s +>++++++++[<++++>-] " " ++>+++++++++++[<++++++++++>-] o +++>++++++++++[<++++++++++>-] f +>++++++++[<++++>-] " " +>++++++++++++++[<+++++++>-] b ++>++++++++++[<++++++++++>-] e ++>++++++++++[<++++++++++>-] e +>+++++++++++++++++++[<++++++>-] r +>++++++++[<++++>-] " " ++>+++++++++++[<++++++++++>-] o +>+++++++++++[<++++++++++>-] n +>++++++++[<++++>-] " " +++>+++++++++++++++++++[<++++++>-] t +++++>++++++++++[<++++++++++>-] h ++>++++++++++[<++++++++++>-] e +>++++++++[<++++>-] " " +++>+++++++++++++[<+++++++++>-] w ++>++++++++++++[<++++++++>-] a +>++++++++++++[<+++++++++>-] l +>++++++++++++[<+++++++++>-] l +>+++++[<++>-] LF +++>+++++++++++++++++++[<++++++>-] t ++>++++++++++++[<++++++++>-] a ++++>+++++++++++++[<++++++++>-] k ++>++++++++++[<++++++++++>-] e +>++++++++[<++++>-] " " ++>+++++++++++[<++++++++++>-] o +>+++++++++++[<++++++++++>-] n ++>++++++++++[<++++++++++>-] e +>++++++++[<++++>-] " " +>++++++++++[<++++++++++>-] d ++>+++++++++++[<++++++++++>-] o +++>+++++++++++++[<+++++++++>-] w +>+++++++++++[<++++++++++>-] n +>++++++++[<++++>-] " " ++>++++++++++++[<++++++++>-] a +>+++++++++++[<++++++++++>-] n +>++++++++++[<++++++++++>-] d +>++++++++[<++++>-] " " +++>+++++++++++[<++++++++++>-] p ++>++++++++++++[<++++++++>-] a ++>+++++++++++++++++++[<++++++>-] s ++>+++++++++++++++++++[<++++++>-] s +>++++++++[<++++>-] " " ++>+++++++++++++[<++++++++>-] i +++>+++++++++++++++++++[<++++++>-] t +>++++++++[<++++>-] " " ++>++++++++++++[<++++++++>-] a +>+++++++++++++++++++[<++++++>-] r ++>+++++++++++[<++++++++++>-] o +>+++++++++++++[<+++++++++>-] u +>+++++++++++[<++++++++++>-] n +>++++++++++[<++++++++++>-] d +>+++++[<++>-] LF ++++++++++++++ CR + +[<]>>>> go back to fourth cell + +################################# +### initiate the display loop ### +################################# + +[ loop + < back to cell 3 + [ loop + [>]<< go to last cell and back to LF + .. output 2 newlines + [<]> go to first cell + + ################################### + #### begin display of characters### + ################################### + # + #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #X X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l N + #[<]> go to first cell + #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> + #X X b o t t l e s o f b e e r N + #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #t a k e o n e d o w n a n d p a s s + #.>.>.>.>.>.>.>.>.>. + #i t a r o u n d N + ##### + + [<]>> go to cell 2 + - subtract 1 from cell 2 + < go to cell 1 + + ######################## + ### display last line ## + ######################## + # + #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #X X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l + ##### + + [<]>>>- go to cell 3/subtract 1 + ] end loop when cell 3 is 0 + ++++++++++ add 10 to cell 3 + <++++++++++ back to cell 2/add 10 + <- back to cell 1/subtract 1 + [>]<. go to last line/carriage return + [<]> go to first line + +######################## +### correct last line ## +######################## +# +#.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> +#X X b o t t l e s o f b e e r +#.>.>.>.>.>.>.>.>.>.>. +#o n t h e w a l l +##### + + [<]>>>>- go to cell 4/subtract 1 +] end loop when cell 4 is 0 + +############################################################## +### By this point verses 99\10 are displayed but to work ### +### with the lower numbered verses in a more readable way ### +### we initiate a new loop for verses 9{CODE} that will not ### +### use the fourth cell at all ### +############################################################## + ++ add 1 to cell four (to keep it non\zero) +<-- back to cell 3/subtract 2 + +[ loop + [>]<< go to last cell and back to LF + .. output 2 newlines + [<]> go to first cell + + ################################### + #### begin display of characters### + ################################### + # + #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + # X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l N + #[<]> go to first cell + #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> + # X b o t t l e s o f b e e r N + #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #t a k e o n e d o w n a n d p a s s + #.>.>.>.>.>.>.>.>.>. + #i t a r o u n d N + ##### + + [<]>> go to cell 2 + - subtract 1 from cell 2 + + ######################## + ### display last line ## + ######################## + # + #.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l + ##### + + [<]>>>- go to cell 3/subtract 1 +] end loop when cell 3 is 0 ++ add 1 to cell 3 to keep it non\zero + +[>]<. go to last line/carriage return +[<]> go to first line + +######################## +### correct last line ## +######################## +# +#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.> +# X b o t t l e o f b e e r +#.>.>.>.>.>.>.>.>.>.>.<<<<. +#o n t h e w a l l +##### + +[>]<< go to last cell and back to LF +.. output 2 newlines +[<]> go to first line + +######################### +### the final verse ## +######################### +# +#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.> +# X b o t t l e o f b e e r +#.>.>.>.>.>.>.>.>.>.>.>. +#o n t h e w a l l N +#[<]> go to first cell +#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> +# X b o t t l e o f b e e r N +#.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> +#t a k e o n e d o w n a n d p a s s +#.>.>.>.>.>.>.>.>.>. +#i t a r o u n d N +#[>]< go to last line +#<<<.<<.<<<. +# n o +#[<]>>>> go to fourth cell +#>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> +# b o t t l e s o f b e e r +#.>.>.>.>.>.>.>.>.>.>.>. +#o n t h e w a l l N +#####fin## +\ No newline at end of file diff --git a/pbfi/pbfi-1.1/src/Frame.java b/pbfi/pbfi-1.1/src/Frame.java @@ -0,0 +1,209 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; 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.BorderLayout; +import java.awt.event.*; +import java.io.*; + +public class Frame extends JFrame { +public static int valoreChooser; + public static boolean firstSave; + public static String defaultSave; + public static Main main; + public static JTextArea textArea; + public static JButton runButton; + public static JMenuBar bar; + public static JMenu menuFile, menuAiuto; + public static JMenuItem esci, esegui, salva, salvaConNome, apri, info; + public static JFileChooser chooser; + public static FileInputStream in; + public static FileOutputStream out; + public Frame() { + super( "Porky's BrainF** Interpreter - v1.1" ); + firstSave = true; + main = new Main(); + defaultSave = ""; + chooser = new JFileChooser(); + textArea = new JTextArea( "Digitare qui il codice BrainF***", 15, 15 ); + bar = new JMenuBar(); + menuFile = new JMenu( "File" ); + menuAiuto = new JMenu( "?" ); + esci = new JMenuItem( "Esci" ); + esegui = new JMenuItem( "Esegui" ); + salva = new JMenuItem( "Salva" ); + salvaConNome = new JMenuItem( "Salva con nome" ); + apri = new JMenuItem( "Apri" ); + info = new JMenuItem( "Aiuto" ); + menuFile.setMnemonic( 'F' ); + menuAiuto.setMnemonic( '?' ); + esci.setMnemonic( 'E' ); + esegui.setMnemonic( 's' ); + salva.setMnemonic( 'a' ); + salvaConNome.setMnemonic( 'n' ); + apri.setMnemonic( 'p' ); + info.setMnemonic( 'i' ); + esci.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + System.exit( 0 ); + } + } + ); + esegui.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + salva.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + if ( firstSave ) { + valoreChooser = chooser.showSaveDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + out = new FileOutputStream( chooser.getSelectedFile().getPath() ); + defaultSave = chooser.getSelectedFile().getPath(); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + firstSave = false; + } else { + try { + out = new FileOutputStream( defaultSave ); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + } + } + } + ); + salvaConNome.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + valoreChooser = chooser.showSaveDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + out = new FileOutputStream( chooser.getSelectedFile().getPath() ); + defaultSave = chooser.getSelectedFile().getPath(); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + firstSave = false; + } + } + ); + apri.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + valoreChooser = chooser.showOpenDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + String stringa; + byte bytes[]; + char caratteri[]; + in = new FileInputStream( chooser.getSelectedFile().getPath() ); + bytes = new byte[in.available()]; + caratteri = new char[in.available()]; + in.read( bytes ); + for ( int i = 0; i < bytes.length; i++ ) + caratteri[i] = ( char ) bytes[i]; + stringa = new String( caratteri ); + textArea.setText( stringa ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + } + } + ); + info.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + JOptionPane.showMessageDialog( Frame.this, "Brainfuck è un linguaggio di programmazione esoterico per computer,\ncreato da Urban Müller intorno al 1993. Il linguaggio viene\nin taluni casi denominato Brainf*ck, Brainf***\no anche soltanto BF per evitare di offendere\nla sensibilità altrui.\nNella cartella src trovate alcuni esempi di programmi in questo linguaggio.\n\nPer maggiori informazioni visitate la pagina:\nhttp://it.wikipedia.org/wiki/Brainfuck", "BrainF*** - Informazioni", JOptionPane.INFORMATION_MESSAGE ); + } + } + ); + menuFile.add( esegui ); + menuFile.add( salva ); + menuFile.add( salvaConNome ); + menuFile.add( apri ); + menuFile.add( esci ); + menuAiuto.add( info ); + bar.add( menuFile ); + bar.add( menuAiuto ); + runButton = new JButton( "Esegui" ); + runButton.addActionListener( + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + setLayout( new BorderLayout() ); + setJMenuBar( bar ); + add( new JScrollPane( textArea ), BorderLayout.CENTER ); + add( runButton, BorderLayout.SOUTH ); + } +} +\ No newline at end of file diff --git a/pbfi/pbfi-1.1/src/HelloWorld.bfk b/pbfi/pbfi-1.1/src/HelloWorld.bfk @@ -0,0 +1,20 @@ +Questo è un esempio Hello World in BrainFuck (fonte: wikipedia) +notare che tutti i caratteri diversi dagli 8 comandi sono considerati un commento + +++++++++++ +[ + >+++++++>++++++++++>+++>+<<<<- +] +>++. Loop iniziale (dopo viene stampata una H) +>+. e ++++++++. l +. l ++++. o +>++. +<<+++++++++++++++. +>. ++++. +------. +--------. +>+. +>. diff --git a/pbfi/pbfi-1.1/src/Main.java b/pbfi/pbfi-1.1/src/Main.java @@ -0,0 +1,119 @@ +/* +Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; +import java.util.Scanner; +public class Main { + public static Scanner scanner; + public static char totalCode[], charCodeAux[], charCode[], chars; + public static byte a[]; + public static int i; + public static void main( String args[] ) { + Frame frame = new Frame(); + frame.setSize( 200, 300 ); + frame.setVisible( true ); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + } + public static void run( String code ) { + chars = 'a'; + int j = 0; + totalCode = code.toCharArray(); + charCodeAux = new char[totalCode.length*2]; + for ( int k = 0; k < totalCode.length; k++ ) { + switch ( totalCode[k] ) { + case '>': + case '<': + case '+': + case '-': + case '.': + case ',': + charCodeAux[j] = totalCode[k]; + j++; + break; + case '[': + charCodeAux[j] = totalCode[k]; + j++; + charCodeAux[j] = chars; + chars++; + j++; + break; + case ']': + chars--; + charCodeAux[j] = chars; + j++; + charCodeAux[j] = totalCode[k]; + j++; + break; + } + } + charCode = new char[j]; + for ( int k = 0; k < charCode.length; k++ ) + charCode[k] = charCodeAux[k]; + scanner = new Scanner( System.in ); + a = new byte[30000]; + for ( int count = 0; count < a.length; count++ ) + a[count] = 0; + i = 0; + execute( scanner, charCode, a, i, 0, charCode.length ); + } + public static void execute( Scanner scanner, char charCode[], byte a[], int i, int start, int stop ) { + for ( int count = start; count < stop; count++ ) { + switch ( charCode[count] ) { + case '>': + i++; + break; + case '<': + i--; + break; + case '+': + a[i]++; + break; + case '-': + a[i]--; + break; + case '.': + System.out.print( (char) a[i] ); + break; + case ',': + String stringa = scanner.nextLine(); + a[i] = (byte) ( ( stringa.toCharArray() )[0] ); + break; + case '[': + if ( a[i] == 0 ) { + count++; + char key = charCode[count]; + count++; + for ( ; charCode[count] != key; count++ ) ; + count++; + } + break; + case ']': + if ( a[i] != 0 ) { + count --; + char key = charCode[count]; + count --; + for ( ; charCode[count] != key; count-- ) ; + } + break; + } + } + } +} +\ No newline at end of file diff --git a/pbfi/pbfi-1.1/src/Quine.bfk b/pbfi/pbfi-1.1/src/Quine.bfk @@ -0,0 +1,13 @@ +Questo programma è un esempio di quine (programma che mostra in output il suo codice sorgente) in BrainFuck (fonte: wikipedia) + + ->+>+++>>+>++>+>+++>>+>++>>>+>+>+>++>+>>>>+++>+>>++>+>+++>>++>++>>+>>+>++>++> + +>>>>+++>+>>>>++>++>>>>+>>++>+>+++>>>++>>++++++>>+>>++>+>>>>+++>>+++++>>+>+++ + >>>++>>++>>+>>++>+>+++>>>++>>+++++++++++++>>+>>++>+>+++>+>+++>>>++>>++++>>+>> + ++>+>>>>+++>>+++++>>>>++>>>>+>+>++>>+++>+>>>>+++>+>>>>+++>+>>>>+++>>++>++>+>+ + ++>+>++>++>>>>>>++>+>+++>>>>>+++>>>++>+>+++>+>+>++>>>>>>++>>>+>>>++>+>>>>+++> + +>>>+>>++>+>++++++++++++++++++>>>>+>+>>>+>>++>+>+++>>>++>>++++++++>>+>>++>+>> + >>+++>>++++++>>>+>++>>+++>+>+>++>+>+++>>>>>+++>>>+>+>>++>+>+++>>>++>>++++++++ + >>+>>++>+>>>>+++>>++++>>+>+++>>>>>>++>+>+++>>+>++>>>>+>+>++>+>>>>+++>>+++>>>+ + [[->>+<<]<+]+++++[->+++++++++<]>.[+]>>[<<+++++++[->+++++++++<]>- + .------------------->-[-<.<+>>]<[+]<+>>>]<<<[-[-[-[>>+<++++++[->+++++<]]>++++ + ++++++++++<]>+++<]++++++[->+++++++<]>+<<<-[->>>++<<<]>[->>.<<]<<] diff --git a/robottino/Robottino.jar b/robottino/Robottino.jar Binary files differ. diff --git a/robottino/all_versions/Changelog.txt b/robottino/all_versions/Changelog.txt @@ -0,0 +1,20 @@ +v1.0: La prima versione. + +v2.0: Aggiunte funzionalità crea/rinomina/cambia robottino. + +v2.1: Sostituiti gli array con i Vector. Aggiunta funzionalità elimina robottino. + +v2.2: Agiunta la finestra. + +v2.3: Aggiunte le funzioni per dare comandi attraverso la finestra. + + Non è più possibile dare comandi a linea di comando. +v3.0: Aggiunta delle immagini. + +v4.0: Cambiata la grafica da awt a swing. + Finalmente ad ogni comando il robottino si muove e non è più presente + l'output a riga di comando. Molte delle vecchie funzioni devono essere re-implementate. + +v4.0.1: Fixato il bug di sfarfallio - immagini tagliate. + +v4.1: Re-implementate tute le vecchie funzioni. diff --git a/robottino/all_versions/v1.0/Esegui.bat b/robottino/all_versions/v1.0/Esegui.bat @@ -0,0 +1,2 @@ +cd ./bin +java Robottino diff --git a/robottino/all_versions/v1.0/Esegui.sh b/robottino/all_versions/v1.0/Esegui.sh @@ -0,0 +1,2 @@ +cd ./bin +java Robottino diff --git a/robottino/all_versions/v1.0/Readme.txt b/robottino/all_versions/v1.0/Readme.txt @@ -0,0 +1,10 @@ +Il programma necessita della JVM (Java Virtual Machine) per funzionare correttamente + +Se si usano sistemi Windows aprire il file Esegui.bat +Se si usano sistemi Unix dare i permessi necessari ed eseguire il file Esegui.sh +Se si usano altri sistemi aprire una shell e digitare i comandi + +cd <percorsoFile>/bin +java Robottino + +dove percorsoFile è il percorso di questo file. diff --git a/robottino/all_versions/v1.0/bin/PartiDelRobot.class b/robottino/all_versions/v1.0/bin/PartiDelRobot.class Binary files differ. diff --git a/robottino/all_versions/v1.0/bin/Robottino.class b/robottino/all_versions/v1.0/bin/Robottino.class Binary files differ. diff --git a/robottino/all_versions/v1.0/src/PartiDelRobot.java b/robottino/all_versions/v1.0/src/PartiDelRobot.java @@ -0,0 +1,9 @@ +class PartiDelRobot { + PartiDelRobot() { }; + PartiDelRobot(boolean b, String s) { + this.stringaParte = s; + this.statoParte = b; + } + public String stringaParte; + public boolean statoParte; +} diff --git a/robottino/all_versions/v1.0/src/Robottino.java b/robottino/all_versions/v1.0/src/Robottino.java @@ -0,0 +1,160 @@ +import java.util.Scanner; +class Robottino extends PartiDelRobot { + public static void main(String argv[]) { + Robottino robot = new Robottino(); + PartiDelRobot pdr[] = { new PartiDelRobot (false, "il braccio sinistro alzato"), + new PartiDelRobot (false, "il braccio destro alzato"), + new PartiDelRobot (false, "la gamba sinistra alzata"), + new PartiDelRobot (false, "la gamba destra alzata") }; + Scanner sc = new Scanner(System.in); + String comando; + String nomeRobot[] = { "" }; + System.out.println("**********************************************"); + System.out.println("**********************************************"); + System.out.println("*************Programma interattivo************"); + System.out.println("**********************************************"); + System.out.println("***Software realizzato da Sebastiano Tronto***"); + System.out.println("**********************************************"); + System.out.println("**********************************************"); + System.out.println("Questo programma simula un robot al quale ven-"); + System.out.println("gono assegnati ordini tramite comandi, simil-" ); + System.out.println("mente a quanto bisognava fare con i computer " ); + System.out.println("alcuni anni fa." ); + System.out.println("Dato che all'epoca i comandi che dovevano es-" ); + System.out.println("sere dati erano (e sono tutt'ora) in similin-" ); + System.out.println("glese, ho cercato di mantenerli tali." ); + System.out.println("Il programma non fa distinzioni tra lettere" ); + System.out.println("maiuscole o minuscole." ); + System.out.println("" ); + System.out.println("Digita un comando e premi invio" ); + System.out.println("l = legenda comandi" ); + do { + comando = sc.nextLine(); + System.out.println ("Siamo spiacenti, ma per motivi tecnici non sono in grado di visualizzare l'immagine del robot."); + System.out.println (robot.Azioni(comando, nomeRobot, pdr)); + } while ( !(comando.equalsIgnoreCase("exit")) ); + } + String Azioni(String comando, String nomeRobot[], PartiDelRobot pdr[]) { + Scanner sc2 = new Scanner(System.in); + int contatore = 0; + String stat[] = {"", "", "", ""}; + String Return = "Errore - si consiglia di picchiare il programmatore"; + if (comando.equalsIgnoreCase("leftarmmove")) + pdr[0].statoParte = !pdr[0].statoParte; + else if (comando.equalsIgnoreCase("rightarmmove")) + pdr[1].statoParte = !pdr[1].statoParte; + else if (comando.equalsIgnoreCase("leftlegmove")) + pdr[2].statoParte = !pdr[2].statoParte; + else if (comando.equalsIgnoreCase("rightlegmove")) + pdr[3].statoParte = !pdr[3].statoParte; + else if (comando.equalsIgnoreCase("leftarmon")) + pdr[0].statoParte = true; + else if (comando.equalsIgnoreCase("rightarmon")) + pdr[1].statoParte = true; + else if (comando.equalsIgnoreCase("leftlegon")) + pdr[2].statoParte = true; + else if (comando.equalsIgnoreCase("rightlegon")) + pdr[3].statoParte = true; + else if (comando.equalsIgnoreCase("leftarmoff")) + pdr[0].statoParte = false; + else if (comando.equalsIgnoreCase("rightarmoff")) + pdr[1].statoParte = false; + else if (comando.equalsIgnoreCase("leftlegoff")) + pdr[2].statoParte = false; + else if (comando.equalsIgnoreCase("rightlegoff")) + pdr[3].statoParte = false; + else if (comando.equalsIgnoreCase("exploud")) { + System.out.println ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot[0] + "! Aspetta che te ne faccio un altro"); + System.out.println ("..."); + for (int i = 0; i < pdr.length; i++) { + pdr[i].statoParte = false; + } + nomeRobot[0] = ""; + return "Fatto, puoi continuare a giocare"; + } + else if (comando.equalsIgnoreCase("bier")) { + System.out.println ("Il robottino " + nomeRobot[0] + "sta trangugiando una birra..."); + System.out.println ("Buurrrrrrrrp!"); + return "La birra analcolica fa schifo!"; + } + else if (comando.equalsIgnoreCase("rename")) { + System.out.println ("Con questo comando quoi cambiare il nome del robottino " + nomeRobot[0]); + System.out.println ("Digita il nuovo nome e premi invio per coninuare"); + nomeRobot[0] = sc2.nextLine(); + if (!(nomeRobot[0].equalsIgnoreCase(""))) + nomeRobot[0] += " "; + return "Ora il robottino si chiama " + nomeRobot[0]; + } + else if (comando.equalsIgnoreCase("porky")) { + System.out.println ("Porky è un grande"); + System.out.println ("Per maggiori informazioni visita il sito"); + return "http://kakati.forumfree.net/"; + } + else if (comando.equalsIgnoreCase("xxx")) { + System.out.println ("Il robottino " + nomeRobot[0] + "ha incontrato una bella robottina..."); + return "*Censura*"; + } + else if (comando.equalsIgnoreCase("l")) { + System.out.println ("Legenda comandi"); + System.out.println (""); + System.out.println ("LeftArmMove: cambia la posizione corrente del braccio sinistro del robot"); + System.out.println ("RightArmMove: cambia la posizione corrente del braccio destro del robot"); + System.out.println ("LeftLegMove: cambia la posizione corrente della gamba sinistra del robot"); + System.out.println ("RightLegMove: cambia la posizione corrente della gamba destra del robot"); + System.out.println ("LeftArmOn: se il braccio sinistro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOn: se il braccio destro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOn: se la gamba sinistra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOn: se la gamba destra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftArmOff: se il braccio sinistro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOff: se il braccio destro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOff: se la gamba sinistra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOff: se la gamba destra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println ("Exit: esci dal programma"); + System.out.println (""); + System.out.println ("Comandi a sorpresa:"); + System.out.println (""); + System.out.println ("Exploud"); + System.out.println ("Bier"); + System.out.println ("Rename"); + System.out.println ("Porky"); + System.out.println ("xxx"); + return ""; + + } + else + System.out.println ("Comando non riconosciuto - digitare l per una legenda dei comandi disponibili"); + for (int i = 0, j = 0; i < pdr.length; i++) { + if (pdr[i].statoParte) { + contatore += 1; + stat[j++] = pdr[i].stringaParte; + } + } + switch (contatore) { + case 0: + Return = "Comunque il robottino " + nomeRobot[0] + "non sta facendo niente"; + break; + case 1: + Return = "Immagini che il robottino " + nomeRobot[0] + "abbia " + stat[0] + "."; + break; + case 2: + Return = "Immagini che il robottino " + nomeRobot[0] + "abbia " + stat[0] + " e " + stat[1] + "."; + break; + case 3: + Return = "Immagini che il robottino " + nomeRobot[0] + "abbia " + stat[0] + ", " + stat[1] + " e " + stat[2] + "."; + break; + case 4: + Return = "Immagini che il robottino " + nomeRobot[0] + "abbia " + stat[0] + ", " + stat[1] + ", " + stat[2] + " e " + stat[3] + "."; + break; + } + return Return; + } +} + + + + + + + + + diff --git a/robottino/all_versions/v2.0/Esegui.bat b/robottino/all_versions/v2.0/Esegui.bat @@ -0,0 +1,2 @@ +cd ./bin +java Robottino diff --git a/robottino/all_versions/v2.0/Esegui.sh b/robottino/all_versions/v2.0/Esegui.sh @@ -0,0 +1,2 @@ +cd ./bin +java Robottino diff --git a/robottino/all_versions/v2.0/Readme.txt b/robottino/all_versions/v2.0/Readme.txt @@ -0,0 +1,10 @@ +Il programma necessita della JVM (Java Virtual Machine) per funzionare correttamente + +Se si usano sistemi Windows aprire il file Esegui.bat +Se si usano sistemi Unix dare i permessi necessari ed eseguire il file Esegui.sh +Se si usano altri sistemi aprire una shell e digitare i comandi + +cd <percorsoFile>/bin +java Robottino + +dove percorsoFile è il percorso di questo file. diff --git a/robottino/all_versions/v2.0/bin/PartiDelRobot.class b/robottino/all_versions/v2.0/bin/PartiDelRobot.class Binary files differ. diff --git a/robottino/all_versions/v2.0/bin/Robottino.class b/robottino/all_versions/v2.0/bin/Robottino.class Binary files differ. diff --git a/robottino/all_versions/v2.0/src/PartiDelRobot.java b/robottino/all_versions/v2.0/src/PartiDelRobot.java @@ -0,0 +1,9 @@ +public class PartiDelRobot { + PartiDelRobot() { }; + PartiDelRobot(boolean b, String s) { + this.stringaParte = s; + this.statoParte = b; + } + public String stringaParte; + public boolean statoParte; +} diff --git a/robottino/all_versions/v2.0/src/Robottino.java b/robottino/all_versions/v2.0/src/Robottino.java @@ -0,0 +1,270 @@ +import java.util.Scanner; +class Robottino extends PartiDelRobot { + static PartiDelRobot pdr[][] = { + { + new PartiDelRobot (false, "il braccio sinistro alzato"), + new PartiDelRobot (false, "il braccio destro alzato"), + new PartiDelRobot (false, "la gamba sinistra alzata"), + new PartiDelRobot (false, "la gamba destra alzata") + } + }; + static String nomeRobot[] = { "" }; + int robotIndex = 0; + public static void main(String argv[]) { + Scanner sc = new Scanner(System.in); + String comando; + Robottino robottino = new Robottino(); + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("*************Programma interattivo************"); + System.out.println ("**********************************************"); + System.out.println ("***Software realizzato da Sebastiano Tronto***"); + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("Questo programma simula un robot al quale ven-"); + System.out.println ("gono assegnati ordini tramite comandi, simil-" ); + System.out.println ("mente a quanto bisognava fare con i computer " ); + System.out.println ("alcuni anni fa." ); + System.out.println ("Dato che all'epoca i comandi che dovevano es-" ); + System.out.println ("sere dati erano (e sono tutt'ora) in similin-" ); + System.out.println ("glese, ho cercato di mantenerli tali." ); + System.out.println ("Il programma non fa distinzioni tra lettere" ); + System.out.println ("maiuscole o minuscole." ); + System.out.println ("In questa versione non sono ancora disponibi-" ); + System.out.println ("li immagini e/o effetti grafici." ); + System.out.println ("" ); + System.out.println ("Digita un comando e premi INVIO" ); + System.out.println ("l = legenda comandi" ); + System.out.println (""); + do { + comando = sc.nextLine(); + System.out.println (""); + System.out.println (robottino.Azioni(comando, nomeRobot, pdr)); + System.out.println (""); + } while ( !(comando.equalsIgnoreCase("exit")) ); + } + String Azioni(String comando, String nomeRobot[], PartiDelRobot pdr[][]) { + Scanner sc2 = new Scanner(System.in); + int contatore = 0; + String stat[] = {"", "", "", ""}; + String Return = "Errore - si consiglia di picchiare il programmatore"; + if (comando.equalsIgnoreCase("leftarmmove")) + this.pdr[this.robotIndex][0].statoParte = !this.pdr[this.robotIndex][0].statoParte; + else if (comando.equalsIgnoreCase("rightarmmove")) + this.pdr[this.robotIndex][1].statoParte = !this.pdr[this.robotIndex][1].statoParte; + else if (comando.equalsIgnoreCase("leftlegmove")) + this.pdr[this.robotIndex][2].statoParte = !this.pdr[this.robotIndex][2].statoParte; + else if (comando.equalsIgnoreCase("rightlegmove")) + this.pdr[this.robotIndex][3].statoParte = !this.pdr[this.robotIndex][3].statoParte; + else if (comando.equalsIgnoreCase("leftarmon")) + this.pdr[this.robotIndex][0].statoParte = true; + else if (comando.equalsIgnoreCase("rightarmon")) + this.pdr[this.robotIndex][1].statoParte = true; + else if (comando.equalsIgnoreCase("leftlegon")) + this.pdr[this.robotIndex][2].statoParte = true; + else if (comando.equalsIgnoreCase("rightlegon")) + this.pdr[this.robotIndex][3].statoParte = true; + else if (comando.equalsIgnoreCase("leftarmoff")) + this.pdr[this.robotIndex][0].statoParte = false; + else if (comando.equalsIgnoreCase("rightarmoff")) + this.pdr[this.robotIndex][1].statoParte = false; + else if (comando.equalsIgnoreCase("leftlegoff")) + this.pdr[this.robotIndex][2].statoParte = false; + else if (comando.equalsIgnoreCase("rightlegoff")) + this.pdr[this.robotIndex][3].statoParte = false; + else if (comando.equalsIgnoreCase("exploud")) { + System.out.println ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot[this.robotIndex] + "! Aspetta che te ne faccio un altro"); + System.out.println ("..."); + for (int i = 0; i < pdr[this.robotIndex].length; i++) { + pdr[this.robotIndex][i].statoParte = false; + } + nomeRobot[this.robotIndex] = ""; + return "Fatto, puoi continuare a giocare"; + } + else if (comando.equalsIgnoreCase("bier")) { + System.out.println ("Il robottino " + nomeRobot[this.robotIndex] + "sta trangugiando una birra..."); + System.out.println ("Buurrrrrrrrp!"); + return "La birra analcolica fa schifo!"; + } + else if (comando.equalsIgnoreCase("rename")) { + System.out.println ("Con questo comando quoi cambiare il nome del robottino " + nomeRobot[this.robotIndex]); + System.out.println ("Digita il nuovo nome e premi invio per coninuare"); + nomeRobot[this.robotIndex] = sc2.nextLine(); + if (!(nomeRobot[this.robotIndex].equalsIgnoreCase(""))) + nomeRobot[this.robotIndex] += " "; + return "Ora il robottino si chiama " + nomeRobot[this.robotIndex]; + } + else if (comando.equalsIgnoreCase("porky")) { + System.out.println ("Porky è un grande"); + System.out.println ("Per maggiori informazioni visita il sito"); + return "http://kakati.forumfree.net/"; + } + else if (comando.equalsIgnoreCase("xxx")) { + System.out.println ("Il robottino " + nomeRobot[this.robotIndex] + "ha incontrato una bella robottina..."); + return "*Censura*"; + } + else if (comando.equalsIgnoreCase("dance")) { + System.out.println ("Immagini che il robottino " + nomeRobot[this.robotIndex] + " stia ballando..."); + System.out.println ("Il robottino ha smesso di ballare"); + for (int i = 0; i < pdr[this.robotIndex].length; i++) { + pdr[0][i].statoParte = false; + } + return "Il robottino " + nomeRobot[this.robotIndex] + "si è fermato ed è tornato nella posizione originale"; + } + else if (comando.equalsIgnoreCase("newrobot")) { + PartiDelRobot pdrAus[][] = new PartiDelRobot[(addRobot(this.pdr, this.pdr[this.robotIndex])).length][(addRobot(this.pdr, this.pdr[this.robotIndex]))[(addRobot(this.pdr, this.pdr[this.robotIndex])).length-1].length]; + this.pdr = new PartiDelRobot[pdrAus.length][pdrAus[pdrAus.length-1].length]; + for (int i=0; i<pdrAus.length; i++) { + for (int j=0; j<pdrAus[i].length; j++) { + pdrAus[i][j] = (addRobot(pdr, pdr[this.robotIndex]))[i][j]; + pdrAus[i][j].stringaParte = (addRobot(pdr, pdr[this.robotIndex]))[i][j].stringaParte; + pdrAus[i][j].statoParte = (addRobot(pdr, pdr[this.robotIndex]))[i][j].statoParte; + } + } + for (int i=0; i<this.pdr.length; i++) { + for (int j=0; j<this.pdr[i].length; j++) { + this.pdr[i][j] = pdrAus[i][j]; + this.pdr[i][j].stringaParte = pdrAus[i][j].stringaParte; + this.pdr[i][j].statoParte = pdrAus[i][j].statoParte; + } + } + System.out.println ("È stato creato un nuovo robot. Vuoi dare un nome al nuovo robot?"); + System.out.println ("Inserisci il nuovo nome e premi INVIO oppure lascia vuoto e premi INVIO"); + String newName = sc2.nextLine(); + String nomeRobotAus[] = new String[(addName(this.nomeRobot, newName)).length]; + this.nomeRobot = new String[nomeRobotAus.length]; + for (int i=0; i<nomeRobotAus.length; i++) { + nomeRobotAus[i] = (addName(nomeRobot, newName))[i]; + } + for (int i=0; i<nomeRobotAus.length; i++) { + this.nomeRobot[i] = nomeRobotAus[i]; + } + return "È stato creato il robottino " + newName; + } + else if (comando.equalsIgnoreCase("deleterobot")) + return "Comando non disponibile in questa versione del programma"; + else if (comando.equalsIgnoreCase("changerobot")) { + if (pdr.length==1) { + return "Hai solo un robottino, non puoi cambiarlo con un altro!"; + } + else { + System.out.println ("A quale robottino vuoi dare i comandi?"); + System.out.println (""); + for (int numRobot = 0; numRobot<this.pdr.length; numRobot++) { + System.out.println (numRobot + ". " + this.nomeRobot[numRobot]); + } + System.out.println (""); + System.out.println ("Digita il numero corrispondente alla tua scelta e premi INVIO"); + this.robotIndex = sc2.nextInt(); + if (this.robotIndex<this.pdr.length) + return "È stato selezionato il robottino numero " + this.robotIndex + ": " + this.nomeRobot[this.robotIndex]; + else + return "Numero non valido"; + } + } + else if (comando.equalsIgnoreCase("robotlist")) { + for (int numRobot = 0; numRobot<this.pdr.length; numRobot++) { + System.out.println (numRobot + ". " + this.nomeRobot[numRobot]); + } + return ""; + } + else if (comando.equalsIgnoreCase("l")) { + System.out.println ("Legenda comandi"); + System.out.println (""); + System.out.println ("Comandi relativi agli arti"); + System.out.println (""); + System.out.println ("LeftArmMove: cambia la posizione corrente del braccio sinistro del robot"); + System.out.println ("RightArmMove: cambia la posizione corrente del braccio destro del robot"); + System.out.println ("LeftLegMove: cambia la posizione corrente della gamba sinistra del robot"); + System.out.println ("RightLegMove: cambia la posizione corrente della gamba destra del robot"); + System.out.println ("LeftArmOn: se il braccio sinistro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOn: se il braccio destro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOn: se la gamba sinistra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOn: se la gamba destra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftArmOff: se il braccio sinistro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOff: se il braccio destro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOff: se la gamba sinistra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOff: se la gamba destra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println (""); + System.out.println ("Altri comandi:"); + System.out.println (""); + System.out.println ("NewRobot: aggiunge un nuovo robot"); + System.out.println ("ChangeRobot: cambia il robot attuale"); + System.out.println ("RobotList: visualizza la lista dei robot"); + System.out.println ("Rename: rinomina il robottino"); + System.out.println (""); + System.out.println ("Comandi a sorpresa:"); + System.out.println (""); + System.out.println ("Exploud"); + System.out.println ("Bier"); + System.out.println ("Porky"); + System.out.println ("xxx"); + System.out.println ("dance"); + System.out.println (""); + System.out.println ("Exit: esci dal programma"); + return ""; + + } + else if (comando.equalsIgnoreCase("exit")) + return ""; + else + System.out.println ("Comando non riconosciuto - digitare l per una legenda dei comandi disponibili"); + System.out.println (""); + for (int i = 0, j = 0; i < pdr[this.robotIndex].length; i++) { + if (pdr[robotIndex][i].statoParte) { + contatore += 1; + stat[j++] = pdr[this.robotIndex][i].stringaParte; + } + } + switch (contatore) { + case 0: + Return = "Comunque il robottino " + nomeRobot[this.robotIndex] + "non sta facendo niente"; + break; + case 1: + Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + "."; + break; + case 2: + Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + " e " + stat[1] + "."; + break; + case 3: + Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + ", " + stat[1] + " e " + stat[2] + "."; + break; + case 4: + Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + ", " + stat[1] + ", " + stat[2] + " e " + stat[3] + "."; + break; + } + return Return; + } + static PartiDelRobot[][] addRobot(PartiDelRobot pdrOld[][], PartiDelRobot pdrElement[]) { + PartiDelRobot pdrNew[][] = new PartiDelRobot [pdrOld.length+1][pdrOld[pdrOld.length-1].length]; + for (int i=0; i<pdrOld.length; i++) { + for (int j=0; j<pdrOld[i].length; j++) { + pdrNew[i][j] = new PartiDelRobot(pdrOld[i][j].statoParte, pdrOld[i][j].stringaParte); + } + } + for (int i=0; i<pdrElement.length; i++) { + pdrNew[pdrNew.length-1][i] = new PartiDelRobot(false, pdrElement[i].stringaParte); + } + return pdrNew; + } + static String[] addName(String nomeRobot[], String name) { + String nomeNewRobot[] = new String [nomeRobot.length+1]; + for (int i=0; i<nomeRobot.length; i++) { + nomeNewRobot[i] = nomeRobot[i]; + } + nomeNewRobot[nomeNewRobot.length-1] = name; + if (!(nomeNewRobot[nomeNewRobot.length-1].equalsIgnoreCase(""))) { + nomeNewRobot[nomeNewRobot.length-1] += " "; + } + return nomeNewRobot; + } +} + + + + + + + + + diff --git a/robottino/all_versions/v2.1/Esegui.bat b/robottino/all_versions/v2.1/Esegui.bat @@ -0,0 +1,2 @@ +cd ./bin +java Robottino diff --git a/robottino/all_versions/v2.1/Esegui.sh b/robottino/all_versions/v2.1/Esegui.sh @@ -0,0 +1,2 @@ +cd ./bin +java Robottino diff --git a/robottino/all_versions/v2.1/Readme.txt b/robottino/all_versions/v2.1/Readme.txt @@ -0,0 +1,10 @@ +Il programma necessita della JVM (Java Virtual Machine) per funzionare correttamente + +Se si usano sistemi Windows aprire il file Esegui.bat +Se si usano sistemi Unix dare i permessi necessari ed eseguire il file Esegui.sh +Se si usano altri sistemi aprire una shell e digitare i comandi + +cd <percorsoFile>/bin +java Robottino + +dove percorsoFile è il percorso di questo file. diff --git a/robottino/all_versions/v2.1/bin/PartiDelRobot.class b/robottino/all_versions/v2.1/bin/PartiDelRobot.class Binary files differ. diff --git a/robottino/all_versions/v2.1/bin/Robottino.class b/robottino/all_versions/v2.1/bin/Robottino.class Binary files differ. diff --git a/robottino/all_versions/v2.1/src/PartiDelRobot.java b/robottino/all_versions/v2.1/src/PartiDelRobot.java @@ -0,0 +1,9 @@ +public class PartiDelRobot { + PartiDelRobot() { }; + PartiDelRobot(boolean b, String s) { + this.stringaParte = s; + this.statoParte = b; + } + public String stringaParte; + public boolean statoParte; +} diff --git a/robottino/all_versions/v2.1/src/Robottino.java b/robottino/all_versions/v2.1/src/Robottino.java @@ -0,0 +1,258 @@ +import java.util.Scanner; +import java.util.Vector; +class Robottino extends PartiDelRobot { + static Robottino robottino = new Robottino(); + static Vector pdrA = new Vector(1); + static Vector pdrB = new Vector(4); + static PartiDelRobot leftArm = new PartiDelRobot(false, "il braccio sinistro alzato"); + static PartiDelRobot rightArm = new PartiDelRobot(false, "il braccio destro alzato"); + static PartiDelRobot leftLeg = new PartiDelRobot(false, "la gamba sinistra alzata"); + static PartiDelRobot rightLeg = new PartiDelRobot(false, "la gamba destra alzata"); + static Vector nomeRobot = new Vector(1); + static int robotIndex = 0; + public static void main(String argv[]) { + pdrB.addElement(leftArm); + pdrB.addElement(rightArm); + pdrB.addElement(leftLeg); + pdrB.addElement(rightLeg); + pdrA.addElement(pdrB); + nomeRobot.addElement(""); + Scanner sc = new Scanner(System.in); + String comando; + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("*************Programma interattivo************"); + System.out.println ("**********************************************"); + System.out.println ("***Software realizzato da Sebastiano Tronto***"); + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("Questo programma simula un robot al quale ven-"); + System.out.println ("gono assegnati ordini tramite comandi, simil-" ); + System.out.println ("mente a quanto bisognava fare con i computer " ); + System.out.println ("alcuni anni fa." ); + System.out.println ("Dato che all'epoca i comandi che dovevano es-" ); + System.out.println ("sere dati erano (e sono tutt'ora) in similin-" ); + System.out.println ("glese, ho cercato di mantenerli tali." ); + System.out.println ("Il programma non fa distinzioni tra lettere" ); + System.out.println ("maiuscole o minuscole." ); + System.out.println ("In questa versione non sono ancora disponibi-" ); + System.out.println ("li immagini e/o effetti grafici." ); + System.out.println ("" ); + System.out.println ("Digita un comando e premi INVIO" ); + System.out.println ("l = legenda comandi" ); + System.out.println (""); + do { + comando = sc.nextLine(); + System.out.println (""); + System.out.println (robottino.Azioni(comando, nomeRobot, pdrA)); + System.out.println (""); + } while ( !(comando.equalsIgnoreCase("exit")) ); + } + String Azioni(String comando, Vector nomeRobot, Vector pdrA) { + Scanner sc2 = new Scanner(System.in); + int contatore = 0; + String stat[] = {"", "", "", ""}; + String Return = "Errore - si consiglia di picchiare il programmatore"; + if (comando.equalsIgnoreCase("leftarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte; + else if (comando.equalsIgnoreCase("rightarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte; + else if (comando.equalsIgnoreCase("leftlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte; + else if (comando.equalsIgnoreCase("rightlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte; + else if (comando.equalsIgnoreCase("leftarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = true; + else if (comando.equalsIgnoreCase("rightarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = true; + else if (comando.equalsIgnoreCase("leftlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = true; + else if (comando.equalsIgnoreCase("rightlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = true; + else if (comando.equalsIgnoreCase("leftarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = false; + else if (comando.equalsIgnoreCase("rightarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = false; + else if (comando.equalsIgnoreCase("leftlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = false; + else if (comando.equalsIgnoreCase("rightlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = false; + else if (comando.equalsIgnoreCase("exploud")) { + System.out.println ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot.elementAt(this.robotIndex) + "! Aspetta che te ne faccio un altro"); + System.out.println ("..."); + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + this.nomeRobot.setElementAt("", this.robotIndex); + return "Fatto, puoi continuare a giocare"; + } + else if (comando.equalsIgnoreCase("bier")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "sta trangugiando una birra..."); + System.out.println ("Buurrrrrrrrp!"); + return "La birra analcolica fa schifo!"; + } + else if (comando.equalsIgnoreCase("rename")) { + System.out.println ("Con questo comando quoi cambiare il nome del robottino " + nomeRobot.elementAt(this.robotIndex)); + System.out.println ("Digita il nuovo nome e premi invio per coninuare"); + this.nomeRobot.setElementAt(sc2.nextLine(), this.robotIndex); + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + return "Ora il robottino si chiama " + nomeRobot.elementAt(this.robotIndex); + } + else if (comando.equalsIgnoreCase("porky")) { + System.out.println ("Porky è un grande"); + System.out.println ("Per maggiori informazioni visita il sito"); + return "http://kakati.forumfree.net/"; + } + else if (comando.equalsIgnoreCase("xxx")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "ha incontrato una bella robottina..."); + return "*Censura*"; + } + else if (comando.equalsIgnoreCase("dance")) { + System.out.println ("Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + " stia ballando..."); + System.out.println ("Il robottino ha smesso di ballare"); + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + return "Il robottino " + nomeRobot.elementAt(this.robotIndex) + "si è fermato ed è tornato nella posizione originale"; + } + else if (comando.equalsIgnoreCase("newrobot")) { + this.pdrA.addElement(pdrB); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftLeg); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightLeg); + System.out.println ("È stato creato un nuovo robot. Vuoi dare un nome al nuovo robot?"); + System.out.println ("Inserisci il nuovo nome e premi INVIO oppure lascia vuoto e premi INVIO"); + String newName = sc2.nextLine(); + this.nomeRobot.addElement(newName); + return "È stato creato il robottino " + newName; + } + else if (comando.equalsIgnoreCase("deleterobot")) { + if (pdrA.size()>1) { + System.out.println ("Quale robottino vuoi eliminare?"); + System.out.println (""); + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + System.out.println (""); + System.out.println("Scegliere il robottino da eliminare digitando il numero corrispondente e premendo INVIO"); + System.out.println("Digitare un qualunque altro numero e premere INVIO per annullare"); + int num = sc2.nextInt(); + if (num<this.pdrA.size()) { + this.pdrA.removeElementAt(num); + this.nomeRobot.removeElementAt(num); + return "È stato eliminato il robottino numero " + num; + } + else { + return "Operazione annullata"; + } + } + else { + return "Hai solo un robottino, non puoi eliminarlo!"; + } + } + else if (comando.equalsIgnoreCase("changerobot")) { + if (pdrA.size()>1) { + System.out.println ("A quale robottino vuoi dare i comandi?"); + System.out.println (""); + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + System.out.println (""); + System.out.println ("Digita il numero corrispondente alla tua scelta e premi INVIO"); + this.robotIndex = sc2.nextInt(); + if (this.robotIndex<this.pdrA.size()) + return "È stato selezionato il robottino numero " + this.robotIndex + ": " + + this.nomeRobot.elementAt(this.robotIndex); + else + return "Numero non valido"; + } + else { + return "Hai solo un robottino, non puoi cambiarlo con un altro!"; + } + } + else if (comando.equalsIgnoreCase("robotlist")) { + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + return ""; + } + else if (comando.equalsIgnoreCase("l")) { + System.out.println ("Legenda comandi"); + System.out.println (""); + System.out.println ("Comandi relativi agli arti"); + System.out.println (""); + System.out.println ("LeftArmMove: cambia la posizione corrente del braccio sinistro del robot"); + System.out.println ("RightArmMove: cambia la posizione corrente del braccio destro del robot"); + System.out.println ("LeftLegMove: cambia la posizione corrente della gamba sinistra del robot"); + System.out.println ("RightLegMove: cambia la posizione corrente della gamba destra del robot"); + System.out.println ("LeftArmOn: se il braccio sinistro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOn: se il braccio destro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOn: se la gamba sinistra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOn: se la gamba destra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftArmOff: se il braccio sinistro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOff: se il braccio destro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOff: se la gamba sinistra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOff: se la gamba destra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println (""); + System.out.println ("Altri comandi:"); + System.out.println (""); + System.out.println ("NewRobot: aggiunge un nuovo robot"); + System.out.println ("ChangeRobot: cambia il robot attuale"); + System.out.println ("RobotList: visualizza la lista dei robot"); + System.out.println ("Rename: rinomina il robottino"); + System.out.println ("DeleteRobot: rimuovi un robottino"); + System.out.println (""); + System.out.println ("Comandi a sorpresa:"); + System.out.println (""); + System.out.println ("Exploud"); + System.out.println ("Bier"); + System.out.println ("Porky"); + System.out.println ("xxx"); + System.out.println ("dance"); + System.out.println (""); + System.out.println ("Exit: esci dal programma"); + return ""; + + } + else if (comando.equalsIgnoreCase("exit")) + return ""; + else + System.out.println ("Comando non riconosciuto - digitare l per una legenda dei comandi disponibili"); + System.out.println (""); + for (int i = 0, j = 0; i < ((Vector)pdrA.elementAt(this.robotIndex)).size(); i++) { + if (((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte) { + contatore += 1; + stat[j++] = ((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).stringaParte; + } + } + switch (contatore) { + case 0: + Return = "Comunque il robottino " + nomeRobot.elementAt(this.robotIndex) + "non sta facendo niente"; + break; + case 1: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + "."; + break; + case 2: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + " e " + stat[1] + "."; + break; + case 3: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + ", " + stat[1] + " e " + stat[2] + "."; + break; + case 4: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + ", " + stat[1] + ", " + stat[2] + " e " + stat[3] + "."; + break; + } + return Return; + } +} + + + + + + + + + diff --git a/robottino/all_versions/v2.2/Esegui.bat b/robottino/all_versions/v2.2/Esegui.bat @@ -0,0 +1,3 @@ +cd ./bin +java RobottinoMain/Robottino +cd diff --git a/robottino/all_versions/v2.2/Esegui.sh b/robottino/all_versions/v2.2/Esegui.sh @@ -0,0 +1,3 @@ +cd ./bin +java RobottinoMain/Robottino +cd diff --git a/robottino/all_versions/v2.2/Readme.txt b/robottino/all_versions/v2.2/Readme.txt @@ -0,0 +1,10 @@ +Il programma necessita della JVM (Java Virtual Machine) per funzionare correttamente + +Se si usano sistemi Windows aprire il file Esegui.bat +Se si usano sistemi Unix dare i permessi necessari ed eseguire il file Esegui.sh +Se si usano altri sistemi aprire una shell e digitare i comandi + +cd <percorsoFile>/bin +java Robottino + +dove percorsoFile è il percorso di questo file. diff --git a/robottino/all_versions/v2.2/bin/RobottinoAzioni/RobottinoAzioni.class b/robottino/all_versions/v2.2/bin/RobottinoAzioni/RobottinoAzioni.class Binary files differ. diff --git a/robottino/all_versions/v2.2/bin/RobottinoMain/Robottino.class b/robottino/all_versions/v2.2/bin/RobottinoMain/Robottino.class Binary files differ. diff --git a/robottino/all_versions/v2.2/bin/RobottinoUtils/Grafica.class b/robottino/all_versions/v2.2/bin/RobottinoUtils/Grafica.class Binary files differ. diff --git a/robottino/all_versions/v2.2/bin/RobottinoUtils/Listener.class b/robottino/all_versions/v2.2/bin/RobottinoUtils/Listener.class Binary files differ. diff --git a/robottino/all_versions/v2.2/bin/RobottinoUtils/PartiDelRobot.class b/robottino/all_versions/v2.2/bin/RobottinoUtils/PartiDelRobot.class Binary files differ. diff --git a/robottino/all_versions/v2.2/src/RobottinoAzioni/RobottinoAzioni.java b/robottino/all_versions/v2.2/src/RobottinoAzioni/RobottinoAzioni.java @@ -0,0 +1,369 @@ +// Dichiaro che questa classa farà parte del package RobottinoAzioni, che verrà poi importato dalle classi Robottino e Grafica. +package RobottinoAzioni; + +// Anche qui impoerto i package necessari. +import java.util.Scanner; +import java.util.Vector; +import RobottinoUtils.*; + +public class RobottinoAzioni { + + // Creo gli oggetti statici che riempiranno il vettore pdrA: + // pdrA è un vettore multidimensionale che a sua volta contiene vettori + // (il primo si chiama pdrB, i successivi non avranno nome) che coontengono + // 4 istanze di PartiDelRobot, cioè i 4 arti del robot. + // Poi creo un vettore che conterrà i nomi dei robot. + // Creo il vettore principale... + public static Vector pdrA = new Vector(1); + + // ...e il "sottovettore" come istanze della classe Vector + public static Vector pdrB = new Vector(4); + + // Creo le quattro istanze di PartidelRobot utilizzando l'apposito costruttore + // passo a tutte una stringa e un valore boleano che determina lo stato + // (alzato/a se true, abbassato/a se false). + public static PartiDelRobot leftArm = new PartiDelRobot(false, "il braccio sinistro alzato"); + public static PartiDelRobot rightArm = new PartiDelRobot(false, "il braccio destro alzato"); + public static PartiDelRobot leftLeg = new PartiDelRobot(false, "la gamba sinistra alzata"); + public static PartiDelRobot rightLeg = new PartiDelRobot(false, "la gamba destra alzata"); + + // Il vettore nomeRobot per i nomi + // il vettore può contenere stringhe, poichè non sono tipi primitivi ma oggetti della classe String + public static Vector nomeRobot = new Vector(1); + + // La variabile robotIndex serve a tenere in memoria su quale robot si sta operando: + // in seguito verrà usata quando l'utente deciderà di creare più di un robot + // e poi di dare comandi a uno o all'altro/i. + int robotIndex = 0; + + // Dichiarazione del metodo Azioni. + public String Azioni(String comando, Vector nomeRobot, Vector pdrA) { + + // Crea un'istanza della classe Scanner per + // ricevere gli input nel caso in cui debba essere dato il nome + // al robottino o scelto un robottino da una lista. + Scanner sc2 = new Scanner(System.in); + + // La variabile contatore memorizza il numero di variabili "PartiDelRobot.statoParte" + // che hanno valore true, ossia il numero di arti alzati di un robottino + // in modo da poter scegliere la frase giusta da dare come output + // al posto dell'immagine del robottino con tali arti alzati. + int contatore = 0; + + // Questo array ha il compito di memorizzare le stringhe corrispondenti agli alzati + // per motivi simili a quelli della variabile "contatore". + String stat[] = {"", "", "", ""}; + + // La stringa Return verrà successivamente modificata e restituita in alcuni casi. + String Return = "Errore - si consiglia di picchiare il programmatore"; + + // Per far si che il programma non distingua tra lettere maiuscole o minuscole per quanto riguardo gli input + // è stato usato il metodo "equalsIgnoreCase" della classe String. + // I quattro casi successivi cambiano il valore della varibalie "statoParte" relativa all'arto + // Che deve mouversi (quindi cambiare la sua posizione). + if (comando.equalsIgnoreCase("leftarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte; + + else if (comando.equalsIgnoreCase("rightarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte; + + else if (comando.equalsIgnoreCase("leftlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte; + + else if (comando.equalsIgnoreCase("rightlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte; + + // I casi successivi modificano il valore della varibile analogamente ai 4 precedenti. + else if (comando.equalsIgnoreCase("leftarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = true; + + else if (comando.equalsIgnoreCase("rightarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = true; + + else if (comando.equalsIgnoreCase("leftlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = true; + + else if (comando.equalsIgnoreCase("rightlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = true; + + else if (comando.equalsIgnoreCase("leftarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = false; + + else if (comando.equalsIgnoreCase("rightarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = false; + + else if (comando.equalsIgnoreCase("leftlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = false; + + else if (comando.equalsIgnoreCase("rightlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = false; + + // Il caso successi si verica quando il comando è "exploud". + else if (comando.equalsIgnoreCase("exploud")) { + + // Scrive sullo schermo la seguente frase, che comprende il nome del robottino che non è ancora stato fatto eliminare + System.out.println + ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot.elementAt(this.robotIndex) + "! Aspetta che te ne faccio un altro"); + System.out.println ("..."); + + // Con un ciclo for rendo false tutte le variabili "statoParte" per far sì che il robottino sia come nuovo. + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + + // E azzero anche il nome del robot + this.nomeRobot.setElementAt("", this.robotIndex); + + return "Fatto, puoi continuare a giocare"; + } + + // Caso per il comando "bier". + // La reazione a questo comando è un semplice output quasi totalmente scorrelato al robottino + // se non per il fatto che appare il nome del robottino attuale. + else if (comando.equalsIgnoreCase("bier")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "sta trangugiando una birra..."); + System.out.println ("Buurrrrrrrrp!"); + return "La birra analcolica fa schifo!"; + } + + // Per il comando "rename", rinomina. + else if (comando.equalsIgnoreCase("rename")) { + + System.out.println ("Con questo comando quoi cambiare il nome del robottino " + nomeRobot.elementAt(this.robotIndex)); + System.out.println ("Digita il nuovo nome e premi INVIO per coninuare"); + + // Cambia il nome del robottino attuale con quello dell'input. + this.nomeRobot.setElementAt(sc2.nextLine(), this.robotIndex); + + // Se il nome non è vuoto, aggiunge un carattere di spazio per migliorare la visualizzazione nelle frasi di output. + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + + // Semplice output con il nuovo nome. + return "Ora il robottino si chiama " + nomeRobot.elementAt(this.robotIndex); + } + + // Per il comando "porky". + // Ancora meno che per "bier". + else if (comando.equalsIgnoreCase("porky")) { + System.out.println ("Porky è un grande"); + System.out.println ("Per maggiori informazioni visita il sito"); + return "http://kakati.forumfree.net/"; + } + + // Il comando "xxx" ha funzioni analoghe a bier. + else if (comando.equalsIgnoreCase("xxx")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "ha incontrato una bella robottina..."); + return "*Censura*"; + } + + // "dance" setta tutte le variabili "statoParte" a false... + else if (comando.equalsIgnoreCase("dance")) { + + System.out.println ("Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + " stia ballando..."); + System.out.println ("Il robottino ha smesso di ballare"); + + //...con questo ciclo for + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + + return "Il robottino " + nomeRobot.elementAt(this.robotIndex) + "si è fermato ed è tornato nella posizione originale"; + + // Per il comando "newrobot", che crea un nuovo robottino. + } + else if (comando.equalsIgnoreCase("newrobot")) { + + // Aggiunge un elemento a "pdrA" con il metodo "addElement", della classe Vector. + // È stata necessaria la dicitura this. per modificare realmente il vettore. + // Se non lo avessi fatto non sarebbe successo, in quanto i metodi operano + // su i valori e non sulle variabili/oggetti. + this.pdrA.addElement(pdrB); + + // Aggiungo le 4 parti del robot. + // Forse avete già notato (ma quì sono più evidenti) alcuni cast che ho fatto: + // sono per far si che il compilatore capisca che il metodo viene invocato da un oggetto + // della classe vector, che senza cast considererebbe della classe Object. + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftLeg); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightLeg); + + // Semplice output con richiesta di nome per il nuovo robottino. + System.out.println ("È stato creato un nuovo robot. Vuoi dare un nome al nuovo robot?"); + System.out.println ("Inserisci il nuovo nome e premi INVIO oppure lascia vuoto e premi INVIO"); + + String newName = sc2.nextLine(); + + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + + this.nomeRobot.addElement(newName); + + return "È stato creato il robottino " + newName; + } + + // Il comando "deleterobot", per eliminare un robot. + else if (comando.equalsIgnoreCase("deleterobot")) { + + // Se c'è più di un robot esegue l'eliminazione. + if (pdrA.size()>1) { + System.out.println ("Quale robottino vuoi eliminare?"); + System.out.println (""); + + // Con un ciclo for scrive i nomi di tutti i robot preceduti da un numero in sequenza. + // Il numero è il corrispondente del loro indice di vettore. + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + + // Dà le istruzioni all'utente affinché capisca come eliminare un robot. + System.out.println (""); + System.out.println("Scegliere il robottino da eliminare digitando il numero corrispondente e premendo INVIO"); + System.out.println("Digitare un qualunque altro numero e premere INVIO per annullare"); + + // Riceve in input il numero e ne assegna il valore alla variabile "num". + int num = sc2.nextInt(); + + // Elimina gli elementi corrispondenti al robottino (nome e robot) dai + // rispettivi vettori con il metodo "removeElementAt" della classe Vector. + if (num<this.pdrA.size()) { + this.pdrA.removeElementAt(num); + this.nomeRobot.removeElementAt(num); + return "È stato eliminato il robottino numero " + num; + } + + // Se il numero ricevuto in input è superiore all'indice dei robot + // non elimina alcun robot. + else return "Operazione annullata"; + } + + // Se c'è solo un robot non esegue l'eliminazione. + else return "Hai solo un robottino, non puoi eliminarlo!"; + } + + // Il comando "changerobot" per cambiare il robot a cui dare le istruzioni + else if (comando.equalsIgnoreCase("changerobot")) { + + // L'esecuzione è simile a quella per il comando "deleterobot", con la differenza che il robot non viene eliminato + // ma viene semplicemente cambiato il valore della variabile "robotIndex". + if (pdrA.size()>1) { + System.out.println ("A quale robottino vuoi dare i comandi?"); + System.out.println (""); + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + System.out.println (""); + System.out.println ("Digita il numero corrispondente alla tua scelta e premi INVIO"); + int newIndex = sc2.nextInt(); + + // Prima di cambiare valore alla variabile di indice verifica che il numero sia valido. + if (newIndex<this.pdrA.size()) { + this.robotIndex = newIndex; + return "È stato selezionato il robottino numero " + this.robotIndex + ": " + this.nomeRobot.elementAt + (this.robotIndex); + } + + // Se non lo è non esegue l'assegnamento. + else return "Numero non valido"; + } + else { + return "Hai solo un robottino, non puoi cambiarlo con un altro!"; + } + } + + // Il comando "robotlist" visualizza una lista dei robot presenti. + else if (comando.equalsIgnoreCase("robotlist")) { + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + return ""; + } + + // Il comando "l", per la legenda, visualizza la lista dei comandi con relativa descrizione. + else if (comando.equalsIgnoreCase("l")) { + System.out.println ("Legenda comandi"); + System.out.println (""); + System.out.println ("Comandi relativi agli arti"); + System.out.println (""); + System.out.println ("LeftArmMove: cambia la posizione corrente del braccio sinistro del robot"); + System.out.println ("RightArmMove: cambia la posizione corrente del braccio destro del robot"); + System.out.println ("LeftLegMove: cambia la posizione corrente della gamba sinistra del robot"); + System.out.println ("RightLegMove: cambia la posizione corrente della gamba destra del robot"); + System.out.println ("LeftArmOn: se il braccio sinistro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOn: se il braccio destro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOn: se la gamba sinistra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOn: se la gamba destra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftArmOff: se il braccio sinistro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOff: se il braccio destro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOff: se la gamba sinistra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOff: se la gamba destra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println (""); + System.out.println ("Altri comandi:"); + System.out.println (""); + System.out.println ("NewRobot: aggiunge un nuovo robot"); + System.out.println ("ChangeRobot: cambia il robot attuale"); + System.out.println ("RobotList: visualizza la lista dei robot"); + System.out.println ("Rename: rinomina il robottino"); + System.out.println (""); + System.out.println ("Comandi a sorpresa:"); + System.out.println (""); + System.out.println ("Exploud"); + System.out.println ("Bier"); + System.out.println ("Porky"); + System.out.println ("xxx"); + System.out.println ("dance"); + System.out.println (""); + System.out.println ("Exit: esci dal programma"); + + return ""; + + } + + // Se il comando è exit, non viene eseguita nessuna operazione (tranne restituire una stringa vuota) + // Perché il ciclo do-while nel metodo main, appena verificherà la condizione che il comando è + // uguale a "exit", terminerà da solo l'esecuzione del programma. + else if (comando.equalsIgnoreCase("exit")) return ""; + + // Se l'input non è tra i comandi prestabiliti, visualizza la seguente scritta sullo schermo. + else + System.out.println ("Comando non riconosciuto - digitare l per una legenda dei comandi disponibili"); + System.out.println (""); + + // Quì di seguito viene chiarito l'utilizzo di "contatore" e "sta[]". + // Per ogni varibile "statoParte" che ha valore true, contatore viene incrementato + // e l'elemento successivo dell'array "stat[]" assume il valore della stringa corrispondente. + for (int i = 0, j = 0; i < 4; i++) { + if (((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte) { + contatore += 1; + stat[j++] = ((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).stringaParte; + } + } + + // La restituzione finale delle frasi, con uno switch che a seconda del valore di contatore + // restituisce una frase o l'altra. + switch (contatore) { + case 0: + Return = "Comunque il robottino " + nomeRobot.elementAt(this.robotIndex) + "non sta facendo niente"; + break; + case 1: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + "."; + break; + case 2: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + " e " + stat[1] + "."; + break; + case 3: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + ", " + stat[1] + " e " + stat[2] + "."; + break; + case 4: + Return = "Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + "abbia " + stat[0] + ", " + stat[1] + ", " + stat[2] + " e " + stat[3] + "."; + break; + } + return Return; + } + //Fine del metodo Azioni +} diff --git a/robottino/all_versions/v2.2/src/RobottinoMain/Robottino.java b/robottino/all_versions/v2.2/src/RobottinoMain/Robottino.java @@ -0,0 +1,115 @@ +// Robottino versione 2.2 +// Da questa versione illustrerò tutte le parti del programma con dei commenti come questo. + +// Dichiaro che questa classe fa parte del package RobottinoMain, che verrà poi importato +// dalle classi che dovranno interagire con essa. +package RobottinoMain; + +// Importo le librerie iniziali: +// java.Util.Scanner per gestire gli input da tastiera. +import java.util.Scanner; + +// java.util.Vector serve a gestire i vettori. +// I vettori sono come array, ma hanno due differenze principali: +// 1) la loro lunghezza può variare durante l'esecuzione del programma +// (per questo li ho preferiti agli array); +// 2) possono contenere soltanto oggetti, e non tipi primitivi. +import java.util.Vector; + +// Questo è il package di utility da me creato per semplificare l'utilizzo degli elementi di altre classi +// (Grafica, PartiDelRobot). Nelle versioni precedenti c'erano solo le classi Robottino +// e PartiDelRobot, percui avevo deciso di far sì che una fosse derivata dall'altra. +import RobottinoUtils.*; + +// Altro package da me definito. +import RobottinoAzioni.*; + +// Dichiaro la classe. +public class Robottino { + + // Istanzio anche le classi Robottino e RobottinoAzioni, per poter avere accesso agli elementi non-statici. + static Robottino robottino = new Robottino(); + static RobottinoAzioni robottinoazioni = new RobottinoAzioni(); + + // Istanzio la classe Thread per poter utilizzare il metodo sleep(int millisecondi) + // che in un metodo dell'interfaccia WindowListener, overridato nella classe Listener + // servirà a mettere il programma in uno stato di pausa. + // Sarebbe comunque possibile invocarlo, ma così sarà più facile da modificare in futuro. + public static Thread threadMain; + + // Inizio del metodo main... + public static void main(String[] args) { + + threadMain = new Thread(Thread.currentThread()); + + // Aggiungo gli elementi ai vettori. + // non potevo farlo prima, poiché al di fuori di un metodo è possibile soltanto + // dichiarare oggetti/variabili (e inizializzarli) o dichiarare un metodo + // e in RobottinoAzioni è presente solo il metodo Azioni che viene richiamato più volte. + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.leftArm); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.rightArm); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.leftLeg); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.rightLeg); + RobottinoAzioni.pdrA.addElement(RobottinoAzioni.pdrB); + RobottinoAzioni.nomeRobot.addElement(""); + + // Istanzio la classe Scanner per poter ricevere input + Scanner sc = new Scanner(System.in); + + // Dichiaro la variabile comando che memorizzerà l'input dell'utente + String comando; + + // Crea la finestra tramite un'istanza della classe Grafica, del package RobottinoUtils + Grafica finestra = new Grafica(); + + // Output iniziale nellla shell + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("*************Programma interattivo************"); + System.out.println ("**********************************************"); + System.out.println ("***Software realizzato da Sebastiano Tronto***"); + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("Questo programma simula un robot al quale ven-"); + System.out.println ("gono assegnati ordini tramite comandi, simil-" ); + System.out.println ("mente a quanto bisognava fare con i computer " ); + System.out.println ("alcuni anni fa." ); + System.out.println ("Dato che all'epoca i comandi che dovevano es-" ); + System.out.println ("sere dati erano (e sono tutt'ora) in similin-" ); + System.out.println ("glese, ho cercato di mantenerli tali." ); + System.out.println ("Il programma non fa distinzioni tra lettere" ); + System.out.println ("maiuscole o minuscole." ); + System.out.println ("da questa versione (2.2) sono disponibili ef-" ); + System.out.println ("fetti grafici minimali e totalmente inutili." ); + System.out.println ("" ); + System.out.println ("Digita un comando e premi INVIO" ); + System.out.println ("l = legenda comandi" ); + System.out.println (""); + + // Inizio del ciclo do-while che fa in modo di ricevere input ed eseguire il metodo "Azioni" + // fintando che il comando non è exit. + do { + + // Inizializza la stringa comando con il valore dell'input. + comando = sc.nextLine(); + System.out.println (""); + + // Esegue il metodo "Azioni" passando come argomenti il comando e i due vettori. + System.out.println (robottinoazioni.Azioni(comando, RobottinoAzioni.nomeRobot, RobottinoAzioni.pdrA)); + System.out.println (""); + } while ( !(comando.equalsIgnoreCase("exit")) ); + + // Al termine del metodo main invoco il metodo "System.exit" per terminare completamente l'esecuzione del programma + System.exit(0); + } + // Fine del metodo main. +} + + + + + + + + + diff --git a/robottino/all_versions/v2.2/src/RobottinoUtils/Grafica.java b/robottino/all_versions/v2.2/src/RobottinoUtils/Grafica.java @@ -0,0 +1,60 @@ +// Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. +package RobottinoUtils; + +// Importo i package standard relativi al funzionamento delle finestre e della grafica in generale. +import java.awt.*; + +// E i package RobottinoAzioni e RobottinoUtils da me definiti. +import RobottinoAzioni.*; +import RobottinoUtils.Listener; + +// La classe è una sottoclasse di Frame per poter sfruttare gli effetti grafici +// ma implementa anche l'interfaccia WindowListener, necessaria per gestire gli eventi collegati alle finestre +// (riduzione a icona, chiusura...); per questo devo successivamente ridefinire tutti i +// metodi dell'interfaccia. +public class Grafica extends Frame { + + // Creo un'istanza della classe Listener che userò come listener per gli eventi. + public static Listener listener; + + // Il costruttore senza argomenti. + public Grafica () { + + // Il metodo "setBounds" posiziona e dimensiona la finestra. + setBounds (this.orizzontale, this.verticale, this.larghezza, this.altezza); + + // "setTitle" per il titolo della finestra. + setTitle ("Robottino v2.2"); + + // "setVisible" per poterla visualizzare. + setVisible (true); + + // E addWindowListener per l'ascoltatore (listener). + listener = new Listener(); + addWindowListener (listener); + } + + // Questo costruttore permette di modificare la posizione o la dimensione della finestra + // rispetto al predefinito. + public Grafica (int orizzontale, int verticale, int larghezza, int altezza) { + this.orizzontale =orizzontale; + this.verticale = verticale; + this.larghezza = larghezza; + this.altezza = altezza; + setBounds (this.orizzontale, this.verticale, this.larghezza, this.altezza); + setTitle ("Robottino v2.2"); + setVisible (true); + listener = new Listener(); + addWindowListener (listener); + } + + // Le variabili pubbliche di classe per il metodo "setBounds". + public int orizzontale = 0; + public int verticale = 0; + public int larghezza = 500; + public int altezza = 500; +} + + + + diff --git a/robottino/all_versions/v2.2/src/RobottinoUtils/Listener.java b/robottino/all_versions/v2.2/src/RobottinoUtils/Listener.java @@ -0,0 +1,62 @@ +// Questa classe è il listener per gli eventi relativi alle finestre. +// Dichiaro che farà parte del package RobottinoUtils +package RobottinoUtils; + +// Importo i package necessari. +import java.awt.event.*; +import RobottinoMain.*; + +public class Listener implements WindowListener { + + // Ridefinisco i metodi dell'interfaccia WindowListener: + // Metodo invocato quando la finestra è stata chiusa: + public void windowClosed (WindowEvent evt) { + + // Invoco il metodo sleep(int millisecondi) per mettere il programma in uno stato di attesa + // di durata pari ai millisecondi indicati come argomento. + System.out.println("La finestra è stata chiusa, il programma terminarà fra 3 secondi"); + try { + Robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("2"); + try { + Robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("1"); + try { + Robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("Programma terminato"); + System.exit(0); + } + + // Metodo invocato quando la finestra è in fase di chiusura: + public void windowClosing (WindowEvent evt) { + System.out.println ("Chiusura finestra in corso"); + evt.getWindow().dispose(); + } + + // Metodo invocato quando una finestra viene ridotta a icona: + public void windowIconified (WindowEvent evt) { + System.out.println("La finestra è stata ridotta a icona"); + } + + // Metodo invocato quando una finestra ridotta a icona viene ingrandita: + public void windowDeiconified (WindowEvent evt) { + System.out.println("La finestra ridotta a icona è stata ingrandita"); + } + + // Metodo invocato quando una finestra viene aperta: + public void windowOpened (WindowEvent evt) {} + + // Metodo invocato quando una finestra diventa attiva: + public void windowActivated (WindowEvent evt) {} + + // Metodo invocato quando una finestra viene disattivata: + public void windowDeactivated (WindowEvent evt) {} +} + + + + + diff --git a/robottino/all_versions/v2.2/src/RobottinoUtils/PartiDelRobot.java b/robottino/all_versions/v2.2/src/RobottinoUtils/PartiDelRobot.java @@ -0,0 +1,22 @@ +// Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. +package RobottinoUtils; + +// Dichiaro la classe. +public class PartiDelRobot { + + // Creo un costruttore senza argomenti. + // Se non lo facessi sarei obbligato a passare gli argomenti + // del secondo costruttore ogni volta che voglio istanziare la classe. + public PartiDelRobot() {} + + // Il secondo costruttore riceve come argomenti un booleano che passerà il valore a "statoParte" + // e una stringa che passa il valore a "stringaParte". + public PartiDelRobot(boolean b, String s) { + this.stringaParte = s; + this.statoParte = b; + } + + // Infine le due variabili pubbliche della classe. + public String stringaParte; + public boolean statoParte; +} diff --git a/robottino/all_versions/v2.3/Esegui.bat b/robottino/all_versions/v2.3/Esegui.bat @@ -0,0 +1,3 @@ +cd ./bin +java RobottinoMain/Robottino +cd diff --git a/robottino/all_versions/v2.3/Esegui.sh b/robottino/all_versions/v2.3/Esegui.sh @@ -0,0 +1,3 @@ +cd ./bin +java RobottinoMain/Robottino +cd diff --git a/robottino/all_versions/v2.3/Readme.txt b/robottino/all_versions/v2.3/Readme.txt @@ -0,0 +1,10 @@ +Il programma necessita della JVM (Java Virtual Machine) per funzionare correttamente + +Se si usano sistemi Windows aprire il file Esegui.bat +Se si usano sistemi Unix dare i permessi necessari ed eseguire il file Esegui.sh +Se si usano altri sistemi aprire una shell e digitare i comandi + +cd <percorsoFile>/bin +java Robottino + +dove percorsoFile è il percorso di questo file. diff --git a/robottino/all_versions/v2.3/bin/RobottinoAzioni/RobottinoAzioni.class b/robottino/all_versions/v2.3/bin/RobottinoAzioni/RobottinoAzioni.class Binary files differ. diff --git a/robottino/all_versions/v2.3/bin/RobottinoMain/Robottino.class b/robottino/all_versions/v2.3/bin/RobottinoMain/Robottino.class Binary files differ. diff --git a/robottino/all_versions/v2.3/bin/RobottinoUtils/Grafica.class b/robottino/all_versions/v2.3/bin/RobottinoUtils/Grafica.class Binary files differ. diff --git a/robottino/all_versions/v2.3/bin/RobottinoUtils/Listener.class b/robottino/all_versions/v2.3/bin/RobottinoUtils/Listener.class Binary files differ. diff --git a/robottino/all_versions/v2.3/bin/RobottinoUtils/PartiDelRobot.class b/robottino/all_versions/v2.3/bin/RobottinoUtils/PartiDelRobot.class Binary files differ. diff --git a/robottino/all_versions/v2.3/src/RobottinoAzioni/RobottinoAzioni.java b/robottino/all_versions/v2.3/src/RobottinoAzioni/RobottinoAzioni.java @@ -0,0 +1,397 @@ +// Dichiaro che questa classa farà parte del package RobottinoAzioni, che verrà poi importato dalle classi Listener e Grafica. +package RobottinoAzioni; + +// Anche qui impoerto i package necessari. +// java.util.Scanner gestisce gli input da tastiera +import java.util.Scanner; + +// java.util.Vector +import java.util.Vector; + +// Package definito da me. +import RobottinoUtils.*; + +public class RobottinoAzioni { + + // Creo gli oggetti statici che riempiranno il vettore pdrA: + // pdrA è un vettore multidimensionale che a sua volta contiene vettori + // (il primo si chiama pdrB, i successivi non avranno nome) che coontengono + // 4 istanze di PartiDelRobot, cioè i 4 arti del robot. + // Poi creo un vettore che conterrà i nomi dei robot. + // Creo il vettore principale... + public static Vector pdrA = new Vector(1); + + // ...e il "sottovettore" come istanze della classe Vector + public static Vector pdrB = new Vector(4); + + // Creo le quattro istanze di PartidelRobot utilizzando l'apposito costruttore + // passo a tutte una stringa e un valore boleano che determina lo stato + // (alzato/a se true, abbassato/a se false). + public static PartiDelRobot leftArm = new PartiDelRobot(false, "il braccio sinistro alzato"); + public static PartiDelRobot rightArm = new PartiDelRobot(false, "il braccio destro alzato"); + public static PartiDelRobot leftLeg = new PartiDelRobot(false, "la gamba sinistra alzata"); + public static PartiDelRobot rightLeg = new PartiDelRobot(false, "la gamba destra alzata"); + + // Il vettore nomeRobot per i nomi + // il vettore può contenere stringhe, poichè non sono tipi primitivi ma oggetti della classe String + public static Vector nomeRobot = new Vector(1); + + // La variabile robotIndex serve a tenere in memoria su quale robot si sta operando: + // in seguito verrà usata quando l'utente deciderà di creare più di un robot + // e poi di dare comandi a uno o all'altro/i. + int robotIndex = 0; + + // Dichiarazione del metodo Azioni. + public String Azioni(String comando, Vector nomeRobot, Vector pdrA) { + + // Crea un'istanza della classe Scanner per + // ricevere gli input nel caso in cui debba essere dato il nome + // al robottino o scelto un robottino da una lista. + Scanner sc2 = new Scanner(System.in); + + // La variabile contatore memorizza il numero di variabili "PartiDelRobot.statoParte" + // che hanno valore true, ossia il numero di arti alzati di un robottino + // in modo da poter scegliere la frase giusta da dare come output + // al posto dell'immagine del robottino con tali arti alzati. + int contatore = 0; + + // Questo array ha il compito di memorizzare le stringhe corrispondenti agli alzati + // per motivi simili a quelli della variabile "contatore". + String stat[] = {"", "", "", ""}; + + // La stringa Return verrà successivamente modificata e restituita in alcuni casi. + String Return = "Errore - si consiglia di picchiare il programmatore"; + + // Per far si che il programma non distingua tra lettere maiuscole o minuscole per quanto riguardo gli input + // è stato usato il metodo "equalsIgnoreCase" della classe String. + // I quattro casi successivi cambiano il valore della varibalie "statoParte" relativa all'arto + // Che deve mouversi (quindi cambiare la sua posizione). + if (comando.equalsIgnoreCase("leftarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte; + + else if (comando.equalsIgnoreCase("rightarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte; + + else if (comando.equalsIgnoreCase("leftlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte; + + else if (comando.equalsIgnoreCase("rightlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte; + + // I casi successivi modificano il valore della varibile analogamente ai 4 precedenti. + else if (comando.equalsIgnoreCase("leftarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = true; + + else if (comando.equalsIgnoreCase("rightarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = true; + + else if (comando.equalsIgnoreCase("leftlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = true; + + else if (comando.equalsIgnoreCase("rightlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = true; + + else if (comando.equalsIgnoreCase("leftarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = false; + + else if (comando.equalsIgnoreCase("rightarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = false; + + else if (comando.equalsIgnoreCase("leftlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = false; + + else if (comando.equalsIgnoreCase("rightlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = false; + + // Il caso successi si verica quando il comando è "exploud". + else if (comando.equalsIgnoreCase("exploud")) { + + // Scrive sullo schermo la seguente frase, che comprende il nome del robottino che non è ancora stato fatto eliminare + System.out.println + ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot.elementAt(this.robotIndex) + "! Aspetta che te ne faccio un altro"); + System.out.println ("..."); + + // Con un ciclo for rendo false tutte le variabili "statoParte" per far sì che il robottino sia come nuovo. + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + + // E azzero anche il nome del robot + this.nomeRobot.setElementAt("", this.robotIndex); + + return "Fatto, puoi continuare a giocare"; + } + + // Caso per il comando "bier". + // La reazione a questo comando è un semplice output quasi totalmente scorrelato al robottino + // se non per il fatto che appare il nome del robottino attuale. + else if (comando.equalsIgnoreCase("bier")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "sta trangugiando una birra..."); + System.out.println ("Buurrrrrrrrp!"); + return "La birra analcolica fa schifo!"; + } + + // Per il comando "rename", rinomina. + else if (comando.equalsIgnoreCase("rename")) { + + System.out.println ("Con questo comando quoi cambiare il nome del robottino " + nomeRobot.elementAt(this.robotIndex)); + System.out.println ("Digita il nuovo nome e premi INVIO per coninuare"); + + // Cambia il nome del robottino attuale con quello dell'input. + this.nomeRobot.setElementAt(sc2.nextLine(), this.robotIndex); + + // Se il nome non è vuoto, aggiunge un carattere di spazio per migliorare la visualizzazione nelle frasi di output. + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + + // Semplice output con il nuovo nome. + return "Ora il robottino si chiama " + nomeRobot.elementAt(this.robotIndex); + } + + // Per il comando "porky". + // Ancora meno che per "bier". + else if (comando.equalsIgnoreCase("porky")) { + System.out.println ("Porky è un grande"); + System.out.println ("Per maggiori informazioni visita il sito"); + return "http://kakati.forumfree.net/"; + } + + // Il comando "xxx" ha funzioni analoghe a bier. + else if (comando.equalsIgnoreCase("xxx")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "ha incontrato una bella robottina..."); + return "*Censura*"; + } + + // "dance" setta tutte le variabili "statoParte" a false... + else if (comando.equalsIgnoreCase("dance")) { + + System.out.println ("Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + " stia ballando..."); + System.out.println ("Il robottino ha smesso di ballare"); + + //...con questo ciclo for + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + + return "Il robottino " + nomeRobot.elementAt(this.robotIndex) + "si è fermato ed è tornato nella posizione originale"; + + // Per il comando "newrobot", che crea un nuovo robottino. + } + else if (comando.equalsIgnoreCase("newrobot")) { + + // Aggiunge un elemento a "pdrA" con il metodo "addElement", della classe Vector. + // È stata necessaria la dicitura this. per modificare realmente il vettore. + // Se non lo avessi fatto non sarebbe successo, in quanto i metodi operano + // su i valori e non sulle variabili/oggetti. + this.pdrA.addElement(pdrB); + + // Aggiungo le 4 parti del robot. + // Forse avete già notato (ma quì sono più evidenti) alcuni cast che ho fatto: + // sono per far si che il compilatore capisca che il metodo viene invocato da un oggetto + // della classe vector, che senza cast considererebbe della classe Object. + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftLeg); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightLeg); + + // Semplice output con richiesta di nome per il nuovo robottino. + System.out.println ("È stato creato un nuovo robot. Vuoi dare un nome al nuovo robot?"); + System.out.println ("Inserisci il nuovo nome e premi INVIO oppure lascia vuoto e premi INVIO"); + + String newName = sc2.nextLine(); + + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + + this.nomeRobot.addElement(newName); + + return "È stato creato il robottino " + newName; + } + + // Il comando "deleterobot", per eliminare un robot. + else if (comando.equalsIgnoreCase("deleterobot")) { + + // Se c'è più di un robot esegue l'eliminazione. + if (pdrA.size()>1) { + System.out.println ("Quale robottino vuoi eliminare?"); + System.out.println (""); + + // Con un ciclo for scrive i nomi di tutti i robot preceduti da un numero in sequenza. + // Il numero è il corrispondente del loro indice di vettore. + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + + // Dà le istruzioni all'utente affinché capisca come eliminare un robot. + System.out.println (""); + System.out.println("Scegliere il robottino da eliminare digitando il numero corrispondente e premendo INVIO"); + System.out.println("Digitare un qualunque altro numero e premere INVIO per annullare"); + + int num = this.pdrA.size()+1; + + try { + + // Riceve in input il numero e ne assegna il valore alla variabile "num". + num = sc2.nextInt(); + + } catch (Exception e) { + System.out.println("Puoi inserire solo numeri"); + } + + // Elimina gli elementi corrispondenti al robottino (nome e robot) dai + // rispettivi vettori con il metodo "removeElementAt" della classe Vector. + if (num<this.pdrA.size()) { + this.pdrA.removeElementAt(num); + this.nomeRobot.removeElementAt(num); + return "È stato eliminato il robottino numero " + num; + } + + // Se il numero ricevuto in input è superiore all'indice dei robot + // non elimina alcun robot. + else return "Operazione annullata"; + } + + // Se c'è solo un robot non esegue l'eliminazione. + else return "Hai solo un robottino, non puoi eliminarlo!"; + } + + // Il comando "changerobot" per cambiare il robot a cui dare le istruzioni + else if (comando.equalsIgnoreCase("changerobot")) { + + // L'esecuzione è simile a quella per il comando "deleterobot", con la differenza che il robot non viene eliminato + // ma viene semplicemente cambiato il valore della variabile "robotIndex". + if (pdrA.size()>1) { + System.out.println ("A quale robottino vuoi dare i comandi?"); + System.out.println (""); + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + System.out.println (""); + System.out.println ("Digita il numero corrispondente alla tua scelta e premi INVIO"); + + int newIndex = this.pdrA.size()+1; + + try { + + newIndex = sc2.nextInt(); + + } catch (Exception e) { + System.out.println("Puoi inserire solo numeri"); + } + + // Prima di cambiare valore alla variabile di indice verifica che il numero sia valido. + if (newIndex<this.pdrA.size()) { + this.robotIndex = newIndex; + return "È stato selezionato il robottino numero " + this.robotIndex + ": " + this.nomeRobot.elementAt + (this.robotIndex); + } + + // Se non lo è non esegue l'assegnamento. + else return "Numero non valido - Operazione annullata"; + } + else { + return "Hai solo un robottino, non puoi cambiarlo con un altro!"; + } + } + + // Il comando "robotlist" visualizza una lista dei robot presenti. + else if (comando.equalsIgnoreCase("robotlist")) { + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + return ""; + } + + // Il comando "l", per la legenda, visualizza la lista dei comandi con relativa descrizione. + else if (comando.equalsIgnoreCase("l")) { + System.out.println ("Legenda comandi"); + System.out.println (""); + System.out.println ("Comandi relativi agli arti"); + System.out.println (""); + System.out.println ("LeftArmMove: cambia la posizione corrente del braccio sinistro del robot"); + System.out.println ("RightArmMove: cambia la posizione corrente del braccio destro del robot"); + System.out.println ("LeftLegMove: cambia la posizione corrente della gamba sinistra del robot"); + System.out.println ("RightLegMove: cambia la posizione corrente della gamba destra del robot"); + System.out.println ("LeftArmOn: se il braccio sinistro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOn: se il braccio destro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOn: se la gamba sinistra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOn: se la gamba destra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftArmOff: se il braccio sinistro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOff: se il braccio destro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOff: se la gamba sinistra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOff: se la gamba destra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println (""); + System.out.println ("Altri comandi:"); + System.out.println (""); + System.out.println ("NewRobot: aggiunge un nuovo robot"); + System.out.println ("ChangeRobot: cambia il robot attuale"); + System.out.println ("RobotList: visualizza la lista dei robot"); + System.out.println ("Rename: rinomina il robottino"); + System.out.println (""); + System.out.println ("Comandi a sorpresa:"); + System.out.println (""); + System.out.println ("Exploud"); + System.out.println ("Bier"); + System.out.println ("Porky"); + System.out.println ("xxx"); + System.out.println ("dance"); + System.out.println (""); + System.out.println ("Exit: esci dal programma"); + + return ""; + + } + + // Se il comando è exit, esce dal programma. + else if (comando.equalsIgnoreCase("exit")) { + System.exit(0); + return ""; + } + + // Se l'input non è tra i comandi prestabiliti, visualizza la seguente scritta sullo schermo. + else + System.out.println ("Comando non riconosciuto - digitare l per una legenda dei comandi disponibili"); + System.out.println (""); + + // Quì di seguito viene chiarito l'utilizzo di "contatore" e "sta[]". + // Per ogni varibile "statoParte" che ha valore true, contatore viene incrementato + // e l'elemento successivo dell'array "stat[]" assume il valore della stringa corrispondente. + for (int i = 0, j = 0; i < 4; i++) { + if (((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte) { + contatore += 1; + stat[j++] = ((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).stringaParte; + } + } + + // La restituzione finale delle frasi, con uno switch che a seconda del valore di contatore + // restituisce una frase o l'altra. + switch (contatore) { + case 0: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"non ha nessun arto alzato"; + break; + case 1: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0] + "."; + break; + case 2: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0]+" e "+stat[1]+"."; + break; + case 3: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0]+", "+stat[1]+" e "+stat[2]+"."; + break; + case 4: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0]+", "+stat[1]+", "+stat[2]+" e "+stat[3]+". Sta per cadere! Ah no, può restare sospeso in aria"; + break; + } + return Return; + } + //Fine del metodo Azioni +} + + + + + diff --git a/robottino/all_versions/v2.3/src/RobottinoMain/Robottino.java b/robottino/all_versions/v2.3/src/RobottinoMain/Robottino.java @@ -0,0 +1,83 @@ +// Robottino versione 2.2 +// Da questa versione illustrerò tutte le parti del programma con dei commenti come questo. + +// Dichiaro che questa classe fa parte del package RobottinoMain, che verrà poi importato +// dalle classi che dovranno interagire con essa. +package RobottinoMain; + +// Importo la classe Grafica per poter "costruire" una finestra. +import RobottinoUtils.Grafica; + +// E il package Robottinoazioni per poterne inizializzare i vettori +import RobottinoAzioni.*; + +// java.util.Vector serve a gestire i vettori. +// I vettori sono come array, ma hanno due differenze principali: +// 1) la loro lunghezza può variare durante l'esecuzione del programma +// (per questo li ho preferiti agli array); +// 2) possono contenere soltanto oggetti, e non tipi primitivi. +import java.util.Vector; + +// Dichiaro la classe. +public class Robottino { + + + // Istanzio la classe Thread per poter utilizzare il metodo sleep(int millisecondi) + // che in un metodo dell'interfaccia WindowListener, overridato nella classe Listener + // servirà a mettere il programma in uno stato di pausa. + // Sarebbe comunque possibile invocarlo, ma così sarà più facile da modificare in futuro. + public static Thread threadMain; + + // Inizio del metodo main... + public static void main(String[] args) { + + threadMain = new Thread(Thread.currentThread()); + + // Aggiungo gli elementi ai vettori. + // non potevo farlo prima, poiché al di fuori di un metodo è possibile soltanto + // dichiarare oggetti/variabili (e inizializzarli) o dichiarare un metodo + // e in RobottinoAzioni è presente solo il metodo Azioni che viene richiamato più volte. + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.leftArm); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.rightArm); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.leftLeg); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.rightLeg); + RobottinoAzioni.pdrA.addElement(RobottinoAzioni.pdrB); + RobottinoAzioni.nomeRobot.addElement(""); + + // Crea la finestra tramite un'istanza della classe Grafica, del package RobottinoUtils + Grafica finestra = new Grafica(); + + // Output iniziale nellla shell + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("*************Programma interattivo************"); + System.out.println ("**********************************************"); + System.out.println ("***Software realizzato da Sebastiano Tronto***"); + System.out.println ("**********************************************"); + System.out.println ("**********************************************"); + System.out.println ("Questo programma simula un robot al quale ven-"); + System.out.println ("gono assegnati ordini tramite comandi, simil-" ); + System.out.println ("mente a quanto bisognava fare con i computer " ); + System.out.println ("alcuni anni fa." ); + System.out.println ("Dato che all'epoca i comandi che dovevano es-" ); + System.out.println ("sere dati erano (e sono tutt'ora) in similin-" ); + System.out.println ("glese, ho cercato di mantenerli tali." ); + System.out.println ("Da questa versione (v2.3) i comandi devono es-"); + System.out.println ("sere dati attraverso i menu File, Modifica o " ); + System.out.println ("Azioni della finestra." ); + System.out.println ("" ); + System.out.println ("Tuttavia la reazione del robottino verrà vi-" ); + System.out.println ("sualizzata attraverso la shell." ); + System.out.println (""); + } + // Fine del metodo main. +} + + + + + + + + + diff --git a/robottino/all_versions/v2.3/src/RobottinoUtils/Grafica.java b/robottino/all_versions/v2.3/src/RobottinoUtils/Grafica.java @@ -0,0 +1,210 @@ +// Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. +package RobottinoUtils; + +// Importo i package standard relativi al funzionamento delle finestre e della grafica in generale. +import java.awt.*; + +// E i package RobottinoAzioni e RobottinoUtils da me definiti. +import RobottinoAzioni.*; +import RobottinoUtils.Listener; + +// La classe è una sottoclasse di Frame per poter sfruttare gli effetti grafici +// ma implementa anche l'interfaccia WindowListener, necessaria per gestire gli eventi collegati alle finestre +// (riduzione a icona, chiusura...); per questo devo successivamente ridefinire tutti i +// metodi dell'interfaccia. +public class Grafica extends Frame { + + // Creo un'istanza della classe Listener che userò come listener per gli eventi. + public static Listener listener; + + // Il costruttore senza argomenti. + public Grafica () { + + // Il metodo "setBounds" posiziona e dimensiona la finestra. + setBounds (this.orizzontale, this.verticale, this.larghezza, this.altezza); + + // "setTitle" per il titolo della finestra. + setTitle ("Robottino v2.2"); + + // "setVisible" per poterla visualizzare. + setVisible (true); + + // E addWindowListener per l'ascoltatore (listener). + listener = new Listener(); + addWindowListener (listener); + + // Aggiungo la barra del menu con i vari sottomenu + setMenuBar (barraMenu); + + // Il menu file. + NewRobot.addActionListener(listener); + NewRobot.setActionCommand("newrobot"); + + ChangeRobot.addActionListener(listener); + ChangeRobot.setActionCommand("changerobot"); + + DeleteRobot.addActionListener(listener); + DeleteRobot.setActionCommand("deleterobot"); + + Exit.addActionListener(listener); + Exit.setActionCommand("exit"); + + file.add(NewRobot); + file.add(ChangeRobot); + file.add(DeleteRobot); + file.addSeparator(); + file.add(Exit); + + barraMenu.add(file); + + // Il braccio sinistro. + LeftArmMove.addActionListener(listener); + LeftArmMove.setActionCommand("leftarmmove"); + + LeftArmOn.addActionListener(listener); + LeftArmOn.setActionCommand("leftarmon"); + + LeftArmOff.addActionListener(listener); + LeftArmOff.setActionCommand("leftarmoff"); + + LeftArm.add(LeftArmMove); + LeftArm.add(LeftArmOn); + LeftArm.add(LeftArmOff); + + // Il braccio destro. + RightArmMove.addActionListener(listener); + RightArmMove.setActionCommand("rightarmmove"); + + RightArmOn.addActionListener(listener); + RightArmOn.setActionCommand("rightarmon"); + + RightArmOff.addActionListener(listener); + RightArmOff.setActionCommand("rightarmoff"); + + RightArm.add(RightArmMove); + RightArm.add(RightArmOn); + RightArm.add(RightArmOff); + + // La gamba sinistra. + LeftLegMove.addActionListener(listener); + LeftLegMove.setActionCommand("leftlegmove"); + + LeftLegOn.addActionListener(listener); + LeftLegOn.setActionCommand("leftlegon"); + + LeftLegOff.addActionListener(listener); + LeftLegOff.setActionCommand("leftlegoff"); + + LeftLeg.add(LeftLegMove); + LeftLeg.add(LeftLegOn); + LeftLeg.add(LeftLegOff); + + // La gamba destra. + RightLegMove.addActionListener(listener); + RightLegMove.setActionCommand("rightlegmove"); + + RightLegOn.addActionListener(listener); + RightLegOn.setActionCommand("rightlegon"); + + RightLegOff.addActionListener(listener); + RightLegOff.setActionCommand("rightlegoff"); + + RightLeg.add(RightLegMove); + RightLeg.add(RightLegOn); + RightLeg.add(RightLegOff); + + // Menu rinomina. + Rename.addActionListener(listener); + Rename.setActionCommand("rename"); + + Menu modifica = new Menu("Modifica"); + modifica.add(LeftArm); + modifica.add(RightArm); + modifica.add(LeftLeg); + modifica.add(RightLeg); + modifica.addSeparator(); + modifica.add(Rename); + + barraMenu.add(modifica); + + // Menu azioni. + Exploud.addActionListener(listener); + Exploud.setActionCommand("exploud"); + + Bier.addActionListener(listener); + Bier.setActionCommand("bier"); + + xxx.addActionListener(listener); + xxx.setActionCommand("xxx"); + + Dance.addActionListener(listener); + Dance.setActionCommand("dance"); + + azioni.add(Exploud); + azioni.add(Bier); + azioni.add(xxx); + azioni.add(Dance); + + barraMenu.add(azioni); + + // Menu info. + Porky.addActionListener(listener); + Porky.setActionCommand("porky"); + + l.addActionListener(listener); + l.setActionCommand("l"); + + RobotList.addActionListener(listener); + RobotList.setActionCommand("robotlist"); + + info.add(Porky); + info.add(l); + info.add(RobotList); + + barraMenu.add(info); + } + + // Le variabili pubbliche di classe per il metodo "setBounds". + public int orizzontale = 0; + public int verticale = 0; + public int larghezza = 500; + public int altezza = 500; + + // E i vari Menu e MenuItem. + MenuBar barraMenu = new MenuBar(); + Menu file = new Menu("File"); + MenuItem NewRobot = new MenuItem("Nuovo robot"); + MenuItem ChangeRobot = new MenuItem("Dai i comandi a un altro robot"); + MenuItem DeleteRobot = new MenuItem("Elimina un robot"); + MenuItem Exit = new MenuItem("Esci"); + Menu LeftArm = new Menu("Braccio sinistro"); + MenuItem LeftArmMove = new MenuItem("Cambia posizione"); + MenuItem LeftArmOn = new MenuItem("Alza"); + MenuItem LeftArmOff = new MenuItem("Abbassa"); + Menu RightArm = new Menu("Braccio destro"); + MenuItem RightArmMove = new MenuItem("Cambia posizione"); + MenuItem RightArmOn = new MenuItem("Alza"); + MenuItem RightArmOff = new MenuItem("Abbassa"); + Menu LeftLeg = new Menu("Gamba sinistra"); + MenuItem LeftLegMove = new MenuItem("Cambia posizione"); + MenuItem LeftLegOn = new MenuItem("Alza"); + MenuItem LeftLegOff = new MenuItem("Abbassa"); + Menu RightLeg = new Menu("Gamba destra"); + MenuItem RightLegMove = new MenuItem("Cambia posizione"); + MenuItem RightLegOn = new MenuItem("Alza"); + MenuItem RightLegOff = new MenuItem("Abbassa"); + MenuItem Rename = new MenuItem("Rinomina"); + Menu azioni = new Menu("Azioni"); + MenuItem Exploud = new MenuItem("Esplodi"); + MenuItem Bier = new MenuItem("Birra"); + MenuItem xxx = new MenuItem("xxx"); + MenuItem Dance = new MenuItem("Balla"); + Menu info = new Menu("?"); + MenuItem Porky = new MenuItem("Informazioni sul programmatore"); + MenuItem l = new MenuItem("Legenda Comandi"); + MenuItem RobotList = new MenuItem("Lista robot"); +} + + + + diff --git a/robottino/all_versions/v2.3/src/RobottinoUtils/Listener.java b/robottino/all_versions/v2.3/src/RobottinoUtils/Listener.java @@ -0,0 +1,72 @@ +// Questa classe è il listener per gli eventi relativi alle finestre. +// Dichiaro che farà parte del package RobottinoUtils +package RobottinoUtils; + +// Importo i package necessari. +import java.awt.event.*; +import RobottinoMain.*; +import RobottinoAzioni.*; + +public class Listener implements WindowListener, ActionListener { + + RobottinoAzioni robottinoazioni = new RobottinoAzioni(); + + // Ridefinisco i metodi dell'interfaccia WindowListener: + // Metodo invocato quando la finestra è stata chiusa: + public void windowClosed (WindowEvent evt) { + + // Invoco il metodo sleep(int millisecondi) per mettere il programma in uno stato di attesa + // di durata pari ai millisecondi indicati come argomento. + System.out.println("La finestra è stata chiusa, il programma terminarà fra 3 secondi"); + try { + Robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("2"); + try { + Robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("1"); + try { + Robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("Programma terminato"); + System.exit(0); + } + + // Metodo invocato quando la finestra è in fase di chiusura: + public void windowClosing (WindowEvent evt) { + System.out.println ("Chiusura finestra in corso"); + evt.getWindow().dispose(); + } + + // Metodo invocato quando una finestra viene ridotta a icona: + public void windowIconified (WindowEvent evt) { + System.out.println("La finestra è stata ridotta a icona"); + } + + // Metodo invocato quando una finestra ridotta a icona viene ingrandita: + public void windowDeiconified (WindowEvent evt) { + System.out.println("La finestra ridotta a icona è stata ingrandita"); + } + + // Metodo invocato quando una finestra viene aperta: + public void windowOpened (WindowEvent evt) {} + + // Metodo invocato quando una finestra diventa attiva: + public void windowActivated (WindowEvent evt) {} + + // Metodo invocato quando una finestra viene disattivata: + public void windowDeactivated (WindowEvent evt) {} + + // Metodo invocato quando viene utilizzata la barra del menu: + // descrive tutte le azioni da compiere per ogni evento ricevuto + // dal menu. + public void actionPerformed (ActionEvent e) { + System.out.println (robottinoazioni.Azioni(e.getActionCommand(), RobottinoAzioni.nomeRobot, RobottinoAzioni.pdrA)); + } +} + + + + + diff --git a/robottino/all_versions/v2.3/src/RobottinoUtils/PartiDelRobot.java b/robottino/all_versions/v2.3/src/RobottinoUtils/PartiDelRobot.java @@ -0,0 +1,22 @@ +// Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. +package RobottinoUtils; + +// Dichiaro la classe. +public class PartiDelRobot { + + // Creo un costruttore senza argomenti. + // Se non lo facessi sarei obbligato a passare gli argomenti + // del secondo costruttore ogni volta che voglio istanziare la classe. + public PartiDelRobot() {} + + // Il secondo costruttore riceve come argomenti un booleano che passerà il valore a "statoParte" + // e una stringa che passa il valore a "stringaParte". + public PartiDelRobot(boolean b, String s) { + this.stringaParte = s; + this.statoParte = b; + } + + // Infine le due variabili pubbliche della classe. + public String stringaParte; + public boolean statoParte; +} diff --git a/robottino/all_versions/v3.0/Esegui.bat b/robottino/all_versions/v3.0/Esegui.bat @@ -0,0 +1,3 @@ +cd ./bin +java RobottinoMain/Robottino +cd diff --git a/robottino/all_versions/v3.0/Esegui.sh b/robottino/all_versions/v3.0/Esegui.sh @@ -0,0 +1,3 @@ +cd ./bin +java RobottinoMain/Robottino +cd diff --git a/robottino/all_versions/v3.0/Readme.txt b/robottino/all_versions/v3.0/Readme.txt @@ -0,0 +1,10 @@ +Il programma necessita della JVM (Java Virtual Machine) per funzionare correttamente + +Se si usano sistemi Windows aprire il file Esegui.bat +Se si usano sistemi Unix dare i permessi necessari ed eseguire il file Esegui.sh +Se si usano altri sistemi aprire una shell e digitare i comandi + +cd <percorsoFile>/bin +java Robottino + +dove percorsoFile è il percorso di questo file. diff --git a/robottino/all_versions/v3.0/bin/Immagini/ImmagineRobot.class b/robottino/all_versions/v3.0/bin/Immagini/ImmagineRobot.class Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/Immagini/img/laoff.gif b/robottino/all_versions/v3.0/bin/Immagini/img/laoff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/Immagini/img/lloff.gif b/robottino/all_versions/v3.0/bin/Immagini/img/lloff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/Immagini/img/raoff.gif b/robottino/all_versions/v3.0/bin/Immagini/img/raoff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/Immagini/img/rloff.gif b/robottino/all_versions/v3.0/bin/Immagini/img/rloff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/Immagini/img/robot.gif b/robottino/all_versions/v3.0/bin/Immagini/img/robot.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/RobottinoAzioni/RobottinoAzioni.class b/robottino/all_versions/v3.0/bin/RobottinoAzioni/RobottinoAzioni.class Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/RobottinoMain/Robottino.class b/robottino/all_versions/v3.0/bin/RobottinoMain/Robottino.class Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/RobottinoUtils/Grafica.class b/robottino/all_versions/v3.0/bin/RobottinoUtils/Grafica.class Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/RobottinoUtils/Listener.class b/robottino/all_versions/v3.0/bin/RobottinoUtils/Listener.class Binary files differ. diff --git a/robottino/all_versions/v3.0/bin/RobottinoUtils/PartiDelRobot.class b/robottino/all_versions/v3.0/bin/RobottinoUtils/PartiDelRobot.class Binary files differ. diff --git a/robottino/all_versions/v3.0/src/Immagini/ImmagineRobot.java b/robottino/all_versions/v3.0/src/Immagini/ImmagineRobot.java @@ -0,0 +1,35 @@ +package Immagini; +import java.awt.*; +import java.awt.image.*; + +public class ImmagineRobot { + + public Toolkit t; + public Image robot; + public Image raon; + public Image raoff; + public Image laon; + public Image laoff; + public Image rlon; + public Image rloff; + public Image llon; + public Image lloff; + public Image birra; + + public ImmagineRobot() { + + t = Toolkit.getDefaultToolkit(); + robot = t.getImage("./Immagini/img/robot.gif"); + raon = t.getImage("./Immagini/img/raon.gif"); + raoff = t.getImage("./Immagini/img/raoff.gif"); + laon = t.getImage("./Immagini/img/laon.gif"); + laoff = t.getImage("./Immagini/img/laoff.gif"); + rlon = t.getImage("./Immagini/img/rlon.gif"); + rloff = t.getImage("./Immagini/img/rloff.gif"); + llon = t.getImage("./Immagini/img/llon.gif"); + lloff = t.getImage("./Immagini/img/lloff.gif"); + birra = t.getImage("./Immagini/img/birra.gif"); + + } + +} diff --git a/robottino/all_versions/v3.0/src/Immagini/img/laoff.gif b/robottino/all_versions/v3.0/src/Immagini/img/laoff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/src/Immagini/img/lloff.gif b/robottino/all_versions/v3.0/src/Immagini/img/lloff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/src/Immagini/img/raoff.gif b/robottino/all_versions/v3.0/src/Immagini/img/raoff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/src/Immagini/img/rloff.gif b/robottino/all_versions/v3.0/src/Immagini/img/rloff.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/src/Immagini/img/robot.gif b/robottino/all_versions/v3.0/src/Immagini/img/robot.gif Binary files differ. diff --git a/robottino/all_versions/v3.0/src/RobottinoAzioni/RobottinoAzioni.java b/robottino/all_versions/v3.0/src/RobottinoAzioni/RobottinoAzioni.java @@ -0,0 +1,397 @@ +// Dichiaro che questa classa farà parte del package RobottinoAzioni, che verrà poi importato dalle classi Listener e Grafica. +package RobottinoAzioni; + +// Anche qui impoerto i package necessari. +// java.util.Scanner gestisce gli input da tastiera +import java.util.Scanner; + +// java.util.Vector +import java.util.Vector; + +// Package definito da me. +import RobottinoUtils.*; + +public class RobottinoAzioni { + + // Creo gli oggetti statici che riempiranno il vettore pdrA: + // pdrA è un vettore multidimensionale che a sua volta contiene vettori + // (il primo si chiama pdrB, i successivi non avranno nome) che coontengono + // 4 istanze di PartiDelRobot, cioè i 4 arti del robot. + // Poi creo un vettore che conterrà i nomi dei robot. + // Creo il vettore principale... + public static Vector pdrA = new Vector(1); + + // ...e il "sottovettore" come istanze della classe Vector + public static Vector pdrB = new Vector(4); + + // Creo le quattro istanze di PartidelRobot utilizzando l'apposito costruttore + // passo a tutte una stringa e un valore boleano che determina lo stato + // (alzato/a se true, abbassato/a se false). + public static PartiDelRobot leftArm = new PartiDelRobot(false, "il braccio sinistro alzato"); + public static PartiDelRobot rightArm = new PartiDelRobot(false, "il braccio destro alzato"); + public static PartiDelRobot leftLeg = new PartiDelRobot(false, "la gamba sinistra alzata"); + public static PartiDelRobot rightLeg = new PartiDelRobot(false, "la gamba destra alzata"); + + // Il vettore nomeRobot per i nomi + // il vettore può contenere stringhe, poichè non sono tipi primitivi ma oggetti della classe String + public static Vector nomeRobot = new Vector(1); + + // La variabile robotIndex serve a tenere in memoria su quale robot si sta operando: + // in seguito verrà usata quando l'utente deciderà di creare più di un robot + // e poi di dare comandi a uno o all'altro/i. + int robotIndex = 0; + + // Dichiarazione del metodo Azioni. + public String Azioni(String comando, Vector nomeRobot, Vector pdrA) { + + // Crea un'istanza della classe Scanner per + // ricevere gli input nel caso in cui debba essere dato il nome + // al robottino o scelto un robottino da una lista. + Scanner sc2 = new Scanner(System.in); + + // La variabile contatore memorizza il numero di variabili "PartiDelRobot.statoParte" + // che hanno valore true, ossia il numero di arti alzati di un robottino + // in modo da poter scegliere la frase giusta da dare come output + // al posto dell'immagine del robottino con tali arti alzati. + int contatore = 0; + + // Questo array ha il compito di memorizzare le stringhe corrispondenti agli alzati + // per motivi simili a quelli della variabile "contatore". + String stat[] = {"", "", "", ""}; + + // La stringa Return verrà successivamente modificata e restituita in alcuni casi. + String Return = "Errore - si consiglia di picchiare il programmatore"; + + // Per far si che il programma non distingua tra lettere maiuscole o minuscole per quanto riguardo gli input + // è stato usato il metodo "equalsIgnoreCase" della classe String. + // I quattro casi successivi cambiano il valore della varibalie "statoParte" relativa all'arto + // Che deve mouversi (quindi cambiare la sua posizione). + if (comando.equalsIgnoreCase("leftarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte; + + else if (comando.equalsIgnoreCase("rightarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte; + + else if (comando.equalsIgnoreCase("leftlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte; + + else if (comando.equalsIgnoreCase("rightlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = + !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte; + + // I casi successivi modificano il valore della varibile analogamente ai 4 precedenti. + else if (comando.equalsIgnoreCase("leftarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = true; + + else if (comando.equalsIgnoreCase("rightarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = true; + + else if (comando.equalsIgnoreCase("leftlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = true; + + else if (comando.equalsIgnoreCase("rightlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = true; + + else if (comando.equalsIgnoreCase("leftarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = false; + + else if (comando.equalsIgnoreCase("rightarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = false; + + else if (comando.equalsIgnoreCase("leftlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = false; + + else if (comando.equalsIgnoreCase("rightlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = false; + + // Il caso successi si verica quando il comando è "exploud". + else if (comando.equalsIgnoreCase("exploud")) { + + // Scrive sullo schermo la seguente frase, che comprende il nome del robottino che non è ancora stato fatto eliminare + System.out.println + ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot.elementAt(this.robotIndex) + "! Aspetta che te ne faccio un altro"); + System.out.println ("..."); + + // Con un ciclo for rendo false tutte le variabili "statoParte" per far sì che il robottino sia come nuovo. + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + + // E azzero anche il nome del robot + this.nomeRobot.setElementAt("", this.robotIndex); + + return "Fatto, puoi continuare a giocare"; + } + + // Caso per il comando "bier". + // La reazione a questo comando è un semplice output quasi totalmente scorrelato al robottino + // se non per il fatto che appare il nome del robottino attuale. + else if (comando.equalsIgnoreCase("bier")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "sta trangugiando una birra..."); + System.out.println ("Buurrrrrrrrp!"); + return "La birra analcolica fa schifo!"; + } + + // Per il comando "rename", rinomina. + else if (comando.equalsIgnoreCase("rename")) { + + System.out.println ("Con questo comando quoi cambiare il nome del robottino " + nomeRobot.elementAt(this.robotIndex)); + System.out.println ("Digita il nuovo nome e premi INVIO per coninuare"); + + // Cambia il nome del robottino attuale con quello dell'input. + this.nomeRobot.setElementAt(sc2.nextLine(), this.robotIndex); + + // Se il nome non è vuoto, aggiunge un carattere di spazio per migliorare la visualizzazione nelle frasi di output. + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + + // Semplice output con il nuovo nome. + return "Ora il robottino si chiama " + nomeRobot.elementAt(this.robotIndex); + } + + // Per il comando "porky". + // Ancora meno che per "bier". + else if (comando.equalsIgnoreCase("porky")) { + System.out.println ("Porky è un grande"); + System.out.println ("Per maggiori informazioni visita il sito"); + return "http://kakati.forumfree.net/"; + } + + // Il comando "xxx" ha funzioni analoghe a bier. + else if (comando.equalsIgnoreCase("xxx")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(this.robotIndex) + "ha incontrato una bella robottina..."); + return "*Censura*"; + } + + // "dance" setta tutte le variabili "statoParte" a false... + else if (comando.equalsIgnoreCase("dance")) { + + System.out.println ("Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + " stia ballando..."); + System.out.println ("Il robottino ha smesso di ballare"); + + //...con questo ciclo for + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + + return "Il robottino " + nomeRobot.elementAt(this.robotIndex) + "si è fermato ed è tornato nella posizione originale"; + + // Per il comando "newrobot", che crea un nuovo robottino. + } + else if (comando.equalsIgnoreCase("newrobot")) { + + // Aggiunge un elemento a "pdrA" con il metodo "addElement", della classe Vector. + // È stata necessaria la dicitura this. per modificare realmente il vettore. + // Se non lo avessi fatto non sarebbe successo, in quanto i metodi operano + // su i valori e non sulle variabili/oggetti. + this.pdrA.addElement(pdrB); + + // Aggiungo le 4 parti del robot. + // Forse avete già notato (ma quì sono più evidenti) alcuni cast che ho fatto: + // sono per far si che il compilatore capisca che il metodo viene invocato da un oggetto + // della classe vector, che senza cast considererebbe della classe Object. + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftLeg); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightLeg); + + // Semplice output con richiesta di nome per il nuovo robottino. + System.out.println ("È stato creato un nuovo robot. Vuoi dare un nome al nuovo robot?"); + System.out.println ("Inserisci il nuovo nome e premi INVIO oppure lascia vuoto e premi INVIO"); + + String newName = sc2.nextLine(); + + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + + this.nomeRobot.addElement(newName); + + return "È stato creato il robottino " + newName; + } + + // Il comando "deleterobot", per eliminare un robot. + else if (comando.equalsIgnoreCase("deleterobot")) { + + // Se c'è più di un robot esegue l'eliminazione. + if (pdrA.size()>1) { + System.out.println ("Quale robottino vuoi eliminare?"); + System.out.println (""); + + // Con un ciclo for scrive i nomi di tutti i robot preceduti da un numero in sequenza. + // Il numero è il corrispondente del loro indice di vettore. + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + + // Dà le istruzioni all'utente affinché capisca come eliminare un robot. + System.out.println (""); + System.out.println("Scegliere il robottino da eliminare digitando il numero corrispondente e premendo INVIO"); + System.out.println("Digitare un qualunque altro numero e premere INVIO per annullare"); + + int num = this.pdrA.size()+1; + + try { + + // Riceve in input il numero e ne assegna il valore alla variabile "num". + num = sc2.nextInt(); + + } catch (Exception e) { + System.out.println("Puoi inserire solo numeri"); + } + + // Elimina gli elementi corrispondenti al robottino (nome e robot) dai + // rispettivi vettori con il metodo "removeElementAt" della classe Vector. + if (num<this.pdrA.size()) { + this.pdrA.removeElementAt(num); + this.nomeRobot.removeElementAt(num); + return "È stato eliminato il robottino numero " + num; + } + + // Se il numero ricevuto in input è superiore all'indice dei robot + // non elimina alcun robot. + else return "Operazione annullata"; + } + + // Se c'è solo un robot non esegue l'eliminazione. + else return "Hai solo un robottino, non puoi eliminarlo!"; + } + + // Il comando "changerobot" per cambiare il robot a cui dare le istruzioni + else if (comando.equalsIgnoreCase("changerobot")) { + + // L'esecuzione è simile a quella per il comando "deleterobot", con la differenza che il robot non viene eliminato + // ma viene semplicemente cambiato il valore della variabile "robotIndex". + if (pdrA.size()>1) { + System.out.println ("A quale robottino vuoi dare i comandi?"); + System.out.println (""); + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + System.out.println (""); + System.out.println ("Digita il numero corrispondente alla tua scelta e premi INVIO"); + + int newIndex = this.pdrA.size()+1; + + try { + + newIndex = sc2.nextInt(); + + } catch (Exception e) { + System.out.println("Puoi inserire solo numeri"); + } + + // Prima di cambiare valore alla variabile di indice verifica che il numero sia valido. + if (newIndex<this.pdrA.size()) { + this.robotIndex = newIndex; + return "È stato selezionato il robottino numero " + this.robotIndex + ": " + this.nomeRobot.elementAt + (this.robotIndex); + } + + // Se non lo è non esegue l'assegnamento. + else return "Numero non valido - Operazione annullata"; + } + else { + return "Hai solo un robottino, non puoi cambiarlo con un altro!"; + } + } + + // Il comando "robotlist" visualizza una lista dei robot presenti. + else if (comando.equalsIgnoreCase("robotlist")) { + for (int i = 0; i<this.pdrA.size(); i++) { + System.out.println (i + ". " + this.nomeRobot.elementAt(i)); + } + return ""; + } + + // Il comando "l", per la legenda, visualizza la lista dei comandi con relativa descrizione. + else if (comando.equalsIgnoreCase("l")) { + System.out.println ("Legenda comandi"); + System.out.println (""); + System.out.println ("Comandi relativi agli arti"); + System.out.println (""); + System.out.println ("LeftArmMove: cambia la posizione corrente del braccio sinistro del robot"); + System.out.println ("RightArmMove: cambia la posizione corrente del braccio destro del robot"); + System.out.println ("LeftLegMove: cambia la posizione corrente della gamba sinistra del robot"); + System.out.println ("RightLegMove: cambia la posizione corrente della gamba destra del robot"); + System.out.println ("LeftArmOn: se il braccio sinistro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOn: se il braccio destro non è alzato, lo alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOn: se la gamba sinistra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOn: se la gamba destra non è alzata, la alza, altrimenti la posizione resta invariata"); + System.out.println ("LeftArmOff: se il braccio sinistro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightArmOff: se il braccio destro non è abbassato, lo abbassa, altrimenti la posizione resta invariata"); + System.out.println ("LeftLegOff: se la gamba sinistra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println ("RightLegOff: se la gamba destra non è abbassata, la abbassa, altrimenti la posizione resta invariata"); + System.out.println (""); + System.out.println ("Altri comandi:"); + System.out.println (""); + System.out.println ("NewRobot: aggiunge un nuovo robot"); + System.out.println ("ChangeRobot: cambia il robot attuale"); + System.out.println ("RobotList: visualizza la lista dei robot"); + System.out.println ("Rename: rinomina il robottino"); + System.out.println (""); + System.out.println ("Comandi a sorpresa:"); + System.out.println (""); + System.out.println ("Exploud"); + System.out.println ("Bier"); + System.out.println ("Porky"); + System.out.println ("xxx"); + System.out.println ("dance"); + System.out.println (""); + System.out.println ("Exit: esci dal programma"); + + return ""; + + } + + // Se il comando è exit, esce dal programma. + else if (comando.equalsIgnoreCase("exit")) { + System.exit(0); + return ""; + } + + // Se l'input non è tra i comandi prestabiliti, visualizza la seguente scritta sullo schermo. + else + System.out.println ("Comando non riconosciuto - digitare l per una legenda dei comandi disponibili"); + System.out.println (""); + + // Quì di seguito viene chiarito l'utilizzo di "contatore" e "sta[]". + // Per ogni varibile "statoParte" che ha valore true, contatore viene incrementato + // e l'elemento successivo dell'array "stat[]" assume il valore della stringa corrispondente. + for (int i = 0, j = 0; i < 4; i++) { + if (((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte) { + contatore += 1; + stat[j++] = ((PartiDelRobot)((Vector)pdrA.elementAt(this.robotIndex)).elementAt(i)).stringaParte; + } + } + + // La restituzione finale delle frasi, con uno switch che a seconda del valore di contatore + // restituisce una frase o l'altra. + switch (contatore) { + case 0: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"non ha nessun arto alzato"; + break; + case 1: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0] + "."; + break; + case 2: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0]+" e "+stat[1]+"."; + break; + case 3: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0]+", "+stat[1]+" e "+stat[2]+"."; + break; + case 4: + Return = "Il robottino "+nomeRobot.elementAt(this.robotIndex)+"ha "+stat[0]+", "+stat[1]+", "+stat[2]+" e "+stat[3]+". Sta per cadere! Ah no, può restare sospeso in aria"; + break; + } + return Return; + } + //Fine del metodo Azioni +} + + + + + diff --git a/robottino/all_versions/v3.0/src/RobottinoMain/Robottino.java b/robottino/all_versions/v3.0/src/RobottinoMain/Robottino.java @@ -0,0 +1,63 @@ +// Robottino versione 3.0 + +// Dichiaro che questa classe fa parte del package RobottinoMain, che verrà poi importato +// dalle classi che dovranno interagire con essa. +package RobottinoMain; + +// Importo la classe Grafica per poter "costruire" una finestra. +import RobottinoUtils.*; + +// E il package Robottinoazioni per poterne inizializzare i vettori +import RobottinoAzioni.*; + +// java.util.Vector serve a gestire i vettori. +// I vettori sono come array, ma hanno due differenze principali: +// 1) la loro lunghezza può variare durante l'esecuzione del programma +// (per questo li ho preferiti agli array); +// 2) possono contenere soltanto oggetti, e non tipi primitivi. +import java.util.Vector; + +// Dichiaro la classe. +public class Robottino { + + // Istanzio la classe Thread per poter utilizzare il metodo sleep(int millisecondi) + // che in un metodo dell'interfaccia WindowListener, overridato nella classe Listener + // servirà a mettere il programma in uno stato di pausa. + // Sarebbe comunque possibile invocarlo, ma così sarà più facile da modificare in futuro. + public Thread threadMain; + + // Crea la finestra tramite un'istanza della classe Grafica, del package RobottinoUtils. + public Grafica finestra; + + // Creo anche un'istanza di questa classe per avere accesso agli elementi non statici. + public static Robottino robottino; + + // Inizio del metodo main... + public static void main(String[] args) { + + // Inizializzo i vari oggetti. + robottino = new Robottino(); + robottino.finestra = new Grafica(); + robottino.threadMain = new Thread(Thread.currentThread()); + + // Aggiungo gli elementi ai vettori. + // non potevo farlo prima, poiché al di fuori di un metodo è possibile soltanto + // dichiarare oggetti/variabili (e inizializzarli) o dichiarare un metodo + // e in RobottinoAzioni è presente solo il metodo Azioni che viene richiamato più volte. + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.leftArm); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.rightArm); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.leftLeg); + RobottinoAzioni.pdrB.addElement(RobottinoAzioni.rightLeg); + RobottinoAzioni.pdrA.addElement(RobottinoAzioni.pdrB); + RobottinoAzioni.nomeRobot.addElement(""); + } +} + + + + + + + + + diff --git a/robottino/all_versions/v3.0/src/RobottinoUtils/Grafica.java b/robottino/all_versions/v3.0/src/RobottinoUtils/Grafica.java @@ -0,0 +1,226 @@ +// Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. +package RobottinoUtils; + +// Importo i package standard relativi al funzionamento delle finestre e della grafica in generale. +import java.awt.*; + +// E i package RobottinoAzioni, RobottinoUtils e Immagini da me definiti. +import RobottinoAzioni.*; +import RobottinoUtils.Listener; +import Immagini.*; + +// La classe è una sottoclasse di Frame per poter sfruttare gli effetti grafici +// ma implementa anche l'interfaccia WindowListener, necessaria per gestire gli eventi collegati alle finestre +// (riduzione a icona, chiusura...); per questo devo successivamente ridefinire tutti i +// metodi dell'interfaccia. +public class Grafica extends Frame { + + // Creo un'istanza della classe Listener che userò come listener per gli eventi. + public static Listener listener; + + // E una di ImmagineRobot per le immagini. + public static ImmagineRobot immagineRobot = new ImmagineRobot(); + + // Il costruttore senza argomenti. + public Grafica () { + + // Il metodo "setBounds" posiziona e dimensiona la finestra. + setBounds (this.orizzontale, this.verticale, this.larghezza, this.altezza); + + // "setTitle" per il titolo della finestra. + setTitle ("Robottino v2.2"); + + // "setVisible" per poterla visualizzare. + setVisible (true); + + // E addWindowListener per l'ascoltatore (listener). + listener = new Listener(); + addWindowListener (listener); + + // Aggiungo la barra del menu con i vari sottomenu + setMenuBar (barraMenu); + + // Il menu file. + NewRobot.addActionListener(listener); + NewRobot.setActionCommand("newrobot"); + + ChangeRobot.addActionListener(listener); + ChangeRobot.setActionCommand("changerobot"); + + DeleteRobot.addActionListener(listener); + DeleteRobot.setActionCommand("deleterobot"); + + Exit.addActionListener(listener); + Exit.setActionCommand("exit"); + + file.add(NewRobot); + file.add(ChangeRobot); + file.add(DeleteRobot); + file.addSeparator(); + file.add(Exit); + + barraMenu.add(file); + + // Il braccio sinistro. + LeftArmMove.addActionListener(listener); + LeftArmMove.setActionCommand("leftarmmove"); + + LeftArmOn.addActionListener(listener); + LeftArmOn.setActionCommand("leftarmon"); + + LeftArmOff.addActionListener(listener); + LeftArmOff.setActionCommand("leftarmoff"); + + LeftArm.add(LeftArmMove); + LeftArm.add(LeftArmOn); + LeftArm.add(LeftArmOff); + + // Il braccio destro. + RightArmMove.addActionListener(listener); + RightArmMove.setActionCommand("rightarmmove"); + + RightArmOn.addActionListener(listener); + RightArmOn.setActionCommand("rightarmon"); + + RightArmOff.addActionListener(listener); + RightArmOff.setActionCommand("rightarmoff"); + + RightArm.add(RightArmMove); + RightArm.add(RightArmOn); + RightArm.add(RightArmOff); + + // La gamba sinistra. + LeftLegMove.addActionListener(listener); + LeftLegMove.setActionCommand("leftlegmove"); + + LeftLegOn.addActionListener(listener); + LeftLegOn.setActionCommand("leftlegon"); + + LeftLegOff.addActionListener(listener); + LeftLegOff.setActionCommand("leftlegoff"); + + LeftLeg.add(LeftLegMove); + LeftLeg.add(LeftLegOn); + LeftLeg.add(LeftLegOff); + + // La gamba destra. + RightLegMove.addActionListener(listener); + RightLegMove.setActionCommand("rightlegmove"); + + RightLegOn.addActionListener(listener); + RightLegOn.setActionCommand("rightlegon"); + + RightLegOff.addActionListener(listener); + RightLegOff.setActionCommand("rightlegoff"); + + RightLeg.add(RightLegMove); + RightLeg.add(RightLegOn); + RightLeg.add(RightLegOff); + + // Menu rinomina. + Rename.addActionListener(listener); + Rename.setActionCommand("rename"); + + Menu modifica = new Menu("Modifica"); + modifica.add(LeftArm); + modifica.add(RightArm); + modifica.add(LeftLeg); + modifica.add(RightLeg); + modifica.addSeparator(); + modifica.add(Rename); + + barraMenu.add(modifica); + + // Menu azioni. + Exploud.addActionListener(listener); + Exploud.setActionCommand("exploud"); + + Bier.addActionListener(listener); + Bier.setActionCommand("bier"); + + xxx.addActionListener(listener); + xxx.setActionCommand("xxx"); + + Dance.addActionListener(listener); + Dance.setActionCommand("dance"); + + azioni.add(Exploud); + azioni.add(Bier); + azioni.add(xxx); + azioni.add(Dance); + + barraMenu.add(azioni); + + // Menu info. + Porky.addActionListener(listener); + Porky.setActionCommand("porky"); + + l.addActionListener(listener); + l.setActionCommand("l"); + + RobotList.addActionListener(listener); + RobotList.setActionCommand("robotlist"); + + info.add(Porky); + info.add(l); + info.add(RobotList); + + barraMenu.add(info); + } + + // Le variabili pubbliche di classe per il metodo "setBounds". + public int orizzontale = 0; + public int verticale = 0; + public int larghezza = 360; + public int altezza = 550; + + // E i vari Menu e MenuItem. + MenuBar barraMenu = new MenuBar(); + Menu file = new Menu("File"); + MenuItem NewRobot = new MenuItem("Nuovo robot"); + MenuItem ChangeRobot = new MenuItem("Dai i comandi a un altro robot"); + MenuItem DeleteRobot = new MenuItem("Elimina un robot"); + MenuItem Exit = new MenuItem("Esci"); + Menu LeftArm = new Menu("Braccio sinistro"); + MenuItem LeftArmMove = new MenuItem("Cambia posizione"); + MenuItem LeftArmOn = new MenuItem("Alza"); + MenuItem LeftArmOff = new MenuItem("Abbassa"); + Menu RightArm = new Menu("Braccio destro"); + MenuItem RightArmMove = new MenuItem("Cambia posizione"); + MenuItem RightArmOn = new MenuItem("Alza"); + MenuItem RightArmOff = new MenuItem("Abbassa"); + Menu LeftLeg = new Menu("Gamba sinistra"); + MenuItem LeftLegMove = new MenuItem("Cambia posizione"); + MenuItem LeftLegOn = new MenuItem("Alza"); + MenuItem LeftLegOff = new MenuItem("Abbassa"); + Menu RightLeg = new Menu("Gamba destra"); + MenuItem RightLegMove = new MenuItem("Cambia posizione"); + MenuItem RightLegOn = new MenuItem("Alza"); + MenuItem RightLegOff = new MenuItem("Abbassa"); + MenuItem Rename = new MenuItem("Rinomina"); + Menu azioni = new Menu("Azioni"); + MenuItem Exploud = new MenuItem("Esplodi"); + MenuItem Bier = new MenuItem("Birra"); + MenuItem xxx = new MenuItem("xxx"); + MenuItem Dance = new MenuItem("Balla"); + Menu info = new Menu("?"); + MenuItem Porky = new MenuItem("Informazioni sul programmatore"); + MenuItem l = new MenuItem("Legenda Comandi"); + MenuItem RobotList = new MenuItem("Lista robot"); + + + // Il metodo per disegnare l'immagine del robot. + public void paint(Graphics g){ + g.drawImage(immagineRobot.robot, 100, 60, this); + g.drawImage(immagineRobot.raoff, 66, 248, this); + g.drawImage(immagineRobot.laoff, 225, 242, this); + g.drawImage(immagineRobot.rloff, 84, 367, this); + g.drawImage(immagineRobot.lloff, 148, 367, this); + } + + +} + + + + diff --git a/robottino/all_versions/v3.0/src/RobottinoUtils/Listener.java b/robottino/all_versions/v3.0/src/RobottinoUtils/Listener.java @@ -0,0 +1,73 @@ +// Questa classe è il listener per gli eventi relativi alle finestre. +// Dichiaro che farà parte del package RobottinoUtils +package RobottinoUtils; + +// Importo i package necessari. +import java.awt.event.*; +import RobottinoMain.*; +import RobottinoAzioni.*; + +public class Listener implements WindowListener, ActionListener { + + RobottinoAzioni robottinoazioni = new RobottinoAzioni(); + + + // Ridefinisco i metodi dell'interfaccia WindowListener: + // Metodo invocato quando la finestra è stata chiusa: + public void windowClosed (WindowEvent evt) { + + // Invoco il metodo sleep(int millisecondi) per mettere il programma in uno stato di attesa + // di durata pari ai millisecondi indicati come argomento. + System.out.println("La finestra è stata chiusa, il programma terminarà fra 3 secondi"); + try { + Robottino.robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("2"); + try { + Robottino.robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("1"); + try { + Robottino.robottino.threadMain.sleep(1000); + } catch (Exception e) { e.printStackTrace(); } + System.out.println("Programma terminato"); + System.exit(0); + } + + // Metodo invocato quando la finestra è in fase di chiusura: + public void windowClosing (WindowEvent evt) { + System.out.println ("Chiusura finestra in corso"); + evt.getWindow().dispose(); + } + + // Metodo invocato quando una finestra viene ridotta a icona: + public void windowIconified (WindowEvent evt) { + System.out.println("La finestra è stata ridotta a icona"); + } + + // Metodo invocato quando una finestra ridotta a icona viene ingrandita: + public void windowDeiconified (WindowEvent evt) { + System.out.println("La finestra ridotta a icona è stata ingrandita"); + } + + // Metodo invocato quando una finestra viene aperta: + public void windowOpened (WindowEvent evt) {} + + // Metodo invocato quando una finestra diventa attiva: + public void windowActivated (WindowEvent evt) {} + + // Metodo invocato quando una finestra viene disattivata: + public void windowDeactivated (WindowEvent evt) {} + + // Metodo invocato quando viene utilizzata la barra del menu: + // descrive tutte le azioni da compiere per ogni evento ricevuto + // dal menu. + public void actionPerformed (ActionEvent e) { + System.out.println (robottinoazioni.Azioni(e.getActionCommand(), RobottinoAzioni.nomeRobot, RobottinoAzioni.pdrA)); + } +} + + + + + diff --git a/robottino/all_versions/v3.0/src/RobottinoUtils/PartiDelRobot.java b/robottino/all_versions/v3.0/src/RobottinoUtils/PartiDelRobot.java @@ -0,0 +1,22 @@ +// Dichiaro che questa classa farà parte del package RobottinoUtils, che verrà poi importato dalla classe Robottino. +package RobottinoUtils; + +// Dichiaro la classe. +public class PartiDelRobot { + + // Creo un costruttore senza argomenti. + // Se non lo facessi sarei obbligato a passare gli argomenti + // del secondo costruttore ogni volta che voglio istanziare la classe. + public PartiDelRobot() {} + + // Il secondo costruttore riceve come argomenti un booleano che passerà il valore a "statoParte" + // e una stringa che passa il valore a "stringaParte". + public PartiDelRobot(boolean b, String s) { + this.stringaParte = s; + this.statoParte = b; + } + + // Infine le due variabili pubbliche della classe. + public String stringaParte; + public boolean statoParte; +} diff --git a/robottino/all_versions/v4.0.1/Robottino.jar b/robottino/all_versions/v4.0.1/Robottino.jar Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/Frame.java b/robottino/all_versions/v4.0.1/src/Frame.java @@ -0,0 +1,66 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; + +public class Frame extends JFrame { + public class Listener implements ActionListener { + public void actionPerformed( ActionEvent e ) { + if ( e.getSource() == exit ) + System.exit(0); + else if ( e.getSource() == informazioni ) + JOptionPane.showMessageDialog( main.frame, "info", "Robottino v4.0 - Informazioni", JOptionPane.INFORMATION_MESSAGE ); + else if ( e.getSource() == nuovo ) { + String nome = JOptionPane.showInputDialog( main.frame, "Inserire il nome del nuovo robottino:", "Robot " + ( ++main.robots ) ); + if ( nome != null ) + main.list.newRobot( nome ); + } + } + } + public static Listener listener; + public static Main main; + public static JMenuBar barraMenu = new JMenuBar(); + public static JMenu file = new JMenu( "File" ); + public static JMenu info = new JMenu( "?" ); + public static JMenuItem exit = new JMenuItem( "Esci" ); + public static JMenuItem informazioni = new JMenuItem( "Informazioni" ); + public static JMenuItem nuovo = new JMenuItem( "Nuovo Robot" ); + public Frame() { + super( "Robottino versione 4.0" ); + listener = new Listener(); + main = new Main(); + exit.addActionListener( listener ); + exit.setMnemonic( 'E' ); + informazioni.addActionListener( listener ); + informazioni.setMnemonic( 'I' ); + nuovo.addActionListener( listener ); + nuovo.setMnemonic( 'N' ); + file.add( exit ); + file.add( nuovo ); + file.setMnemonic( 'F' ); + info.add( informazioni ); + info.setMnemonic( '?' ); + barraMenu.add( file ); + barraMenu.add( info ); + setJMenuBar( barraMenu ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0.1/src/List.java b/robottino/all_versions/v4.0.1/src/List.java @@ -0,0 +1,74 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JOptionPane; + +public class List { + public static Main main = new Main(); + public Robot primoRobot, ultimoRobot; + public List() { + primoRobot = ultimoRobot = null; + } + public boolean vuota() { + return primoRobot == null; + } + public Robot getRobot( String nome ) { + Robot i = primoRobot; + for ( ; !i.nomeRobot.equals( nome ); i = i.prossimoRobot ) ; + return i; + } + public void newRobot() { + newRobot( false, false, false, false, "" ); + } + public void newRobot( String nome ) { + newRobot( false, false, false, false, nome ); + } + public void newRobot( boolean la, boolean ra, boolean ll, boolean rl, String nome ) { + if ( vuota() ) + primoRobot = ultimoRobot = new Robot( la, ra, ll, rl, nome, null, null ); + else { + ultimoRobot = new Robot( la, ra, ll, rl, nome, ultimoRobot, null ); + ultimoRobot.precedenteRobot.prossimoRobot = ultimoRobot; + } + } + public void deleteRobot( String nome ) { + if ( vuota() ) + JOptionPane.showMessageDialog( main.frame, "Nessun robottino presente. Impossibile cancellarne uno", "Robottino v4.0 - Errore", JOptionPane.ERROR_MESSAGE ); + else { + Robot i = primoRobot; + for ( ; !i.nomeRobot.equals( nome ); i = i.prossimoRobot ) ; + if ( i.precedenteRobot != null ) + i.precedenteRobot.prossimoRobot = i.prossimoRobot; + else + primoRobot = i.prossimoRobot; + if ( i.prossimoRobot != null ) + i.prossimoRobot.precedenteRobot = i.precedenteRobot; + else + ultimoRobot = i.precedenteRobot; + } + } + public void printList() { + String lista = ""; + for ( Robot i = primoRobot; i != null; i = i.prossimoRobot ) + lista += i.getName() + " "; + JOptionPane.showMessageDialog( main.frame, lista, "Robottino v4.0 - Robottini Presenti", JOptionPane.PLAIN_MESSAGE ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0.1/src/Main.java b/robottino/all_versions/v4.0.1/src/Main.java @@ -0,0 +1,36 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; + +public class Main { + public static int robots; + public static List list; + public static Frame frame; + public static void main ( String args[] ) { + robots = 0; + list = new List(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + frame.setSize( 350, 150 ); + frame.setVisible( true ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0.1/src/Robot.java b/robottino/all_versions/v4.0.1/src/Robot.java @@ -0,0 +1,107 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; +import java.awt.*; + +public class Robot { + public static Main main = new Main(); + boolean leftArm, rightArm, leftLeg, rightLeg; + String nomeRobot; + Robot precedenteRobot, prossimoRobot; + RobotFrame robotFrame; + Robot() { + this( false, false, false, false, "", main.list.ultimoRobot, null ); + } + Robot( String nome ) { + this ( false, false, false, false, nome, main.list.ultimoRobot, null ); + } + Robot( boolean la, boolean ra, boolean ll, boolean rl, String nome, Robot prec, Robot prox ) { + leftArm = la; + rightArm = ra; + leftLeg = ll; + rightLeg = rl; + nomeRobot = nome; + precedenteRobot = prec; + prossimoRobot = prox; + robotFrame = new RobotFrame( nome ); + robotFrame.setSize( 350, 600 ); + robotFrame.setVisible( true ); + robotFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + robotFrame.addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Robot.this.robotFrame, "Eliminare il robottino " + Robot.this.getName() + " ?", "Robottino v4.0 - Cancellazione robottino", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.list.deleteRobot( Robot.this.getName() ); + robotFrame.dispose(); + } + else { + try { + Thread.currentThread().sleep( 50 ); + } catch ( Exception e2 ) {} + robotFrame.repaint(); + } + } + } + ); + } + void setLA( boolean la ) { + setPositions( la, this.rightArm, this.leftLeg, this.rightLeg ); + } + void setRA( boolean ra ) { + setPositions( this.leftArm, ra, this.leftLeg, this.rightLeg ); + } + void setLL( boolean ll ) { + setPositions( this.leftArm, this.rightArm, ll, this.rightLeg ); + } + void setRL( boolean rl ) { + setPositions( this.leftArm, this.rightArm, this.leftLeg, rl ); + } + void setPositions( boolean la, boolean ra, boolean ll, boolean rl ) { + leftArm = la; + rightArm = ra; + leftLeg = ll; + rightLeg = rl; + } + void setName( String nome ) { + nomeRobot = nome; + } + boolean getLA() { + return leftArm; + } + boolean getRA() { + return rightArm; + } + boolean getLL() { + return leftLeg; + } + boolean getRL() { + return rightLeg; + } + String getName() { + return nomeRobot; + } + Robot getNext() { + return prossimoRobot; + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0.1/src/RobotFrame.java b/robottino/all_versions/v4.0.1/src/RobotFrame.java @@ -0,0 +1,118 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; +import java.awt.*; + +public class RobotFrame extends JFrame implements ActionListener { + public static Main main; + public static RobotPanel robotPanel; + public static JMenuBar barraMenu; + public static JMenu modifica, raMenu, laMenu, rlMenu, llMenu; + public static JMenuItem raonMenuItem, raoffMenuItem, rachangeMenuItem, laonMenuItem, laoffMenuItem, lachangeMenuItem; + public static JMenuItem rlonMenuItem, rloffMenuItem, rlchangeMenuItem, llonMenuItem, lloffMenuItem, llchangeMenuItem; + RobotFrame( String titolo ) { + super ( titolo ); + robotPanel = new RobotPanel( titolo ); + raonMenuItem = new JMenuItem( "Alza" ); + laonMenuItem = new JMenuItem( "Alza" ); + rlonMenuItem = new JMenuItem( "Alza" ); + llonMenuItem = new JMenuItem( "Alza" ); + raoffMenuItem = new JMenuItem( "Abbassa" ); + laoffMenuItem = new JMenuItem( "Abbassa" ); + rloffMenuItem = new JMenuItem( "Abbassa" ); + lloffMenuItem = new JMenuItem( "Abbassa" ); + rachangeMenuItem = new JMenuItem( "Cambia posizione" ); + lachangeMenuItem = new JMenuItem( "Cambia posizione" ); + rlchangeMenuItem = new JMenuItem( "Cambia posizione" ); + llchangeMenuItem = new JMenuItem( "Cambia posizione" ); + raonMenuItem.addActionListener( this ); + raoffMenuItem.addActionListener( this ); + rachangeMenuItem.addActionListener( this ); + laonMenuItem.addActionListener( this ); + laoffMenuItem.addActionListener( this ); + lachangeMenuItem.addActionListener( this ); + rlonMenuItem.addActionListener( this ); + rloffMenuItem.addActionListener( this ); + rlchangeMenuItem.addActionListener( this ); + llonMenuItem.addActionListener( this ); + lloffMenuItem.addActionListener( this ); + llchangeMenuItem.addActionListener( this ); + raMenu = new JMenu( "Braccio destro" ); + raMenu.add( raonMenuItem ); + raMenu.add( raoffMenuItem ); + raMenu.add( rachangeMenuItem ); + laMenu = new JMenu( "Braccio sinistro" ); + laMenu.add( laonMenuItem ); + laMenu.add( laoffMenuItem ); + laMenu.add( lachangeMenuItem ); + rlMenu = new JMenu( "Gamba destra" ); + rlMenu.add( rlonMenuItem ); + rlMenu.add( rloffMenuItem ); + rlMenu.add( rlchangeMenuItem ); + llMenu = new JMenu( "Gamba sinistra" ); + llMenu.add( llonMenuItem ); + llMenu.add( lloffMenuItem ); + llMenu.add( llchangeMenuItem ); + modifica = new JMenu( "Modifica" ); + modifica.add( raMenu ); + modifica.add( laMenu ); + modifica.add( rlMenu ); + modifica.add( llMenu ); + barraMenu = new JMenuBar(); + barraMenu.add( modifica ); + setJMenuBar( barraMenu ); + add( robotPanel ); + } + public void actionPerformed( ActionEvent e ) { + esegui( e ); + } + public void esegui( ActionEvent e ) { + if ( e.getSource() == raonMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = true; + else if ( e.getSource() == raoffMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = false; + else if ( e.getSource() == rachangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = !main.list.getRobot( this.getTitle() ).rightArm; + else if ( e.getSource() == laonMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = true; + else if ( e.getSource() == laoffMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = false; + else if ( e.getSource() == lachangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = !main.list.getRobot( this.getTitle() ).leftArm; + if ( e.getSource() == rlonMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = true; + else if ( e.getSource() == rloffMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = false; + else if ( e.getSource() == rlchangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = !main.list.getRobot( this.getTitle() ).rightLeg; + else if ( e.getSource() == llonMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = true; + else if ( e.getSource() == lloffMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = false; + else if ( e.getSource() == llchangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = !main.list.getRobot( this.getTitle() ).leftLeg; + robotPanel.setImages(); + repaint(); + } + +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0.1/src/RobotPanel.java b/robottino/all_versions/v4.0.1/src/RobotPanel.java @@ -0,0 +1,96 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.*; + +public class RobotPanel extends JPanel { + public static String nomeRobot; + public static Main main; + public static ImageIcon ra, la, rl, ll, body; + public static int rax, ray, lax, lay, rlx, rly, llx, lly; + RobotPanel( String nomeRobot ) { + this.nomeRobot = nomeRobot; + rax = 66; + ray = 248; + lax = 225; + lay = 242; + rlx = 84; + rly = 367; + llx = 148; + lly = 367; + body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + } + public void paint ( Graphics g ) { + super.paint( g ); + body.paintIcon( this, g, 100, 60 ); + ra.paintIcon( this, g, this.rax, this.ray ); + la.paintIcon( this, g, this.lax, this.lay ); + rl.paintIcon( this, g, this.rlx, this.rly ); + ll.paintIcon( this, g, this.llx, this.lly ); + } + public void setImages() { + if ( main.list.getRobot( nomeRobot ).rightArm ) { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raon.gif" ) ); + this.rax = 68; + this.ray = 128; + } + else { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + this.rax = 66; + this.ray = 248; + } + if ( main.list.getRobot( nomeRobot ).leftArm ) { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laon.gif" ) ); + this.lax = 224; + this.lay = 118; + } + else { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + this.lax = 225; + this.lay = 242; + } + if ( main.list.getRobot( nomeRobot ).rightLeg ) { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rlon.gif" ) ); + this.rlx = 84; + this.rly = 356; + } + else { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + this.rlx = 84; + this.rly = 367; + } + if ( main.list.getRobot( nomeRobot ).leftLeg ) { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/llon.gif" ) ); + this.llx = 140; + this.lly = 363; + } + else { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + this.llx = 148; + this.lly = 367; + } + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0.1/src/img/birra1.jpg b/robottino/all_versions/v4.0.1/src/img/birra1.jpg Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/birra2.jpg b/robottino/all_versions/v4.0.1/src/img/birra2.jpg Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/birra3.jpg b/robottino/all_versions/v4.0.1/src/img/birra3.jpg Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/birra4.jpg b/robottino/all_versions/v4.0.1/src/img/birra4.jpg Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/birra5.gif b/robottino/all_versions/v4.0.1/src/img/birra5.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/laoff.gif b/robottino/all_versions/v4.0.1/src/img/laoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/laon.gif b/robottino/all_versions/v4.0.1/src/img/laon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/lloff.gif b/robottino/all_versions/v4.0.1/src/img/lloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/llon.gif b/robottino/all_versions/v4.0.1/src/img/llon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/raoff.gif b/robottino/all_versions/v4.0.1/src/img/raoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/raon.gif b/robottino/all_versions/v4.0.1/src/img/raon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/rloff.gif b/robottino/all_versions/v4.0.1/src/img/rloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/rlon.gif b/robottino/all_versions/v4.0.1/src/img/rlon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0.1/src/img/robot.gif b/robottino/all_versions/v4.0.1/src/img/robot.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/Robottino.jar b/robottino/all_versions/v4.0/Robottino.jar Binary files differ. diff --git a/robottino/all_versions/v4.0/src/Frame.java b/robottino/all_versions/v4.0/src/Frame.java @@ -0,0 +1,66 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; + +public class Frame extends JFrame { + public class Listener implements ActionListener { + public void actionPerformed( ActionEvent e ) { + if ( e.getSource() == exit ) + System.exit(0); + else if ( e.getSource() == informazioni ) + JOptionPane.showMessageDialog( main.frame, "info", "Robottino v4.0 - Informazioni", JOptionPane.INFORMATION_MESSAGE ); + else if ( e.getSource() == nuovo ) { + String nome = JOptionPane.showInputDialog( main.frame, "Inserire il nome del nuovo robottino:", "Robot " + ( ++main.robots ) ); + if ( nome != null ) + main.list.newRobot( nome ); + } + } + } + public static Listener listener; + public static Main main; + public static JMenuBar barraMenu = new JMenuBar(); + public static JMenu file = new JMenu( "File" ); + public static JMenu info = new JMenu( "?" ); + public static JMenuItem exit = new JMenuItem( "Esci" ); + public static JMenuItem informazioni = new JMenuItem( "Informazioni" ); + public static JMenuItem nuovo = new JMenuItem( "Nuovo Robot" ); + public Frame() { + super( "Robottino versione 4.0" ); + listener = new Listener(); + main = new Main(); + exit.addActionListener( listener ); + exit.setMnemonic( 'E' ); + informazioni.addActionListener( listener ); + informazioni.setMnemonic( 'I' ); + nuovo.addActionListener( listener ); + nuovo.setMnemonic( 'N' ); + file.add( exit ); + file.add( nuovo ); + file.setMnemonic( 'F' ); + info.add( informazioni ); + info.setMnemonic( '?' ); + barraMenu.add( file ); + barraMenu.add( info ); + setJMenuBar( barraMenu ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0/src/List.java b/robottino/all_versions/v4.0/src/List.java @@ -0,0 +1,74 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JOptionPane; + +public class List { + public static Main main = new Main(); + public Robot primoRobot, ultimoRobot; + public List() { + primoRobot = ultimoRobot = null; + } + public boolean vuota() { + return primoRobot == null; + } + public Robot getRobot( String nome ) { + Robot i = primoRobot; + for ( ; !i.nomeRobot.equals( nome ); i = i.prossimoRobot ) ; + return i; + } + public void newRobot() { + newRobot( false, false, false, false, "" ); + } + public void newRobot( String nome ) { + newRobot( false, false, false, false, nome ); + } + public void newRobot( boolean la, boolean ra, boolean ll, boolean rl, String nome ) { + if ( vuota() ) + primoRobot = ultimoRobot = new Robot( la, ra, ll, rl, nome, null, null ); + else { + ultimoRobot = new Robot( la, ra, ll, rl, nome, ultimoRobot, null ); + ultimoRobot.precedenteRobot.prossimoRobot = ultimoRobot; + } + } + public void deleteRobot( String nome ) { + if ( vuota() ) + JOptionPane.showMessageDialog( main.frame, "Nessun robottino presente. Impossibile cancellarne uno", "Robottino v4.0 - Errore", JOptionPane.ERROR_MESSAGE ); + else { + Robot i = primoRobot; + for ( ; !i.nomeRobot.equals( nome ); i = i.prossimoRobot ) ; + if ( i.precedenteRobot != null ) + i.precedenteRobot.prossimoRobot = i.prossimoRobot; + else + primoRobot = i.prossimoRobot; + if ( i.prossimoRobot != null ) + i.prossimoRobot.precedenteRobot = i.precedenteRobot; + else + ultimoRobot = i.precedenteRobot; + } + } + public void printList() { + String lista = ""; + for ( Robot i = primoRobot; i != null; i = i.prossimoRobot ) + lista += i.getName() + " "; + JOptionPane.showMessageDialog( main.frame, lista, "Robottino v4.0 - Robottini Presenti", JOptionPane.PLAIN_MESSAGE ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0/src/Main.java b/robottino/all_versions/v4.0/src/Main.java @@ -0,0 +1,36 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; + +public class Main { + public static int robots; + public static List list; + public static Frame frame; + public static void main ( String args[] ) { + robots = 0; + list = new List(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + frame.setSize( 350, 150 ); + frame.setVisible( true ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0/src/Robot.java b/robottino/all_versions/v4.0/src/Robot.java @@ -0,0 +1,126 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; +import java.awt.*; + +public class Robot { + public static Main main = new Main(); + boolean leftArm, rightArm, leftLeg, rightLeg; + String nomeRobot; + Robot precedenteRobot, prossimoRobot; + RobotFrame robotFrame; + Robot() { + this( false, false, false, false, "", main.list.ultimoRobot, null ); + } + Robot( String nome ) { + this ( false, false, false, false, nome, main.list.ultimoRobot, null ); + } + Robot( boolean la, boolean ra, boolean ll, boolean rl, String nome, Robot prec, Robot prox ) { + leftArm = la; + rightArm = ra; + leftLeg = ll; + rightLeg = rl; + nomeRobot = nome; + precedenteRobot = prec; + prossimoRobot = prox; + robotFrame = new RobotFrame( nome ); + robotFrame.setSize( 350, 550 ); + robotFrame.setVisible( true ); + robotFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + robotFrame.addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Robot.this.robotFrame, "Eliminare il robottino " + Robot.this.getName() + " ?", "Robottino v4.0 - Cancellazione robottino", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.list.deleteRobot( Robot.this.getName() ); + robotFrame.dispose(); + } + else { + try { + Thread.currentThread().sleep( 50 ); + } catch ( Exception e2 ) {} + robotFrame.repaint(); + } + } + public void windowActivated( WindowEvent e ) { + robotFrame.repaint(); + } + } + ); + robotFrame.addComponentListener( + new ComponentAdapter() { + public void componentMoved( ComponentEvent e ) { + try { + Thread.currentThread().sleep( 50 ); + } catch ( Exception e2 ) {} + robotFrame.repaint(); + } + public void componentResized( ComponentEvent e ) { + try { + Thread.currentThread().sleep( 50 ); + } catch ( Exception e2 ) {} + robotFrame.repaint(); + } + } + ); + } + void setLA( boolean la ) { + setPositions( la, this.rightArm, this.leftLeg, this.rightLeg ); + } + void setRA( boolean ra ) { + setPositions( this.leftArm, ra, this.leftLeg, this.rightLeg ); + } + void setLL( boolean ll ) { + setPositions( this.leftArm, this.rightArm, ll, this.rightLeg ); + } + void setRL( boolean rl ) { + setPositions( this.leftArm, this.rightArm, this.leftLeg, rl ); + } + void setPositions( boolean la, boolean ra, boolean ll, boolean rl ) { + leftArm = la; + rightArm = ra; + leftLeg = ll; + rightLeg = rl; + } + void setName( String nome ) { + nomeRobot = nome; + } + boolean getLA() { + return leftArm; + } + boolean getRA() { + return rightArm; + } + boolean getLL() { + return leftLeg; + } + boolean getRL() { + return rightLeg; + } + String getName() { + return nomeRobot; + } + Robot getNext() { + return prossimoRobot; + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0/src/RobotFrame.java b/robottino/all_versions/v4.0/src/RobotFrame.java @@ -0,0 +1,179 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; +import java.awt.*; + +public class RobotFrame extends JFrame implements ActionListener { + public static int rax, ray, lax, lay, rlx, rly, llx, lly; + public static Main main; + public static ImageIcon ra, la, rl, ll, body; + public static JMenuBar barraMenu; + public static JMenu modifica, raMenu, laMenu, rlMenu, llMenu; + public static JMenuItem raonMenuItem, raoffMenuItem, rachangeMenuItem, laonMenuItem, laoffMenuItem, lachangeMenuItem; + public static JMenuItem rlonMenuItem, rloffMenuItem, rlchangeMenuItem, llonMenuItem, lloffMenuItem, llchangeMenuItem; + RobotFrame( String titolo ) { + super ( titolo ); + rax = 66; + ray = 248; + lax = 225; + lay = 242; + rlx = 84; + rly = 367; + llx = 148; + lly = 367; + ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + raonMenuItem = new JMenuItem( "Alza" ); + laonMenuItem = new JMenuItem( "Alza" ); + rlonMenuItem = new JMenuItem( "Alza" ); + llonMenuItem = new JMenuItem( "Alza" ); + raoffMenuItem = new JMenuItem( "Abbassa" ); + laoffMenuItem = new JMenuItem( "Abbassa" ); + rloffMenuItem = new JMenuItem( "Abbassa" ); + lloffMenuItem = new JMenuItem( "Abbassa" ); + rachangeMenuItem = new JMenuItem( "Cambia posizione" ); + lachangeMenuItem = new JMenuItem( "Cambia posizione" ); + rlchangeMenuItem = new JMenuItem( "Cambia posizione" ); + llchangeMenuItem = new JMenuItem( "Cambia posizione" ); + raonMenuItem.addActionListener( this ); + raoffMenuItem.addActionListener( this ); + rachangeMenuItem.addActionListener( this ); + laonMenuItem.addActionListener( this ); + laoffMenuItem.addActionListener( this ); + lachangeMenuItem.addActionListener( this ); + rlonMenuItem.addActionListener( this ); + rloffMenuItem.addActionListener( this ); + rlchangeMenuItem.addActionListener( this ); + llonMenuItem.addActionListener( this ); + lloffMenuItem.addActionListener( this ); + llchangeMenuItem.addActionListener( this ); + raMenu = new JMenu( "Braccio destro" ); + raMenu.add( raonMenuItem ); + raMenu.add( raoffMenuItem ); + raMenu.add( rachangeMenuItem ); + laMenu = new JMenu( "Braccio sinistro" ); + laMenu.add( laonMenuItem ); + laMenu.add( laoffMenuItem ); + laMenu.add( lachangeMenuItem ); + rlMenu = new JMenu( "Gamba destra" ); + rlMenu.add( rlonMenuItem ); + rlMenu.add( rloffMenuItem ); + rlMenu.add( rlchangeMenuItem ); + llMenu = new JMenu( "Gamba sinistra" ); + llMenu.add( llonMenuItem ); + llMenu.add( lloffMenuItem ); + llMenu.add( llchangeMenuItem ); + modifica = new JMenu( "Modifica" ); + modifica.add( raMenu ); + modifica.add( laMenu ); + modifica.add( rlMenu ); + modifica.add( llMenu ); + barraMenu = new JMenuBar(); + barraMenu.add( modifica ); + setJMenuBar( barraMenu ); + } + public void paint ( Graphics g ) { + super.paint( g ); + body.paintIcon( this, g, 100, 60 ); + ra.paintIcon( this, g, this.rax, this.ray ); + la.paintIcon( this, g, this.lax, this.lay ); + rl.paintIcon( this, g, this.rlx, this.rly ); + ll.paintIcon( this, g, this.llx, this.lly ); + } + public void actionPerformed( ActionEvent e ) { + esegui( e ); + } + public void esegui( ActionEvent e ) { + if ( e.getSource() == raonMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = true; + else if ( e.getSource() == raoffMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = false; + else if ( e.getSource() == rachangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = !main.list.getRobot( this.getTitle() ).rightArm; + else if ( e.getSource() == laonMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = true; + else if ( e.getSource() == laoffMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = false; + else if ( e.getSource() == lachangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = !main.list.getRobot( this.getTitle() ).leftArm; + if ( e.getSource() == rlonMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = true; + else if ( e.getSource() == rloffMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = false; + else if ( e.getSource() == rlchangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = !main.list.getRobot( this.getTitle() ).rightLeg; + else if ( e.getSource() == llonMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = true; + else if ( e.getSource() == lloffMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = false; + else if ( e.getSource() == llchangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = !main.list.getRobot( this.getTitle() ).leftLeg; + setImages(); + repaint(); + } + public void setImages() { + if ( main.list.getRobot( this.getTitle() ).rightArm ) { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raon.gif" ) ); + this.rax = 68; + this.ray = 128; + } + else { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + this.rax = 66; + this.ray = 248; + } + if ( main.list.getRobot( this.getTitle() ).leftArm ) { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laon.gif" ) ); + this.lax = 224; + this.lay = 118; + } + else { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + this.lax = 225; + this.lay = 242; + } + if ( main.list.getRobot( this.getTitle() ).rightLeg ) { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rlon.gif" ) ); + this.rlx = 84; + this.rly = 356; + } + else { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + this.rlx = 84; + this.rly = 367; + } + if ( main.list.getRobot( this.getTitle() ).leftLeg ) { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/llon.gif" ) ); + this.llx = 140; + this.lly = 363; + } + else { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + this.llx = 148; + this.lly = 367; + } + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.0/src/img/laoff.gif b/robottino/all_versions/v4.0/src/img/laoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/laon.gif b/robottino/all_versions/v4.0/src/img/laon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/lloff.gif b/robottino/all_versions/v4.0/src/img/lloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/llon.gif b/robottino/all_versions/v4.0/src/img/llon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/raoff.gif b/robottino/all_versions/v4.0/src/img/raoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/raon.gif b/robottino/all_versions/v4.0/src/img/raon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/rloff.gif b/robottino/all_versions/v4.0/src/img/rloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/rlon.gif b/robottino/all_versions/v4.0/src/img/rlon.gif Binary files differ. diff --git a/robottino/all_versions/v4.0/src/img/robot.gif b/robottino/all_versions/v4.0/src/img/robot.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/Robottino.jar b/robottino/all_versions/v4.1/Robottino.jar Binary files differ. diff --git a/robottino/all_versions/v4.1/license.txt b/robottino/all_versions/v4.1/license.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program 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. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/robottino/all_versions/v4.1/src/Frame.java b/robottino/all_versions/v4.1/src/Frame.java @@ -0,0 +1,66 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; + +public class Frame extends JFrame { + public static Listener listener; + public static Main main; + public static JMenuBar barraMenu = new JMenuBar(); + public static JMenu file = new JMenu( "File" ); + public static JMenu info = new JMenu( "?" ); + public static JMenuItem exit = new JMenuItem( "Esci" ); + public static JMenuItem informazioni = new JMenuItem( "Informazioni" ); + public static JMenuItem nuovo = new JMenuItem( "Nuovo Robot" ); + public Frame() { + super( "Robottino versione 4.1" ); + listener = new Listener(); + main = new Main(); + exit.addActionListener( listener ); + exit.setMnemonic( 'E' ); + informazioni.addActionListener( listener ); + informazioni.setMnemonic( 'I' ); + nuovo.addActionListener( listener ); + nuovo.setMnemonic( 'N' ); + file.add( exit ); + file.add( nuovo ); + file.setMnemonic( 'F' ); + info.add( informazioni ); + info.setMnemonic( '?' ); + barraMenu.add( file ); + barraMenu.add( info ); + setJMenuBar( barraMenu ); + } + public class Listener implements ActionListener { + public void actionPerformed( ActionEvent e ) { + if ( e.getSource() == exit ) + System.exit(0); + else if ( e.getSource() == informazioni ) + JOptionPane.showMessageDialog( main.frame, "info", "Robottino v4.1 - Informazioni", JOptionPane.INFORMATION_MESSAGE ); + else if ( e.getSource() == nuovo ) { + String nome = JOptionPane.showInputDialog( main.frame, "Inserire il nome del nuovo robottino:", "Robot " + ( ++main.robots ) ); + if ( nome != null ) + main.list.newRobot( nome ); + } + } + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.1/src/List.java b/robottino/all_versions/v4.1/src/List.java @@ -0,0 +1,74 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JOptionPane; + +public class List { + public static Main main = new Main(); + public Robot primoRobot, ultimoRobot; + public List() { + primoRobot = ultimoRobot = null; + } + public boolean vuota() { + return primoRobot == null; + } + public Robot getRobot( String nome ) { + Robot i = primoRobot; + for ( ; !i.nomeRobot.equals( nome ); i = i.prossimoRobot ) ; + return i; + } + public void newRobot() { + newRobot( false, false, false, false, "" ); + } + public void newRobot( String nome ) { + newRobot( false, false, false, false, nome ); + } + public void newRobot( boolean la, boolean ra, boolean ll, boolean rl, String nome ) { + if ( vuota() ) + primoRobot = ultimoRobot = new Robot( la, ra, ll, rl, nome, null, null ); + else { + ultimoRobot = new Robot( la, ra, ll, rl, nome, ultimoRobot, null ); + ultimoRobot.precedenteRobot.prossimoRobot = ultimoRobot; + } + } + public void deleteRobot( String nome ) { + if ( vuota() ) + JOptionPane.showMessageDialog( main.frame, "Nessun robottino presente. Impossibile cancellarne uno", "Robottino v4.1 - Errore", JOptionPane.ERROR_MESSAGE ); + else { + Robot i = primoRobot; + for ( ; !i.nomeRobot.equals( nome ); i = i.prossimoRobot ) ; + if ( i.precedenteRobot != null ) + i.precedenteRobot.prossimoRobot = i.prossimoRobot; + else + primoRobot = i.prossimoRobot; + if ( i.prossimoRobot != null ) + i.prossimoRobot.precedenteRobot = i.precedenteRobot; + else + ultimoRobot = i.precedenteRobot; + } + } + public void printList() { + String lista = ""; + for ( Robot i = primoRobot; i != null; i = i.prossimoRobot ) + lista += i.getName() + " "; + JOptionPane.showMessageDialog( main.frame, lista, "Robottino v4.1 - Robottini Presenti", JOptionPane.PLAIN_MESSAGE ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.1/src/Main.java b/robottino/all_versions/v4.1/src/Main.java @@ -0,0 +1,36 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; + +public class Main { + public static int robots; + public static List list; + public static Frame frame; + public static void main ( String args[] ) { + robots = 0; + list = new List(); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + frame.setSize( 350, 150 ); + frame.setVisible( true ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.1/src/Robot.java b/robottino/all_versions/v4.1/src/Robot.java @@ -0,0 +1,101 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; +import java.awt.*; + +public class Robot { + public static Main main = new Main(); + boolean leftArm, rightArm, leftLeg, rightLeg; + String nomeRobot; + Robot precedenteRobot, prossimoRobot; + RobotFrame robotFrame; + Robot() { + this( false, false, false, false, "", main.list.ultimoRobot, null ); + } + Robot( String nome ) { + this ( false, false, false, false, nome, main.list.ultimoRobot, null ); + } + Robot( boolean la, boolean ra, boolean ll, boolean rl, String nome, Robot prec, Robot prox ) { + leftArm = la; + rightArm = ra; + leftLeg = ll; + rightLeg = rl; + nomeRobot = nome; + precedenteRobot = prec; + prossimoRobot = prox; + robotFrame = new RobotFrame( nome ); + robotFrame.setSize( 350, 600 ); + robotFrame.setVisible( true ); + robotFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + robotFrame.addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Robot.this.robotFrame, "Eliminare il robottino " + Robot.this.getName() + " ?", "Robottino v4.1 - Cancellazione robottino", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.list.deleteRobot( Robot.this.getName() ); + robotFrame.dispose(); + } + } + } + ); + } + void setLA( boolean la ) { + setPositions( la, this.rightArm, this.leftLeg, this.rightLeg ); + } + void setRA( boolean ra ) { + setPositions( this.leftArm, ra, this.leftLeg, this.rightLeg ); + } + void setLL( boolean ll ) { + setPositions( this.leftArm, this.rightArm, ll, this.rightLeg ); + } + void setRL( boolean rl ) { + setPositions( this.leftArm, this.rightArm, this.leftLeg, rl ); + } + void setPositions( boolean la, boolean ra, boolean ll, boolean rl ) { + this.leftArm = la; + this.rightArm = ra; + this.leftLeg = ll; + this.rightLeg = rl; + } + void setName( String nome ) { + nomeRobot = nome; + } + boolean getLA() { + return leftArm; + } + boolean getRA() { + return rightArm; + } + boolean getLL() { + return leftLeg; + } + boolean getRL() { + return rightLeg; + } + String getName() { + return nomeRobot; + } + Robot getNext() { + return prossimoRobot; + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.1/src/RobotFrame.java b/robottino/all_versions/v4.1/src/RobotFrame.java @@ -0,0 +1,312 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; +import java.awt.*; + +public class RobotFrame extends JFrame implements ActionListener { + public static int numeroCopie, i; + public static Main main; + public static RobotPanel robotPanel; + public static Timer timer; + public static JMenuBar barraMenu; + public static JMenu file, modifica, azioni, info, raMenu, laMenu, rlMenu, llMenu; + public static JMenuItem raonMenuItem, raoffMenuItem, rachangeMenuItem, laonMenuItem, laoffMenuItem, lachangeMenuItem; + public static JMenuItem rlonMenuItem, rloffMenuItem, rlchangeMenuItem, llonMenuItem, lloffMenuItem, llchangeMenuItem; + public static JMenuItem rinomina, elimina, duplica, birra, balla, esplodi, informazioni; + RobotFrame( String titolo ) { + super ( titolo ); + numeroCopie = 0; + robotPanel = new RobotPanel( titolo ); + rinomina = new JMenuItem( "Cambia nome" ); + elimina = new JMenuItem( "Elimina" ); + duplica = new JMenuItem( "Duplica robot" ); + birra = new JMenuItem( "Birra" ); + balla = new JMenuItem( "Balla" ); + esplodi = new JMenuItem( "Esplodi" ); + informazioni = new JMenuItem( "Informazioni" ); + raonMenuItem = new JMenuItem( "Alza" ); + laonMenuItem = new JMenuItem( "Alza" ); + rlonMenuItem = new JMenuItem( "Alza" ); + llonMenuItem = new JMenuItem( "Alza" ); + raoffMenuItem = new JMenuItem( "Abbassa" ); + laoffMenuItem = new JMenuItem( "Abbassa" ); + rloffMenuItem = new JMenuItem( "Abbassa" ); + lloffMenuItem = new JMenuItem( "Abbassa" ); + rachangeMenuItem = new JMenuItem( "Cambia posizione" ); + lachangeMenuItem = new JMenuItem( "Cambia posizione" ); + rlchangeMenuItem = new JMenuItem( "Cambia posizione" ); + llchangeMenuItem = new JMenuItem( "Cambia posizione" ); + rinomina.addActionListener( this ); + elimina.addActionListener( this ); + duplica.addActionListener( this ); + birra.addActionListener( this ); + balla.addActionListener( this ); + esplodi.addActionListener( this ); + informazioni.addActionListener( this ); + raonMenuItem.addActionListener( this ); + raoffMenuItem.addActionListener( this ); + rachangeMenuItem.addActionListener( this ); + laonMenuItem.addActionListener( this ); + laoffMenuItem.addActionListener( this ); + lachangeMenuItem.addActionListener( this ); + rlonMenuItem.addActionListener( this ); + rloffMenuItem.addActionListener( this ); + rlchangeMenuItem.addActionListener( this ); + llonMenuItem.addActionListener( this ); + lloffMenuItem.addActionListener( this ); + llchangeMenuItem.addActionListener( this ); + raMenu = new JMenu( "Braccio destro" ); + raMenu.add( raonMenuItem ); + raMenu.add( raoffMenuItem ); + raMenu.add( rachangeMenuItem ); + laMenu = new JMenu( "Braccio sinistro" ); + laMenu.add( laonMenuItem ); + laMenu.add( laoffMenuItem ); + laMenu.add( lachangeMenuItem ); + rlMenu = new JMenu( "Gamba destra" ); + rlMenu.add( rlonMenuItem ); + rlMenu.add( rloffMenuItem ); + rlMenu.add( rlchangeMenuItem ); + llMenu = new JMenu( "Gamba sinistra" ); + llMenu.add( llonMenuItem ); + llMenu.add( lloffMenuItem ); + llMenu.add( llchangeMenuItem ); + modifica = new JMenu( "Modifica" ); + modifica.add( raMenu ); + modifica.add( laMenu ); + modifica.add( rlMenu ); + modifica.add( llMenu ); + file = new JMenu( "File" ); + file.add( rinomina ); + file.add( duplica ); + file.add( elimina ); + azioni = new JMenu( "Azioni" ); + azioni.add( birra ); + azioni.add( balla ); + azioni.add( esplodi ); + info = new JMenu( "?" ); + info.add( informazioni ); + barraMenu = new JMenuBar(); + barraMenu.add( file ); + barraMenu.add( azioni ); + barraMenu.add( modifica ); + barraMenu.add( info ); + setJMenuBar( barraMenu ); + add( robotPanel ); + } + public void actionPerformed( ActionEvent e ) { + esegui( e ); + } + public void esegui( ActionEvent e ) { + if ( e.getSource() == raonMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = true; + else if ( e.getSource() == raoffMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = false; + else if ( e.getSource() == rachangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightArm = !main.list.getRobot( this.getTitle() ).rightArm; + else if ( e.getSource() == laonMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = true; + else if ( e.getSource() == laoffMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = false; + else if ( e.getSource() == lachangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftArm = !main.list.getRobot( this.getTitle() ).leftArm; + else if ( e.getSource() == rlonMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = true; + else if ( e.getSource() == rloffMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = false; + else if ( e.getSource() == rlchangeMenuItem ) + main.list.getRobot( this.getTitle() ).rightLeg = !main.list.getRobot( this.getTitle() ).rightLeg; + else if ( e.getSource() == llonMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = true; + else if ( e.getSource() == lloffMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = false; + else if ( e.getSource() == llchangeMenuItem ) + main.list.getRobot( this.getTitle() ).leftLeg = !main.list.getRobot( this.getTitle() ).leftLeg; + else if ( e.getSource() == rinomina ) { + String newName = JOptionPane.showInputDialog( this, "Inserire il nuovo nome per questo robot:", this.getTitle() ); + if ( newName != null ) { + main.list.getRobot( this.getTitle() ).setName( newName ); + this.setTitle( newName ); + robotPanel.nomeRobot = newName; + } + } + else if ( e.getSource() == elimina ) { + int selezione = JOptionPane.showOptionDialog( this, "Eliminare il robottino " + this.getTitle() + " ?", "Robottino v4.1 - Cancellazione robottino", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) { + main.list.deleteRobot( this.getTitle() ); + this.dispose(); + } + } + else if ( e.getSource() == duplica ) { + String newName = JOptionPane.showInputDialog( this, "Inserire il nome per il nuovo robot:", this.getTitle() + " #" + (++numeroCopie) ); + if ( newName != null ) { + main.list.newRobot( main.list.getRobot( this.getTitle() ).leftArm, main.list.getRobot( this.getTitle() ).rightArm, main.list.getRobot( this.getTitle() ).leftLeg, main.list.getRobot( this.getTitle() ).rightLeg, newName ); + } + } + else if ( e.getSource() == birra ) { + ImageIcon birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra5.gif" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra1.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra2.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra3.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra4.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, birra ); + JOptionPane.showMessageDialog( this, "Che bevuta!", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + JOptionPane.showMessageDialog( this, "Buuuuuuurp!", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + robotPanel.body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + } + else if ( e.getSource() == balla ) { + this.i = 0; + main.list.getRobot( this.getTitle() ).setPositions( false, false, false, false ); + timer = new Timer( 250, + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + RobotFrame.this.i++; + switch( RobotFrame.this.i ) { + case 1: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setRA( true ); + break; + case 2: + break; + case 3: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setLA( true ); + break; + case 4: + break; + case 5: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 6: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, true, false, false ); + break; + case 7: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 8: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, true, false, false ); + break; + case 9: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, false, false, true ); + break; + case 10: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 11: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, false, false, true ); + break; + case 12: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, true, true, false ); + break; + case 13: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 14: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, true, true, false ); + break; + case 15: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 16: + break; + case 17: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 18: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 19: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 20: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 21: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, true, false ); + break; + case 22: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, true ); + break; + case 23: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( true, true, true, true ); + break; + case 24: + break; + case 25: + break; + case 26: + RobotFrame.main.list.getRobot( RobotFrame.this.getTitle() ).setPositions( false, false, false, false ); + break; + case 27: + JOptionPane.showMessageDialog( RobotFrame.this, "Cha fatica!", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + JOptionPane.showMessageDialog( RobotFrame.this, RobotFrame.this.getTitle() + " è tornato alla posizione di partenza", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE ); + break; + default: + timer.stop(); + break; + } + RobotFrame.robotPanel.setImages(); + RobotFrame.robotPanel.repaint(); + RobotFrame.this.repaint(); + } + } + ); + timer.start(); + } + if ( e.getSource() == esplodi ) { + String aux = this.getTitle(); + main.list.deleteRobot( this.getTitle() ); + this.dispose(); + ImageIcon boom = new ImageIcon( ClassLoader.getSystemResource( "img/boom.png" ) ); + JOptionPane.showMessageDialog( null, "", "Robottino v4.1", JOptionPane.PLAIN_MESSAGE, boom ); + JOptionPane.showMessageDialog( null, aux + " si è autodistrutto!", "Robottino v4.1", JOptionPane.WARNING_MESSAGE ); + } + if ( e.getSource() == informazioni ) { + String aux = this.getTitle() + ":\n\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).rightArm ) + aux += "Braccio destro: alzato\n"; + else + aux += "Braccio destro: abbassato\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).leftArm ) + aux += "Braccio sinistro: alzato\n"; + else + aux += "Braccio sinistro: abbassato\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).rightLeg ) + aux += "Gamba destra: alzata\n"; + else + aux += "Gamba destra: abbassata\n"; + if ( main.list.getRobot( RobotFrame.this.getTitle() ).leftLeg ) + aux += "Gamba sinistra: alzata\n"; + else + aux += "Gamba sinistra: abbassata\n"; + JOptionPane.showMessageDialog( this, aux, "Robottino - v4.1", JOptionPane.INFORMATION_MESSAGE ); + } + try { + robotPanel.setImages(); + robotPanel.repaint(); + repaint(); + } catch ( NullPointerException n ) { } + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.1/src/RobotPanel.java b/robottino/all_versions/v4.1/src/RobotPanel.java @@ -0,0 +1,96 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.*; + +public class RobotPanel extends JPanel { + public static String nomeRobot; + public static Main main; + public static ImageIcon ra, la, rl, ll, body; + public static int rax, ray, lax, lay, rlx, rly, llx, lly; + RobotPanel( String nomeRobot ) { + this.nomeRobot = nomeRobot; + rax = 66; + ray = 248; + lax = 225; + lay = 242; + rlx = 84; + rly = 367; + llx = 148; + lly = 367; + body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + } + public void paint ( Graphics g ) { + super.paint( g ); + body.paintIcon( this, g, 100, 60 ); + ra.paintIcon( this, g, this.rax, this.ray ); + la.paintIcon( this, g, this.lax, this.lay ); + rl.paintIcon( this, g, this.rlx, this.rly ); + ll.paintIcon( this, g, this.llx, this.lly ); + } + public void setImages() { + if ( main.list.getRobot( nomeRobot ).rightArm ) { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raon.gif" ) ); + this.rax = 68; + this.ray = 128; + } + else { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + this.rax = 66; + this.ray = 248; + } + if ( main.list.getRobot( nomeRobot ).leftArm ) { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laon.gif" ) ); + this.lax = 224; + this.lay = 118; + } + else { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + this.lax = 225; + this.lay = 242; + } + if ( main.list.getRobot( nomeRobot ).rightLeg ) { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rlon.gif" ) ); + this.rlx = 84; + this.rly = 356; + } + else { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + this.rlx = 84; + this.rly = 367; + } + if ( main.list.getRobot( nomeRobot ).leftLeg ) { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/llon.gif" ) ); + this.llx = 140; + this.lly = 363; + } + else { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + this.llx = 148; + this.lly = 367; + } + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.1/src/img/birra1.jpg b/robottino/all_versions/v4.1/src/img/birra1.jpg Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/birra2.jpg b/robottino/all_versions/v4.1/src/img/birra2.jpg Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/birra3.jpg b/robottino/all_versions/v4.1/src/img/birra3.jpg Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/birra4.jpg b/robottino/all_versions/v4.1/src/img/birra4.jpg Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/birra5.gif b/robottino/all_versions/v4.1/src/img/birra5.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/boom.png b/robottino/all_versions/v4.1/src/img/boom.png Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/laoff.gif b/robottino/all_versions/v4.1/src/img/laoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/laon.gif b/robottino/all_versions/v4.1/src/img/laon.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/lloff.gif b/robottino/all_versions/v4.1/src/img/lloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/llon.gif b/robottino/all_versions/v4.1/src/img/llon.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/raoff.gif b/robottino/all_versions/v4.1/src/img/raoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/raon.gif b/robottino/all_versions/v4.1/src/img/raon.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/rloff.gif b/robottino/all_versions/v4.1/src/img/rloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/rlon.gif b/robottino/all_versions/v4.1/src/img/rlon.gif Binary files differ. diff --git a/robottino/all_versions/v4.1/src/img/robot.gif b/robottino/all_versions/v4.1/src/img/robot.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/Robottino.jar b/robottino/all_versions/v4.2/Robottino.jar Binary files differ. diff --git a/robottino/all_versions/v4.2/license.txt b/robottino/all_versions/v4.2/license.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program 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. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/robottino/all_versions/v4.2/src/Frame.java b/robottino/all_versions/v4.2/src/Frame.java @@ -0,0 +1,314 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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 implements ActionListener { + public static int i; + public static Main main; + public static RobotPanel robotPanel; + public static JLabel label; + public static Timer timer; + public static JMenuBar barraMenu; + public static JMenu file, modifica, azioni, info, raMenu, laMenu, rlMenu, llMenu; + public static JMenuItem raonMenuItem, raoffMenuItem, rachangeMenuItem, laonMenuItem, laoffMenuItem, lachangeMenuItem; + public static JMenuItem rlonMenuItem, rloffMenuItem, rlchangeMenuItem, llonMenuItem, lloffMenuItem, llchangeMenuItem; + public static JMenuItem rinomina, birra, balla, esplodi, informazioni, esci; + public Frame() { + super( "Robottino versione 4.2" ); + i = 0; + main = new Main(); + robotPanel = new RobotPanel(); + label = new JLabel( "Robot: " + main.robot.getName() ); + label.setFont( new Font( "Monospace", 0, 30 ) ); + barraMenu = new JMenuBar(); + rinomina = new JMenuItem( "Cambia nome" ); + birra = new JMenuItem( "Birra" ); + balla = new JMenuItem( "Balla" ); + esplodi = new JMenuItem( "Esplodi" ); + informazioni = new JMenuItem( "Informazioni" ); + esci = new JMenuItem( "Esci" ); + raonMenuItem = new JMenuItem( "Alza" ); + laonMenuItem = new JMenuItem( "Alza" ); + rlonMenuItem = new JMenuItem( "Alza" ); + llonMenuItem = new JMenuItem( "Alza" ); + raoffMenuItem = new JMenuItem( "Abbassa" ); + laoffMenuItem = new JMenuItem( "Abbassa" ); + rloffMenuItem = new JMenuItem( "Abbassa" ); + lloffMenuItem = new JMenuItem( "Abbassa" ); + rachangeMenuItem = new JMenuItem( "Cambia posizione" ); + lachangeMenuItem = new JMenuItem( "Cambia posizione" ); + rlchangeMenuItem = new JMenuItem( "Cambia posizione" ); + llchangeMenuItem = new JMenuItem( "Cambia posizione" ); + esci.addActionListener( this ); + rinomina.addActionListener( this ); + birra.addActionListener( this ); + balla.addActionListener( this ); + esplodi.addActionListener( this ); + informazioni.addActionListener( this ); + raonMenuItem.addActionListener( this ); + raoffMenuItem.addActionListener( this ); + rachangeMenuItem.addActionListener( this ); + laonMenuItem.addActionListener( this ); + laoffMenuItem.addActionListener( this ); + lachangeMenuItem.addActionListener( this ); + rlonMenuItem.addActionListener( this ); + rloffMenuItem.addActionListener( this ); + rlchangeMenuItem.addActionListener( this ); + llonMenuItem.addActionListener( this ); + lloffMenuItem.addActionListener( this ); + llchangeMenuItem.addActionListener( this ); + raMenu = new JMenu( "Braccio destro" ); + raMenu.add( raonMenuItem ); + raMenu.add( raoffMenuItem ); + raMenu.add( rachangeMenuItem ); + laMenu = new JMenu( "Braccio sinistro" ); + laMenu.add( laonMenuItem ); + laMenu.add( laoffMenuItem ); + laMenu.add( lachangeMenuItem ); + rlMenu = new JMenu( "Gamba destra" ); + rlMenu.add( rlonMenuItem ); + rlMenu.add( rloffMenuItem ); + rlMenu.add( rlchangeMenuItem ); + llMenu = new JMenu( "Gamba sinistra" ); + llMenu.add( llonMenuItem ); + llMenu.add( lloffMenuItem ); + llMenu.add( llchangeMenuItem ); + modifica = new JMenu( "Modifica" ); + modifica.add( raMenu ); + modifica.add( laMenu ); + modifica.add( rlMenu ); + modifica.add( llMenu ); + file = new JMenu( "File" ); + file.add( rinomina ); + file.add( esci ); + azioni = new JMenu( "Azioni" ); + azioni.add( birra ); + azioni.add( balla ); + azioni.add( esplodi ); + info = new JMenu( "?" ); + info.add( informazioni ); + barraMenu.add( file ); + barraMenu.add( modifica ); + barraMenu.add( azioni ); + barraMenu.add( info ); + setJMenuBar( barraMenu ); + add( robotPanel, BorderLayout.CENTER ); + add( label, BorderLayout.SOUTH ); + addWindowListener( + new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + int selezione = JOptionPane.showOptionDialog( Frame.this, "Vuoi davvero uscire?", "Robottino v4.2", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + } + ); + } + public void actionPerformed( ActionEvent e ) { + if ( e.getSource() == esci ) { + int selezione = JOptionPane.showOptionDialog( this, "Vuoi davvero uscire?", "Robottino v4.2", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Si", "No" }, "No" ); + if ( selezione == JOptionPane.YES_OPTION ) + System.exit( 0 ); + } + else if ( e.getSource() == rinomina ) { + String newName = main.robot.getName(); + newName = JOptionPane.showInputDialog( this, "Inserire il nuovo nome per il robottino:", newName ); + if ( newName != null ) { + main.robot.setName( newName ); + label .setText( "Robot: " + main.robot.getName() ); + } + } + else if ( e.getSource() == raonMenuItem ) + main.robot.setRA( true ); + else if ( e.getSource() == raoffMenuItem ) + main.robot.setRA( false ); + else if ( e.getSource() == rachangeMenuItem ) + main.robot.setRA( !main.robot.rightArm ); + else if ( e.getSource() == laonMenuItem ) + main.robot.setLA( true ); + else if ( e.getSource() == laoffMenuItem ) + main.robot.setLA( false ); + else if ( e.getSource() == lachangeMenuItem ) + main.robot.setLA( !main.robot.leftArm ); + else if ( e.getSource() == rlonMenuItem ) + main.robot.setRL( true ); + else if ( e.getSource() == rloffMenuItem ) + main.robot.setRL( false ); + else if ( e.getSource() == rlchangeMenuItem ) + main.robot.setRL( !main.robot.rightLeg ); + else if ( e.getSource() == llonMenuItem ) + main.robot.setLL( true ); + else if ( e.getSource() == lloffMenuItem ) + main.robot.setLL( false ); + else if ( e.getSource() == llchangeMenuItem ) + main.robot.setLL( !main.robot.leftLeg ); + else if ( e.getSource() == birra ) { + ImageIcon birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra5.gif" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra1.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra2.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra3.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra ); + birra = new ImageIcon( ClassLoader.getSystemResource( "img/birra4.jpg" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, birra ); + JOptionPane.showMessageDialog( this, "Che bevuta!", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE ); + JOptionPane.showMessageDialog( this, "Buuuuuuurp!", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE ); + robotPanel.body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + } + if ( e.getSource() == esplodi ) { + String aux = main.robot.getName(); + main.robot.setPositions( false, false, false, false ); + main.robot.setName( "no-name" ); + label.setText( "Robot: " + main.robot.getName() ); + ImageIcon boom = new ImageIcon( ClassLoader.getSystemResource( "img/boom.png" ) ); + JOptionPane.showMessageDialog( this, "", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE, boom ); + JOptionPane.showMessageDialog( this, aux + " si è autodistrutto!", "Robottino v4.2", JOptionPane.WARNING_MESSAGE ); + JOptionPane.showMessageDialog( this, "È stato creato un nuovo robottino: " + main.robot.getName(), "Robottino v4.2", JOptionPane.INFORMATION_MESSAGE ); + } + if ( e.getSource() == informazioni ) { + String aux = main.robot.getName() + ":\n\n"; + if ( main.robot.rightArm ) + aux += "Braccio destro: alzato\n"; + else + aux += "Braccio destro: abbassato\n"; + if ( main.robot.leftArm ) + aux += "Braccio sinistro: alzato\n"; + else + aux += "Braccio sinistro: abbassato\n"; + if ( main.robot.rightLeg ) + aux += "Gamba destra: alzata\n"; + else + aux += "Gamba destra: abbassata\n"; + if ( main.robot.leftLeg ) + aux += "Gamba sinistra: alzata\n"; + else + aux += "Gamba sinistra: abbassata\n"; + JOptionPane.showMessageDialog( this, aux, "Robottino - v4.2", JOptionPane.INFORMATION_MESSAGE ); + } + else if ( e.getSource() == balla ) { + this.i = 0; + main.robot.setPositions( false, false, false, false ); + timer = new Timer( 250, + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + Frame.this.i++; + switch( Frame.this.i ) { + case 1: + Frame.main.robot.setRA( true ); + break; + case 2: + break; + case 3: + Frame.main.robot.setLA( true ); + break; + case 4: + break; + case 5: + Frame.main.robot.setPositions( false, false, false, true ); + break; + case 6: + Frame.main.robot.setPositions( true, true, false, false ); + break; + case 7: + Frame.main.robot.setPositions( false, false, true, false ); + break; + case 8: + Frame.main.robot.setPositions( true, true, false, false ); + break; + case 9: + Frame.main.robot.setPositions( true, false, false, true ); + break; + case 10: + Frame.main.robot.setPositions( false, false, false, false ); + break; + case 11: + Frame.main.robot.setPositions( true, false, false, true ); + break; + case 12: + Frame.main.robot.setPositions( false, true, true, false ); + break; + case 13: + Frame.main.robot.setPositions( false, false, false, false ); + break; + case 14: + Frame.main.robot.setPositions( false, true, true, false ); + break; + case 15: + Frame.main.robot.setPositions( false, false, false, false ); + break; + case 16: + break; + case 17: + Frame.main.robot.setPositions( false, false, true, false ); + break; + case 18: + Frame.main.robot.setPositions( false, false, false, true ); + break; + case 19: + Frame.main.robot.setPositions( false, false, true, false ); + break; + case 20: + Frame.main.robot.setPositions( false, false, false, true ); + break; + case 21: + Frame.main.robot.setPositions( false, false, true, false ); + break; + case 22: + Frame.main.robot.setPositions( false, false, false, true ); + break; + case 23: + Frame.main.robot.setPositions( true, true, true, true ); + break; + case 24: + break; + case 25: + break; + case 26: + Frame.main.robot.setPositions( false, false, false, false ); + break; + case 27: + JOptionPane.showMessageDialog( Frame.this, "Cha fatica!", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE ); + JOptionPane.showMessageDialog( Frame.this, Frame.main.robot.getName() + " è tornato alla posizione di partenza", "Robottino v4.2", JOptionPane.PLAIN_MESSAGE ); + break; + default: + timer.stop(); + break; + } + Frame.this.robotPanel.setImages(); + Frame.this.robotPanel.repaint(); + Frame.this.repaint(); + } + } + ); + timer.start(); + } + try { + this.robotPanel.setImages(); + this.robotPanel.repaint(); + this.repaint(); + } catch ( NullPointerException n ) { } + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.2/src/Main.java b/robottino/all_versions/v4.2/src/Main.java @@ -0,0 +1,34 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; + +public class Main { + public static Robot robot; + public static Frame frame; + public static void main ( String args[] ) { + robot = new Robot( "no-name" ); + frame = new Frame(); + frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); + frame.setSize( 350, 600 ); + frame.setVisible( true ); + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.2/src/Robot.java b/robottino/all_versions/v4.2/src/Robot.java @@ -0,0 +1,72 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.event.*; +import java.awt.*; + +public class Robot { + boolean leftArm, rightArm, leftLeg, rightLeg; + String nomeRobot; + Robot( String nome ) { + this.leftArm = false; + this.rightArm = false; + this.leftLeg = false; + this.rightLeg = false; + this.nomeRobot = nome; + } + void setLA( boolean la ) { + setPositions( la, this.rightArm, this.leftLeg, this.rightLeg ); + } + void setRA( boolean ra ) { + setPositions( this.leftArm, ra, this.leftLeg, this.rightLeg ); + } + void setLL( boolean ll ) { + setPositions( this.leftArm, this.rightArm, ll, this.rightLeg ); + } + void setRL( boolean rl ) { + setPositions( this.leftArm, this.rightArm, this.leftLeg, rl ); + } + void setPositions( boolean la, boolean ra, boolean ll, boolean rl ) { + this.leftArm = la; + this.rightArm = ra; + this.leftLeg = ll; + this.rightLeg = rl; + } + void setName( String nome ) { + nomeRobot = nome; + } + boolean getLA() { + return leftArm; + } + boolean getRA() { + return rightArm; + } + boolean getLL() { + return leftLeg; + } + boolean getRL() { + return rightLeg; + } + String getName() { + return nomeRobot; + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.2/src/RobotPanel.java b/robottino/all_versions/v4.2/src/RobotPanel.java @@ -0,0 +1,94 @@ +/* +Copyright 2008, 2009 Sebastiano Tronto <sebastiano@luganega.org> + +This file is part of Robottino. + + Robottino 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. + + Robottino 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 Robottino; 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.*; + +public class RobotPanel extends JPanel { + public static Main main; + public static ImageIcon ra, la, rl, ll, body; + public static int rax, ray, lax, lay, rlx, rly, llx, lly; + RobotPanel() { + rax = 66; + ray = 248; + lax = 225; + lay = 242; + rlx = 84; + rly = 367; + llx = 148; + lly = 367; + body = new ImageIcon( ClassLoader.getSystemResource( "img/robot.gif" ) ); + ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + } + public void paint ( Graphics g ) { + super.paint( g ); + body.paintIcon( this, g, 100, 60 ); + ra.paintIcon( this, g, this.rax, this.ray ); + la.paintIcon( this, g, this.lax, this.lay ); + rl.paintIcon( this, g, this.rlx, this.rly ); + ll.paintIcon( this, g, this.llx, this.lly ); + } + public void setImages() { + if ( main.robot.rightArm ) { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raon.gif" ) ); + this.rax = 68; + this.ray = 128; + } + else { + this.ra = new ImageIcon( ClassLoader.getSystemResource( "img/raoff.gif" ) ); + this.rax = 66; + this.ray = 248; + } + if ( main.robot.leftArm ) { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laon.gif" ) ); + this.lax = 224; + this.lay = 118; + } + else { + this.la = new ImageIcon( ClassLoader.getSystemResource( "img/laoff.gif" ) ); + this.lax = 225; + this.lay = 242; + } + if ( main.robot.rightLeg ) { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rlon.gif" ) ); + this.rlx = 84; + this.rly = 356; + } + else { + this.rl = new ImageIcon( ClassLoader.getSystemResource( "img/rloff.gif" ) ); + this.rlx = 84; + this.rly = 367; + } + if ( main.robot.leftLeg ) { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/llon.gif" ) ); + this.llx = 140; + this.lly = 363; + } + else { + this.ll = new ImageIcon( ClassLoader.getSystemResource( "img/lloff.gif" ) ); + this.llx = 148; + this.lly = 367; + } + } +} +\ No newline at end of file diff --git a/robottino/all_versions/v4.2/src/img/birra1.jpg b/robottino/all_versions/v4.2/src/img/birra1.jpg Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/birra2.jpg b/robottino/all_versions/v4.2/src/img/birra2.jpg Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/birra3.jpg b/robottino/all_versions/v4.2/src/img/birra3.jpg Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/birra4.jpg b/robottino/all_versions/v4.2/src/img/birra4.jpg Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/birra5.gif b/robottino/all_versions/v4.2/src/img/birra5.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/boom.png b/robottino/all_versions/v4.2/src/img/boom.png Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/laoff.gif b/robottino/all_versions/v4.2/src/img/laoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/laon.gif b/robottino/all_versions/v4.2/src/img/laon.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/lloff.gif b/robottino/all_versions/v4.2/src/img/lloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/llon.gif b/robottino/all_versions/v4.2/src/img/llon.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/raoff.gif b/robottino/all_versions/v4.2/src/img/raoff.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/raon.gif b/robottino/all_versions/v4.2/src/img/raon.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/rloff.gif b/robottino/all_versions/v4.2/src/img/rloff.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/rlon.gif b/robottino/all_versions/v4.2/src/img/rlon.gif Binary files differ. diff --git a/robottino/all_versions/v4.2/src/img/robot.gif b/robottino/all_versions/v4.2/src/img/robot.gif Binary files differ.