Skip to content

Commit

Permalink
#0000 building blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
HDouss committed Dec 21, 2023
1 parent 01e9d76 commit 8390cc4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target/
.classpath
.project
/.settings/*
57 changes: 57 additions & 0 deletions src/main/java/learnmind/state/Code.java
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;
}
}

0 comments on commit 8390cc4

Please sign in to comment.