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

 

 
 /**
  *  public void run()
  *  Handle the main thread of this applet.
  *
  */
    public void run() { } // À§·Î
 
 /**
  *  public boolean action(Event evt, Object arg)
  *  Handle the differents actions.
  *  @param Event evt the event to handle
  *  @param Object arg the argument
  */
    public boolean action(Event evt, Object arg) {

        return true;
 
    } // À§·Î
 
 /**
  *  public boolean mouseDown(Event evt, int x, int y)
  *  Handle the mouse clicks.
  *  @param Event evt the event to handle
  *  @param int x,y the coordinates of the mouse click
  */
    public boolean mouseDown(Event evt, int x, int y) {

        // Default value
        int i = -1;
        int j = -1;
 
        // FIND i
         if(x > H_GAP && x < H_GAP+CARD_WIDTH)
            i = 0;

        else if(x > 2*H_GAP+CARD_WIDTH && x < 2*H_GAP+2*CARD_WIDTH)
            i = 1;

        else if(x > 3*H_GAP+2*CARD_WIDTH && x < 3*H_GAP+3*CARD_WIDTH)
            i = 2;

        else if(x > 4*H_GAP+3*CARD_WIDTH && x < 4*H_GAP+4*CARD_WIDTH)
            i = 3;

        else if(x > 5*H_GAP+4*CARD_WIDTH && x < 5*H_GAP+5*CARD_WIDTH)
            i = 4;

        else if(x > 6*H_GAP+5*CARD_WIDTH && x < 6*H_GAP+6*CARD_WIDTH)
            i = 5;

        else if(x > 7*H_GAP+6*CARD_WIDTH && x < 7*H_GAP+7*CARD_WIDTH)
            i = 6;

        else if(x > 8*H_GAP+5*CARD_WIDTH && x < 8*H_GAP+8*CARD_WIDTH)
            i = 7;
 
        // FIND j
 
        if(y > 60+V_GAP && y < 60+V_GAP+CARD_HEIGHT)
            j = 0;

        else if(y > 60+2*V_GAP+CARD_HEIGHT && y < 60+2*V_GAP+2*CARD_HEIGHT)
            j = 1;

        else if(y > 60+3*V_GAP+2*CARD_HEIGHT && y < 60+3*V_GAP+3*CARD_HEIGHT)
            j = 2;

        else if(y > 60+4*V_GAP+3*CARD_HEIGHT && y < 60+4*V_GAP+4*CARD_HEIGHT)
            j = 3;

        else if(y > 60+5*V_GAP+4*CARD_HEIGHT && y < 60+5*V_GAP+5*CARD_HEIGHT)
            j = 4;
 
        if(!(i == -1 || j == -1)) {

            if(Board[j][i].getStatus() != GONE)
                   Proceed(Board[j][i]);
 
            repaint();
        }
 
        return true;
 
    } // À§·Î
 
 /**
  *  public void Proceed(Card card)
  *  Proceed the action to take.
  *
  */
    public void Proceed(Card card) {
 
        if(pick == 0) {

            if(turn == PLAYER1)
                setMessage(message2);

            else
                setMessage(message4);
 
             for(int i = 0; i < ROW; i++) {     //HIDE ALL CARD
 
                for(int j = 0; j < COLUMN; j++) {

                    if(Board[i][j].getStatus() == SHOW)
                        Board[i][j].setStatus(HIDE);
                }
             }

            card.setStatus(SHOW);
            lastCard = card;

            pick++;

        } else if(pick == 1) {

            if(card != lastCard) {

                if(card.getID() == lastCard.getID() && card != lastCard) {

                    if(turn == PLAYER1)
                        setScore(PLAYER1);

                    else
                        setScore(PLAYER2);
 
                    yahoo.play();
 
                    card.setStatus(GONE);
                    lastCard.setStatus(GONE);
 
                    matchCard++;
 
                    if(matchCard == CARDS) {

                        if(Score1.intValue() == Score2.intValue())
                            setMessage("TIE GAME ! " + message1);

                        else if(Score1.intValue() > Score2.intValue())
                            setMessage(message5 + " " + message1);

                        else
                            setMessage(message6 + " " + message1);

                        initBoard();
                    }

                } else {

                    card.setStatus(SHOW);
                    lastCard.setStatus(SHOW);

                    lastCard2 = card;
                    beep.play();

                    changeTurn();
                }

                pick = 0;
            }
        }
    } // À§·Î
 
 /**
  *  public void update(Graphics g)
  *  To avoid flickering.
  *
  */
    public void update(Graphics g) {

        paint(g);
 
    } // À§·Î

 /**
  *  public void paint(Graphics g)
  *  To paint
  *  @param Graphics g the graphic.
  */
 
    public void paint(Graphics g) {

        Image offScreenImage = createImage(WIDTH, HEIGHT); // 500 x 390
        Graphics offSG = offScreenImage.getGraphics();
 
        offSG.setColor(BGCOLOR);
        offSG.fillRect(0, 0, WIDTH, HEIGHT); // (0, 0) x (500, 390)

        offSG.setColor(Color.yellow);

        offSG.drawImage(Mnemonic, (WIDTH-Mnemonic.getWidth(this))/2, 5, this); // ŸÀÌƲ

        int bottom = 60 + ROW*50 + (ROW+1)*V_GAP + 10;

        offSG.drawString(message, H_GAP, 50);

        offSG.drawString("¼Ò¿ä½Ã°£: ", 260, 50);
        offSG.drawString(Time.toString(), 260+50, 50);

        offSG.drawString("Ãִܽð£: ", 380, 50);
        offSG.drawString(Mintime.toString(), 380+50, 50);

        offSG.drawString("PLAYER 1: ", H_GAP, bottom);
        offSG.drawString(Score1.toString(), H_GAP+80, bottom);

        offSG.drawString("PLAYER 2: ", 200, bottom);
        offSG.drawString(Score2.toString(), 200+80, bottom);
 
        offSG.drawString(message7, 360, bottom);
 
        for(int i = 0; i < ROW; i++) {

            for(int j = 0; j < COLUMN; j++) {

                    if(Board[i][j].getStatus() == HIDE)

                        offSG.drawImage(Hide_Card,
                              ((j+1)*H_GAP + j*CARD_WIDTH),
                               (60+(i+1)*V_GAP + i*CARD_HEIGHT), this);

                    else if(Board[i][j].getStatus() == SHOW)

                        offSG.drawImage(Board[i][j].getImage(),
                              ((j+1)*H_GAP + j*CARD_WIDTH),
                               (60+(i+1)*V_GAP + i*CARD_HEIGHT), this);

                    else {

                        offSG.setColor(BGCOLOR);

                        offSG.fillRect(((j+1)*H_GAP+j*CARD_WIDTH),
                             (60+(i+1)*V_GAP+i*CARD_HEIGHT),
                             CARD_WIDTH, CARD_HEIGHT);
                    }
                }
        }
        g.drawImage(offScreenImage, 0, 0, WIDTH, HEIGHT, this);
 
    } // À§·Î

 /**
  *  public void changeTurn()
  *  Change to next player turn's.
  *
  */
    public void changeTurn() {

        if(turn == PLAYER1) {

            turn = PLAYER2;
            setMessage(message3);

        } else {

            turn = PLAYER1;
            setMessage(message1);
        }
    } // À§·Î

 /**
  *  public void setMessage(String s)
  *  Sets the message on the board.
  *
  */
 
    public void setMessage(String s) {

        message = new String(s);
 
    } // À§·Î
 
 /**
  *  public void setScore(int player)
  *  Sets the message on the board.
  *  @param int player : The player who scored.
  *
  */
    public void setScore(int player) {

        int score;

        if(player == PLAYER1) {

            score = Score1.intValue();
            score++;
            Score1 = new Integer(score);

        } else {

            score = Score2.intValue();
            score++;
            Score2 = new Integer(score);
        }
    }
} // À§·Î