Il Solitario Vittoriano sul telefonino Nokia 3410



Per scaricare il gioco sul telefonino e' sufficiente connettersi tramite il servizio Wap del cellulare all'indirizzo http://spazioinwind.libero.it/giochiweb/vitt3410.htm

Qui sotto ho inserito il listato del gioco per chi e' curioso di sapere come e' realizzato

Buon divertimento

Antonino Iacono
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class Vittoriano extends MIDlet implements CommandListener {

    private Solitario theGame;
    private Command exitCmd  = new Command("Uscita", Command.SCREEN, 3);
    private Command startCmd = new Command("Start", Command.SCREEN, 1);
    private Command restartCmd = new Command("Restart", Command.SCREEN, 1);
    private Command cancelCmd = new Command("Cancella", Command.ITEM, 1);
    private Command OKCmd = new Command("OK", Command.OK, 1);

    public Vittoriano() {

	theGame = new Solitario();
	theGame.addCommand(exitCmd);
	theGame.addCommand(startCmd);
	theGame.setCommandListener(this);
    }

    protected void destroyApp(boolean unconditional) {
	Display.getDisplay(this).setCurrent(null);
    }

    protected void pauseApp() {
    }

    protected void startApp() {
	Display.getDisplay(this).setCurrent(theGame);

	try {
	    Thread myThread = new Thread(theGame);
	    myThread.start();
	} catch (Error e) {
	    destroyApp(false);
	    notifyDestroyed();
	}
    }


    public void commandAction(Command c, Displayable d) {
        if (c == restartCmd) {
	    theGame.restart();
        } else if (c == exitCmd) {
	    destroyApp(false);
	    notifyDestroyed();
        } else if (c == startCmd) {
	    theGame.removeCommand(startCmd);
	    theGame.addCommand(restartCmd);
	    theGame.restart();
        } else if (c == OKCmd) {
	    Form f = (Form)d;
	    Gauge g = (Gauge)f.get(0);
	    Display.getDisplay(this).setCurrent(theGame);
        } else if (c == cancelCmd) {
	    Display.getDisplay(this).setCurrent(theGame);
	}
    }

}


class Solitario extends Canvas implements Runnable {

