# Sprint #2
- When the board is clicked, the coordinates are passed to the back end every time
- Front end doesn't know what game it is playing or where the pieces are
## Data Files
### Part of Pawn File
```xml=
<FiniteSlide>
<changeX>0</changeX>
<changeY>2</changeY>
<mustTake>False</mustTake>
<takeX>null</takeX>
<takeY>null</takeY>
<restrictions>
<PawnFirstMove></PawnFirstMove>
</restrictions>
</FiniteSlide>
```
### chess.xml file
```xml=
<rules rules="chess">
<turnConditions>
<condition>NoHeldPiece</condition>
</turnConditions>
</rules>
```
### `WelcomeScene` Properties File
```
sceneType = WelcomeScene
width = 500
height = 500
CSS = DefaultStyle.css
title-text = Welcome to BrainMate!
goButton = Start
```
### `WelcomeScene` CSS File
```css=
.title {
-fx-border-color: #000000;
-fx-background-image: url("WelcomeBackground.jpg");
-fx-background-color: #000000;
-fx-background-radius: 5.0;
-fx-padding: 8;
-fx-background-size: 500,300;
-fx-background-repeat: no-repeat;
-fx-font-size: 25pt;
-fx-font-family: "Silom";
-fx-text-fill: #000000;
-fx-font-weight: bold;
-fx-text-alignment: center;
```
## Java Files
### TurnConditions Parts
### `TurnCondition` example class
```java=
public class NoHeldPieceTurnCondition implements TurnCondition{
@Override
public TurnConditionResult isTurnOver(GameBoard gameBoard, GamePiece gamePiece) {
if(gameBoard.getIsHeldPiece()){
return TurnConditionResult.STAY;
}
return TurnConditionResult.SWITCH;
}
```
### `GameEngine` Turn implementation
```java=
public void runTurn(int x, int y){
if(currentPlayerTurn == null){
System.err.println("No player turn set");
return;
}
if(isStartOfTurn){
startPlayerTimer(currentPlayerTurn);
}
if(!actOnCoordinates(x, y)){
return;
}
boolean isTurnOver = curRules.checkForNextTurn(curBoard, curBoard.getPieceAtCoordinate(new Coordinate(x, y)));
if(isTurnOver){
stopPlayerTimer(currentPlayerTurn);
swapTurn();
isStartOfTurn = true;
} else {
isStartOfTurn = false;
}
}
```
### Associated JUnit Test:
```java=
gameEngine.runTurn(3,1);
assertEquals(player1, gameEngine.getCurrentPlayerTurn());
gameEngine.runTurn(4,4);
//printBoard();
assertEquals(player1, gameEngine.getCurrentPlayerTurn());
gameEngine.runTurn(4,1);
assertEquals(player1, gameEngine.getCurrentPlayerTurn());
gameEngine.runTurn(4,2);
//printBoard();
assertEquals(player2, gameEngine.getCurrentPlayerTurn());
```
### Checking for Check
```java=
public boolean opponentInCheck(GameBoard board, String currentPlayer) {
Coordinate kingLocation = board.findKing(getOppositePlayer(currentPlayer));
for (GamePiece piece : getPiecesByTeam(board, currentPlayer).values()) {
for (Coordinate coord : piece.determineAllLegalMoves()) {
return (coord == kingLocation);
}
}
return false;
}
```
### Pawn First Movement
```java=
public boolean checkRestriction(Coordinate endingCoordinates) {
if(piece.getLocationHistory().size() == 1){
return true;
}
return false;
}
```
### Associated JUnit Test
```java=
@Test
void testPawnFirstMoveRestriction(){
print("testPawnFirstMoveRestriction");
//Click pawn to get moves
actOnCoordinates(0,1);
testActualExpectedCoordinates("0:2 0:3");
//Move pawn
actOnCoordinates(0,2);
//Click pawn again to get moves
actOnCoordinates(0,2);
testActualExpectedCoordinates("0:3");
}
```
### `GameScene` Creation Method
```java=
public GameScene makeScene(ResourceBundle resources,
EventHandler<ActionEvent> handler) {
this.handler = handler;
Parent root = new GridPane();
String sceneType = resources.getString("sceneType");
GameScene myScene = null;
try {
myScene = (GameScene) this.getClass()
.getDeclaredMethod("make" + sceneType, Parent.class, ResourceBundle.class)
.invoke(this, new Object[]{root, resources});
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();# will remove
}
return myScene;
}
```
### Notable Parts Tile Class
```java
public Tile extends Parent {
private Point myPosition;
private ImageView myPieceImage;
private EventHandler myEventHandler;
private Rectangle rec;
private static final Color HIGHLIGHT_COLOR = Color.LIGHTGREEN;
private final Color DEFAULT_COLOR;
public Tile(Color fill, int size, Point position, EventHandler<MouseEvent> e) {
super();
DEFAULT_COLOR = fill;
rec = new Rectangle(size, size, DEFAULT_COLOR);
myEventHandler = e;
rec.setOnMouseClicked(myEventHandler);
this.getChildren().add(rec);
myPosition = position;
hasPiece = false;
}
public ImageView getPiece(){
return myPieceImage;
}
public void addPiece(ImageView piece) {
piece.setOnMouseClicked(myEventHandler);
this.getChildren().add(piece);
hasPiece = true;
myPieceImage = piece;
}
public void removePiece() {
this.getChildren().remove(myPieceImage);//does this work
hasPiece = false;
myPieceImage = null;
}
}
```
### Method in Board where Tiles are made
```java=
private Tile createTile(int i, int j, Color color){
return new Tile(color, SQUARE_SIZE, new Point(i, j), e -> handleTileClick(i, j));
}
```
## Next Sprint Plans/This sprint completion
- We did most of what we set out to do
- Didn't quite finish chess, but we only have a couple small things to finish up
- pieces move successfully
- still need to finish other chess features such as clock
- check/checkmate are close, but still in testing
- For the next sprint the priorities are:
- Tying up the loose ends
- Implementing checkers (which is much simpler than chess, and we already have the code infastructure)
- AI
## Significant Events
- Positive
- Came to a good consensus on how to pass coordinates to the back end
- Debated for a while on how exactly to do it but ultimately decided that the back end gets the coordinates every time the board is clicked
- Negative
- Missed the deadline to move pieces, so it was hard to test for a while
## Teamwork
- Slack messages worked well
- Mini timelines and due dates were missed but still kept on track
- Team meetings were useful to get on same page and prepare this presentation
- Pair progamming useful to complete code together and more efficiently
- When something was high priority ensured that two people could still both contribute
- Teamwork Improvement
- More specifically, we were able to get the backend sections all linked together and working coopertively.
- Were able to effectively communicate API design in order to ensure the front/back end were on the same page
- Planning to more effectively communicate top priorities, because the end of the project is nearing
## Features For Final
- Casey and Cole: Finish up a few of the chess loose ends, checkers, and player files
- Shaw: Work on our AI, get checkers and othello up and running
- Yi and Kenny:
- Yi:
- Create a menubar
- Add multi window option
- Allow users to change the view theme
- Possibly animate piece movement
- Kenny
- Tile class and Board class
- board pieces read in from file
- different colors for chess board
- different pieces
- make sure checkers works