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

import java.awt.*;
import java.io.*;
import java.applet.*;
import java.util.*;
 
// public class zzak extends Applet implements Runnable, MouseListener, KeyListener
 
public class zzak extends Applet implements Runnable
{
 Image  sin[];       // À̹ÌÁö¸¦ ÀúÀåÇÏ´Â º¯¼ö
 Image  title_image; // ÃʱâÈ­¸é À̹ÌÁö

 int   stage[]; // ½ºÅ×ÀÌÁö¸¦ ¸¸µå´Â º¯¼ö
 int   check[]; // ¸¶¿ì½º·Î Ŭ¸¯ÀÌ µÇ¾úÀ» ¶§ °¢°¢ÀÇ ¾ÆÀÌÅÛ¿¡ ´ëÇÑ Ã¼Å©

 Font  fnt;

 int   width, height;

 long  score = 0;
 int   stg = 1;
 int   card_count=0;

 int   i, j, k, l;

 long  hi_score = 100;
 int   rest = 20;
 int   timer = 2400;

 int   card_x, card_y, card_first; // Ä«µå À§Ä¡¿Í Ä«µå ÃʱâÈ­¸¦ À§ÇÑ º¯¼ö

 Thread  offThread;
 
 AudioClip auClip[];  // voice1 : º¸¿©ÁÖ±â, voice2 : ¼±ÅÃ, voice3 :  ¸ÂÀ½, voice4 : Ʋ¸²

 int  game_state=0;   // ÇöÀç °ÔÀÓ»óŸ¦ º¸°üÇÏ´Â °ªÀ¸·Î 0=Image Loading
 
 Image      offScrImage; // ¿ÀÇÁ È­¸é¿¡ À̹ÌÁö 󸮸¦ À§ÇÑ º¯¼ö
 Graphics   offScrGC;    // ¿ÀÇÁ È­¸éÀÇ Å©±â

 Image      PlayScrImage; // ½ÇÁ¦ Ç÷¹À̰¡ µÇ´Â À̹ÌÁö ó¸®
 Graphics   PlayScrGC;    // ½ÇÁ¦ È­¸éÀÇ Å©±â

 boolean start_checking = false;
 boolean show_on = true;
 boolean over_on = false;
 boolean loaded=false;

 public void init()
 {
  setBackground(Color.black);
  sin = new Image[26];  // 25°³ÀÇ Ç÷¹ÀÌ Ä«µå(1~25)¿Í µÞ¸é(26)

  stage = new int[50];
  check = new int[50];

  auClip = new AudioClip[4];

  width  = 450;
  height = 260;
 
//  addKeyListener(this);
//  addMouseListener(this);

  for (i=1; i<=4; i++)
    auClip[i-1] = getAudioClip(getCodeBase(),"au/voice"+i+".au");

  // Creates an off-screen drawable image to be used for double buffering. (Component)
  offScrImage = createImage(width, height);
 
  // Creates a graphics context for drawing to an off-screen image.
  offScrGC    = offScrImage.getGraphics();

  offScrGC.setColor(Color.black);
  offScrGC.fillRect(0, 0, width, height);
 
  PlayScrImage = createImage(width, height);
  PlayScrGC    = PlayScrImage.getGraphics();

  PlayScrGC.setColor(Color.black);
  PlayScrGC.fillRect(0, 0, width, height);
 } // start()·Î