    private boolean gameOver = false;
    int posizione = 13 ;
    int posizionevecchia = 13 ;
    int visualizza_riquadro = 0;
    int cancella = 0;
    int inizio = 1;
    int ok = 0;
    boolean libero;
    int mosse;
    int h;
    int h1;
    int h2;
    int e;
    int r;
    int cella;
    int cella2;
    int a[] = { 0, 18, 9, 0, 27, 18, 9, 36,27,18,54,45,63,54,45,72,63,54};
    int b[] = { 0, 9,18,27,18,27,36,27,36,45,9,18,18,27,36,27,36,45};
    int ce3[] = { 0, 1, 1, 1, 1, 1, 1, 3,1,1,2,2,2,2,2,2,2,2};
    int ce[];
    int ceno[][];
    int ceno2[][];
    int ceno_1[]={0,2,5,2,7,7,5,4,5,5,11,7,11,7,8,12,14,14};
    int ceno_2[]={0,4,4,5,5,2,8,5,7,6,12,14,13,11,7,13,13,13};
    int ceno_3[]={0,5,3,6,11,3,2,8,14,8,13,4,10,12,13,16,15,16};
    int ceno_4[]={0,0,1,0,8,4,3,11,6,0,0,13,15,10,11,0,12,0};
    int ceno_5[]={0,0,6,0,1,6,9,13,9,0,0,12,16,15,16,0,17,0};
    int ceno_6[]={0,0,0,0,2,1,0,14,4,0,0,10,0,14,17,0,0,0};
    int ceno_7[]={0,0,0,0,0,8,0,0,0,0,0,0,0,16,0,0,0,0};
    int ceno_8[]={0,0,0,0,0,9,0,0,0,0,0,0,0,17,0,0,0,0};
    int ceno2_1[]={0,3,8,1,14,13,4,1,2,1,7,8,4,5,6,10,8,7};
    int ceno2_2[]={0,7,11,7,6,0,14,3,11,3,15,16,14,0,4,7,11,10};
    int ceno2_3[]={0,9,0,9,12,0,0,9,16,7,17,2,0,0,12,17,0,15};
    int ceno2_4[]={0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0};
    int ceno2_5[]={0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0};
    int ceno2_6[]={0,0,0,0,0,0,0,17,0,0,0,0,0,0,0,0,0,0};
    int ceno2_7[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int ceno2_8[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

    static {
	Font defaultFont  = Font.getDefaultFont();
    }

    public Solitario() {

        libero = false;
        mosse = 0;
        ce = new int[18];
        ceno = new int[18][9];
        ceno2 = new int[18][9];

            for(h = 1; h <= 17; h++)
		{
                ce[h] = ce3[h];
		ceno[h][1] = ceno_1[h];
		ceno[h][2] = ceno_2[h];
		ceno[h][3] = ceno_3[h];
		ceno[h][4] = ceno_4[h];
		ceno[h][5] = ceno_5[h];
		ceno[h][6] = ceno_6[h];
		ceno[h][7] = ceno_7[h];
		ceno[h][8] = ceno_8[h];

		ceno2[h][1] = ceno2_1[h];
		ceno2[h][2] = ceno2_2[h];
		ceno2[h][3] = ceno2_3[h];
		ceno2[h][4] = ceno2_4[h];
		ceno2[h][5] = ceno2_5[h];
		ceno2[h][6] = ceno2_6[h];
		ceno2[h][7] = ceno2_7[h];
		ceno2[h][8] = ceno2_8[h];
	        }
        mosse = 0;
    }

    public void riquadro(int direzione)
    {
posizionevecchia = posizione;

if((direzione == 55 || direzione==9)&& (posizione == 1 || posizione == 2 || posizione ==4 || posizione == 5 || posizione == 8 || posizione == 7 || posizione == 10 || posizione == 12 || posizione == 13 || posizione == 15|| posizione == 16)) { posizione = posizione +1 ;   }
else if ((direzione == 55 || direzione ==9) && posizione == 11) { posizione = posizione - 4;   }
else if ((direzione == 57 || direzione ==10)&& (posizione == 1 || posizione == 2 || posizione ==3 || posizione == 4 || posizione == 5 || posizione == 6 || posizione == 12 || posizione == 13 || posizione == 14)) { posizione = posizione +3 ;   }
else if ((direzione == 57 || direzione ==10)&& (posizione == 10 || posizione == 11)) { posizione = posizione +2;   }
else if ((direzione == 57 || direzione ==10)&& posizione == 7) { posizione = posizione +7;   }
else if(direzione == 49 && (posizione == 4 || posizione == 5 || posizione ==6 || posizione == 7 || posizione == 8 || posizione == 9 || posizione == 15 || posizione == 16 || posizione == 17)) { posizione = posizione -3 ;   }
else if (direzione == 49 && posizione == 14) { posizione = posizione -7;   }
else if (direzione == 49 && (posizione == 12 || posizione == 13)) { posizione = posizione -2;   }
else if(direzione == 51 && (posizione == 2 || posizione == 3 || posizione ==5 || posizione == 6 || posizione == 8 || posizione == 9 || posizione == 11 || posizione == 13 || posizione == 14 || posizione == 16 || posizione == 17 )) { posizione = posizione -1 ;   }
else if (direzione == 51 && posizione == 7) { posizione = posizione +4;   }
else if((direzione == 56 || direzione == DOWN) && (posizione == 1 || posizione == 2 || posizione ==4 || posizione == 5 || posizione == 12 ||  posizione == 13)) { posizione = posizione + 4;   }
else if ((direzione == 56 || direzione ==DOWN) && (posizione == 10 || posizione == 11)) { posizione = posizione +3;   }
else if((direzione == 50 || direzione == UP) && (posizione == 5 || posizione == 6 || posizione ==8 || posizione == 9 || posizione == 16 ||  posizione == 17)) { posizione = posizione - 4;   }
else if ((direzione == 50 || direzione == UP) && (posizione == 13 || posizione == 14)) { posizione = posizione -3;   }
else if((direzione == 54 || direzione == RIGHT)&& (posizione == 2 || posizione == 3  || posizione == 5 || posizione == 6 ||  posizione == 13 ||  posizione == 14)) { posizione = posizione + 2;   }
else if ((direzione == 54 || direzione == RIGHT)&& posizione == 4 ) { posizione = posizione +7;   }
else if ((direzione == 54 || direzione == RIGHT)&& posizione == 11 ) { posizione = posizione +1;   }
else if ((direzione == 54 || direzione == RIGHT)&& (posizione == 8 || posizione == 7)) { posizione = posizione +6;   }
else if((direzione == 52 || direzione == LEFT) && (posizione == 4 || posizione == 5  || posizione == 7 || posizione == 15 ||  posizione == 16 ||  posizione == 8)) { posizione = posizione - 2;   }
else if ((direzione == 52 || direzione == LEFT)&& posizione == 11 ) { posizione = posizione -7;   }
else if ((direzione == 52 || direzione == LEFT)&& (posizione == 14 || posizione == 13)) { posizione = posizione -6;   }
else if ((direzione == 52 || direzione == LEFT)&& posizione == 12 ) { posizione = posizione -1; }

if (posizionevecchia != posizione)
    {
visualizza_riquadro = 1;
repaint();
    }
}

    public void riquadro_ok()
    {
            cella = posizione;
            libero = false;
if(ce[cella] == 1 || ce[cella]==2)
cella2=0;
for(h = 1; h <= 8; h++)
{
if (ce[ceno[cella][h]]==3)
{
cella2=ceno[cella][h];
libero=true;
}
if (ce[ceno2[cella][h]]==3 && (ce[ceno[cella][h]]==1 || ce[ceno[cella][h]]==2))
{
cella2=ceno2[cella][h];
libero=true;
}
}
        if(libero)
        {
            ce[cella2] = ce[cella];
            ce[cella] = 3;
	repaint();      
      mosse++;

if(ce[1]==2 && ce[2]==2 &&  ce[3]==2 && ce[4]==2 && ce[5]==2 && ce[6]==2 && ce[7]==3 && ce[8]==2 && ce[9]==2 && ce[10]==1 && ce[11]==1 && ce[12]==1 && ce[13]==1 && ce[14]==1 && ce[15]==1 && ce[16]==1 && ce[17]==1) gameOver = true; 
}
}

    public void scacchiera(Graphics g)
    {
int h2;

for(h2 = 1; h2 <= 17; h2++)
    {
g.drawLine(a[h2],b[h2],a[h2]+9,b[h2]-9);
g.drawLine(a[h2]+9,b[h2]-9,a[h2]+18,b[h2]);
g.drawLine(a[h2]+18,b[h2],a[h2]+9,b[h2]+9);
g.drawLine(a[h2]+9,b[h2]+9,a[h2],b[h2]);
    }

        String f8="M."+Integer.toString(mosse);
	g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL));
	g.setColor(255,255,255);
	g.fillRect(36,46,18,10);
	g.setColor(0,0,0);
        g.drawString(f8, 36, 46, g.TOP|g.LEFT);

        for(h = 1; h <= 17; h++)
        {
            if(ce[h] == 1)
            {
                g.fillArc(a[h]+6, b[h]-4, 7, 8 ,0,360);
            }
            if(ce[h] == 2)
            {
                g.drawArc(a[h]+6, b[h]-4, 7, 7 ,0,360);
            }
            if(ce[h] == 3)
            {
                g.setGrayScale(255);
		g.fillRect(a[h]+6,b[h]-4,8,8);
                g.setGrayScale(0);

            }
        }

g.drawLine(a[posizione]+9,b[posizione]-8,a[posizione]+17,b[posizione]);

    }

