상세 컨텐츠

본문 제목

카드게임

청강컴정/소프트웨어공학

by luckey 2009. 5. 4. 15:07

본문

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

public class CardGameEx extends Jlet
{
 protected void startApp(String args[])
 {
  Display dis = Display.getDefaultDisplay();
  MainCard card = new MainCard();
  dis.pushCard(card);
 }
 protected void destroyApp(boolean b){}
}

class MainCard extends Card
{
 Font font;
 Image CardImg1, CardImg2;
 int x = 0, y = 0, w = getWidth(), h = getHeight();
 int card1x = 10, card1y = 20;
 int card2x = 60, card2y = 20;
 int cardW = 40, cardH = 60;

 int cardNum1, cardNum2;

 public void paint(Graphics g)
 {
  Random rnd = new Random();

  cardNum1 = Math.abs(rnd.nextInt()) % 13 + 2;
  while(true)
  {
   cardNum2 = Math.abs(rnd.nextInt()) % 13 + 2;
   if(cardNum1 != cardNum2)
   {
    break;
   }
  }

  g.setColor(255,255,255);
  g.fillRect(x, y, w, h);

  g.setColor(0,0,0);
  g.drawRect(card1x, card1y, cardW, cardH);
  g.drawRect(card2x, card2y, cardW, cardH);

  font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
  g.setFont(font);
  g.drawString("PC", card1x + 20, card1y - 15, g.HCENTER);
  g.drawString("Player", card2x + 20, card2y - 15, g.HCENTER);

  try
  {
    CardImg1 = Image.createImage("/CardGame/" + cardNum1 + ".png");
    CardImg2 = Image.createImage("/CardGame/" + cardNum2 + ".png");
  }
  catch (Exception e)
  {
  }

  g.drawImage(CardImg1, card1x, card1y, g.LEFT | g.TOP);
  g.drawImage(CardImg2, card2x, card2y, g.LEFT | g.TOP);

//  font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD | Font.STYLE_UNDERLINED, Font.SIZE_LARGE);
//  g.setFont(font);
//  g.drawString("" + cardNum1, card1x + 20, card1y + 15, g.HCENTER);
//  g.drawString("" + cardNum2, card2x + 20, card2y + 15, g.HCENTER);
 }

 public boolean keyNotify(int type, int keyCode)
 {
  if(type == EventQueue.KEY_PRESSED && keyCode == EventQueue.KEY_NUM1)
  {
   repaint();
  }
  return true;
 }
}

관련글 더보기

댓글 영역