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

📄 gameeditor.java

📁 控制移到机器人的例子程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
	A basic extension of the java.awt.Frame class
 */
 
import java.awt.*;
import java.io.*;
import java.util.zip.*;
import java.util.*;

public class GameEditor extends Frame
{
    MazeGraphics maze;
    GameWorld myGameWorld;
    int maze_x, maze_y;
    int edit_state;
    int roboDirection;
    int[] myLocation;
    static final int WALLS = 1;
    static final int GOLDS = 2;
    static final int ROBOTS = 3;
    static final int PORTS = 4;
	public GameEditor()
	{
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		setLayout(null);
		setVisible(false);
		setSize(insets().left + insets().right + 804,insets().top + insets().bottom + 387);
		button_x = new java.awt.Button();
		button_x.setActionCommand("button");
		button_x.setLabel("x");
		button_x.setBounds(insets().left + 216,insets().top + 84,49,24);
		button_x.setBackground(new Color(12632256));
		add(button_x);
		button_y = new java.awt.Button();
		button_y.setActionCommand("button");
		button_y.setLabel("y");
		button_y.setBounds(insets().left + 96,insets().top + 144,24,50);
		button_y.setBackground(new Color(12632256));
		add(button_y);
		button_walls = new java.awt.Button();
		button_walls.setActionCommand("button");
		button_walls.setLabel("walls");
		button_walls.setBounds(insets().left + 12,insets().top + 48,44,24);
		button_walls.setBackground(new Color(12632256));
		add(button_walls);
		button_golds = new java.awt.Button();
		button_golds.setActionCommand("button");
		button_golds.setLabel("golds");
		button_golds.setBounds(insets().left + 12,insets().top + 84,44,24);
		button_golds.setBackground(new Color(12632256));
		add(button_golds);
		button_robotN = new java.awt.Button();
		button_robotN.setActionCommand("button");
		button_robotN.setLabel("robotN");
		button_robotN.setBounds(insets().left + 12,insets().top + 156,44,24);
		button_robotN.setBackground(new Color(12632256));
		add(button_robotN);
		button_load = new java.awt.Button();
		button_load.setActionCommand("button");
		button_load.setLabel("load...");
		button_load.setBounds(insets().left + 72,insets().top + 12,51,20);
		button_load.setBackground(new Color(12632256));
		add(button_load);
		button_save = new java.awt.Button();
		button_save.setActionCommand("button");
		button_save.setLabel("save...");
		button_save.setBounds(insets().left + 144,insets().top + 12,51,20);
		button_save.setBackground(new Color(12632256));
		add(button_save);
		button_robotW = new java.awt.Button();
		button_robotW.setActionCommand("button");
		button_robotW.setLabel("robotW");
		button_robotW.setBounds(insets().left + 12,insets().top + 192,44,24);
		button_robotW.setBackground(new Color(12632256));
		add(button_robotW);
		button_robotS = new java.awt.Button();
		button_robotS.setActionCommand("button");
		button_robotS.setLabel("robotS");
		button_robotS.setBounds(insets().left + 12,insets().top + 228,44,24);
		button_robotS.setBackground(new Color(12632256));
		add(button_robotS);
		button_robotE = new java.awt.Button();
		button_robotE.setActionCommand("button");
		button_robotE.setLabel("robotE");
		button_robotE.setBounds(insets().left + 12,insets().top + 264,44,24);
		button_robotE.setBackground(new Color(12632256));
		add(button_robotE);
		headCountField = new java.awt.TextField();
		headCountField.setText("1");
		headCountField.setBounds(insets().left + 288,insets().top + 12,60,18);
		headCountField.setFont(new Font("Dialog", Font.PLAIN, 10));
		add(headCountField);
		headCountLabel = new java.awt.Label("Head count:");
		headCountLabel.setBounds(insets().left + 216,insets().top + 12,72,18);
		headCountLabel.setFont(new Font("Dialog", Font.PLAIN, 10));
		add(headCountLabel);
		button_ports = new java.awt.Button();
		button_ports.setActionCommand("button");
		button_ports.setLabel("ports");
		button_ports.setBounds(insets().left + 12,insets().top + 120,44,24);
		button_ports.setBackground(new Color(12632256));
		add(button_ports);
		setTitle("GameEditor");
		//}}
        this.setVisible(true);
        this.maze_x = insets().left + 70;
        this.maze_y = insets().top + 36;
        maze = new MazeGraphics(this, 2, 2, 
                  this.maze_x, this.maze_y);
        maze.refresh();
        moveButtons();
        this.buttonWalls_MouseClick(null);
		//{{INIT_MENUS
		//}}

		//{{REGISTER_LISTENERS
		SymWindow aSymWindow = new SymWindow();
		this.addWindowListener(aSymWindow);
		SymMouse aSymMouse = new SymMouse();
		button_x.addMouseListener(aSymMouse);
		button_y.addMouseListener(aSymMouse);
		this.addMouseListener(aSymMouse);
		button_walls.addMouseListener(aSymMouse);
		button_golds.addMouseListener(aSymMouse);
		button_robotN.addMouseListener(aSymMouse);
		button_save.addMouseListener(aSymMouse);
		button_load.addMouseListener(aSymMouse);
		button_robotW.addMouseListener(aSymMouse);
		button_robotS.addMouseListener(aSymMouse);
		button_robotE.addMouseListener(aSymMouse);
		SymAction lSymAction = new SymAction();
		button_ports.addMouseListener(aSymMouse);
		//}}
	}

