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); // 카드 뒷면
};
}