Android Open Source - RPGWorld Background Grid






From Project

Back to project page RPGWorld.

License

The source code is released under:

MIT License

If you think the Android project RPGWorld listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Jun 6, 2013/* www  . ja v  a  2 s . c  o  m*/
 * BackgroundGrid.java
 * Daniel Pok
 * AP Java 6th
 */
package com.nokarateclass.rpgworld.grid;

import android.util.Log;

import com.nokarateclass.rpgworld.characters.CharacterActor;
import com.nokarateclass.rpgworld.ui.ImageGridView;

/**
 * @author poler_000
 *
 */
public class BackgroundGrid extends CharacterGrid {

  /**
   * 
   */
  private static final long serialVersionUID = 5592380041166090258L;

  /**
   * @param view
   */
  public BackgroundGrid(ImageGridView view) {
    super(view, true);
    mView.setBackgroundGrid(this);
  }

  public void updateView(CharacterActor character){
    mView.changeBackground(character.getSprite(), character.getLocation().getRow(), character.getLocation().getCol());
  }
  
  public void updateAll(){
    for(int i = 0; i < getRows(); i++){
      for(int j = 0; j < getCols(); j++){
        updateView(mGrid[i][j]);
      }
    }
  }
  
  /**
   * 
   * @param character
   * @param row
   * @param col
   */
  public boolean addCharacter(CharacterActor character, int row, int col){
    if(!isValidLocation(row, col) || mGrid[row][col] != null || character == null){
      Log.i("Character NOT added", "NOT ADDED");
      return false;
    } else{
      mGrid[row][col] = character;
      character.setGrid(this);
      character.setLocation(new Location(row, col));
      if(mView != null){
        mView.changeBackground(character.getSprite(), row, col);
        Log.i("Character Added", "Added!");
      }
      return true;
    }
  }
  
  /**
   * 
   * @param row
   * @param col
   * @return true if the object at that location was removed, false if the location is invalid or nothing was in that position
   */
  public boolean removeCharacter(int row, int col){
    if(!isValidLocation(row,col) || mGrid[row][col] == null){
      return false;
    } else {
      mGrid[row][col].setGrid(null);
      mGrid[row][col].setLocation(null);
      mGrid[row][col] = null;
      mView.changeBackground(null, row, col);
      return true;
    }
  }
  
  /**Similar to addCharacter, but doesn't associate grid/loc with character and can set null
   * More raw than addCharacter, use only when addCharacter would have undesirable side effects.
   * @param character
   * @param row
   * @param col
   * @return
   */
  public boolean set(CharacterActor character, int row, int col){
    if(!isValidLocation(row, col)){
      return false;
    } else{
      mGrid[row][col] = character;
      if(mView != null){
        if(character == null){
          mView.changeBackground(null, row, col);
        } else {
          mView.changeBackground(character.getSprite(), row, col);
        }
      }
      return true;
    }
  }
}




Java Source Code List

com.nokarateclass.rpgworld.Grid.java
com.nokarateclass.rpgworld.MapEditor.java
com.nokarateclass.rpgworld.backgrounds.BackgroundCharacter.java
com.nokarateclass.rpgworld.backgrounds.GrassBackground.java
com.nokarateclass.rpgworld.backgrounds.SandBackground.java
com.nokarateclass.rpgworld.characters.AndroidCharacter.java
com.nokarateclass.rpgworld.characters.CactusCharacter.java
com.nokarateclass.rpgworld.characters.CharacterActor.java
com.nokarateclass.rpgworld.characters.HeroCharacter.java
com.nokarateclass.rpgworld.characters.MonsterCharacter.java
com.nokarateclass.rpgworld.characters.Player.java
com.nokarateclass.rpgworld.characters.RockCharacter.java
com.nokarateclass.rpgworld.characters.Status.java
com.nokarateclass.rpgworld.characters.TreeCharacter.java
com.nokarateclass.rpgworld.editor.CharacterFactory.java
com.nokarateclass.rpgworld.editor.EditorGrid.java
com.nokarateclass.rpgworld.grid.BackgroundGrid.java
com.nokarateclass.rpgworld.grid.BeatTask.java
com.nokarateclass.rpgworld.grid.CharacterGrid.java
com.nokarateclass.rpgworld.grid.Location.java
com.nokarateclass.rpgworld.grid.MainCharacterGrid.java
com.nokarateclass.rpgworld.io.FileExporter.java
com.nokarateclass.rpgworld.io.FileIO.java
com.nokarateclass.rpgworld.io.FileImporter.java
com.nokarateclass.rpgworld.io.GridSerializer.java
com.nokarateclass.rpgworld.io.SettingsHolder.java
com.nokarateclass.rpgworld.ui.GridClickListener.java
com.nokarateclass.rpgworld.ui.ImageGridView.java
com.nokarateclass.rpgworld.world.Region.java
com.nokarateclass.rpgworld.world.World.java
com.nokarateclass.rpgworld.world.Zone.java