SubKorea > CYBER JAVA GAME > ±â¾ï·ÂÅ×½ºÆ®2 > ¼Ò½ººÐ¼® #1, 2

// ÇÁ·Î±×·¥ÀÇ ½ÃÀ۽à Àüü Ä«µå¸¦ ªÀº ½Ã°£µ¿¾È º¸¿©ÁÖ´Â ÇÔ¼ö
 public void show_allcards()
 {
  for (i=0; i<50; i++)

    if (check[i]==2)
       PlayScrGC.drawImage(sin[stage[i]], (i%10)*40, (i/10)*40, this);

    else if (check[i]==0){

       PlayScrGC.setColor(Color.black);
       PlayScrGC.fillRect((i%10)*40, (i/10)*40, 40, 40);

    } else
       PlayScrGC.drawImage(sin[25], (i%10)*40, (i/10)*40, this); // Ä«µå µÞ¸é
 }

// ÇÁ·Î±×·¥ ÁøÇàÇÔ¼ö·Î ½ºÄÚ¾î¿Í °¢Á¾ Ä«µå üũ±â·ÏÀ̳ª
// ½Ã°£ µîÀ» È­¸é¿¡ Ãâ·ÂÇÏ°í ¹«ÇÑ·çÇÁ·Î ÇÁ·Î±×·¥ ÁøÇà
 public void gameplay()
 {
  if (show_on) {

     j = 0;

     show_score_board(); //  Ç÷¹À̾ ¾òÀº Á¡¼ö

     do {
        show_cards(); // °°Àº Á¾·ùÀÇ Ä«µå°¡ ¼±ÅõǸé È­¸é¿¡ Ä«µå
        repaint();

        auClip[0].play();

        delay(1000);

        show_uncards(); // ¼­·Î ¸ÂÃßÁö ¸øÇÑ °æ¿ì µ¤¿© ÀÖµµ·Ï ÇÔ
        repaint();

        delay(300);

        j++;

     } while (j<4);

     show_on = false;
   }

  show_allcards(); // ½ÃÀ۽à Àüü Ä«µå¸¦ ªÀº ½Ã°£µ¿¾È º¸¿©ÁÖ´Â ÇÔ¼ö

  if (start_checking){

     PlayScrGC.drawImage(sin[stage[card_x + card_y*10]], card_x*40, card_y*40, this);

     repaint();
     delay(1000);

     if (card_first==stage[card_x + card_y*10]) {

        check[card_x + card_y*10] = 0;

        for (i=0; i<50; i++) if (check[i]==2) check[i] = 0;

        score += 100;

        if (card_first==6 || card_first==24){

            if (card_first==24) rest += 5;
            show_score_board();
            show_on=true;

        };

       auClip[2].play();

       } else {

        rest--;
        auClip[3].play();

     }

     for (i=0; i<50; i++) if (check[i]==2) check[i] = 1;
     start_checking = false;

   };

   k = 0;

   for (i=0; i<50; i++)   k+=check[i];

   if (k==0) {

     show_on = true;

     show_allcards();
     show_stageclear();
     repaint();

     score += 1000;
     stg++;
     rest += 15;
     timer = 1500;

     for (i=0; i<50; i++){
        stage[i] = -1;
        check[i] = 1;
     };

     for (i=0; i<50; i++){

        k=0;

        do {
          j = (int)(Math.random()*50);

          if (stage[j]==-1){

             stage[j] = i/2;
             k = 1;

          };
        } while (k==0);
     };

   delay(2000);
   show_on=true;
   };

  timer--;

  if (timer==0 || rest==0){

    over_on = true;
    show_score_board();
    show_gameover();
    repaint();

    delay(3000);
    game_state=1;
  };

  show_score_board(); // Title Image Loading
 };

 public void run()
 {
  while (offThread!=null){

   delay(10);

   switch(game_state){

    case 0 :
     load_image(); // Image Loading
     break;

    case 1 :
     show_title_screen(); // Title Image Loading
     break;

    case 2 :
     prepare_stage(); // °¢Á¾ º¯¼öµéÀÇ ÃʱⰪ
     break;

    case 3 :
     gameplay();
     break;

    default :
     break;

   };
   repaint();
  };
 };

 public void paint(Graphics g)
 {
  if (game_state==0) // Image Loading
     g.drawImage(offScrImage, 0, 0, null);

  else
     g.drawImage(PlayScrImage, 0, 0, null);
 };
  
 public void update(Graphics g)
 {
  paint(g);
 };

 public void keyPressed(KeyEvent e){  };

 public void keyReleased(KeyEvent e){  };

 public void keyTyped(KeyEvent e){  }
//
// public void mouseReleased(MouseEvent e)
// {
//  card_x = (int)(e.getX()/40);    0~10+  width  = 450;
//  card_y = (int)(e.getY()/40);    0~5+   height = 260;
//
//  if (game_state==0) return;      case 0: load_image()
//
//  if (game_state==1) {
//     game_state=2;       // case 2: prepare_stage()
//     return;
//   };
//
//  if (show_on || over_on || start_checking) return;
//
//  if (card_count==0) {
//
//     if (check[card_x + card_y*10]!=1) return;
        // check[ 0 ~  9]
        // check[10 ~ 19]
         // .......
        // check[40 ~ 49]
//
//     check[card_x + card_y*10] = 2;            check[0 ~ 49] = 2
//     card_first = stage[card_x + card_y*10];   cardfirst=stage[0 ~ 49]
//
//     auClip[1].play();
//     card_count = 1;
//
//    } else if (card_count==1){
//
//     if (check[card_x + card_y*10]!=1) return;
//     card_count = 0;
//     start_checking = true;
//  }
// }
//
// public void mousePressed(MouseEvent e) {  }
//
// public void mouseClicked(MouseEvent e) {  }
//
// public void mouseEntered(MouseEvent e) {  }
//
// public void mouseExited(MouseEvent e) {  }
 
// for JDK 1.0
 public boolean mouseUp(Event e, int x, int y)
 {
   card_x = (int)(x/40);
   card_y = (int)(y/40);

   if (game_state==0) return true;     // Image Loading

   if (game_state==1) {    // Title Image Loading
      game_state=2;        // °¢Á¾ º¯¼öµéÀÇ ÃʱâÈ­
      return true;
   };

   if (show_on || over_on || start_checking) return true;

   if (card_count==0) {

     if (check[card_x + card_y*10]!=1) return true;
 
     check[card_x + card_y*10] = 2;
     card_first = stage[card_x + card_y*10];
 
     auClip[1].play();
     card_count = 1;
 
   } else if (card_count==1){
 
      if (check[card_x + card_y*10]!=1) return true;
      card_count = 0;
      start_checking = true;
   }
   return true;
 }

 public void start()
 {
  if (offThread == null)
  {
    offThread = new Thread(this);
    offThread.start();
  }
 }; // run()À¸·Î

 public void stop()
 {
  if (offThread != null && offThread.isAlive())  offThread=null;

  offThread = null;
  for (i=0; i<3; i++)  stopAudio(i);
 };

 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
 {
  if (infoflags==ALLBITS)
  {
    loaded = true;
    return false;

  } else return true;
 };

 public void startAudio(int num)
 {
  if (auClip[num] != null) auClip[num].play();
 };

 public void stopAudio(int num)
 {
  if (auClip[num] != null) auClip[num].stop();
 };

};