Sliding puzzle works fine, but it need some addings, Other puzzles will
[puzzles.git] / src / com / github / puzzles / core / AbstractPuzzle.java
blob5fc427929b8096d5131244657382d6b97f81fcd4
1 /**
2 * All puzzles must inherit this class.
3 */
5 package com.github.puzzles.core;
7 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 /**
19 * Check to see if the puzzle is correct or not.
20 * @return true if the puzzle is correct, otherwise false.
22 public abstract boolean check();
24 /**
25 * Increment the counter of played times.
26 * @return the counter.
28 protected int incrementCounter(){
29 setCounter(++counter);
30 return counter;
33 /**
34 * Decrement the counter of played times.
35 * @return the counter.
37 protected int decrementCounter(){
38 setCounter(--counter);
39 return counter;
42 /**
43 * Set the counter value.
44 * @param counter
46 protected void setCounter(int counter){
47 this.counter = counter;
50 /**
51 * Getter.
52 * @return the size of the puzzle.
54 public final int getSize() {
55 return size;
58 /**
59 * Getter.
60 * @return the number of the played times.
62 public final int getCounter() {
63 return counter;
66 /**
67 * Getter.
68 * @return the difficulty of the puzzle.
70 public final Difficulty getDifficulty() {
71 return difficulty;
74 /* (non-Javadoc)
75 * @see java.lang.Object#hashCode()
77 @Override
78 public int hashCode() {
79 final int prime = 31;
80 int result = 1;
81 result = prime * result + counter;
82 result = prime * result
83 + ((difficulty == null) ? 0 : difficulty.hashCode());
84 result = prime * result + size;
85 return result;
88 /* (non-Javadoc)
89 * @see java.lang.Object#equals(java.lang.Object)
91 @Override
92 public boolean equals(Object obj) {
93 if (this == obj)
94 return true;
95 if (obj == null)
96 return false;
97 if (getClass() != obj.getClass())
98 return false;
99 AbstractPuzzle other = (AbstractPuzzle) obj;
100 if (counter != other.counter)
101 return false;
102 if (difficulty != other.difficulty)
103 return false;
104 if (size != other.size)
105 return false;
106 return true;