Nick Stolbov
3 years ago
2 changed files with 98 additions and 0 deletions
@ -0,0 +1,64 @@ |
|||
package Game.ChessObj; |
|||
|
|||
public class ChessFigure { |
|||
|
|||
public enum Type { |
|||
KING, |
|||
QUEEN, |
|||
CASTLE, |
|||
BISHOP, |
|||
KNIGHT, |
|||
PAWN |
|||
} |
|||
|
|||
public enum Team { |
|||
WHITE, |
|||
BLACK |
|||
} |
|||
|
|||
private final Type type; |
|||
private final Team team; |
|||
|
|||
public ChessFigure(Type type, Team team) { |
|||
this.type = type; |
|||
this.team = team; |
|||
} |
|||
|
|||
public Type getType() { |
|||
return this.type; |
|||
} |
|||
|
|||
public Team getTeam() { |
|||
return this.team; |
|||
} |
|||
|
|||
public String getSymbol() { |
|||
String symbol = ""; |
|||
switch(getType()) { |
|||
case KING: |
|||
symbol = "K"; |
|||
break; |
|||
case QUEEN: |
|||
symbol = "Q"; |
|||
break; |
|||
case CASTLE: |
|||
symbol = "T"; |
|||
break; |
|||
case BISHOP: |
|||
symbol = "I"; |
|||
break; |
|||
case KNIGHT: |
|||
symbol = "Z"; |
|||
break; |
|||
case PAWN: |
|||
symbol = "o"; |
|||
break; |
|||
default: |
|||
} |
|||
|
|||
symbol = ((this.getTeam()==Team.WHITE)?" ":"|") + symbol + ((this.getTeam()==Team.WHITE)?" ":"|"); |
|||
|
|||
return symbol; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package Game.ChessObj; |
|||
|
|||
import org.junit.jupiter.api.AfterEach; |
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
class ChessFigureTest { |
|||
|
|||
@BeforeEach |
|||
void setUp() { |
|||
} |
|||
|
|||
@AfterEach |
|||
void tearDown() { |
|||
} |
|||
|
|||
@Test |
|||
void getSymbol() { |
|||
assertEquals(" K ", new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.WHITE).getSymbol()); |
|||
assertEquals(" Q ", new ChessFigure(ChessFigure.Type.QUEEN, ChessFigure.Team.WHITE).getSymbol()); |
|||
assertEquals(" I ", new ChessFigure(ChessFigure.Type.BISHOP, ChessFigure.Team.WHITE).getSymbol()); |
|||
assertEquals(" T ", new ChessFigure(ChessFigure.Type.CASTLE, ChessFigure.Team.WHITE).getSymbol()); |
|||
assertEquals(" Z ", new ChessFigure(ChessFigure.Type.KNIGHT, ChessFigure.Team.WHITE).getSymbol()); |
|||
assertEquals(" o ", new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE).getSymbol()); |
|||
assertEquals("|K|", new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.BLACK).getSymbol()); |
|||
assertEquals("|Q|", new ChessFigure(ChessFigure.Type.QUEEN, ChessFigure.Team.BLACK).getSymbol()); |
|||
assertEquals("|I|", new ChessFigure(ChessFigure.Type.BISHOP, ChessFigure.Team.BLACK).getSymbol()); |
|||
assertEquals("|T|", new ChessFigure(ChessFigure.Type.CASTLE, ChessFigure.Team.BLACK).getSymbol()); |
|||
assertEquals("|Z|", new ChessFigure(ChessFigure.Type.KNIGHT, ChessFigure.Team.BLACK).getSymbol()); |
|||
assertEquals("|o|", new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK).getSymbol()); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue