Making some changes, I added makeCorrectPuzzle method, which i have to
[puzzles.git] / src / com / github / puzzles / core / AbstractPuzzle.java
blob2ad735978591e1a71b00d532d3c19710d1562cb7
1 /**
2 * All puzzles must inherit this class.
3 */
4 package com.github.puzzles.core;
6 public abstract class AbstractPuzzle {
8 private int size;
9 private int counter;
10 private Difficulty difficulty;
12 protected AbstractPuzzle(int size, int count, Difficulty difficulty) {
13 this.size = size;
14 this.counter = count;
15 this.difficulty = difficulty;
18 protected AbstractPuzzle(AbstractPuzzle puzzle) {
19 this.size = puzzle.size;
20 this.counter = puzzle.counter;
21 this.difficulty = puzzle.difficulty;
24 /**
25 * Check to see if the puzzle is correct or not.
27 * @return true if the puzzle is correct, otherwise false.
29 public abstract boolean check();
31 /**
32 * Increment the counter of played times.
34 * @return the counter.
36 protected int incrementCounter() {
37 return --counter;
40 /**
41 * Decrement the counter of played times.
43 * @return the counter.
45 protected int decrementCounter() {
46 return --counter;
49 /**
50 * Set the counter value.
52 * @param counter
54 protected void setCounter(int counter) {
55 this.counter = counter;
58 protected void reintialiseCounter() {
59 this.counter = 0;
62 /**
63 * Getter.
65 * @return the size of the puzzle.
67 public final int getSize() {
68 return size;
71 /**
72 * Getter.
74 * @return the number of the played times.
76 public final int getCounter() {
77 return counter;
80 /**
81 * Getter.
83 * @return the difficulty of the puzzle.
85 public final Difficulty getDifficulty() {
86 return difficulty;
90 * (non-Javadoc)
92 * @see java.lang.Object#hashCode()
94 @Override
95 public int hashCode() {
96 final int prime = 31;
97 int result = 1;
98 result = prime * result + counter;
99 result = prime * result
100 + ((difficulty == null) ? 0 : difficulty.hashCode());
101 result = prime * result + size;
102 return result;
106 * (non-Javadoc)
108 * @see java.lang.Object#toString()
110 @Override
111 public String toString() {
112 return "AbstractPuzzle [size=" + size + ", counter=" + counter
113 + ", difficulty=" + difficulty + "]";
117 * (non-Javadoc)
119 * @see java.lang.Object#equals(java.lang.Object)
121 @Override
122 public boolean equals(Object obj) {
123 if (this == obj) {
124 return true;
126 if (obj == null) {
127 return false;
129 if (getClass() != obj.getClass()) {
130 return false;
132 AbstractPuzzle other = (AbstractPuzzle) obj;
133 if (counter != other.counter) {
134 return false;
136 if (difficulty != other.difficulty) {
137 return false;
139 if (size != other.size) {
140 return false;
142 return true;