Skip to content
Snippets Groups Projects
Commit bc3c9794 authored by ACIKBAS TUNA's avatar ACIKBAS TUNA
Browse files

Imaginary Pieces with mouvement finished

parent e2ac73d6
1 merge request!6Imaginary Pieces with mouvement finished
package model;
import java.util.ArrayList;
public class Giant extends Piece{
protected Giant(Position p, int color) {
super(p, color);
}
@Override
public ArrayList<Position> getAvailableMoves(Board b) {
ArrayList<Position> moves = new ArrayList<Position>();
Position arrival;
int i = 1;
boolean left = false;
boolean right = false;
boolean top = false;
boolean down = false;
while (i < 4) {
//left
arrival = new Position(p.getX() + (i*2), p.getY());
if (Position.isCorrect(arrival)) {
if (!left) {
if (b.isEnnemy(arrival, p) || b.isFree(arrival)) {
moves.add(arrival);
}
if (b.isKing(arrival)) {
moves.add(arrival);
}
}
if (!b.isFree(arrival)) {
left = true;
}
}
//right
arrival = new Position(p.getX() - (i*2), p.getY());
if (Position.isCorrect(arrival)) {
if (!right) {
if (b.isEnnemy(arrival, p) || b.isFree(arrival)) {
moves.add(arrival);
}
if (b.isKing(arrival)) {
moves.add(arrival);
}
}
if (!b.isFree(arrival)) {
right = true;
}
}
arrival = new Position(p.getX(), p.getY() + (i*2));
if (Position.isCorrect(arrival)) {
if (!top) {
if (b.isEnnemy(arrival, p)|| b.isFree(arrival)) {
moves.add(arrival);
}
}
if (!b.isFree(arrival)) {
top = true;
}
}
arrival = new Position(p.getX(), p.getY() - (i*2));
if (Position.isCorrect(arrival)) {
if (!down) {
if (b.isEnnemy(arrival, p)|| b.isFree(arrival)) {
moves.add(arrival);
}
}
if (!b.isFree(arrival)) {
top = true;
}
}
i++;
}
return moves;
}
}
package model;
import java.util.ArrayList;
public class Kamikaze extends Pawn {
public Kamikaze(Position p, int color) {
super(p, color);
}
@Override
public ArrayList<Position> getAvailableMoves(Board b) {
ArrayList<Position> moves = new ArrayList<Position>();
Position arrival;
// Self-Detonation Position no need for checks as the Kamikaze is already in place
arrival = new Position(p.getX(),p.getY());
moves.add(arrival);
if(color == Piece.WHITE) { // black and white have an opposite direction behavior
if(this.p.getID() == this.original.getID()){
arrival = new Position(p.getX(),p.getY()+2);
if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);}
}
arrival = new Position(p.getX(),p.getY()+1);
if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);}
}
else {
if(this.p.getID() == this.original.getID()){
arrival = new Position(p.getX(),p.getY()-2);
if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);}
}
arrival = new Position(p.getX(),p.getY()-1);
if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);}
}
return moves;
}
}
package model;
import java.util.ArrayList;
public class Magician extends Piece{
private Piece CopiedPiece;
protected Magician(Position p, int color) {
super(p, color);
}
public void setCopiedPiece(Piece copiedPiece) {
this.CopiedPiece = copiedPiece;
}
public void setPosition(Position p) {
this.p = p;
CopiedPiece.setPosition(p);
}
}
package model;
import java.util.ArrayList;
public class Nwap extends Pawn {
public Nwap(Position p, int color) {
super(p, color);
}
@Override
public ArrayList<Position> getAvailableMoves(Board b) {
ArrayList<Position> moves = new ArrayList<Position>();
Position arrival;
if(color == Piece.WHITE) { // black and white have an opposite direction behavior
if(this.p.getID() == this.original.getID()){
// up left 2
arrival = new Position(p.getX()-2, p.getY() +2);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
// up left 2
arrival = new Position(p.getX()+2, p.getY() +2);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
}
// up left 1
arrival = new Position(p.getX()-1, p.getY() +1);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
// up left 1
arrival = new Position(p.getX()+1, p.getY() +1);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
arrival = new Position(p.getX(),p.getY()+1);
if(b.isEnnemy(arrival,p)) {moves.add(arrival);}
}
else {
if(this.p.getID() == this.original.getID()){
// up left 2
arrival = new Position(p.getX()-2, p.getY() -2);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
// up left 2
arrival = new Position(p.getX()+2, p.getY() -2);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
}
// up left 1
arrival = new Position(p.getX()-1, p.getY() -1);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
// up left 1
arrival = new Position(p.getX()+1, p.getY() -1);
if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); }
arrival = new Position(p.getX(),p.getY()-1);
if(b.isEnnemy(arrival,p)) {moves.add(arrival);}
}
return moves;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment