📄 titlecanvas.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package demo;import java.io.IOException;import java.util.Timer;import java.util.TimerTask;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.game.GameCanvas;import javax.microedition.lcdui.game.LayerManager;import javax.microedition.lcdui.game.Sprite;import javax.microedition.lcdui.game.TiledLayer;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;/** * * @author Slawek */public class TitleCanvas extends GameCanvas implements Runnable { private int viewPortX = 0; private int viewPortY = 0; private LayerManager lm; private GameDesign gameDesign; private Timer timer; private Sprite spriteTitleMario; private TiledLayer tlTitleBorder; private TiledLayer tlTitleground; //Wybor uzytkownika //1-rozpoczecie gry //2-statystyki //3-wyjscie private int choose = 1; //Czy zostala wybrana jakas opcja private boolean done = false; //Czy koniec programu private boolean finish=false; public TitleCanvas() { super(true); try { this.setFullScreenMode(true); this.init(); } catch (IOException ex) { ex.printStackTrace(); } } private void init() throws IOException { this.timer = new Timer(); this.gameDesign = new GameDesign(); this.spriteTitleMario = gameDesign.getTitleMario(); this.tlTitleBorder = this.gameDesign.getTitleBorder(); this.tlTitleground = this.gameDesign.getTitleground(); this.lm = new LayerManager(); gameDesign.updateLayerManagerForTitle(lm); } /** * The main game loop that checks for user input and repaints canvas. */ public void run() { Graphics g = getGraphics(); while(!this.done){ //check for user input int keyState = getKeyStates(); if ((keyState & UP_PRESSED) != 0) { if ( choose == 2 || choose == 3 ){ choose = choose - 1; } System.out.println(choose); continue; }else if ((keyState & DOWN_PRESSED) != 0) { if (choose == 1 || choose == 2 ){ choose=choose + 1; } System.out.println(choose); continue; }else if ((keyState & FIRE_PRESSED) != 0) { this.stop(true); /*switch(choose){ case 1: //Start gry System.out.println("Wcisniete klawisz startu"); break; case 2: //Wyswietlenie wynikow System.out.println("Wcisnieto klawisz wynikow"); break; case 3: //Koniec gry System.out.println("Wcisniete klawisz konca"); this.stop(true); return; }*/ continue; } //Ustawienie Animacji dla Mario, Reka do gory, w dol, albo na srodku switch (choose){ case 1: System.out.println(choose+"Hand up"); this.spriteTitleMario.setFrameSequence(gameDesign.TitleMarioUp); break; case 2: System.out.println(choose+"Hand middle"); this.spriteTitleMario.setFrameSequence(gameDesign.TitleMarioMiddle); break; case 3: System.out.println(choose+"Hand down"); this.spriteTitleMario.setFrameSequence(gameDesign.TitleMarioDown); break; } this.lm.paint(g, 0, 0); flushGraphics(0, 0, this.getWidth(), this.getHeight()); try { Thread.sleep(500); } catch (InterruptedException ex) { ex.printStackTrace(); } } switch(choose){ case 1: //Start gry System.out.println("Wcisniete klawisz startu"); break; case 2: //Wyswietlenie wynikow System.out.println("Wcisnieto klawisz wynikow"); break; case 3: //Koniec gry System.out.println("Wcisniete klawisz konca"); this.finish(true); return; } } /** * Zatrzymuje glowna petle programu */ public void stop(boolean state) { this.done = state; } public boolean stopped(){ return done; } public void finish(boolean state){ this.finish=true; } public boolean finished(){ return finish; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -