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

📄 lightcycleswithui.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
字号:
package sim.app.lightcycles;import sim.engine.*;import sim.display.*;import sim.portrayal.grid.*;import java.awt.*;import javax.swing.*;public class LightCyclesWithUI extends GUIState    {    public Display2D display;    public JFrame displayFrame;        // For keyboard input    public ControlUI controls;        // gridPortrayal draws the "walls" created in the paths of the cycles    FastValueGridPortrayal2D gridPortrayal = new FastValueGridPortrayal2D();    // cycleGridPortrayal draws the cycles themselves    SparseGridPortrayal2D cycleGridPortrayal = new SparseGridPortrayal2D();        public static void main(String[] args)        {        LightCyclesWithUI cycles = new LightCyclesWithUI();        Console c = new Console(cycles);        c.setVisible(true);        }        public LightCyclesWithUI() { super(new LightCycles(System.currentTimeMillis())); }    public LightCyclesWithUI(SimState state) { super(state); }        public String getName() { return "LightCycles"; }        public String getInfo()        {        LightCycles lc = (LightCycles) state;                return             "<H2>LightCycles</H2>" +            "by Dan Kuebrich<br>" +            "The classic game of Tron, simulated with a very basic AI.  With keyboard controls--<br>" +            "<b>Controls</b><br><br>" +            "Spacebar - rotate through cycles to select user-controlled one<br>" +            "a - Play simulator<br>" +            "s - Pause simulator<br>" +            "d - Stop simulator<br>" +            "Left, Right - Turn left, right<br>";        }        public void start()        {        super.start();        // set up our portrayals        setupPortrayals();                // If this is not the first time we have played the sim in this run,        // the user might still have a cycle selected... so clear the cycle var        if(controls != null)            controls.c = null;        }        public void load(SimState state)        {        super.load(state);        // we now have new grids.  Set up the portrayals to reflect that        setupPortrayals();        }    public void setupPortrayals()        {        // portray varying levels on the gradient of transparent to red for cycle trails        gridPortrayal.setField(((LightCycles)state).grid);        gridPortrayal.setMap(new sim.util.gui.SimpleColorMap(0,((LightCycles)state).cycleCount+5,new Color(0,0,0,0),Color.red));                // just draw the cycles as white ovals        cycleGridPortrayal.setField(((LightCycles)state).cycleGrid);        cycleGridPortrayal.setPortrayalForClass(Cycle.class,                                                new sim.portrayal.simple.OvalPortrayal2D(Color.white));                // reschedule the displayer        display.reset();                        // redraw the display        display.repaint();        }        public void init(Controller c)        {        super.init(c);                // Make the Display2D.  We'll have it display stuff later.        display = new Display2D(400,400,this,1); // at 400x400, we've got 4x4 per array position        displayFrame = display.createFrame();        c.registerFrame(displayFrame);   // register the frame so it appears in the "Display" list        displayFrame.setVisible(true);        // attach the portrayals        display.attach(gridPortrayal,"Paths");        display.attach(cycleGridPortrayal,"Cycles");        // make the ControlUI the first time around        controls = new ControlUI(this, cycleGridPortrayal);        // Specify the backdrop color  -- what gets painted behind the displays        display.setBackdrop(new Color(0,0,128));          // or try: display.setBackdrop(new GradientPaint(0,0,Color.green,400,400,Color.blue));        // but be prepared to have to increase the amount of memory because it GC's a lot.  But        // it's nifty nonetheless!        }            public void quit()        {        super.quit();                if (displayFrame!=null) displayFrame.dispose();        displayFrame = null;  // let gc        display = null;       // let gc        }    }

⌨️ 快捷键说明

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