    void restart() {
		mosse = 0;
		gameOver = false;
    		posizione = 13 ;
		posizionevecchia = 13 ;
            for(h = 0; h <= 17; h++)
                ce[h] = ce3[h];
		cancella = 1;
		repaint();
    }

 protected void keyRepeated(int keyCode){
 keyPressed(keyCode);
    }

    public void keyPressed(int keyCode) {
int direz = (getGameAction(keyCode));
if (direz == FIRE) riquadro_ok();
if (direz == 0) direz=keyCode;
if (direz == Canvas.KEY_NUM5) riquadro_ok();
riquadro(direz);
    }

    public void paint(Graphics g) {

if (inizio == 1) {
g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL));
g.setColor(255,255,255);
g.fillRect(0,0,97,57);
g.setColor(0,0,0);
g.drawString("Solitario Vittoriano", 2,0,g.TOP|g.LEFT);
g.drawString("Scopo del gioco e' ", 2,9,g.TOP|g.LEFT);
g.drawString("spostare le pedine ", 2,17,g.TOP|g.LEFT);
g.drawString("bianche a sinistra e", 2,25,g.TOP|g.LEFT);
g.drawString("le nere a destra. ", 2,33,g.TOP|g.LEFT);
g.drawString("ant_iacono@tin.it", 2,42,g.TOP|g.LEFT);
inizio = 0;
    }