	public GameEditor(String title)
	{
		this();
		setTitle(title);
	}

	public synchronized void show()
	{
		move(50, 50);
		super.show();
	}

	public void addNotify()
	{
	    // Record the size of the window prior to calling parents addNotify.
	    Dimension d = getSize();
	    
		super.addNotify();

		if (fComponentsAdjusted)
			return;

		// Adjust components according to the insets
		setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
		Component components[] = getComponents();
		for (int i = 0; i < components.length; i++)
		{
			Point p = components[i].getLocation();
			p.translate(insets().left, insets().top);
			components[i].setLocation(p);
		}
		fComponentsAdjusted = true;
	}

    // Used for addNotify check.
	boolean fComponentsAdjusted = false;

	//{{DECLARE_CONTROLS
	java.awt.Button button_x;
	java.awt.Button button_y;
	java.awt.Button button_walls;
	java.awt.Button button_golds;
	java.awt.Button button_robotN;
	java.awt.Button button_load;
	java.awt.Button button_save;
	java.awt.Button button_robotW;
	java.awt.Button button_robotS;
	java.awt.Button button_robotE;
	java.awt.TextField headCountField;
	java.awt.Label headCountLabel;
	java.awt.Button button_ports;
	//}}

	//{{DECLARE_MENUS
	//}}

	class SymWindow extends java.awt.event.WindowAdapter
	{
		public void windowClosing(java.awt.event.WindowEvent event)
		{
			Object object = event.getSource();
			if (object == GameEditor.this)
				MazeEditor_WindowClosing(event);
		}
	}
	
	void MazeEditor_WindowClosing(java.awt.event.WindowEvent event)
	{
		hide();		 // hide the Frame
	}
	
	public void paint(Graphics g)
	{
	    if (this.maze != null)
	        maze.update();	   
	} // paint()
	
	// updates position of x and y buttons //
	public void moveButtons()
	{
        button_x.setLocation(this.maze_x+ 5 +
                             (maze.width*maze.cellsize),
                             this.maze_y - 12 +
                             (int)(maze.height*maze.cellsize*0.5));
        button_y.setLocation(this.maze_x - 12 +
                             (int)(maze.width*maze.cellsize*0.5),
                             this.maze_y+5+
                             (maze.height*maze.cellsize));
	} // moveButtons()

	class SymMouse extends java.awt.event.MouseAdapter
	{
		public void mouseClicked(java.awt.event.MouseEvent event)
		{
			Object object = event.getSource();
			if (object == button_x)
				buttonX_MouseClick(event);
			else if (object == button_y)
				buttonY_MouseClick(event);
			else if (object == GameEditor.this)
				MazeEditor_MouseClick(event);
			else if (object == button_walls)
				buttonWalls_MouseClick(event);
			else if (object == button_golds)
				buttonGolds_MouseClick(event);
			else if (object == button_robotN)
				buttonRobotN_MouseClick(event);
			else if (object == button_save)
				buttonSave_MouseClick(event);
			else if (object == button_load)
				buttonLoad_MouseClick(event);
			else if (object == button_robotW)
				buttonRobotW_MouseClick(event);
			else if (object == button_robotS)
				buttonRobotS_MouseClick(event);
			else if (object == button_robotE)
				buttonRobotE_MouseClick(event);
			else if (object == button_ports)
				buttonPorts_MouseClick(event);
		}
	}

    // increase width of maze by one (and reinstantiate)
	void buttonX_MouseClick(java.awt.event.MouseEvent event)
	{
        int x = this.maze.width;
        int y = this.maze.height;
        this.maze = new MazeGraphics(this, x+1, y, 
                  this.maze_x, this.maze_y);
        this.moveButtons();
        this.maze.refresh();
	} // buttonX_MouseClick() //

	void buttonY_MouseClick(java.awt.event.MouseEvent event)
	{
        int x = this.maze.width;
        int y = this.maze.height;
        this.maze = new MazeGraphics(this, x, y+1, 
                  this.maze_x, this.maze_y);
        this.moveButtons();
        this.maze.refresh();
	} // buttonY_MouseClick() //

	void MazeEditor_MouseClick(java.awt.event.MouseEvent event)
	{
	    switch (this.edit_state) {
	        case GameEditor.WALLS:
	            this.wallClick(event);
	            break;
	        case GameEditor.GOLDS:
	            this.goldClick(event);
	            break;
	        case GameEditor.ROBOTS:
	            this.robotClick(event);
	            break;
	        case GameEditor.PORTS:
	            this.portClick(event);
	            break;
	    } // endswitch
        this.maze.refresh();
	} // MazeEditor_MouseClick() //
	
	public boolean nearCenter(int x)
	{
	    return ((Math.abs((x % this.maze.cellsize) - 
	                      (this.maze.cellsize/2)))
	                <
	            (this.maze.cellsize/4));
	} // nearCenter() //
	
	public boolean inXBounds(int x)
	{
	    return((x/this.maze.cellsize) < this.maze.width);
	}
	public boolean inYBounds(int y)
	{
	    return((y/this.maze.cellsize) < this.maze.height);
	}
	public boolean nearEdge(int x)
	{
	    return((x % this.maze.cellsize) < 10);
	}
	public int getXCell(int x)
	{

⌨️ 快捷键说明

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