Ho realizzato da poco un giochino per il cellulare...un quiz sul mondo del calcio. Ecco un'immagine:
e queste sono le classi:
main
gui
contatore
GeneratoreCasuale
caricaDomande
e infine carica punteggi
tutto il materiale lo trovate sul sito che ho appositamente creato http://www.conoscicalcio.altervista.org/
sperando che l'applicazione vi piaccia, accetto critiche e domande
e queste sono le classi:
main
Codice:
/* This file is part of Conosci il calcio.
*
* Conosci il calcio 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 3 of the License, or
* (at your option) any later version.
*
* Conosci il calcio 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 Conosci il calcio. If not, see <http://www.gnu.org/licenses/>.
*/
package Principale;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import GUI.domandaG;
/**
* Classe che rappresenta il main del programma
* contiene al suo interno il metodo startApp() che permette di avviare la midlet
* @author Lallo Alessandro
*
*/
public class Main extends MIDlet implements CommandListener {
private static Display d;
private Command exit;
private domandaG dG;
/**
* Costruttore della classe (vuoto)
*/
public Main() {
}
/**
* metodo richiamato per distruggere la midlet
*/
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
dG.chiudiRecordStore();
}
/**
* metodo richiamato quando l'applicazione è messa in pausa
*/
protected void pauseApp() {
// TODO Auto-generated method stub
}
/**
* Avvia la midlet
*/
protected void startApp() throws MIDletStateChangeException {
d=Display.getDisplay(this);
dG=new domandaG(false);
exit=new Command("Esci",Command.EXIT,1);
dG.addCommand(exit);
dG.setCommandListener(this);
d.setCurrent(dG);
}
public void commandAction(Command com, Displayable arg1) {
try{
if(com==exit)//se il pulsante premuto è exit
{
//distruggi la midlet ed esci dall'applicazione
destroyApp(true);
notifyDestroyed();
}
}
catch (Exception e)
{
System.out.println("ERRORE DELL'APPLICAZIONE!");
try {
destroyApp(true);
}
catch (MIDletStateChangeException e1)
{
System.out.println("ERRORE DELL'APPLICAZIONE!");
}
notifyDestroyed();
}
}
}
gui
Codice:
/* This file is part of Conosci il calcio.
*
* Conosci il calcio 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 3 of the License, or
* (at your option) any later version.
*
* Conosci il calcio 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 Conosci il calcio. If not, see <http://www.gnu.org/licenses/>.
*/
package GUI;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import Utility.Contatore;
import Utility.GeneratoreCasualeN;
import Carica.CaricaDomande;
import Carica.CaricaPunteggi;
/**
* Classe che permette la visualizzazione del gioco con una grafica ad alto livello
* Estende la classe GameCanvas che permette di realizzare una grafica di alto livello
* @author Lallo Alessandro
*
*/
public class domandaG extends GameCanvas implements Runnable {
public Image contdom,contd,contev,contdev,corretto,intro1,vocemenu,vocemenu2,domandaI,errato
,vittoria,classifica;
private int tasto=0,risposto=0, rispes=0,primamenu=0,conta=0,indbarra=0,ib=0,domandaAttuale=0;
private static String secondi="";
private int domprec[] ={-1,-1,-1}; //utilizzato per evitare la ripetizione delle stesse domande
private CaricaDomande c;
private String dom;
private Contatore cont;
private Thread myThread;
private Image barra[],erratorisp[],esattarisp[];
private static CaricaPunteggi caricap;
private static String puntiV[];
private GeneratoreCasualeN generator;
private Integer esatto;
private static int j=0,i=0,kk=0,punti=0,finestra=0,imerrata=0,imesatta=0,carica2=0,carica3=0,carica4=0,carica5=0;
/**
* Costruttore della classe ad un posto
*/
public domandaG(boolean suppressKeyEvents) {
super(suppressKeyEvents);
//setto la modalita tutto schermo
setFullScreenMode(true);
//carico le domande
c=new CaricaDomande();
//avvio un nuovo thread
new Thread(this).start();
try {
//carico tutte le immagini
contdom=Image.createImage("/contdom.png");
contd=Image.createImage("/contd.png");
contev=Image.createImage("/contev.png");
contdev=Image.createImage("/contdev.png");
corretto=Image.createImage("/corretto.png");
errato=Image.createImage("/errato.png");
intro1=Image.createImage("/intro1.png");
vocemenu=Image.createImage("/vocemenu.png");
vocemenu2=Image.createImage("/vocemenu2.png");
domandaI=Image.createImage("/domanda.png");
erratorisp=new Image[5];
erratorisp[0]=Image.createImage("/erratogalliani.png");
erratorisp[1]=Image.createImage("/capello.png");
erratorisp[2]=Image.createImage("/mourinho1.png");
erratorisp[3]=Image.createImage("/mourinho2.png");
erratorisp[4]=Image.createImage("/lavezzi.png");
esattarisp=new Image[7];
esattarisp[0]=Image.createImage("/berlusconi.png");
esattarisp[1]=Image.createImage("/mazzone.png");
esattarisp[2]=Image.createImage("/mourinho3.png");
esattarisp[3]=Image.createImage("/delpiero.png");
esattarisp[4]=Image.createImage("/kaka.png");
esattarisp[5]=Image.createImage("/galliani.png");
esattarisp[6]=Image.createImage("/totti.png");
vittoria=Image.createImage("/vittoria.png");
classifica=Image.createImage("/classifica.png");
barra=new Image[10];
barra[0]=Image.createImage("/barra1.png");
barra[1]=Image.createImage("/barra2.png");
barra[2]=Image.createImage("/barra3.png");
barra[3]=Image.createImage("/barra4.png");
barra[4]=Image.createImage("/barra5.png");
barra[5]=Image.createImage("/barra6.png");
barra[6]=Image.createImage("/barra7.png");
barra[7]=Image.createImage("/barra8.png");
barra[8]=Image.createImage("/barra9.png");
barra[9]=Image.createImage("/barra10.png");
punti=0;//setta i punti a 0
//carico i punteggi memorizzati
puntiV=new String [5];
caricap=new CaricaPunteggi();
puntiV=caricap.leggi();
generator = new GeneratoreCasualeN();//istanzio l'oggetto che mi permettera di generare i numeri casuali
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Metodo che disegna a video le diverse finestre a seconda dello stato del gioco
*/
public void paint(Graphics g) {
g.setColor(0xff71f3);
g.fillRect(0, 0, getWidth(), getHeight());
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
switch (finestra){
case 0: //intro1
g.setColor(0xff71f3);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(intro1,12, 29, 4 | 0x10);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.setColor(0x000000);
finestra=1;
repaint();
break;
case 1: //intro2
g.setColor(0xff71f3);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x000000);
g.drawString("Realizzato da:",4, 30,4 | 0x10);
g.drawString("Rendinella Manuel",4, 70,4 | 0x10);
g.drawString("Lallo Alessandro",4, 90,4 | 0x10);
g.setColor(0xffffff);
g.drawString("conoscicalcio.altervista.org",4, 120,4 | 0x10);
g.setColor(0x000000);
g.drawString("Copyright 2009 Lallo, Rendinella",4, 140,4 | 0x10);
try {
Thread.sleep(2000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finestra=2;
repaint();
break;
case 2: //menu
punti=0;//setto i punti a 0 per una nuova partita
//controllo se e' la prima volta che compare il menu
if(primamenu==0)
{
primamenu=1;
try {
Thread.sleep(2200);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
g.setColor(0xff71f3);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE));
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0xFFFFFF);
//Controllo su che tasto e' il focus per aggiornare le immagini
switch(tasto){
case 0:
g.drawImage(vocemenu2, 4, 15, 4 | 0x10);
g.setColor(0xec00e4);
g.drawString("Inizia",63, 30,4 | 0x10);
g.setColor(0xFFFFFF);
g.drawImage(vocemenu, 4, 75, 4 | 0x10);
g.drawString("Istruzioni",63, 90,4 | 0x10);
g.drawImage(vocemenu, 4, 135, 4 | 0x10);
g.drawString("Record",63, 150,4 | 0x10);
g.drawImage(vocemenu, 4, 195, 4 | 0x10);
g.drawString("Info",63, 210,4 | 0x10);
break;
case 1:
g.drawImage(vocemenu, 4, 15, 4 | 0x10);
g.drawString("Inizia",63, 30,4 | 0x10);
g.setColor(0xec00e4);
g.drawImage(vocemenu2, 4, 75, 4 | 0x10);
g.drawString("Istruzioni",63, 90,4 | 0x10);
g.setColor(0xFFFFFF);
g.drawImage(vocemenu, 4, 135, 4 | 0x10);
g.drawString("Record",63, 150,4 | 0x10);
g.drawImage(vocemenu, 4, 195, 4 | 0x10);
g.drawString("Info",63, 210,4 | 0x10);
break;
case 2:
g.drawImage(vocemenu, 4, 15, 4 | 0x10);
g.drawString("Inizia",63, 30,4 | 0x10);
g.drawImage(vocemenu, 4, 75, 4 | 0x10);
g.drawString("Istruzioni",63, 90,4 | 0x10);
g.setColor(0xec00e4);
g.drawImage(vocemenu2, 4, 135, 4 | 0x10);
g.drawString("Record",63, 150,4 | 0x10);
g.setColor(0xFFFFFF);
g.drawImage(vocemenu, 4, 195, 4 | 0x10);
g.drawString("Info",63, 210,4 | 0x10);
break;
case 3:
g.drawImage(vocemenu, 4, 15, 4 | 0x10);
g.drawString("Inizia",63, 30,4 | 0x10);
g.drawImage(vocemenu, 4, 75, 4 | 0x10);
g.drawString("Istruzioni",63, 90,4 | 0x10);
g.drawImage(vocemenu, 4, 135, 4 | 0x10);
g.drawString("Record",63, 150,4 | 0x10);
g.setColor(0xec00e4);
g.drawImage(vocemenu2, 4, 195, 4 | 0x10);
g.drawString("Info",63, 210,4 | 0x10);
break;
}
break;
case 3: //nuova domanda
try {
g.setColor(0x00000);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.drawImage(domandaI, 4, 5, 4 | 0x10);
dom=c.getDomanda();//carico una nuova domanda
//divido la stringa contenente la domanda per essere rappresentata a video
String sottoString="",spazio="";
int k=44,ii=0,ii2=0,ultimo=23,jj=0;
while(ii<dom.length())
{
if(ii2%25==0 & ii2!=0)
{
sottoString=dom.substring(ii-25,ii );
jj=sottoString.length()-1;
while(jj>0)
{
if(sottoString.charAt(jj)==' ')
break;
jj--;
}
spazio=dom.substring(ii-25,ii-(25-jj));
if(spazio.charAt(0)==' ')
g.drawString(spazio.substring(1),21, k,4 | 0x10);
else
g.drawString(spazio,21, k,4 | 0x10);
k=k+15;
ultimo=ii-(25-jj);
ii=ii-(25-jj);
ii2=0;
}
else{
ii++;
ii2++;
}
}
g.drawString(dom.substring(ultimo,ii ),18, k,4 | 0x10);
g.drawString("DOMANDA NUMERO: "+(domandaAttuale+1),5, 265,4 | 0x10);
}catch(Exception e)
{
System.out.println("Errore mentre divido domanda");
}
break;
case 4: //nuova risposta
int sec=0;
try
{
//carico il valore del contatore
sec=Integer.valueOf(secondi).intValue();
}
catch(NumberFormatException e)
{
//nel caso il contatore ancora non parte
}
//seleziono l'immagine della barra del tempo da visualizzare in base ai secondi
ib=getBarra(sec);
//controllo se devo far partire il conto alla rovescia oppure e' gia partito
if(conta==0)
{
cont=new Contatore(g);//creo l'oggetto contatore
myThread = new Thread(cont);//creo un nuovo thread
myThread.start();//avvio il thread
conta++;
secondi="30";
ib=0;
}
g.setColor(0x00000);
g.drawImage(contd, 4, 24, 4 | 0x10);
//visualizzo con le risposte solo i primi 25 caratteri della domanda
if(dom.length()>25)
g.drawString(dom.substring(0,25)+"...",30, 35,4 | 0x10);
else
g.drawString(dom,30, 35,4 | 0x10);
switch(tasto){
case 0:
g.setColor(0x00000);
g.drawImage(contdev, 4, 24, 4 | 0x10);
if(dom.length()>25)
g.drawString(dom.substring(0,25)+"...",30, 35,4 | 0x10);
else
g.drawString(dom,30, 35,4 | 0x10);
g.drawImage(contdom, 4, 80, 4 | 0x10);
g.drawString(c.getRisp1(),20, 87,4 | 0x10);
g.drawImage(contdom, 4, 120, 4 | 0x10);
g.drawString(c.getRisp2(),20, 127,4 | 0x10);
g.drawImage(contdom, 4, 160, 4 | 0x10);
g.drawString(c.getRisp3(),20, 167,4 | 0x10);
g.drawImage(contdom, 4, 200, 4 | 0x10);
g.drawString(c.getRisp4(),20, 207,4 | 0x10);
g.drawImage(barra[ib],4, 240,4 | 0x10);
g.drawString(secondi,96, 251,4 | 0x10);
break;
case 1:
g.drawImage(contev, 4, 80, 4 | 0x10);
g.drawString(c.getRisp1( ),20, 87,4 | 0x10);
g.drawImage(contdom, 4, 120, 4 | 0x10);
g.drawString(c.getRisp2( ),20, 127,4 | 0x10);
g.drawImage(contdom, 4, 160, 4 | 0x10);
g.drawString(c.getRisp3( ),20, 167,4 | 0x10);
g.drawImage(contdom, 4, 200, 4 | 0x10);
g.drawString(c.getRisp4( ),20, 207,4 | 0x10);
g.drawImage(barra[ib],4, 240,4 | 0x10);
g.drawString(secondi,96, 251,4 | 0x10);
break;
case 2:
g.drawImage(contdom, 4, 80, 4 | 0x10);
g.drawString(c.getRisp1( ),20, 87,4 | 0x10);
g.drawImage(contev, 4, 120, 4 | 0x10);
g.drawString(c.getRisp2( ),20, 127,4 | 0x10);
g.drawImage(contdom, 4, 160, 4 | 0x10);
g.drawString(c.getRisp3( ),20, 167,4 | 0x10);
g.drawImage(contdom, 4, 200, 4 | 0x10);
g.drawString(c.getRisp4( ),20, 207,4 | 0x10);
g.drawImage(barra[ib],4, 240,4 | 0x10);
g.drawString(secondi,96, 251,4 | 0x10);
break;
case 3:
g.drawImage(contdom, 4, 80, 4 | 0x10);
g.drawString(c.getRisp1( ),20, 87,4 | 0x10);
g.drawImage(contdom, 4, 120, 4 | 0x10);
g.drawString(c.getRisp2( ),20, 127,4 | 0x10);
g.drawImage(contev, 4, 160, 4 | 0x10);
g.drawString(c.getRisp3( ),20, 167,4 | 0x10);
g.drawImage(contdom, 4, 200, 4 | 0x10);
g.drawString(c.getRisp4( ),20, 207,4 | 0x10);
g.drawImage(barra[ib],4, 240,4 | 0x10);
g.drawString(secondi,96, 251,4 | 0x10);
break;
case 4:
g.drawImage(contdom, 4, 80, 4 | 0x10);
g.drawString(c.getRisp1( ),20, 87,4 | 0x10);
g.drawImage(contdom, 4, 120, 4 | 0x10);
g.drawString(c.getRisp2( ),20, 127,4 | 0x10);
g.drawImage(contdom, 4, 160, 4 | 0x10);
g.drawString(c.getRisp3( ),20, 167,4 | 0x10);
g.drawImage(contev, 4, 200, 4 | 0x10);
g.drawString(c.getRisp4( ),20, 207,4 | 0x10);
g.drawImage(barra[ib],4, 240,4 | 0x10);
g.drawString(secondi,96, 251,4 | 0x10);
break;
}
//controllo se e' stata data una risposta
if(risposto==1)
{
risposto=0;
if(rispes==1)//risposta esatta
{
rispes=0;
finestra=8;
domandaAttuale=j;
cont.quit();//fermo il conto alla rovescia
}
else if(rispes==0)//risposta errata
{
finestra=9;
cont.quit();//fermo il conto alla rovescia
caricap.salva(String.valueOf(punti));//salva i nuovi punteggi
puntiV=caricap.leggi();//carica i punteggi aggiornati
domandaAttuale=j;
j=0;
i=0;//riparto dalla prima domanda
}
else{//risposta esatta ma e' l'ultima domanda
rispes=0;
finestra=12;
domandaAttuale=j;
cont.quit();//fermo il conto alla rovescia
}
}
break;
case 5: //istruzioni
g.setColor(0xff71f3);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x000000);
g.drawString("Premi il tasto fire ",2, 10,4 | 0x10);
g.drawString("o il tasto 5 per scegliere ",2, 25,4 | 0x10);
g.drawString("la risposta esatta.",2, 40,4 | 0x10);
g.drawString("Per ogni domanda hai 30",2, 55,4 | 0x10);
g.drawString("secondi di tempo.",2, 70,4 | 0x10);
g.drawString("Piu rispondi velocemente ",2, 85,4 | 0x10);
g.drawString("e piu punti ti verranno ",2, 100,4 | 0x10);
g.drawString("assegnati. Per uscire",2, 115,4 | 0x10);
g.drawString("premi il pulsante per",2, 130,4 | 0x10);
g.drawString("attivare il menu destro.",2, 145,4 | 0x10);
g.drawString("Buon divertimento!",2, 160,4 | 0x10);
break;
case 6: //record
puntiV=caricap.leggi();
g.setColor(0xff71f3);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0xFFFFFF);
g.drawImage(classifica,8, 10, 4 | 0x10);
g.drawString("1: "+puntiV[0],65, 131,4 | 0x10);
g.drawString("2: "+puntiV[1],65, 146,4 | 0x10);
g.drawString("3: "+puntiV[2],65, 161,4 | 0x10);
g.drawString("4: "+puntiV[3],65, 176,4 | 0x10);
g.drawString("5: "+puntiV[4],65, 191,4 | 0x10);
break;
case 7: //about
g.setColor(0xff71f3);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x000000);
g.drawString("Realizzato da:",8, 30,4 | 0x10);
g.drawString("Rendinella Manuel (Domande)",8, 50,4 | 0x10);
g.drawString("Lallo Alessandro (Software)",8, 70,4 | 0x10);
g.drawString("Per qualsiasi cosa visita il sito:",8, 100,4 | 0x10);
g.drawString("conoscicalcio.altervista.org",8, 120,4 | 0x10);
g.drawString("Copyright 2009 Lallo, Rendinella",8, 140,4 | 0x10);
break;
case 8: //messaggio risposta esatta
g.setColor(0x00000);
g.drawImage(contdev, 4, 24, 4 | 0x10);
if(dom.length()>25)
g.drawString(dom.substring(0,25)+"...",30, 35,4 | 0x10);
else
g.drawString(dom,30, 35,4 | 0x10);
g.drawImage(contdom, 4, 80, 4 | 0x10);
g.drawString(c.getRisp1( ),20, 87,4 | 0x10);
g.drawImage(contdom, 4, 120, 4 | 0x10);
g.drawString(c.getRisp2( ),20, 127,4 | 0x10);
g.drawImage(contdom, 4, 160, 4 | 0x10);
g.drawString(c.getRisp3( ),20, 167,4 | 0x10);
g.drawImage(contdom, 4, 200, 4 | 0x10);
g.drawString(c.getRisp4( ),20, 207,4 | 0x10);
g.drawImage(corretto, 11, 130, 4 | 0x10);
break;
case 9: //messaggio risposta errata
g.setColor(0x00000);
g.drawImage(contdev, 4, 24, 4 | 0x10);
if(dom.length()>25)
g.drawString(dom.substring(0,25)+"...",30, 35,4 | 0x10);
else
g.drawString(dom,30, 35,4 | 0x10);
g.drawImage(contdom, 4, 80, 4 | 0x10);
g.drawString(c.getRisp1( ),20, 87,4 | 0x10);
g.drawImage(contdom, 4, 120, 4 | 0x10);
g.drawString(c.getRisp2( ),20, 127,4 | 0x10);
g.drawImage(contdom, 4, 160, 4 | 0x10);
g.drawString(c.getRisp3( ),20, 167,4 | 0x10);
g.drawImage(contdom, 4, 200, 4 | 0x10);
g.drawString(c.getRisp4( ),20, 207,4 | 0x10);
g.drawImage(errato, 11, 130, 4 | 0x10);
break;
case 10: //finestra risposta esatta
g.setColor(0xff71f3);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(esattarisp[imesatta],20, 24, 4 | 0x10);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.setColor(0x000000);
g.drawString("PUNTI TOTALIZZATI: "+punti,5, 235,4 | 0x10);
g.drawString("DOMANDA NUMERO: "+domandaAttuale,5, 255,4 | 0x10);
repaint();
break;
case 11: //finestra risposta errata
g.setColor(0xff71f3);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(erratorisp[imerrata],20, 24, 4 | 0x10);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.setColor(0x000000);
g.drawString("PUNTEGGIO FINALE: "+punti,5, 235,4 | 0x10);
g.drawString("DOMANDA NUMERO: "+(domandaAttuale+1),5, 255,4 | 0x10);
repaint();
break;
case 12: //finestra vittoria
g.setColor(0xff71f3);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(vittoria,20, 24, 4 | 0x10);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.setColor(0x000000);
g.drawString("PUNTEGGIO FINALE: "+punti,5, 235,4 | 0x10);
repaint();
break;
}
}
/**
* Metodo che permette la gestione degli eventi relativi ai tasti premuti dall'utente
*/
public void keyPressed(int keyCode)
{
//se il tasto premuto e la freccia verso il basso
if (DOWN==getGameAction(keyCode))
{
switch(finestra){//controllo che finestra e' visualizzata
case 2: //menu
if(tasto<3)
tasto++;
break;
case 4: //nuova risposta
if(tasto<4)
tasto++;
break;
}
}
//se il tasto premuto e la freccia verso l'alto
if (UP==getGameAction(keyCode))
{
switch(finestra){
case 2: //menu
if(tasto>0)
tasto--;
break;
case 4: //nuova risposta
if(tasto>0)
tasto--;
break;
}
}
//se il tasto premuto e il tasto di fuoco
if (FIRE==getGameAction(keyCode))
{
switch(finestra){
/*case 0: //primo intro non e' attivo nessun tasto
break;
case 1: //secondo intro non e' attivo nessun tasto
break;*/
case 2: //menu
switch(tasto){//controllo che voce del menu e' stata scelta
case 0: //inizia gioco
finestra=3;
boolean flag=true;
//genera un nuovo numero casuale
while(flag)
{
kk=generator.getRandomInt(303);//genera un numero casuale tra 0 e 302
//controllo che la domanda scelta non sia uguale alle 3 visualizzate in precedenza
if(domprec[0]!=kk && domprec[1]!=kk && domprec[2]!=kk)
{
domprec[0]=domprec[1];
domprec[1]=domprec[2];
domprec[2]=kk;
flag=false;
}
domandaAttuale=0;
}
c.caricaAltreDomande("1",String.valueOf(kk));
esatto=c.getEsatto();
break;
case 1: //istruzioni
finestra=5;
break;
case 2: //record
finestra=6;
break;
case 3: //about
finestra=7;
break;
}
break;
case 3: //nuova domanda
finestra=4;
break;
case 4: //nuova risposta
if(tasto==0)
finestra=3;
else{
risposto=1;
Integer n=new Integer(tasto-1);//prelevo il valore della risposta data
if(n.equals(esatto))
{
if(j==14)//controllo se siamo all'ultima domanda del gioco
{
rispes=2;
punti=calcolaPunti(cont.getSecondi(),j,punti);//calcolo i punti ottenuti
caricap.salva(String.valueOf(punti));//salva i nuovi punteggi
puntiV=caricap.leggi();//carica i punteggi aggiornati
i=0;//riparto dalla prima domanda
j=0;
}
else//altrimenti se ancora non si e' raggiunta l'ultima domanda
{
rispes=1;
punti=calcolaPunti(cont.getSecondi(),j,punti);//calcolo i punti ottenuti
j++;
i++;//passo alla domanda successiva
}
}
}
break;
case 5: //istruzioni
finestra=2;
break;
case 6: //record
finestra=2;
break;
case 7: //about
finestra=2;
break;
case 8: //messaggio risposta esatta
//scelgo a caso l'immagine da visualizzare per la risposta esatta data
imesatta=generator.getRandomInt(6);
finestra=10;
break;
case 9: //messaggio risposta errata
//scelgo a caso l'immagine da visualizzare per la risposta errata data
imerrata=generator.getRandomInt(4);
finestra=11;
break;
case 10://finestra risposta esatta
finestra=3;
tasto=0;
conta=0;
boolean flag=true;
//genera un nuovo numero casuale
while(flag)
{
if(j<3)
kk=generator.getRandomInt(303);
else if(j>2 && j<6)
kk=generator.getRandomInt(171);
else if(j>5 && j<9)
kk=generator.getRandomInt(145);
else if(j>8 && j<12)
kk=generator.getRandomInt(115);
else if(j>11 && j<15)
kk=generator.getRandomInt(100); //controllo che la domanda scelta non sia uguale alle 3 visualizzate in precedenza
if(domprec[0]!=kk && domprec[1]!=kk && domprec[2]!=kk)
{
domprec[0]=domprec[1];
domprec[1]=domprec[2];
domprec[2]=kk;
flag=false;
}
}
if(j>2 && j<6){
c.caricaAltreDomande("2",String.valueOf(kk));
carica2++;
//System.out.println("file2");
}
else if(j>5 && j<9){
c.caricaAltreDomande("3",String.valueOf(kk));
carica3++;
}
else if(j>8 && j<12){
c.caricaAltreDomande("4",String.valueOf(kk));
carica4++;
}
else if(j>11 && j<15 ){
c.caricaAltreDomande("5",String.valueOf(kk));
carica5++;
}
else{
//kk=generator.getRandomInt(190);
c.caricaAltreDomande("1",String.valueOf(kk));
//ystem.out.println("sempre file1");
}
esatto=c.getEsatto();
break;
case 11://finestra risposta errata
finestra=2;
tasto=0;
conta=0;
break;
case 12://finestra vittoria
finestra=2;
tasto=0;
conta=0;
punti=0;
break;
}
}
repaint();
}
/**
* Metodo che permette di aggiornare il valore del contatore visualizzato
* @param s valore in secondi da inserire nel contatore visualizzato
*/
public static void setTempo(String s, Graphics g)
{
secondi=s;
}
/**
* Metodo che avvia un nuovo thread che con un ciclo loop aggiorna continuamente lo schermo
*/
public void run()
{
while (true){
repaint();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
/**
* Metodo che in base all'intero passato, rappresentante i secondi trascorsi, setta la variabile
* indbarra che e' utilizzata per scegliere l'immagine della barra da visualizzare
* @param secondi valore dei secondi trascorsi
*/
private int getBarra(int secondi)
{
switch(secondi)
{
case 30:
indbarra=0;
break;
case 27:
indbarra=1;
break;
case 24:
indbarra=2;
break;
case 21:
indbarra=3;
break;
case 18:
indbarra=4;
break;
case 15:
indbarra=5;
break;
case 12:
indbarra=6;
break;
case 9:
indbarra=7;
break;
case 6:
indbarra=8;
break;
case 3:
indbarra=9;
break;
default:
break;
}
return indbarra;
}
/**
* Metodo che si occupa di calcolare il punteggio ottenuto
* @param sec secondi trascorsi
* @param dom numero della domanda
* @param p punti gia posseduti
* @return punti cioe' il nuovo punteggio calcolato
*/
public int calcolaPunti(int sec,int dom,int p){
int punti=p;
if(sec>20)//se i secondi trascorsi sono maggiori di 20
{
//controlla il numero della domanda e assegna i punti conquistati in base ai parametri
if(dom < 3)
punti=punti+300+100;
else if(dom>2 && dom< 6)
punti=punti+300+200;
else if(dom>5 && dom< 9)
punti=punti+300+300;
else if(dom>8 && dom< 12)
punti=punti+300+400;
else
punti=punti+300+500;
}
else if(sec>10) //se i secondi trascorsi sono maggiori di 10
{
//controlla il numero della domanda e assegna i punti conquistati in base ai parametri
if(dom < 3)
punti=punti+200+100;
else if(dom>2 && dom< 6)
punti=punti+200+200;
else if(dom>5 && dom< 9)
punti=punti+200+300;
else if(dom>8 && dom< 12)
punti=punti+200+400;
else
punti=punti+200+500;
}
else //se i secondi trascorsi sono minori di 10
{
//controlla il numero della domanda e assegna i punti conquistati in base ai parametri
if(dom < 3)
punti=punti+100+100;
else if(dom>2 && dom< 6)
punti=punti+100+200;
else if(dom>5 && dom< 9)
punti=punti+100+300;
else if(dom>8 && dom< 12)
punti=punti+100+400;
else
punti=punti+100+500;
}
return punti;
}
/**
* Metodo che e' richiamato per impostare lo stato del gioco come se la risposta fosse stata sbagliata. Questo
* accade nel momento in cui il tempo e' scaduto e l'utente non ha dato una risposta
*/
public static void setDomandaIniziale()
{
caricap.salva(String.valueOf(punti));//salva i nuovi punteggi
puntiV=caricap.leggi();//carica i punteggi aggiornati
finestra=9;//tempo scaduto mostro finestra risposta errata
j=0;
i=0;
}
/**
* Metodo che si occupa della chiusura del record store su cui sono memorizzati i migliori punteggi
*/
public void chiudiRecordStore()
{
caricap.chiudi();
}
}
contatore
Codice:
/* This file is part of Conosci il calcio.
*
* Conosci il calcio 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 3 of the License, or
* (at your option) any later version.
*
* Conosci il calcio 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 Conosci il calcio. If not, see <http://www.gnu.org/licenses/>.
*/
package Utility;
import javax.microedition.lcdui.Graphics;
import GUI.domandaG;
/**
* Classe che permette di effettuare un conto alla rovescia
* utilizzata per dare un limite di tempo nel rispondere a una domanda
* @author Lallo Alessandro
*
*/
public class Contatore implements Runnable {
private boolean flag=false; //variabile utilizzata per gestire il ciclo while del metodo run()
private int secondi;//variabile utilizzata per memorizzare i secondi trascorsi
private Graphics g;
public Contatore(){
}
public Contatore(Graphics g){
this.g=g;
}
/**
* metodo che permette di realizzare un conto alla rovescia
*/
public void run() {
secondi=30;
while (secondi >= 0 & !flag) {
domandaG.setTempo(String.valueOf(secondi),this.g);
try {
Thread.sleep(1000L);
}
catch (InterruptedException e)
{
System.out.println("ERRORE DELL'APPLICAZIONE!");
}
secondi--;
}
if(!flag)
{
domandaG.setDomandaIniziale();
}
}
/**
* metodo che setta il flag a true per permettere l'uscita dal metodo run
*/
public void quit(){
flag=true;
}
/**
* metodo che ritorna il valore della variabile flag
* @return flag
*/
public boolean getFlag(){
return flag;
}
/**
* metodo che ritorna il valore della variabile secondi
* @return secondi
*/
public int getSecondi(){
return secondi;
}
}
GeneratoreCasuale
Codice:
/* This file is part of Conosci il calcio.
*
* Conosci il calcio 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 3 of the License, or
* (at your option) any later version.
*
* Conosci il calcio 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 Conosci il calcio. If not, see <http://www.gnu.org/licenses/>.
*/
package Utility;
import java.util.Random;
/**
* Classe che permette la generazione di un numero casuale
* @author Lallo Alessandro
*
*/
public class GeneratoreCasualeN extends Random
{
private short i;
/**
* costruttore della classe (vuoto)
*/
public GeneratoreCasualeN()
{
}
/**
* Genera un numero casuale tra 0 e _limit
* @param _limit the Limit value for generation
* @return int value
*/
public int getRandomInt(int _limit)
{
i=(short) System.currentTimeMillis();
this.setSeed(i);
_limit++;
_limit = Math.abs((13*nextInt()) % _limit );
return _limit;
}
}
caricaDomande
Codice:
/* This file is part of Conosci il calcio.
*
* Conosci il calcio 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 3 of the License, or
* (at your option) any later version.
*
* Conosci il calcio 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 Conosci il calcio. If not, see <http://www.gnu.org/licenses/>.
*/
package Carica;
import java.io.*;
/**
* Classe che permette il caricamente delle domande da file. Ogni domanda è rappresentata su
* sei linee del file. Le sei linee sono cosi occupate:
* 1- Domanda
* 2- Prima risposta tra le quattro alternative
* 3- Seconda risposta
* 4- Terza risposta
* 5- Quarta risposta
* 6- Valore intero rappresentante la risposta esatta
* Il valore della risposta esatta varia tra 0 (la prima risposta) e 3 (l'ultima risposta)
* @author Lallo Alessandro
*
*/
public class CaricaDomande {
private String domanda="";
private String risp1="",risp2="",risp3="",risp4="";
private Integer esatto;
private DataInputStream stream;
private String tmp;
private StringBuffer buffer;
/**
* Costruttore della classe vuoto
*/
public CaricaDomande ()
{
}
/**
* Metodo che restituisce la domanda memorizzata
* @param
* @return String rappresentante la domanda i-esima
*/
public String getDomanda(){
return domanda;
}
/**
* Metodo che ritorna la prima risposta
* @param
* @return String rappresentante la prima risposta
*/
public String getRisp1(){
return risp1;
}
/**
* Metodo che ritorna seconda risposta
* @param
* @return String rappresentante la secondarisposta
*/
public String getRisp2(){
return risp2;
}
/**
* Metodo che ritorna terza risposta
* @param
* @return String rappresentante la terza risposta
*/
public String getRisp3(){
return risp3;
}
/**
* Metodo che ritorna quarta risposta
* @param
* @return String rappresentante la quarta risposta
*/
public String getRisp4(){
return risp4;
}
/**
* Metodo che ritorna intero rappresentate la risposta esatta
* @param
* @return int l'indire della risposta esatta
*/
public Integer getEsatto(){
//System.out.println(esatto);
return esatto;
}
/**
* Metodo dove avviene la lettura delle domande da file e la loro
* memorizzazione in 6 variabili(domanda,prima risposta,seconda risposta,terza risposta
* quarta risposta, intero rappresentante la risposta esatta)
* */
public void caricaAltreDomande(String numfile,String i)
{
System.gc();
boolean trovata=false;
try
{
Class c = this.getClass();
stream = new DataInputStream(c.getResourceAsStream("/ans"+numfile));
tmp=new String();
String line;
int length,idx1;
char ca;
if(stream.available()>0)
{
buffer = new StringBuffer();
ca = (char) stream.read();
while (ca!= '#' )
{
buffer.append( ca );
ca = (char) stream.read();
}
tmp= buffer.toString();
// cerco in tmp le stringhe \r\n
idx1 = tmp.toString().indexOf( "\r\n" );
while ( idx1 >= 0 && !trovata )
{
int u=0;
String id="";
char a = 0;
while(u<tmp.length())
{
a=tmp.charAt(u);
if(a=='>')
u=tmp.length();
else
{
id=id+a;
u++;
}
}
if(id.equals(i))
{
trovata=true;
//se le trovo, splitto dentro line il resto di tmp
line = tmp.toString().substring( id.length()+1, idx1 );
//System.out.println("i1: "+i+" line: "+line);
domanda=line;
//System.out.println(line);
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
// System.out.println("i2: "+i+" line: "+line);
risp1=line;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
// System.out.println("i3: "+i+" line: "+line);
risp2=line;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
//System.out.println("i4: "+i+" line: "+line);
risp3=line;
//System.out.println("PRIMA "+idx1+2);
tmp = tmp.toString().substring( idx1 + 2 );
//System.out.println("DOPO");
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
// System.out.println("i5: "+i+" line: "+line);
risp4=line;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
//System.out.println("idx: "+idx1);
if(idx1==-1)//controllo se il file è finito
{
idx1=1;
line = tmp.toString().substring( 0, idx1 );
idx1=-1;
esatto=Integer.valueOf(line);
//i++;
}
else
{
line = tmp.toString().substring( 0, idx1 );
esatto=Integer.valueOf(line);
//i++;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
}
}
else
{
//se le trovo, splitto dentro line il resto di tmp
line = tmp.toString().substring( 0, idx1 );
//System.out.println("i1: "+i+" line: "+line);
//domanda[i]=line;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
//System.out.println("i2: "+i+" line: "+line);
//risp1[i]=line;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
//System.out.println("i3: "+i);//+" line: "+line);
//risp2[i]=line;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
//System.out.println("i4: "+i+" line: "+line);
// risp3[i]=line;
//System.out.println("PRIMA "+idx1+2);
tmp = tmp.toString().substring( idx1 + 2 );
//System.out.println("DOPO");
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
//System.out.println("i5: "+i+" line: "+line);
// risp4[i]=line;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
//System.out.println("idx: "+idx1);
if(idx1==-1)//controllo se il file è finito
{
idx1=1;
line = tmp.toString().substring( 0, idx1 );
idx1=-1;
//esatto[i]=Integer.valueOf(line);
// i++;
}
else
{
line = tmp.toString().substring( 0, idx1 );
//esatto[i]=Integer.valueOf(line);
//i++;
tmp = tmp.toString().substring( idx1 + 2 );
idx1 = tmp.toString().indexOf( "\r\n" );
line = tmp.toString().substring( 0, idx1 );
}
}
}//end while
}//end if
else
{
try
{
Thread.sleep(20);
}
catch (Exception e){}
}
stream.close();
stream=null;
System.gc();
}
catch (IOException e)
{
System.out.println("ERRORE NEL CARICARE DOMANDE");
e.printStackTrace();
}
}
}
e infine carica punteggi
Codice:
/* This file is part of Conosci il calcio.
*
* Conosci il calcio 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 3 of the License, or
* (at your option) any later version.
*
* Conosci il calcio 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 Conosci il calcio. If not, see <http://www.gnu.org/licenses/>.
*/
package Carica;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
/**
* Classe che permette il caricamento dei punteggi del gioco
* i punteggi vengono memorizzati nella memoria del dispositivo
* vengono memorizzati solo i 5 punteggi migliori
* @author Lallo Alessandro
*/
public class CaricaPunteggi {
private RecordStore recordStore;
private String punteggi[];
private int totrec = 0;
/**
* costruttore della calsse a 0 posti
*/
public CaricaPunteggi()
{
recordStore = null;
try {
recordStore = RecordStore.openRecordStore( "classifica", true );
}
catch( RecordStoreException e ){
System.out.println(e.toString());
}
punteggi=new String[5];
//inizializzo il vettore che memorizzerà i punteggi
for(int u=0;u<5;u++)
{
punteggi[u]="0";
}
//carico ultimi punteggi memorizzati
punteggi=leggi();
}
/**
* metodo che salva i punteggi controllando se il punteggio totalizzato in
* questa partita sia un record
* @param String dato punteggio totalizzato in questa partita
*/
public void salva(String dato)
{
String[] totpunt= new String[5];
totpunt=leggi();
chiudi();
try {
//distruggo il vecchio recordstore contenente i vecchi record
RecordStore.deleteRecordStore("classifica");
//creo il nuovo recordstore
recordStore = RecordStore.openRecordStore( "classifica", true );
byte[] record =dato.getBytes();
//controllo che il nuovo punteggio sia un nuovo record e lo posiziono
//in maniera corretta con una serie di if
if(Integer.parseInt(dato)>Integer.parseInt(totpunt[0])){
record = dato.getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[0].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[1].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[2].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[3].getBytes();
recordStore.addRecord(record, 0, record.length);
}else if(Integer.parseInt(dato)>Integer.parseInt(totpunt[1])){
record=totpunt[0].getBytes();
recordStore.addRecord(record, 0, record.length);
record = dato.getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[1].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[2].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[3].getBytes();
recordStore.addRecord(record, 0, record.length);
}else if(Integer.parseInt(dato)>Integer.parseInt(totpunt[2])){
record=totpunt[0].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[1].getBytes();
recordStore.addRecord(record, 0, record.length);
record = dato.getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[2].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[3].getBytes();
recordStore.addRecord(record, 0, record.length);
}else if(Integer.parseInt(dato)>Integer.parseInt(totpunt[3])){
record=totpunt[0].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[1].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[2].getBytes();
recordStore.addRecord(record, 0, record.length);
record = dato.getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[3].getBytes();
recordStore.addRecord(record, 0, record.length);
}else if(Integer.parseInt(dato)>Integer.parseInt(totpunt[4])){
record=totpunt[0].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[1].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[2].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[3].getBytes();
recordStore.addRecord(record, 0, record.length);
record = dato.getBytes();
recordStore.addRecord(record, 0, record.length);
}else{
record = totpunt[0].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[1].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[2].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[3].getBytes();
recordStore.addRecord(record, 0, record.length);
record=totpunt[4].getBytes();
recordStore.addRecord(record, 0, record.length);
}
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
/**
* metodo che permette di leggere i punteggi memorizzati sul dispositivo
*/
public String[] leggi()
{
byte[] record;
int lunghezza;
try
{
//leggo nel recordstore i punteggi e li memorizzo in un vettore
for (totrec = 1; totrec <= recordStore.getNumRecords(); totrec++)
{
record = new byte[recordStore.getRecordSize(totrec)];
lunghezza = recordStore.getRecord(totrec, record, 0);
punteggi[totrec-1]=new String(record);
}
}
catch (Exception e)
{
System.out.println(e.toString());
}
return punteggi;
}
/**
* metodo che chiude il recordstore su cui sono memorizzati i dati
*/
public void chiudi()
{
try
{
recordStore.closeRecordStore();
}
catch(RecordStoreException e )
{
System.out.println(e.toString());
}
}
}
tutto il materiale lo trovate sul sito che ho appositamente creato http://www.conoscicalcio.altervista.org/
sperando che l'applicazione vi piaccia, accetto critiche e domande