 public void delay(int num)
 {
  try {

    offThread.sleep(num);

  } catch(InterruptedException e){};
 }

// À̹ÌÁö¸¦ ÀÐ¾î °¡»ó¸Þ¸ð¸®¿¡ Ãâ·Â
 public void load_image()
 {
  // Creates a new font with the specified name, style and point size.
  fnt = new Font("TimesRoman", 1, 38); // ¼öÁ¤
  offScrGC.setFont(fnt);

  offScrGC.setColor(Color.red);
  offScrGC.drawString("Image Loading...", 50, 90);

  offScrGC.setColor(Color.blue);
  offScrGC.fillRect(50, 110, 272, 40); // (int x, int y, int width, int height)

  offScrGC.setColor(Color.white);
  offScrGC.drawRect(50, 110, 272, 40); // Draws the outline of the specified rectangle.

  fnt = new Font("TimesRoman", 1, 20);
  offScrGC.setFont(fnt);

  offScrGC.drawString("Â¥¹è±âÀ¯¸Ó¿Í ÇÔ²²...", 100, 240);

  k=1;
  title_image = getImage(getCodeBase(), "images/sin.gif");
 
  for (i=1; i<27; i++)
    sin[i-1]=getImage(getCodeBase(), "images/g" + i + ".gif");
    // sin[0~24]=Ä«µå,  sin[25]=g26.gif(µÞ¸é)

  loaded=false;

  PlayScrGC.drawImage(title_image, 0, 0, this);

  while(!loaded) { repaint(); };

  offScrGC.setColor(Color.green);
  offScrGC.fillRect(51, 111, k*10, 39); // k=1 *10 À¸·Î ÁøÇàÁß Ç¥½Ã

  k++;

  for (i=1; i<27; i++){

     loaded=false;
     PlayScrGC.drawImage(sin[i-1], 0, 0, this);

     while(!loaded){ repaint(); };

     offScrGC.fillRect(51, 111, k*10, 39); // k=2~27 * 10 À¸·Î ÁøÇàÁß Ç¥½Ã
 
     k++;
  };

  PlayScrGC.setColor(Color.black);
  PlayScrGC.fillRect(0, 0, width, height);

  game_state=1; // run()ÀÇ  case 1.À¸·Î

 };

// °ÔÀÓÀ̹ÌÁö µ¥ÀÌÅ͸¦ ÀÐ°í ³­ ÈÄ¿¡ °ÔÀÓÀÇ Å¸ÀÌÆ² Ãâ·Â
 public void show_title_screen()
 {
   PlayScrGC.drawImage(title_image, 0, 0, this);
 }; // ŸÀÌÆ² Ãâ·ÂÈÄ ¸¶¿ì½ºÀÇ Å¬¸¯¿¡ µû¶ó ´ÙÀ½ Â÷·Ê¸¦ ÁøÇà

// ÇÁ·Î±×·¥ ÁøÇàÀ» À§ÇØ »ç¿ëÇÒ °¢Á¾ º¯¼öµéÀÇ ÃʱⰪ
// ÁøÇà»óÅÂ, Á¾·á¿©ºÎ, ½ºÄÚ¾î, Ä«µåÁ¡¼ö µî
 public void prepare_stage()
 {
  show_on=true;
  over_on=false;

  score = 0;
  stg = 1;
  card_count=0;
  rest = 30;
  timer = 1500;

  for (i=0; i<50; i++){
      stage[i] = -1; // stage[0~49]= -1
      check[i] = 1;  // check[0~49]=  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);
   };

  game_state=3;

 }; // run()ÀÇ  case 3.·Î

// ÁøÇà½Ã Ç÷¹À̾ ¾òÀº Á¡¼ö¸¦ üũÇÏ¿© È­¸é¿¡ Ãâ·Â
 public void show_score_board()
 {
  PlayScrGC.setColor(Color.blue);
  PlayScrGC.fillRect(0, 200, width, 60);

  if (hi_score < score) hi_score = score;

  fnt = new Font("TimesRaman", 1, 12);
  PlayScrGC.setFont(fnt);

  PlayScrGC.setColor(Color.white);
  PlayScrGC.drawString("SCORE : "+score, 10, 220);
  PlayScrGC.drawString("HI-SCORE : "+hi_score, 210, 220);

  PlayScrGC.drawString("STAGE : "+stg, 10, 240);
  PlayScrGC.drawString("REST : "+rest, 210, 240);

  PlayScrGC.setColor(Color.yellow);
  PlayScrGC.fillRect(10, 252,(int)(timer/5), 5); // ³²Àº ½Ã°£ Ç¥½Ã¸·´ë timer=1500
 };

// ÇÁ·Î±×·¥ Á¾·á½Ã³ª »õ·Ó°Ô ½ÃÀÛÇÒ ¶§ È­¸éÀ» ±ú²ýÀÌ Áö¿öÁÖ´Â ÇÔ¼ö
 public void show_stageclear()
 {
  fnt = new Font("Courier", 1, 40);
  PlayScrGC.setFont(fnt);

  PlayScrGC.setColor(Color.red);
  PlayScrGC.drawString("STAGE CLEAR", 40, 120);

  PlayScrGC.setColor(Color.yellow);
  PlayScrGC.drawString("STAGE CLEAR", 42, 120);

  fnt = new Font("TimesRoman", 1, 12);
  PlayScrGC.setFont(fnt);
 }

// ½Ã°£³» ¸ðµç Ä«µå¸¦ ¸øÃ£¾ÒÀ» ¶§ ÇÁ·Î±×·¥ÀÌ ³¡³µ´Ù´Â ¸Þ½ÃÁö¸¦ È­¸é¿¡ Ãâ·Â
 public void show_gameover()
 {
  fnt = new Font("Courier", 1, 40);
  PlayScrGC.setFont(fnt);

  PlayScrGC.setColor(Color.red);
  PlayScrGC.drawString("GAME OVER",70,120);

  PlayScrGC.setColor(Color.yellow);
  PlayScrGC.drawString("GAME OVER",72,120);

  fnt = new Font("TimesRoman", 1, 12);
  PlayScrGC.setFont(fnt);
 }

// ¸¶¿ì½º·Î Ŭ¸¯ÇÑ Ä«µå¸¦ Ã¼Å©ÇØ¼­
// °°Àº Á¾·ùÀÇ Ä«µå°¡ ¼±ÅõǸé È­¸é¿¡ Ä«µå¸¦ º¸¿©ÁÜ
 public void show_cards()
 {
  for (i=0; i<50; i++) {

    if (check[i]==0) {

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

    } else
       PlayScrGC.drawImage(sin[stage[i]], (i%10)*40, (i/10)*40, this);
  };
 }

// Ŭ¸¯µÈ Ä«µå 2ÀåÀÌ ¼­·Î ¸ÂÃßÁö ¸øÇÑ °æ¿ì
// ´Ù½Ã ¿ø·¡´ë·Î µ¤¿© ÀÖµµ·Ï ÇÔ
 public void show_uncards()
 {
  for (i=0; i<50; i++){

   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); // Ä«µå µÞ¸é
  };
 }