當前位置: 首頁>>代碼示例>>Java>>正文


Java Grid類代碼示例

本文整理匯總了Java中info.gridworld.grid.Grid的典型用法代碼示例。如果您正苦於以下問題:Java Grid類的具體用法?Java Grid怎麽用?Java Grid使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Grid類屬於info.gridworld.grid包,在下文中一共展示了Grid類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeDefaultValue

import info.gridworld.grid.Grid; //導入依賴的package包/類
public Object makeDefaultValue(Class type) {
    if (type == int.class)
        return new Integer(0);
    else if (type == boolean.class)
        return Boolean.FALSE;
    else if (type == double.class)
        return new Double(0);
    else if (type == String.class)
        return "";
    else if (type == Color.class)
        return Color.BLACK;
    else if (type == Location.class)
        return currentLocation;
    else if (Grid.class.isAssignableFrom(type))
        return currentGrid;
    else {
        try {
            return type.newInstance();
        } catch (Exception ex) {
            return null;
        }
    }
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:24,代碼來源:MenuMaker.java

示例2: PropertySheet

import info.gridworld.grid.Grid; //導入依賴的package包/類
/**
 * Constructs a property sheet that shows the editable properties of a given
 * object.
 *
 * @param object the object whose properties are being edited
 */
public PropertySheet(Class[] types, Object[] values) {
    this.values = values;
    editors = new PropertyEditor[types.length];
    setLayout(new FormLayout());
    for (int i = 0; i < values.length; i++) {
        JLabel label = new JLabel(types[i].getName());
        add(label);
        if (Grid.class.isAssignableFrom(types[i])) {
            label.setEnabled(false);
            add(new JPanel());
        } else {
            editors[i] = getEditor(types[i]);
            if (editors[i] != null) {
                editors[i].setValue(values[i]);
                add(getEditorComponent(editors[i]));
            } else
                add(new JLabel("?"));
        }
    }
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:27,代碼來源:MenuMaker.java

示例3: setGrid

import info.gridworld.grid.Grid; //導入依賴的package包/類
/**
 * Sets the grid being displayed. Reset the cellSize to be the
 * largest that fits the entire grid in the current visible area (use
 * default if grid is too large).
 *
 * @param gr the grid to display
 */
public void setGrid(Grid<?> gr) {
    currentLocation = new Location(0, 0);
    JViewport vp = getEnclosingViewport(); // before changing, reset
    // scroll/pan position
    if (vp != null)
        vp.setViewPosition(new Point(0, 0));

    grid = gr;
    originRow = originCol = 0;

    if (grid.getNumRows() == -1 && grid.getNumCols() == -1) {
        numRows = numCols = 2000;
        // This determines the "virtual" size of the pan world
    } else {
        numRows = grid.getNumRows();
        numCols = grid.getNumCols();
    }
    recalculateCellSize(MIN_CELL_SIZE);
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:27,代碼來源:GridPanel.java

示例4: countAts

import info.gridworld.grid.Grid; //導入依賴的package包/類
public int countAts(Location loc)
 {

     Grid gr = this.getGrid();
     if (gr.isValid(loc) == true && gr.get(loc) == "@"){
         setMessage("AtCount at " + loc + " is @ ");
         int x = loc.getRow();
         int y = loc.getCol();
         gr.put(loc,"-");
         countAts(new Location(x + 1, y));
countAts(new Location(x - 1, y));
countAts(new Location(x, y + 1));
countAts(new Location(x, y - 1));
     }
     return 0;
 }
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:17,代碼來源:AtCounterWorld.java

示例5: setGrid

import info.gridworld.grid.Grid; //導入依賴的package包/類
/**
 * Sets the grid being displayed. Reset the cellSize to be the
 * largest that fits the entire grid in the current visible area (use
 * default if grid is too large).
 * @param gr the grid to display
 */
public void setGrid(Grid<?> gr)
{
    currentLocation = new Location(0, 0);
    JViewport vp = getEnclosingViewport(); // before changing, reset
    // scroll/pan position
    if (vp != null)
        vp.setViewPosition(new Point(0, 0));

    grid = gr;
    originRow = originCol = 0;

    if (grid.getNumRows() == -1 && grid.getNumCols() == -1)
    {
        numRows = numCols = 2000; 
        // This determines the "virtual" size of the pan world
    }
    else
    {
        numRows = grid.getNumRows();
        numCols = grid.getNumCols();
    }
    recalculateCellSize(MIN_CELL_SIZE);        
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:30,代碼來源:GridPanel.java

示例6: act

import info.gridworld.grid.Grid; //導入依賴的package包/類
public void act()
{
  //get this actor's grid, location, and direction - store the values in local variables
  Grid gr = getGrid();    // getting this actor's location
  Location loc = this.getLocation();
  
  
  //locate location to the right
  
  Location loc2 = loc.getAdjacentLocation(Location.WEST);
  
  if (gr.isValid(loc2) == true){
      this.moveTo(loc2);
    }
  else if (gr.isValid(loc2) == false){
      this.moveTo(orig);
    }
    
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:20,代碼來源:MoveLeftActor.java

示例7: act

import info.gridworld.grid.Grid; //導入依賴的package包/類
public void act()
{
  Grid gr = getGrid();
    Location loc = this.getLocation();
    Location orig = new Location(8,0);

     
     //locate location to the right
     
     Location loc2 = loc.getAdjacentLocation(Location.NORTHEAST);
     
     if (gr.isValid(loc2) == true){
         this.moveTo(loc2);
       }
     else if (gr.isValid(loc2) == false){
         this.moveTo(orig);
       }
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:19,代碼來源:UpAndOverActor.java

示例8: act

import info.gridworld.grid.Grid; //導入依賴的package包/類
public void act(){
  Grid gr = getGrid();    // getting this actor's location
  Location loc = this.getLocation();
  Location orig = new Location(0,9);
  
  //locate location to the right
  
  Location loc2 = loc.getAdjacentLocation(Location.WEST);
  
  if (gr.isValid(loc2) == true){
      this.moveTo(loc2);
    }
  else if (gr.isValid(loc2) == false){
      this.moveTo(orig);
    }
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:17,代碼來源:MoveLeftActor.java

示例9: act

import info.gridworld.grid.Grid; //導入依賴的package包/類
public void act()
{
  Grid gr = getGrid();
    Location loc = this.getLocation();
    Location orig = new Location(7,7);
  
  //locate location to the right
  
  Location loc2 = loc.getAdjacentLocation(Location.NORTH);
  
  if (gr.isValid(loc2) == true){
      this.moveTo(loc2);
    }
  else if (gr.isValid(loc2) == false){
      this.moveTo(orig);
    }
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:18,代碼來源:MoveNorthActor.java

示例10: act

import info.gridworld.grid.Grid; //導入依賴的package包/類
public void act()
{
  Grid gr = getGrid();
    Location loc = this.getLocation();
    Location orig = new Location(7,7);
  
  //locate location to the right
  
  Location loc2 = loc.getAdjacentLocation(Location.SOUTH);
  
  if (gr.isValid(loc2) == true){
      this.moveTo(loc2);
    }
  else if (gr.isValid(loc2) == false){
      this.moveTo(orig);
    }
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:18,代碼來源:MoveSouthActor.java

示例11: act

import info.gridworld.grid.Grid; //導入依賴的package包/類
public void act()
{
	Location loc = getLocation();
	//int row = loc.getRow();
	//int col = loc.getCol();
	//moveTo(new Location(row,col+1));
	
	//or
	//moveTo(loc.getAdjacentLocation(Location.EAST));
	
	
	//optional blow-up prevention
	Grid<Actor> grid = getGrid();
	Location newLoc = loc.getAdjacentLocation(Location.EAST);
	if(grid.isValid(newLoc))
	{
		moveTo(newLoc);
	}
	else
	{
		moveTo(new Location(loc.getRow(),0));
	}
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:24,代碼來源:SideWaysActorSoln.java

示例12: countAts

import info.gridworld.grid.Grid; //導入依賴的package包/類
public int countAts(Location loc)
{
    Grid gr = this.getGrid();
    if (gr.isValid(loc) == true && gr.get(loc) == "@"){
        setMessage("AtCount at " + loc + " is @ ");
        int x = loc.getRow();
        int y = loc.getCol();
        gr.put(loc,"-");
        countAts(new Location(x + 1, y));
        countAts(new Location(x - 1, y));
        countAts(new Location(x, y + 1));
        countAts(new Location(x, y - 1));
        countAts(new Location(x + 1, y+1));
        countAts(new Location(x - 1, y-1));
        countAts(new Location(x-1, y + 1));
        countAts(new Location(x+1, y - 1));
    }
    return 0;
}
 
開發者ID:ReagentX,項目名稱:heidnerComputerScienceProjects,代碼行數:20,代碼來源:AtCounterWorld.java

示例13: setGrid

import info.gridworld.grid.Grid; //導入依賴的package包/類
@Override
public void setGrid(Grid g) {
    super.setGrid(g);
    if (g instanceof TerrainGrid) {
        ((TerrainGrid) g).hostWorld = this;
    }
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:8,代碼來源:AVWorld.java

示例14: World

import info.gridworld.grid.Grid; //導入依賴的package包/類
public World(Grid<T> g) {
    gr = g;
    gridClassNames = new TreeSet<>();
    occupantClassNames = new TreeSet<>();
    addGridClass("info.gridworld.grid.BoundedGrid");
    addGridClass("info.gridworld.grid.UnboundedGrid");
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:8,代碼來源:World.java

示例15: toString

import info.gridworld.grid.Grid; //導入依賴的package包/類
/**
 * Returns a string that shows the positions of the grid occupants.
 */
public String toString() {
    StringBuilder tmpSB = new StringBuilder("");
    Grid<?> gr = getGrid();

    int rmin = 0;
    int rmax = gr.getNumRows() - 1;
    int cmin = 0;
    int cmax = gr.getNumCols() - 1;
    if (rmax < 0 || cmax < 0) // unbounded grid
    {
        for (Location loc : gr.getOccupiedLocations()) {
            int r = loc.getRow();
            int c = loc.getCol();
            if (r < rmin)
                rmin = r;
            if (r > rmax)
                rmax = r;
            if (c < cmin)
                cmin = c;
            if (c > cmax)
                cmax = c;
        }
    }

    for (int i = rmin; i <= rmax; i++) {
        for (int j = cmin; j < cmax; j++) {
            Object obj = gr.get(new Location(i, j));
            if (obj == null) {
                tmpSB.append(" ");
            } else {
                tmpSB.append(obj.toString().substring(0, 1));
            }
        }
        tmpSB.append("\n");
    }
    return tmpSB.toString();
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:41,代碼來源:World.java


注:本文中的info.gridworld.grid.Grid類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。