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

📄 cubestack.java

📁 一个java写的魔方游戏
💻 JAVA
字号:
// FrontEnd Plus GUI for JAD
// DeCompiled : CubeStack.class

import java.awt.TextComponent;
import java.awt.TextField;
import java.util.EmptyStackException;
import java.util.Stack;

class CubeStack
{

    private int Watermark;
    private int Count;
    private Stack UndoStack;
    private Stack RedoStack;
    private TextField StepText;
    private boolean UpdateEnabled;

    CubeStack(TextField textfield)
    {
        UpdateEnabled = true;
        UndoStack = new Stack();
        RedoStack = new Stack();
        Watermark = 0;
        Count = 0;
        StepText = textfield;
    }

    public void EnableUpdate(boolean flag)
    {
        UpdateEnabled = flag;
        if(UpdateEnabled)
            UpdateStep();
    }

    public void UpdateStep()
    {
        if(UpdateEnabled)
            StepText.setText(String.valueOf(Count - Watermark));
    }

    void Clear()
    {
        for(; !UndoStack.empty(); UndoStack.pop());
        for(; !RedoStack.empty(); RedoStack.pop());
        Watermark = 0;
        Count = 0;
        UpdateStep();
    }

    void Do(CubeAction cubeaction)
    {
        UndoStack.push(cubeaction);
        if(!RedoStack.empty())
            RedoStack = new Stack();
        Count++;
        UpdateStep();
    }

    CubeAction Undo()
    {
        if(Count > Watermark)
        {
            CubeAction cubeaction;
            try
            {
                cubeaction = (CubeAction)UndoStack.pop();
            }
            catch(EmptyStackException _ex)
            {
                return null;
            }
            RedoStack.push(cubeaction);
            Count--;
            UpdateStep();
            return cubeaction;
        } else
        {
            return null;
        }
    }

    CubeAction ForceUndo()
    {
        CubeAction cubeaction;
        try
        {
            cubeaction = (CubeAction)UndoStack.pop();
        }
        catch(EmptyStackException _ex)
        {
            return null;
        }
        Watermark--;
        Count--;
        if(!RedoStack.empty())
            RedoStack = new Stack();
        UpdateStep();
        return cubeaction;
    }

    CubeAction Redo()
    {
        CubeAction cubeaction;
        try
        {
            cubeaction = (CubeAction)RedoStack.pop();
        }
        catch(EmptyStackException _ex)
        {
            return null;
        }
        Count++;
        UpdateStep();
        return (CubeAction)UndoStack.push(cubeaction);
    }

    void SetWatermark()
    {
        Watermark = Count;
        UpdateStep();
    }
}

⌨️ 快捷键说明

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