import com.docomostar.media.MediaImage;
import com.docomostar.media.MediaManager;
import com.docomostar.ui.Canvas;
import com.docomostar.ui.Display;
import com.docomostar.ui.Font;
import com.docomostar.ui.Graphics;
import com.docomostar.ui.Image;
import com.docomostar.ui.ImageMap;
public class MyCanvas extends Canvas {
Image images[]=new Image[9];//ImageMapに使うイメージデータ
private boolean ExitFlag=false;
private int[] mapdata;
private ImageMap map;
private String msg="OK";
private MyPoint p=new MyPoint(9,19);
String s[]=new String[9];//タイル説明
public MyCanvas() {
//地図データ
mapdata = new int[]{
4,4,4,4,4, 4,4,4,4,4, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //00
4,4,4,4,4, 4,4,4,4,4, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //01
4,4,4,4,4, 4,4,4,4,4, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //02
4,4,4,4,4, 4,4,4,4,4, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //03
4,4,4,4,4, 4,4,4,4,4, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //04
4,4,4,4,4, 4,4,4,4,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,2,2,2, 2,2,2,2,2, //05
4,4,4,4,4, 4,4,4,4,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,2,2,2, 2,2,2,2,2, //06
4,4,4,4,4, 4,4,4,4,1, 1,1,1,1,3, 1,1,1,1,1, 1,1,1,1,2, 2,2,2,2,2, //07
4,4,4,4,4, 4,4,4,4,1, 1,1,1,1,3, 1,1,1,1,1, 1,1,1,1,2, 2,2,2,2,2, //08
4,4,4,4,4, 4,4,4,4,1, 1,1,1,1,3, 1,1,1,1,1, 1,1,1,1,1, 2,2,2,2,2, //09
4,4,4,4,4, 4,4,4,1,1, 1,1,1,1,3, 1,1,1,1,1, 1,1,1,1,1, 2,2,2,2,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
4,4,4,4,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //26
4,4,4,4,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //27
4,4,4,4,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //28
4,4,4,4,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, //29
};
//各セルに描くイメージを取得
//イメージマップに使用するイメージの読み込み
images[0]=loadImage("flower.gif"); s[0]="花";
images[1]=loadImage("green.gif"); s[1]="芝";
images[2]=loadImage("tree.gif"); s[2]="森";
images[3]=loadImage("yellow.gif"); s[3]="道";
images[4]=loadImage("water.gif"); s[4]="湖";
images[5]=loadImage("house1.gif"); s[5]="家(小)";
images[6]=loadImage("house2a.gif"); s[6]="家(大)";
images[7]=loadImage("house2b.gif"); s[7]="家(大)";
images[8]=loadImage("yellow.gif"); s[8]="入口";
map=new ImageMap(48,48,30,30,mapdata,images);
map.setWindow(0, 0, 10, 10);
map.setWindowLocation(p.x, p.y);
this.setSoftLabel(SOFT_KEY_2, "おしまい");
this.setSoftLabel(SOFT_KEY_1, s[(mapdata[p.x+5+30*(p.y+5)])]);
this.setSoftLabel(SOFT_KEY_3, Integer.toString(p.x)+","+Integer.toString(p.y));
}
public void paint(Graphics g) {
g.lock();
g.drawImageMap(map,0,0);
g.setFont(Font.getFont(Font.STYLE_PLAIN, 12));
g.setColor(Graphics.getColorOfName(Graphics.RED));
g.drawString(Integer.toString(p.x)+","+Integer.toString(p.y)+","+s[(mapdata[p.x+5+30*(p.y+5)])], 0, 80);
g.drawRect(5*48, 5*48, 48, 48);
g.unlock(true);
}
public void processEvent(int type, int param){
if(type==Display.KEY_PRESSED_EVENT){
switch(param){
case Display.KEY_SOFT2 : ExitFlag=true;
case Display.KEY_LEFT : p.left() ;break;
case Display.KEY_RIGHT : p.right();break;
case Display.KEY_UP : p.up() ;break;
case Display.KEY_DOWN : p.down() ;break;
}
this.setSoftLabel(SOFT_KEY_1, s[(mapdata[p.x+5+30*(p.y+5)])]);
this.setSoftLabel(SOFT_KEY_3, Integer.toString(p.x)+","+Integer.toString(p.y));
map.setWindowLocation(p.x, p.y);
this.repaint();
}
}
public boolean isExit(){
return ExitFlag;
}
//
// ファイルで指定したイメージを読み取る
//
Image loadImage(String fileName){
MediaImage m = MediaManager.getImage("resource:///"+fileName);
try{
m.use();//使用前に有効化
}catch(Exception e){
}
return m.getImage();
}
}
|