Commit c6186266 authored by 9731301's avatar 9731301

Add Cell Class and Block Class

parents
Pipeline #3250 failed with stages
import java.util.ArrayList;
public class Block {
private ArrayList<Cell> allCells;
private int number;
private String turn;
public Block(){
allCells = new ArrayList<>();
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public void createCells(){
Cell cell = new Cell();
for (int i = 0 ; i < 9 ; i++ ){
cell.setNumber(i);;
cell.setColor('O');
allCells.add(cell);
}
}
public void changePositionOfBlock(String turn){
Cell transporterCell;
if ( turn.equals("right")){
allCells.add(2,allCells.get(0));
allCells.remove(0);
allCells.add(0,allCells.get(2));
allCells.remove(3);
allCells.add(5,allCells.get(1));
allCells.remove(1);
allCells.add(1,allCells.get(5));
allCells.remove(6);
allCells.add(8,allCells.get(0));
allCells.remove(8);
allCells.add(0,allCells.get(8));
allCells.remove(9);
allCells.add(3,allCells.get(1));
allCells.remove(1);
allCells.add(1,allCells.get(3));
allCells.remove(4);
allCells.add(6,allCells.get(0));
allCells.remove(0);
allCells.add(0,allCells.get(6));
allCells.remove(7);
allCells.add(7,allCells.get(3));
allCells.remove(3);
allCells.add(3,allCells.get(7));
allCells.remove(8);
}
else if ( turn.equals("left")){
turn = "right";
changePositionOfBlock(turn);
changePositionOfBlock(turn);
changePositionOfBlock(turn);
}
else {
System.out.println("this position doesn't exist");
}
}
public ArrayList<Cell> getAllCells() {
return allCells;
}
}
public class Cell {
private Character color ;
private int number ;
public Cell(){
color = 'O';
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public Character getColor() {
return color;
}
public void setColor(Character color) {
this.color = color;
}
}
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 to comment