-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target/ | ||
.classpath | ||
.project | ||
/.settings/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package learnmind.state; | ||
|
||
/** | ||
* A code is a set of 4 ordered digits to be placed in the mastermind board. | ||
* This class represents the code to be broken as well as the guesses made by the player. | ||
* @author hdouss | ||
* | ||
*/ | ||
public class Code { | ||
|
||
/** | ||
* Numerical representation of the code. | ||
*/ | ||
private final int num; | ||
|
||
/** | ||
* Code constructor. Arguments are ordered from leftmost digit to the rightmost digit | ||
* to be placed in the board. | ||
* @param one First digit | ||
* @param two Second digit | ||
* @param three Third digit | ||
* @param four Fourth digit | ||
*/ | ||
public Code(final int one, final int two, final int three, final int four) { | ||
this.num = 1000 * one + 100 * two + 10 * three + four; | ||
} | ||
|
||
/** | ||
* Accessor for the numerical representation of the code. | ||
* @return A numerical representation of the code. | ||
*/ | ||
public int num() { | ||
return this.num; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + num; | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
Code other = (Code) obj; | ||
if (num != other.num) | ||
return false; | ||
return true; | ||
} | ||
} |