import java.io.IOException; import javax.microedition.lcdui.*; public class GraphClass extends Canvas implements Runnable { private int DeloY; private int minDeloY; private int maxDeloY; private int time1; private int time2; private int futMonth; private int futDay; private int futYear; private int futHour; private int futMinute; private int Month; private int Day; private int Year; private int Hour; private int Minute; private int minutecycle; private int pastDay; private int pastYear; private int pastHour; private int pastMinute; private int fuel; private String timecycle; private String daycl; private int delox; private int delocycle; private int speed; private int tpx; private int cycspeed; private int key; private int key2; public int keyCode; private String futMonthStr; private String MonthStr; private String pastMonthStr; private String fuelstring; private String future; private String present; private String past; private Image timeImg; private Image timeImg2; private Image delorean; private Font theFont; Graphics G; Image I; private boolean clrFlag = true; /** * constructor */ public GraphClass () { setFullScreenMode(true); DeloY = 190; minDeloY = 170; maxDeloY = 210; time1 = 0; time2 = 480; futMonth = 12; futDay = 21; futYear = 1885; futHour = 00; futMinute = 00; Month = 12; Day = 26; Year = 1985; Hour = 14; Minute = 32; minutecycle = 0; pastDay = 26; pastYear = 1955; pastHour = 01; pastMinute = 35; fuel = 0; timecycle = "fut"; daycl = "day"; delox = 1; delocycle = 1; speed = 1; tpx = 0; futMonthStr = "DEC"; MonthStr = "DEC"; pastMonthStr = "OCT"; theFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); try { I = Image.createImage(getWidth(),getHeight()); G = I.getGraphics(); timeImg = Image.createImage("/now_fut_day.png"); timeImg2 = Image.createImage("/now_fut_day.png"); delorean = Image.createImage("/delorean"+String.valueOf(delox)+".png"); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } /** * paint */ public void paint(Graphics g) { if (key==RIGHT){ speed++; } else if (key==LEFT) { speed-=10; } else { speed-=2; } if (key2==KEY_POUND && fuel==0) { fuel=1; } if (key==UP && DeloY>=minDeloY) { speed = 2; DeloY--; } else if (key==DOWN && DeloY<=maxDeloY) { speed = 2; DeloY++; } if (speed>89) { speed = 89; } if (speed<1) { speed = 1; } if (speed == 89 && fuel==1) { tpx++; } else { tpx = 0; } if (speed == 89 && tpx == 62) { pastMonthStr = MonthStr; pastDay = Day; pastYear = Year; pastHour = Hour; pastMinute = Minute; Month = futMonth; Day = futDay; Year = futYear; Hour = futHour; Minute = futMinute; if (Hour>=7 && Hour <=21) { daycl = "day"; futHour = 22; } else { daycl = "night"; futHour = 11; } if (Year==1985) { timecycle = "fut"; futYear = 1955; } else if (Year==1955) { timecycle = "20"; futYear = 1885; } else if (Year==1885) { timecycle = "w"; futYear = 1985; } try { timeImg = Image.createImage("/now_"+timecycle+"_"+daycl+".png"); timeImg2 = Image.createImage("/now_"+timecycle+"_"+daycl+".png"); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } fuel=0; tpx=0; } if (speed<22) { cycspeed = 4; } if (speed>21 && speed<42) { cycspeed = 3; } if (speed>41 && speed<62) { cycspeed = 2; } if (speed>61) { cycspeed = 1; } if (speed>1) { delocycle++; } if (speed>1 && delocycle >= cycspeed) { delox++; delocycle = 1; } if (delox == 5) { delox = 1; } if (speed<89) { try { delorean = Image.createImage("/delorean"+String.valueOf(delox)+".png"); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } if (speed == 89 && tpx<11) { try { delorean = Image.createImage("/delorean_80_"+String.valueOf(delox)+".png"); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } if (speed == 89 && tpx>10 && tpx<19 && fuel == 1) { try { delorean = Image.createImage("/delorean_tm_"+String.valueOf(delox)+".png"); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } if (speed == 89 && tpx>18 && tpx<40 && fuel == 1) { try { delorean = Image.createImage("/delorean_tm1_"+String.valueOf(delox)+".png"); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } if (speed == 89 && tpx>39 && tpx<63 && fuel == 1) { try { delorean = Image.createImage("/delorean_tm2_"+String.valueOf(delox)+".png"); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } if (fuel == 1) { fuelstring = "F"; } else { fuelstring = "E(#)"; } if (speed>0) { time1-=(speed/2); time2-=(speed/2); } if (minutecycle == 20) { Minute++; minutecycle = 1; } else { minutecycle++; } if (Minute == 60) { Hour++; Minute = 0; } if (Hour == 24) { Month++; Hour = 0; } if (Month == 13) { Year+=1; Month = 1; } if (Year == 10000) { Year = 0000; } if (Month == 1) { MonthStr = "JAN"; } if (Month == 2) { MonthStr = "FEB"; } if (Month == 3) { MonthStr = "MAR"; } if (Month == 4) { MonthStr = "APR"; } if (Month == 5) { MonthStr = "MAY"; } if (Month == 6) { MonthStr = "JUN"; } if (Month == 7) { MonthStr = "JUL"; } if (Month == 8) { MonthStr = "AUG"; } if (Month == 9) { MonthStr = "SEP"; } if (Month == 10) { MonthStr = "OCT"; } if (Month == 11) { MonthStr = "NOV"; } if (Month == 12) { MonthStr = "DEC"; } if (futMonth == 1) { futMonthStr = "JAN"; } if (futMonth == 2) { futMonthStr = "FEB"; } if (futMonth == 3) { futMonthStr = "MAR"; } if (futMonth == 4) { futMonthStr = "APR"; } if (futMonth == 5) { futMonthStr = "MAY"; } if (futMonth == 6) { futMonthStr = "JUN"; } if (futMonth == 7) { futMonthStr = "JUL"; } if (futMonth == 8) { futMonthStr = "AUG"; } if (futMonth == 9) { futMonthStr = "SEP"; } if (futMonth == 10) { futMonthStr = "OCT"; } if (futMonth == 11) { futMonthStr = "NOV"; } if (futMonth == 12) { futMonthStr = "DEC"; } if (time1<-241) { time2=480+time1; } if (time2<-241) { time1 = 480+time2; } drawPaint(G); g.drawImage(I, 0, 0, 0); } private void drawPaint(Graphics g) { try { G.setColor(0xffffff); G.fillRect(0, 0, getWidth(), getHeight()); G.drawString(String.valueOf(speed-1),3,getHeight()-60,0); G.drawString(fuelstring,3,getHeight()-20,0); G.drawString(future,40,getHeight()-60,0); G.setColor(0x00ff00); G.drawString(present,40,getHeight()-40,0); G.drawImage(timeImg,time1,0,Graphics.TOP|Graphics.LEFT); G.drawImage(timeImg2,time2,0,Graphics.TOP|Graphics.LEFT); G.drawImage(delorean,3,DeloY,Graphics.TOP|Graphics.LEFT); future = ""+futMonthStr+" "+futDay+" "+futYear+" "+futHour+":"+futMinute; present = ""+MonthStr+" "+Day+" "+Year+" "+Hour+":"+Minute; past = ""+pastMonthStr+" "+pastDay+" "+pastYear+" "+pastHour+":"+pastMinute; G.setColor(0xff0000); G.setFont(theFont); G.drawString(String.valueOf(speed-1),3,getHeight()-60,0); G.drawString(fuelstring,3,getHeight()-20,0); G.drawString(future,40,getHeight()-60,0); G.setColor(0x00ff00); G.drawString(present,40,getHeight()-40,0); G.setColor(0xffff00); G.drawString(past,40,getHeight()-20,0); } catch (Exception e) { } } public void run() { while (true) { try { repaint(); // Sleep to prevent starvation try { Thread.sleep(25); } catch (Exception e) { } } catch (Exception e) { e.printStackTrace(); } } } /** * Called when a key is pressed. */ protected void keyPressed(int keyCode) { key=getGameAction(keyCode); key2=keyCode; } protected void keyRepeated(int keyCode) { key=getGameAction(keyCode); key2=keyCode; } protected void keyReleased(int keyCode) { key=keyCode=0; key2=0; } }