else if (cancella == 1) {
g.setColor(255,255,255);
g.fillRect(0,0,97,57);
g.setColor(0,0,0);
g.drawLine(a[13]+1,b[13],a[13]+9,b[13]-8);
g.drawLine(a[13]+9,b[13]-8,a[13]+17,b[13]);
g.drawLine(a[13]+17,b[13],a[13]+9,b[13]+8);
g.drawLine(a[13]+9,b[13]+8,a[13]+1,b[13]);
ok = 1;
cancella = 0;
scacchiera(g);
    }
	else if (visualizza_riquadro == 1 && ok==1) {

g.drawLine(a[posizione]+1,b[posizione],a[posizione]+9,b[posizione]-8);
g.drawLine(a[posizione]+9,b[posizione]-8,a[posizione]+17,b[posizione]);
g.drawLine(a[posizione]+17,b[posizione],a[posizione]+9,b[posizione]+8);
g.drawLine(a[posizione]+9,b[posizione]+8,a[posizione]+1,b[posizione]);

g.setColor(255,255,255);

g.drawLine(a[posizionevecchia]+1,b[posizionevecchia],a[posizionevecchia]+9,b[posizionevecchia]-8);
g.drawLine(a[posizionevecchia]+9,b[posizionevecchia]-8,a[posizionevecchia]+17,b[posizionevecchia]);
g.drawLine(a[posizionevecchia]+17,b[posizionevecchia],a[posizionevecchia]+9,b[posizionevecchia]+8);
g.drawLine(a[posizionevecchia]+9,b[posizionevecchia]+8,a[posizionevecchia]+1,b[posizionevecchia]);

g.setColor(0,0,0);
visualizza_riquadro = 0;
	}
else if (ok == 1) scacchiera(g);

	if (gameOver) {
	        String f8=Integer.toString(mosse);
                String TheMsg ="in "+ f8+" mosse";

		g.setColor(255,255,255);
		g.fillRect(0,0,97,57);
		g.setColor(0,0,0);

		g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL));

                g.drawString("Hai completato il", 1,1,g.TOP|g.LEFT);
                g.drawString("solitario vittoriano", 1,13,g.TOP|g.LEFT);

                g.drawString(TheMsg, 1, 25,g.TOP|g.LEFT);

                if(mosse==30)
                TheMsg ="Record eguagliato";
		if(mosse>=31 && mosse<37)
                TheMsg = "Ottimo risultato";
                if(mosse>=38 && mosse<=50)
                TheMsg = "Risultato discreto";
                if(mosse>50)
                TheMsg = "Puoi fare di meglio";
                g.drawString(TheMsg, 1,37 ,g.TOP|g.LEFT);
	} 
    }

    public void run() {
	while (true) {
    }
  }
}