Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab4.data;
- import java.util.ArrayList;
- import java.util.Observable;
- /**
- * Represents the 2-d game grid
- */
- public class GameGrid extends Observable{
- ArrayList<int[]> myMoves = new ArrayList<int[]>();
- public static int EMPTY = 0, ME = 1, OTHER = 2;
- public final int INROW = 5;
- int size;
- int[][] grid;
- /**
- * Constructor
- *
- * @param size The width/height of the game grid
- */
- public GameGrid(int size){
- grid = new int[size][size];
- clearGrid();
- this.size = size;
- }
- /**
- * Reads a location of the grid
- *
- * @param x The x coordinate
- * @param y The y coordinate
- * @return the value of the specified location
- */
- public int getLocation(int x, int y){
- return grid[x][y];
- }
- /**
- * Returns the size of the grid
- *
- * @return the grid size
- */
- public int getSize(){
- return size;
- }
- /**
- * Enters a move in the game grid
- *
- * @param x the x position
- * @param y the y position
- * @param player
- * @return true if the insertion worked, false otherwise
- */
- public boolean move(int x, int y, int player){
- if (getLocation(x, y) == EMPTY){
- grid[x][y] = player;
- setChanged();
- notifyObservers();
- return true;
- }
- return false;
- }
- /**
- * Clears the grid of pieces
- */
- public void clearGrid(){
- for (int i = 0; i < size; i++){
- for (int j = 0; j < size; j++) {
- grid[i][j] = EMPTY;
- }
- }
- setChanged();
- notifyObservers();
- }
- /**
- * Check if a player has 5 in row
- *
- * @param player the player to check for
- * @return true if player has 5 in row, false otherwise
- */
- public boolean isWinner(int player){
- //for (int i = 0; i < 8; i++)
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement