[WIPI]0929 - 소스






Project1.java

import org.kwis.msp.handset.BackLight;
import org.kwis.msp.lcdui.*;

public class Project1 extends Jlet {
 
 MainCard mc = new MainCard(); // MainCard 의 객채생성 >> mc
 

 protected void destroyApp(boolean arg0) throws JletStateChangeException {
  // TODO Auto-generated method stub

 }

 protected void startApp(String[] arg0) {
  // TODO Auto-generated method stub
  BackLight.alwaysOn(); // BackLight 항상 켬
  Display dis=Display.getDefaultDisplay(); // Display객체로부터 기본 display가저와서 dis 만듬
  dis.pushCard(mc); // mc를 디스플레이 시킴
  }

}




MainCard.java

import org.kwis.msp.lcdui.*;
import java.io.*;

public class MainCard extends Card implements Runnable
{
 Thread mThread = new Thread(this);
 Display dis = Display.getDefaultDisplay();

 Graphics g;

 public final byte MAINSTATE_MENU = 0;
 public final byte MAINSTATE_GAME = 1;
 public final byte MENU_STARTGAME = 0;
 public final byte MENU_CONTINUEGAME = 1;
 public final byte MENU_EXPGAME = 2;
 public final byte MENU_OPTION = 3;
 public final byte MENU_EXIT = 4;
 public final byte MENU_NUM = 5;
 public final byte LEFT = 0;
 public final byte RIGHT = 1;
 private final byte GROUND_HEIGHT = 20;
 private final byte HERO_WIDTH = 21;
 private final byte HERO_HEIGHT = 26;

 int width, height;
 byte mainState;
 int menuCursor;

 private int heroX;
 private int heroY;
 private int heroDirection;
 private int heroSpeed;
 private int heroFrame;

 Image imgHero;

 public final String MENU_TEXT[] = {
  "게임시작",
  "이어하기",
  "게임설명",
  "환경설정",
  "게임종료"
 };

 public MainCard()
 {
  width = getWidth();
  height = getHeight();
  System.out.println("width->"+width+" height->"+height);

  setMainState(MAINSTATE_MENU);
 
  mThread.start();
 }
 public void run()
 {
  while(true)
  {
   repaint();
   try{
    Thread.sleep(100);
   }
   catch (InterruptedException ex){}
  }
 }
 public void paint(Graphics g){
  this.g = g;
  switch(mainState)
  {
   case MAINSTATE_MENU:
    showMenu();    
    break;
   case MAINSTATE_GAME:
    showGame();
    break;
  }
 }

 public void showMenu()
 {
  String text;

  g.setColor(255, 255, 255);
  g.fillRect(0, 0, width, height);
  g.setColor(0, 0, 0);
  for(int i=0; i<MENU_NUM; i++)
  {
   if(i==menuCursor)
    text = "-> "+MENU_TEXT[i];
   else
    text = MENU_TEXT[i];
   g.drawString(text, width/2, 20+14*i, Graphics.HCENTER|Graphics.TOP);
  }
 }

 public void showGame()
 {
  g.setColor(0, 0, 0);
  g.fillRect(0, 0, width, height);
  g.setColor(255, 255, 255);
  g.fillRect(0, height-GROUND_HEIGHT, width, GROUND_HEIGHT);

  drawHero();
 }

 public void drawHero()
 {
  g.drawImage(imgHero, heroX-HERO_WIDTH/2, heroY-HERO_HEIGHT/2, 0);
 }

 public boolean keyNotify(int type, int key){
  if(type == EventQueue.KEY_PRESSED){
   switch(mainState)
   {
    case MAINSTATE_MENU:
     keyMenu(key);    
     break;
    case MAINSTATE_GAME:
     keyGame(key);
     break;
   }
  }
  repaint();
  return true;
 }

 public int getGameAction(int key)
 {
  if((key >= EventQueue.KEY_NUM0 && key < EventQueue.KEY_NUM9) || key == EventQueue.KEY_POUND || key == EventQueue.KEY_STAR)
   return key;
  else
   return dis.getGameAction(key);
 }

 public void keyMenu(int key)
 {
  switch(getGameAction(key))
  {
   case EventQueue.UP:
   case EventQueue.LEFT:
    menuCursor--;
    if(menuCursor < 0)
     menuCursor = MENU_NUM-1;
    break;

   case EventQueue.DOWN:
   case EventQueue.RIGHT:
    menuCursor++;
    if(menuCursor == MENU_NUM)
     menuCursor = 0;
    break;

   case EventQueue.FIRE:
    switch(menuCursor)
    {
     case MENU_STARTGAME:
      setMainState(MAINSTATE_GAME);
      loadGame();
      break;
     case MENU_CONTINUEGAME:
      break;
     case MENU_EXPGAME:
      break;
     case MENU_OPTION:
      break;
     case MENU_EXIT:
      break;
    }
    break;
  }
 }

 public void keyGame(int key)
 {
  switch(getGameAction(key))
  {
   case EventQueue.UP:
   case EventQueue.FIRE:
    break;
   case EventQueue.DOWN:
    break;
   case EventQueue.LEFT:
    break;
   case EventQueue.RIGHT:
    break;
  }
 }

 public void setMainState(byte state)
 {
  mainState = state;
  switch(mainState)
  {
   case MAINSTATE_MENU:    
    initMenu();    
    break;
   case MAINSTATE_GAME:
    initGame();
    break;
  }
 }

 public void loadGame()
 {
  try
  {
   imgHero = Image.createImage("/img/hero1.png");
  }
  catch(IOException e)
  {}
 }
 public void unloadGame()
 {
  imgHero = null;
  System.gc();
 }

 public void initMenu()
 {
  menuCursor = 0;
 }

 public void initGame()
 {
  heroX = width/2;
  heroY = height - GROUND_HEIGHT - HERO_HEIGHT/2;
  heroDirection = RIGHT;
  heroSpeed = 0;
  heroFrame = 0;
 }
};

Posted by rCan

2008/09/29 11:40 2008/09/29 11:40
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/572

Trackback URL : http://rcan.net/trackback/572

Leave a comment
« Previous : 1 : ... 29 : 30 : 31 : 32 : 33 : 34 : 35 : 36 : 37 : ... 439 : Next »

블로그 이미지

- rCan

Calendar

«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Notices

  1. About Me

Site Stats

Total hits:
113574
Today:
5
Yesterday:
43