diff --git a/src/Assignments/A1/Driver.java b/src/Assignments/A1/Driver.java index 1e3d264..d22674b 100644 --- a/src/Assignments/A1/Driver.java +++ b/src/Assignments/A1/Driver.java @@ -2,6 +2,18 @@ package Assignments.A1; // Potentially will be changed to an UI Implementation with JavaFX if time permits. + +/** + * Board will be used to save locations in a 2D array. + * + * The design of the board locations will be numbered like so: + * 0 1 2 + * 3 4 5 + * 6 7 8 + * + * The values will be specified with an int. Must be between (inclusive) 1-8. + * The empty spot will be represented with null. + */ public class Driver { diff --git a/src/Assignments/A1/models/Piece.java b/src/Assignments/A1/models/Piece.java index 09a5672..c3fce6d 100644 --- a/src/Assignments/A1/models/Piece.java +++ b/src/Assignments/A1/models/Piece.java @@ -1,4 +1,67 @@ package Assignments.A1.models; +/** + * This class allows for abstraction and proper representation of a piece of the 8 puzzle. + * + * @author Jonathan Turner + * @version CS3642 - Spring 2024 + */ public class Piece { + + private int loc; + private int value; + + /** + * Creates a new piece with a specified location and value. + * + * @precondition loc >= 0 & newLoc <= 8 + * & value >= 1 & value <= 8 + * @postcondition the piece is created. + * @param loc + * @param value + */ + public Piece(int loc, int value) { + + this.moveTo(loc); + this.value = value; + } + + /** + * Moves the piece to a new location. + * + * @precondition newLoc >= 0 & newLoc <= 8 + * @precondition location = newLoc + * + * @param newLoc the new location of the piece. + */ + public void moveTo(int newLoc) { + if (newLoc < 0 || newLoc > 8) { + throw new IllegalArgumentException("The new location is not valid."); + } + this.loc = newLoc; + } + + /** + * Gets the location of the piece. + * + * @precondition None + * @postcondition None + * + * @return loc the location of the piece. + */ + public int getLoc() { + return this.loc; + } + + /** + * Gets the value of the piece. + * + * @precondition None + * @postcondition None + * + * @return value the Value of the piece. + */ + public int getValue() { + return this.value; + } }