⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 click-game.txt

📁 用java编写的applet游戏
💻 TXT
字号:
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.lang.*;

public class click extends java.applet.Applet implements Runnable{
        Thread thread;
        TextField text1;
        TextField text2;
        int time;
        int score;
        Image medal0;
        Image medal1;
        Image medal2;
        Image medal3;
        AudioClip audio;

        public void init(){
                resize(400,300);
                setBackground(Color.orange);
                setForeground(Color.blue);
                setLayout(new BorderLayout());
                Panel p=new Panel();
                text1=new TextField("0",10);
                text2=new TextField("0",5);
                p.setLayout(new FlowLayout());
                p.add(new Button("Start"));
                p.add(new Button("Pause"));
                add("South",p);
                Panel t=new Panel();
                t.add(text1);
                t.add(text2);
                add("North",t);
                medal0=getImage(getDocumentBase(),"images/medal0.gif");
                medal1=getImage(getDocumentBase(),"images/medal1.gif");
                medal2=getImage(getDocumentBase(),"images/medal2.gif");
                medal3=getImage(getDocumentBase(),"images/medal3.gif");
                audio=getAudioClip(getDocumentBase(),"audio/medal.au");
                time=0;
                score=0;
        }            

        public void run(){
                while(thread!=null){
                        try{
                                Thread.sleep(10);
                        }catch(InterruptedException e){
                        }
                        repaint();
                }
        }

        public void stop(){
                if(thread!=null)
                        thread.stop();
                        thread=null;
        }

        public void update(Graphics g){
                g.clearRect(0,0,400,300);
                time=time+50;
                text1.setText(Integer.toString(time));
                        if(time>10000){
                                thread=null;
                                text1.setText("Game Over!");
                        }
                g.setColor(Color.red);
                g.drawRect(49,38,302,32);
                g.drawLine(200,38,200,70);
                g.drawLine(260,38,260,70);
                g.drawString("0",50,85);
                g.drawString("50",196,85);
                g.drawString("70",254,85);
                g.drawString("100",346,85);
                g.setColor(Color.green);
                g.fillRect(50,40,score*3,30);
                        if(time>10000){
                                audio.play();
                                g.clearRect(50,40,300,30);
                                Font font=new Font("TimesRoman",Font.BOLD,24);
                                g.setFont(font);
                                g.setColor(Color.blue);
                                if(score<100){
                                        g.drawString("Your Score is "+Integer.toString(score)+" points!!",60,60);
                                                if(score>=70)g.drawImage(medal2,160,120,this);
                                                        if(score>=50&&score<70)g.drawImage(medal3,160,120,this);
                                                                if(score<50)g.drawImage(medal0,160,120,this);
                                }else{
                                        g.drawString("Your Score is Perfect!!",60,60);
                                        g.drawImage(medal1,150,150,this);
                                }
                        }
        }

        public boolean action(Event e,Object o){
                if(e.target instanceof Button){
                        if("Start".equals(o)){
                                if(thread==null){
                                        time=0;
                                        score=0;
                                        text2.setText("0");
                                        thread=new Thread(this);
                                        thread.start();
                                }
                        }else if("Pause".equals(o)){
                                if(thread!=null){
                                        thread.stop();
                                        thread=null;
                                }
                        }
                        return true;
                }
                return false;
        }

        public boolean mouseDown(Event e,int x,int y){
                if(thread!=null){
                        score=score+1;
                        text2.setText(Integer.toString(score));
                                if(score>100){
                                        text2.setText("Wao!!");
                                        score=100;
                                }
                }
                return true;
        }

        public void paint(Graphics g){
                update(g);
        }
}







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -