All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.cschen1205.navigator.gui.MazePanel Maven / Gradle / Ivy

package com.github.cschen1205.navigator.gui;

import com.github.cschen1205.navigator.minefield.env.MineField;
import com.github.cschen1205.navigator.utils.FileUtils;
import com.github.cschen1205.navigator.utils.MazePalette;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.MalformedURLException;

/**
 * Created by chen0469 on 10/2/2015 0002.
 */
public

class MazePanel extends JPanel implements ActionListener {

    final int MAXSTEP = 500;

    private int size = 16;
    private int[][] current;
    private int[] target;
    private int[] bearing;
    private int[] currentBearing;
    private int[] targetBearing;
    private double[] sonar;
    private double range;
    private int[][] mines;
    private int[][][] path;
    private int [] numStep;
    private int agent_num;
    private int maxStep;
    private boolean tracking = false;

    public boolean isTracking(){
        return tracking;
    }

    public void setTracking(boolean tracking){
        this.tracking = tracking;
    }

    /**
     * Background image.
     *
     * @author J.J.
     */
    private BufferedImage bgImage;
    /**
     * Bome image.
     *
     * @author J.J.
     */
    private Image bombIcon;
    /**
     * Tank image.
     *
     * @author J.J.
     */
    private Image [] tankIcon;
    /**
     * Target image.
     *
     * @author J.J.
     */
    private Image targetIcon;
    /**
     * popup menu for bgimage seleciton.
     *
     * @author Jin Jun
     */
    private JPopupMenu popup;

    public MazePanel(MineField m, int numVehicles)
    {
        init_MP( m, numVehicles);
        doRefresh(m, null, 0);
    }

    public void init_MP( MineField m, int numVehicles ) {
        // initiate components first.
        initComponents();

        size = m.getSize();
        this.agent_num = numVehicles;

        int agt;

        numStep = new int[agent_num];
        current = new int[agent_num][];
        currentBearing = new int[agent_num];
        for( agt = 0; agt < agent_num; agt++ )
            current[agt] = new int[2];
        current = m.getCurrentPositions();

        path = new int[MAXSTEP][agent_num][2];

        target = new int[2];
        target = m.getTargetPosition();

        mines = new int[size][size];
        for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy