rendered paste bodyimport javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import java.util.Date;
import java.io.*;
public class SuliMIDlet
extends MIDlet
implements CommandListener {
private Command CmdExit;
private Form LogoF;
private StringItem LogoS1;
private Form SzbF;
private StringItem SzbS1;
private Form ScoreF;
private StringItem ScoreS1;
private Form NyertF;
private StringItem NyertS1;
private Command CUJQJATEK;
private Command CEREDMENYEK;
private Command CTITKOSQMENU;
private Command CINFORMACIO;
private Command COKQ;
private Command CQQQQ;
private Command CTOVABB;
private Canvas Cv1;
private Canvas Cv2;
private Graphics G2;
private String label;
private String Score;
private int n;
private int rnd;
private RecordStore rs;
private String rndS;
private Date today = new Date(System.currentTimeMillis());
private long ido = today.getTime();
private ImageItem imageItem;
private ImageItem imageItem2;
private Image ihatter[] = new Image[9];
public SuliMIDlet() {
// MINDEN F
CmdExit = new Command("Kilépés", Command.SCREEN, 1);
CUJQJATEK = new Command("Új játék", Command.SCREEN, 0);
CEREDMENYEK = new Command("Eredmények", Command.SCREEN, 0);
CTITKOSQMENU = new Command("Titkos menü", Command.SCREEN, 0);
CINFORMACIO = new Command("Információ", Command.SCREEN, 0);
COKQ = new Command("OK ", Command.SCREEN, 0);
CQQQQ = new Command(" ", Command.SCREEN, 0);
CTOVABB = new Command("Tovább", Command.SCREEN, 0);
// LOGO F
LogoF = new Form("Mászkál");
LogoS1 = new StringItem(null, "");
LogoS1.setText("Üdvözöllek");
LogoF.append(LogoS1);
//Image and ImageItem
try {
Image image = Image.createImage("/Logo2.png");
imageItem = new ImageItem("ImageItem is below:", image, ImageItem.LAYOUT_NEWLINE_BEFORE, "Alternate text for the image file");
//LogoF.append(image);
// LogoF.append(imageItem);
}
catch (java.io.IOException e) {}
LogoF.addCommand(CUJQJATEK);
LogoF.addCommand(CEREDMENYEK);
// LogoF.addCommand(CTITKOSQMENU);
LogoF.addCommand(CINFORMACIO);
LogoF.addCommand(CmdExit);
// SZB F
SzbF = new Form("Információ");
SzbS1 = new StringItem(null, "");
SzbS1.setText("A programot SzB készítette. \n\nVerzió: 0.1 \n\nUtolsó frissítés: \n2007. okt. 5.");
SzbF.append(SzbS1);
SzbF.addCommand(COKQ);
SzbF.addCommand(CmdExit);
// SCORE F
ScoreF = new Form("Eredmények");
ScoreS1 = new StringItem(null, "");
ScoreS1.setText(Score);
ScoreF.append(ScoreS1);
ScoreF.addCommand(CQQQQ);
ScoreF.addCommand(COKQ);
// NYERT F
NyertF = new Form("Nyertél!");
NyertS1 = new StringItem(null, "Sikerült teljesíteni a pályát!");
NyertF.append(NyertS1);
NyertF.addCommand(CTOVABB);
}
public void startApp() {
Display.getDisplay(this).setCurrent(SzbF);
SzbF.setCommandListener(this);
try{
rs = RecordStore.openRecordStore("SuliRS",true);
Score = "0";
byte bytes[] = Score.getBytes();
rs.addRecord(bytes,0,bytes.length);
byte b[] = rs.getRecord(1);
Score = new String(b,0,b.length);
rs.closeRecordStore();
}
catch(RecordStoreException rse){}
/*Cv1 = new LineCanvas();
Cv2 = new LineCanvas();
int width = Cv1.getWidth();
int height = Cv1.getHeight();
LogoS1.setText("Szélesség: "+width+"\nMagasság: "+height);
//Cv1.addCommand(CUJQJATEK);
//Cv1.addCommand(COKQ);
Cv1.setFullScreenMode(true);
Display.getDisplay(this).setCurrent(Cv1);
Cv1.setCommandListener(this);*/
preload();
canvas3.setFullScreenMode(true);
Display.getDisplay(this).setCurrent(canvas3);
canvas3.setCommandListener(this);
}
public void preload() {
try {
for(fi=0; fi<=8; fi++){
ihatter[fi] = Image.createImage ("/n"+Integer.toString(fi)+".gif");
}
}
catch (IOException e) {
throw new RuntimeException ("Unable to load Image: "+e);
}
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
label = c.getLabel();
if(label == "Kilépés"){
notifyDestroyed();
}
if(label == "OK "){
label = "XLOGO";
}
if(label == "Vissza"){
label = "XLOGO";
}
if(label == "XLOGO"){
Display.getDisplay(this).setCurrent(LogoF);
LogoF.setCommandListener(this);
}
if(label == "Információ"){
label = "XINFO";
}
if(label == "XINFO"){
Display.getDisplay(this).setCurrent(SzbF);
SzbF.setCommandListener(this);
}
if(label == "Eredmények"){
label = "XSCORE";
}
if(label == "OK"){
label = "XSCORE";
}
if(label == "Megállok"){
label = "XSCORE";
}
if(label == "XSCORE"){
try{
rs = RecordStore.openRecordStore("SuliRS",true);
if(Integer.parseInt(Score)<n){
Score = Integer.toString(n);
}
byte bytes[] = Score.getBytes();
rs.setRecord(1,bytes,0,bytes.length);
byte b[] = rs.getRecord(1);
Score = new String(b,0,b.length);
rs.closeRecordStore();
}
catch(RecordStoreException rse){}
Display.getDisplay(this).setCurrent(ScoreF);
ScoreF.setCommandListener(this);
ScoreS1.setText("Legutóbbi eredmény: \n"+Integer.toString(n)+" pont \n\nEddig elért\nlegnagyobb eredmény: \n"+Score+" pont");
}
ido = System.currentTimeMillis();
rndS = Long.toString(ido);
rndS = "0"+rndS.charAt(rndS.length()-1);
rnd = Integer.parseInt(rndS);
if(label == "Új játék"){
label = "XUJ";
}
if(label == "XUJ"){
Display.getDisplay(this).setCurrent(Cv1);
Cv1.setCommandListener(this);
/*G2.setColor(0xFF0000);
G2.fillRect(0, 0, 200, 200);
Cv2.paint(G2);
Display.getDisplay(this).setCurrent(Cv2);
Cv2.setCommandListener(this);*/
}
}
Canvas canvas3 = new Canvas() {
private int keyi;
private int width = 128; //getWidth();
private int height = 160; //getHeight();
private int fi;
private int hn = 1;
//public void paint(Graphics g){ }
public void paint(Graphics g) {
// super(true);
/*
// Fill the background using black
g.setColor(0);
g.fillRect(0, 0, width, height);
// White horizontal line
g.setColor(0xFFFFFF);
g.drawLine(0, height/2, width - 1, height/2);
// Yellow dotted horizontal line
g.setStrokeStyle(Graphics.DOTTED);
g.setColor(0xFFFF00);
g.drawLine(0, height/4, width - 1, height/4);
// Solid diagonal line in brightest gray
g.setGrayScale(255);
g.setStrokeStyle(Graphics.SOLID);
g.drawLine(0, 0, width - 1, height - 1);
*/
//g.setColor(0xFFFFFF);
//g.fillRect(0, 0, width, height);
g.drawImage(ihatter[hn], hn, 0, Graphics.TOP | Graphics.LEFT);
//g.setColor(0xFF0000);
//g.drawString("*"+keyi+"* w:"+width+" h:"+height, 1, 0, Graphics.TOP | Graphics.LEFT);
}
protected void keyPressed(int keyCode) {
String keym;
keym = "miez "+Integer.toString(keyCode);
if(keyCode==-6){ keym = "soft1"; }
if(keyCode==-7){ keym = "soft2"; }
if(keyCode==-1){ keym = "up"; }
if(keyCode==-2){ keym = "down"; }
if(keyCode==-3){ keym = "left"; }
if(keyCode==-4){ keym = "right"; }
if(keyCode==-5){ keym = "fire"; }
if(keyCode==-8){ keym = "clear"; }
if(keyCode==-11){ keym = "back"; }
if(keyCode==-36){ keym = "volup"; }
if(keyCode==-37){ keym = "voldown"; }
if(49<=keyCode && keyCode<=57){ keym = Integer.toString(keyCode-48); }
if(keyCode==48){ keym = "0"; }
if(keyCode==42){ keym = "*"; }
if(keyCode==35){ keym = "#"; }
KeyAction(keym);
}
protected void keyReleased(int keyCode) {
//KeyAction(keyCode);
}
public void KeyAction(String keyn){
if(keyn=="left"){
hn++;
}
System.out.println("*"+keyn+"* w:"+width+" h:"+height);
repaint();
}
};
}
/*public class Bill
implements KeyListener {
}*/