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

📄 mapui.java

📁 一个已经实现的连连看小游戏的源码
💻 JAVA
字号:
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MapUI.java

package kyodai.map;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import kyodai.*;

// Referenced classes of package kyodai.map:
//            Line, Map

public class MapUI extends JPanel
    implements ActionListener, Runnable
{

    public MapUI(Map map, JButton dots[])
    {
        lastPoint = new Point(0, 0);
        isSelected = false;
        score = 0;
        stepScore = 0;
        limitTime = 0;
        isPlaying = false;
        this.map = map;
        this.dots = dots;
        GridLayout gridLayout = new GridLayout();
        setLayout(gridLayout);
        gridLayout.setRows(10);
        gridLayout.setColumns(17);
        gridLayout.setHgap(2);
        gridLayout.setVgap(2);
        setLayout(gridLayout);
        setBackground(Kyodai.DarkColor);
        for(int row = 0; row < 10; row++)
        {
            for(int col = 0; col < 17; col++)
            {
                int index = row * 17 + col;
                dots[index].addActionListener(this);
                add(dots[index]);
            }

        }

    }

    public void setMap(Map map)
    {
        this.map = map;
    }

    public void setTop10Button(JButton goTop10)
    {
        this.goTop10 = goTop10;
    }

    private void paint()
    {
        for(int row = 0; row < 10; row++)
        {
            for(int col = 0; col < 17; col++)
            {
                int index = row * 17 + col;
                if(map.getMap()[row][col] > 0)
                {
                    dots[index].setIcon(Kyodai.BlocksIcon[map.getMap()[row][col] - 1]);
                    dots[index].setEnabled(true);
                } else
                {
                    dots[index].setIcon(null);
                    dots[index].setEnabled(false);
                }
            }

        }

    }

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

    private boolean validMap(Point a)
    {
        if(map.getCount() == 0)
            return true;
        Line line = new Line(0, new Point(), new Point());
        map.setTest(true);
        line = map.findNext(a);
        int offset = 0;
        return line.direct == 1;
    }

    private void showScore(int l, int c)
    {
        if(scoreAnimate == null)
        {
            return;
        } else
        {
            scoreAnimate.setScore(l, c);
            return;
        }
    }

    public void refresh()
    {
        if(!isPlaying)
            return;
        if(map.getCount() == 0)
            Kyodai.showHint("\u8FD8\u5237\uFF0C\u90FD\u6CA1\u4E86\uFF01");
        if(Setting.Sound == 1)
            new Sound(Sound.REFRESH);
        if(validMap(new Point(-1, -1)))
        {
            score -= 8;
            showScore(score - 1, score);
        } else
        {
            showScore(score, score + 8);
            score += 8;
        }
        score -= 8;
        showScore(score - 1, score);
        map.refresh();
        paint();
    }

    void earse(Point a, Point b)
    {
        int offset = a.x * 17 + a.y;
        dots[offset].setIcon(null);
        dots[offset].setEnabled(false);
        offset = b.x * 17 + b.y;
        dots[offset].setIcon(null);
        dots[offset].setEnabled(false);
        if(map.getCount() == 0)
        {
            int remainTime = limitTime - clockAnimate.getUsedTime();
            message("remainTime = " + remainTime);
            if(remainTime > 0)
            {
                showScore(score, score + remainTime * 2);
                score += remainTime * 2;
            }
            isPlaying = false;
            stop();
            Kyodai.showHint("\u65F6\u95F4+ " + remainTime * 2 + "\uFF0C\u60F3\u770B\u770B\u4F60\u7684\u6392\u540D\u5417\uFF1F");
            goTop10.setEnabled(true);
        }
    }

    public void findNext(Point a)
    {
        if(!isPlaying)
            return;
        if(map.getCount() == 0)
        {
            Kyodai.showHint("\u4F60\u627E\u660F\u4E86\u5934\u5427\uFF0C\u6CA1\u4E86\uFF01");
            return;
        }
        Line line = new Line(0, new Point(), new Point());
        map.setTest(true);
        line = map.findNext(a);
        int offset = 0;
        if(line.direct == 1)
        {
            if(Setting.Sound == 1)
                new Sound(Sound.HINT);
            offset = line.a.x * 17 + line.a.y;
            dots[offset].setBorder(Kyodai.Hint);
            offset = line.b.x * 17 + line.b.y;
            dots[offset].setBorder(Kyodai.Hint);
            score -= 10;
            showScore(score - 1, score);
        } else
        {
            Kyodai.showHint("\u627E\u4E0D\u5230\uFF0C\u8BF7\u5237\u65B0");
        }
    }

    public boolean bomb(Point a, boolean showMessage)
    {
        if(!isPlaying)
            return false;
        if(map.getCount() == 0)
        {
            Kyodai.showHint("\u4F60\u70B8\u660F\u4E86\u5934\u5427\uFF0C\u6CA1\u4E86\uFF01");
            return false;
        }
        Line line = new Line(0, new Point(), new Point());
        map.setTest(false);
        line = map.findNext(a);
        int offset = 0;
        if(line.direct == 1)
        {
            if(Setting.Sound == 1)
                new Sound(Sound.BOMB);
            offset = line.a.x * 17 + line.a.y;
            dots[offset].setBorder(Kyodai.unSelected);
            offset = line.b.x * 17 + line.b.y;
            dots[offset].setBorder(Kyodai.unSelected);
            map.earse(line.a, line.b);
            earse(line.a, line.b);
            score -= 12;
            showScore(score - 1, score);
            return true;
        }
        if(showMessage)
            Kyodai.showHint("\u70B8\u5F39\u7528\u4E0D\u4E86\uFF0C\u8BF7\u5237\u65B0");
        return false;
    }

    private void message(String str)
    {
        Kyodai.showHint(str);
    }

    public void autoPlay()
    {
        if(!isPlaying)
            return;
        limitTime = 0;
        while(map.getCount() > 0) 
            if(bomb(new Point(-1, -1), false))
            {
                message("\u70B8\u5F39\u4F7F\u7528\u6210\u529F\uFF01");
            } else
            {
                message("\u627E\u4E0D\u5230\u53EF\u7528\u70B9\uFF0C\u5237\u65B0\u2026\u2026");
                refresh();
            }
    }

    public void setScore(ScoreAnimate score)
    {
        scoreAnimate = score;
    }

    public void setClock(ClockAnimate clock)
    {
        clockAnimate = clock;
    }

    public void actionPerformed(ActionEvent e)
    {
        JButton button = (JButton)e.getSource();
        int offset = Integer.parseInt(button.getActionCommand());
        int row = Math.round(offset / 17);
        int col = offset - row * 17;
        if(map.getMap()[row][col] < 1)
            return;
        if(Setting.Sound == 1)
            new Sound(Sound.SELECT);
        if(isSelected)
        {
            message("\u4E0A\u6B21\u5DF2\u7ECF\u9009\u62E9\u4E86\u4E00\u4E2A\u70B9");
            message("\u4E0A\u6B21\u9009\u62E9\u70B9\u7684\u5750\u6807\u4E3A\uFF1A " + lastPoint.x + ", " + lastPoint.y + " \u503C\u4E3A\uFF1A " + map.getMap()[lastPoint.x][lastPoint.y] + " \u4F4D\u79FB\u4E3A\uFF1A " + (lastPoint.x * 17 + lastPoint.y));
            if(lastPoint.x == row && lastPoint.y == col)
            {
                message("\u8FD9\u6B21\u9009\u62E9\u7684\u70B9\u548C\u4E0A\u6B21\u7684\u662F\u540C\u4E00\u70B9\uFF0C\u53D6\u6D88\u9009\u62E9\u72B6\u6001");
                button.setBorder(Kyodai.unSelected);
                isSelected = false;
            } else
            {
                message("\u8FD9\u6B21\u9009\u62E9\u7684\u70B9\u548C\u4E0A\u6B21\u7684\u70B9\u5E76\u4E0D\u76F8\u540C");
                Point current = new Point(row, col);
                message("\u8FD9\u6B21\u9009\u62E9\u7684\u70B9\u7684\u5750\u6807\u4E3A\uFF1A " + row + ", " + col + " \u503C\u4E3A\uFF1A " + map.getMap()[row][col] + " \u4F4D\u79FB\u4E3A\uFF1A " + (row * 17 + col));
                map.setTest(false);
                if(map.test(lastPoint, current))
                {
                    message("\u4E24\u70B9\u53EF\u4EE5\u6D88\u9664\uFF0C\u6267\u884C\u6D88\u9664");
                    dots[row * 17 + col].setBorder(Kyodai.unSelected);
                    map.earse(current, lastPoint);
                    earse(current, lastPoint);
                    dots[lastPoint.x * 17 + lastPoint.y].setBorder(Kyodai.unSelected);
                    lastPoint = new Point(0, 0);
                    isSelected = false;
                    showScore(score, score + 10 + stepScore);
                    score += 10 + stepScore;
                    if(Setting.Sound == 1)
                        new Sound(Sound.EARSE);
                } else
                {
                    message("\u8FD9\u6B21\u9009\u62E9\u7684\u70B9\u4E0E\u4E0A\u6B21\u9009\u62E9\u7684\u70B9\u65E0\u89E3\uFF0C\u6539\u53D8\u9009\u62E9\u4E3A\u5F53\u524D\u70B9");
                    dots[lastPoint.x * 17 + lastPoint.y].setBorder(Kyodai.unSelected);
                    button.setBorder(Kyodai.Selected);
                    lastPoint.x = row;
                    lastPoint.y = col;
                    isSelected = true;
                    score--;
                    showScore(score - 1, score);
                }
            }
        } else
        {
            message("\u4E0A\u6B21\u5E76\u672A\u9009\u62E9\u7684\u70B9\uFF0C\u7F6E\u5F53\u524D\u70B9\u4E3A\u9009\u62E9\u70B9");
            message("\u5F53\u524D\u70B9\u5750\u6807\u4E3A\uFF1A " + row + ", " + col + " \u503C\u4E3A\uFF1A " + map.getMap()[row][col] + " \u4F4D\u79FB\u4E3A\uFF1A " + (row * 17 + col));
            button.setBorder(Kyodai.Selected);
            lastPoint.x = row;
            lastPoint.y = col;
            isSelected = true;
        }
    }

    public String encode()
    {
        if(score < 0)
            Kyodai.showHint("\u8D1F\u5206\u8FD8\u60F3\u6709\u6392\u540D\uFF1F\u4E0B\u6B21\u52AA\u529B\u5427\uFF01");
        int level = Setting.LevelIndex;
        int f1 = (score - 102) * (score - 102);
        int f2 = (1978 - score) * (1978 - score);
        return "s=" + score + "&l=" + level + "&f1=" + f1 + "&f2=" + f2;
    }

    public void start()
    {
        goTop10.setEnabled(false);
        isPlaying = true;
        limitTime = map.getCount() * 4;
        message("limitTime = " + limitTime);
        paint();
    }

    public void run()
    {
    }

    public void stop()
    {
        clockAnimate.stop();
    }

    private Map map;
    private JButton dots[];
    private Point lastPoint;
    private boolean isSelected;
    private int score;
    private ClockAnimate clockAnimate;
    JButton goTop10;
    private ScoreAnimate scoreAnimate;
    int stepScore;
    int limitTime;
    private boolean isPlaying;
}

⌨️ 快捷键说明

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