Commit e27c92e5 by Paktalin

Substituted interface with one class

parent 1263e172
package com.example.paktalin.agilejava_exercises;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by Paktalin on 26/05/2018.
*/
class BlackSide implements Side {
private List<Piece> pieces = new ArrayList<>();
@Override
public List<Piece> getPieces() {
return pieces;
}
@Override
public double getStrength() {
double strength = 0.0;
for (Piece piece : pieces)
strength += piece.getStrength();
return strength;
}
@Override
public int getPiecesCount() {
return pieces.size();
}
@Override
public int getPiecesCount(Piece.Type type) {
int count = 0;
for (Piece piece : pieces)
if (piece.isType(type))
count++;
return count;
}
@Override
public void addPiece(Piece piece) {
pieces.add(piece);
Collections.sort(pieces);
}
}
......@@ -15,8 +15,8 @@ class Board {
private Piece[][] pieces = new Piece[ROW_COUNT][COLUMN_COUNT];
private WhiteSide whiteSide = new WhiteSide();
private BlackSide blackSide = new BlackSide();
private Side whiteSide = new Side();
private Side blackSide = new Side();
private Board() {}
......
package com.example.paktalin.agilejava_exercises;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by Paktalin on 26/05/2018.
* Created by Paktalin on 27/05/2018.
*/
interface Side {
class Side {
private List<Piece> pieces = new ArrayList<>();
List<Piece> getPieces();
double getStrength();
int getPiecesCount();
int getPiecesCount(Piece.Type type);
void addPiece(Piece piece);
public List<Piece> getPieces() {
return pieces;
}
public double getStrength() {
double strength = 0.0;
for (Piece piece : pieces)
strength += piece.getStrength();
return strength;
}
public int getPiecesCount() {
return pieces.size();
}
public int getPiecesCount(Piece.Type type) {
int count = 0;
for (Piece piece : pieces)
if (piece.isType(type))
count++;
return count;
}
public void addPiece(Piece piece) {
pieces.add(piece);
Collections.sort(pieces);
}
}
package com.example.paktalin.agilejava_exercises;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by Paktalin on 26/05/2018.
*/
public class WhiteSide implements Side {
private List<Piece> pieces = new ArrayList<>();
@Override
public List<Piece> getPieces() {
return pieces;
}
@Override
public double getStrength() {
double strength = 0.0;
for (Piece piece : pieces)
strength += piece.getStrength();
return strength;
}
@Override
public int getPiecesCount() {
return pieces.size();
}
@Override
public int getPiecesCount(Piece.Type type) {
int count = 0;
for (Piece piece : pieces)
if (piece.isType(type))
count++;
return count;
}
@Override
public void addPiece(Piece piece) {
pieces.add(piece);
Collections.sort(pieces);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment