Commit 93b3ca67 authored by nargessalehi98's avatar nargessalehi98

Pre-final

parent bd314920
import java.util.ArrayList;
import java.util.Scanner;
/**
* provide game rules
* @author Narges Salehi
*/
public class GameRules {
//map of game
private Map map;
/**
* creat new game rules
*/
public GameRules() {
map = new Map();
}
/**
* check all the lines with wining condition for a player - check circles color
* @param Color of player
* @return true or false
*/
public boolean checkWinner(String Color) {
// count lines with wining condition
int counter = 0;
// check horizontal and vertical lines
counter += map.checkLine(0, 1, 2, 0, 1, map.getSquare(1), map.getSquare(2), Color);
counter += map.checkLine(2, 1, 0, 2, 1, map.getSquare(2), map.getSquare(1), Color);
counter += map.checkLine(3, 4, 5, 3, 4, map.getSquare(1), map.getSquare(2), Color);
counter += map.checkLine(5, 4, 3, 5, 4, map.getSquare(2), map.getSquare(1), Color);
counter += map.checkLine(6, 7, 8, 6, 7, map.getSquare(1), map.getSquare(2), Color);
counter += map.checkLine(8, 7, 6, 7, 8, map.getSquare(2), map.getSquare(1), Color);
counter += map.checkLine(0, 3, 6, 0, 3, map.getSquare(1), map.getSquare(3), Color);
counter += map.checkLine(6, 3, 0, 6, 3, map.getSquare(3), map.getSquare(1), Color);
counter += map.checkLine(1, 4, 7, 1, 4, map.getSquare(1), map.getSquare(3), Color);
counter += map.checkLine(7, 4, 1, 7, 4, map.getSquare(3), map.getSquare(1), Color);
counter += map.checkLine(2, 5, 8, 2, 5, map.getSquare(1), map.getSquare(3), Color);
counter += map.checkLine(8, 5, 2, 8, 5, map.getSquare(3), map.getSquare(1), Color);
counter += map.checkLine(0, 1, 2, 0, 1, map.getSquare(3), map.getSquare(4), Color);
counter += map.checkLine(2, 1, 0, 2, 1, map.getSquare(4), map.getSquare(3), Color);
counter += map.checkLine(3, 4, 5, 3, 4, map.getSquare(3), map.getSquare(4), Color);
counter += map.checkLine(5, 4, 3, 5, 4, map.getSquare(4), map.getSquare(3), Color);
counter += map.checkLine(6, 7, 8, 6, 7, map.getSquare(3), map.getSquare(4), Color);
counter += map.checkLine(8, 7, 6, 7, 8, map.getSquare(4), map.getSquare(3), Color);
counter += map.checkLine(0, 3, 6, 0, 3, map.getSquare(2), map.getSquare(4), Color);
counter += map.checkLine(6, 3, 0, 6, 3, map.getSquare(4), map.getSquare(2), Color);
counter += map.checkLine(1, 4, 7, 1, 4, map.getSquare(2), map.getSquare(4), Color);
counter += map.checkLine(7, 4, 1, 7, 4, map.getSquare(4), map.getSquare(2), Color);
counter += map.checkLine(2, 5, 8, 2, 5, map.getSquare(2), map.getSquare(4), Color);
counter += map.checkLine(8, 5, 2, 8, 5, map.getSquare(4), map.getSquare(2), Color);
counter += map.checkLine(2, 4, 6, 2, 4, map.getSquare(2), map.getSquare(3), Color);
counter += map.checkLine(6, 4, 2, 6, 4, map.getSquare(3), map.getSquare(2), Color);
counter += map.checkLine(0, 4, 8, 0, 4, map.getSquare(1), map.getSquare(4), Color);
counter += map.checkLine(8, 4, 0, 8, 4, map.getSquare(4), map.getSquare(1), Color);
// check diagonal lines
if (map.getSquare(2).get(1).equals(map.getSquare(2).get(3)) && map.getSquare(2).get(1).equals(map.getSquare(1).get(8)) &&
map.getSquare(2).get(1).equals(map.getSquare(3).get(1)) && map.getSquare(2).get(1).equals(map.getSquare(3).get(3))) {
if (map.getSquare(2).get(1).equals(Color))
counter += 1;
}
if (map.getSquare(2).get(5).equals(map.getSquare(2).get(7)) && map.getSquare(2).get(5).equals(map.getSquare(4).get(0)) &&
map.getSquare(2).get(5).equals(map.getSquare(3).get(5)) && map.getSquare(2).get(5).equals(map.getSquare(3).get(7))) {
if (map.getSquare(2).get(5).equals(Color))
counter += 1;
}
if (map.getSquare(1).get(1).equals(map.getSquare(1).get(5)) && map.getSquare(1).get(1).equals(map.getSquare(2).get(6)) &&
map.getSquare(1).get(1).equals(map.getSquare(4).get(1)) && map.getSquare(1).get(1).equals(map.getSquare(4).get(5))) {
if (map.getSquare(1).get(1).equals(Color))
counter += 1;
}
if (map.getSquare(1).get(3).equals(map.getSquare(1).get(7)) && map.getSquare(1).get(3).equals(map.getSquare(3).get(2)) &&
map.getSquare(1).get(3).equals(map.getSquare(4).get(3)) && map.getSquare(1).get(3).equals(map.getSquare(4).get(7))) {
if (map.getSquare(1).get(3).equals(Color))
counter += 1;
}
return counter > 0;
}
/**
* rotate given square with given direction
* @param numberOfSquare number of Array list
* @param direction of rotate
*/
public void rotateSquare(int numberOfSquare, String direction) {
//clockwise
if (direction.equals("C")) {
//creat a new array list
ArrayList<String> temp = new ArrayList<String>();
//add each circle of map after rotating in temp
temp.add(0, map.getSquare(numberOfSquare).get(6));
temp.add(1, map.getSquare(numberOfSquare).get(3));
temp.add(2, map.getSquare(numberOfSquare).get(0));
temp.add(3, map.getSquare(numberOfSquare).get(7));
temp.add(4, map.getSquare(numberOfSquare).get(4));
temp.add(5, map.getSquare(numberOfSquare).get(1));
temp.add(6, map.getSquare(numberOfSquare).get(8));
temp.add(7, map.getSquare(numberOfSquare).get(5));
temp.add(8, map.getSquare(numberOfSquare).get(2));
//set temp to given square
map.setSquare(temp, numberOfSquare);
}//non-clockwise
if (direction.equals("NC")) {
ArrayList<String> temp = new ArrayList<String>();
temp.add(0, map.getSquare(numberOfSquare).get(2));
temp.add(1, map.getSquare(numberOfSquare).get(5));
temp.add(2, map.getSquare(numberOfSquare).get(8));
temp.add(3, map.getSquare(numberOfSquare).get(1));
temp.add(4, map.getSquare(numberOfSquare).get(4));
temp.add(5, map.getSquare(numberOfSquare).get(7));
temp.add(6, map.getSquare(numberOfSquare).get(0));
temp.add(7, map.getSquare(numberOfSquare).get(3));
temp.add(8, map.getSquare(numberOfSquare).get(6));
map.setSquare(temp, numberOfSquare);
}
}
/**
* rotate square in map
*/
public void rotate() {
//check if there is an empty square skip rotating
if (map.isEmpty()) {
System.out.println("\nThere is at least one Empty Square ,You can Skip rotating by Entering skip else Enter anything :");
Scanner scanner1 = new Scanner(System.in);
String skip = scanner1.next();
if (!(skip.equals("skip"))) {
System.out.print("Enter number of square and rotate direction like 1 C :");
rotateCheck();
}
} else {
System.out.print("\nEnter number of square and rotate direction like 1 C :");
rotateCheck();
}
}
/**
* check direction and square number for rotating
*/
private void rotateCheck() {
Scanner scanner2 = new Scanner(System.in);
int square = scanner2.nextInt();
String dir = scanner2.next();
if (square == 1) {
rotateSquare(1, dir);
} else if (square == 2) {
rotateSquare(2, dir);
} else if (square == 3) {
rotateSquare(3, dir);
} else if (square == 4) {
rotateSquare(4, dir);
}
}
/**
* put disk in map for player with given color
* @param Color of player
*/
public void putDisk(String Color) {
System.out.println("\nEnter the number of square and circle :");
Scanner scanner = new Scanner(System.in);
int square = scanner.nextInt();
int circle = scanner.nextInt();
if (square > 4 || square < 1 || circle > 9 || circle < 1)
putDisk(Color);
else {
if (square == 1) {
if (map.getSquare(1).get(circle - 1).equals(" ⚪ ")) {
map.getSquare(1).remove(circle - 1);
map.getSquare(1).add(circle - 1, Color);
} else {
System.out.println("Already taken");
putDisk(Color);
}
}
if (square == 2) {
if (map.getSquare(2).get(circle - 1).equals(" ⚪ ")) {
map.getSquare(2).remove(circle - 1);
map.getSquare(2).add(circle - 1, Color);
} else {
System.out.println("Already taken");
putDisk(Color);
}
}
if (square == 3) {
if (map.getSquare(3).get(circle - 1).equals(" ⚪ ")) {
map.getSquare(3).remove(circle - 1);
map.getSquare(3).add(circle - 1, Color);
} else {
System.out.println("Already taken");
putDisk(Color);
}
}
if (square == 4) {
if (map.getSquare(4).get(circle - 1).equals(" ⚪ ")) {
map.getSquare(4).remove(circle - 1);
map.getSquare(4).add(circle - 1, Color);
} else {
System.out.println("Already taken");
putDisk(Color);
}
}
}
}
/**
* print map after applying rules
*/
public void print() {
map.print();
}
}
import java.util.Random; import java.util.Random;
/**
* run whole game
*
* @author Narges Salehi
*/
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
//creat a random number to set random color for player
Random random = new Random(); Random random = new Random();
int rand = random.nextInt(2); int rand = random.nextInt(2);
//color of player
String red = " 🔴 "; String red = " 🔴 ";
String black = " ⚫ "; String black = " ⚫ ";
Map map = new Map(); //creat a new game
map.print(); GameRules game = new GameRules();
game.print();
if (rand == 0) { if (rand == 0) {
//start game
while (true) { while (true) {
map.putDisk(red); game.putDisk(red);
map.print(); game.print();
if (map.checkWinner(red)) { //check wining condition
if (game.checkWinner(red)) {
System.out.println("\nRed is winner !"); System.out.println("\nRed is winner !");
break; break;
} }
map.rotate(); //rotate
map.print(); game.rotate();
if (map.checkWinner(red) && map.checkWinner(black)) { game.print();
//check wining condition
if (game.checkWinner(red) && game.checkWinner(black)) {
System.out.println("\nequal!"); System.out.println("\nequal!");
break; break;
}else if(map.checkWinner(red)){ } else if (game.checkWinner(red)) {
System.out.println("\nRed is winner !"); System.out.println("\nRed is winner !");
break; break;
} } else if (game.checkWinner(black)) {
else if(map.checkWinner(black)){
System.out.println("\nblack is winner !"); System.out.println("\nblack is winner !");
break; break;
} }
map.putDisk(black); //same for next player
map.print(); game.putDisk(black);
if (map.checkWinner(black)) { game.print();
if (game.checkWinner(black)) {
System.out.println("\nblack is winner !"); System.out.println("\nblack is winner !");
break; break;
} }
map.rotate(); game.rotate();
map.print(); game.print();
if (map.checkWinner(red) && map.checkWinner(black)) { if (game.checkWinner(red) && game.checkWinner(black)) {
System.out.println("\nequal!"); System.out.println("\nequal!");
break; break;
}else if(map.checkWinner(red)){ } else if (game.checkWinner(red)) {
System.out.println("\nRed is winner !"); System.out.println("\nRed is winner !");
break; break;
} } else if (game.checkWinner(black)) {
else if(map.checkWinner(black)){
System.out.println("\nblack is winner !"); System.out.println("\nblack is winner !");
break; break;
} }
...@@ -53,41 +64,39 @@ public class Main { ...@@ -53,41 +64,39 @@ public class Main {
} }
} else { } else {
while (true) { while (true) {
map.putDisk(black); game.putDisk(black);
map.print(); game.print();
if (map.checkWinner(black)) { if (game.checkWinner(black)) {
System.out.println("\nblack is winner !"); System.out.println("\nblack is winner !");
break; break;
} }
map.rotate(); game.rotate();
map.print(); game.print();
if (map.checkWinner(red) && map.checkWinner(black)) { if (game.checkWinner(red) && game.checkWinner(black)) {
System.out.println("\nequal!"); System.out.println("\nequal!");
break; break;
}else if(map.checkWinner(red)){ } else if (game.checkWinner(red)) {
System.out.println("\nRed is winner !"); System.out.println("\nRed is winner !");
break; break;
} } else if (game.checkWinner(black)) {
else if(map.checkWinner(black)){
System.out.println("\nblack is winner !"); System.out.println("\nblack is winner !");
break; break;
} }
map.putDisk(red); game.putDisk(red);
map.print(); game.print();
if (map.checkWinner(red)) { if (game.checkWinner(red)) {
System.out.println("\nRed is winner !"); System.out.println("\nRed is winner !");
break; break;
} }
map.rotate(); game.rotate();
map.print(); game.print();
if (map.checkWinner(red) && map.checkWinner(black)) { if (game.checkWinner(red) && game.checkWinner(black)) {
System.out.println("\nequal!"); System.out.println("\nequal!");
break; break;
}else if(map.checkWinner(red)){ } else if (game.checkWinner(red)) {
System.out.println("\nRed is winner !"); System.out.println("\nRed is winner !");
break; break;
} } else if (game.checkWinner(black)) {
else if(map.checkWinner(black)){
System.out.println("\nblack is winner !"); System.out.println("\nblack is winner !");
break; break;
} }
......
import javax.swing.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner;
/**
* this class provide map info and applications - board game
*
* @author Narges Salehi
*/
public class Map { public class Map {
//4 Array list for each square of board game
private ArrayList<String> square1; private ArrayList<String> square1;
private ArrayList<String> square2; private ArrayList<String> square2;
private ArrayList<String> square3; private ArrayList<String> square3;
private ArrayList<String> square4; private ArrayList<String> square4;
String red = " 🔴 ";
String black = " ⚫ ";
/**
* creat a new map for board game
*/
public Map() { public Map() {
//defining map with empty value
square1 = new ArrayList<>(); square1 = new ArrayList<>();
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
square1.add(" ⚪ "); square1.add(" ⚪ ");
...@@ -30,8 +36,22 @@ public class Map { ...@@ -30,8 +36,22 @@ public class Map {
} }
public int checkLine(int main, int a, int b, int c, int d, ArrayList one, ArrayList two, String Color) { /**
* check given line of map that allows player to win - provide game wining rule
* @param main start point of line
* @param a next disk on the line
* @param b next disk on the line
* @param c next disk on the line
* @param d next disk on the line
* @param one a square that contains start point of line
* @param two a square that contains finish point of line
* @param Color color of player
* @return number of line with given condition of wining
*/
public int checkLine(int main, int a, int b, int c, int d, ArrayList<String> one, ArrayList<String> two, String Color) {
//count to one if the line has the condition of wining
int counter = 0; int counter = 0;
//check color of 5 disk in line
if (one.get(main).equals(one.get(a)) && one.get(main).equals(one.get(b)) && one.get(main).equals(two.get(c)) if (one.get(main).equals(one.get(a)) && one.get(main).equals(one.get(b)) && one.get(main).equals(two.get(c))
&& one.get(main).equals(two.get(d))) { && one.get(main).equals(two.get(d))) {
if (one.get(main).equals(Color)) if (one.get(main).equals(Color))
...@@ -40,231 +60,91 @@ public class Map { ...@@ -40,231 +60,91 @@ public class Map {
return counter; return counter;
} }
public boolean checkWinner(String Color) {
int counter = 0;
counter += checkLine(0, 1, 2, 0, 1, square1, square2, Color);
counter += checkLine(2, 1, 0, 2, 1, square2, square1, Color);
counter += checkLine(3, 4, 5, 3, 4, square1, square2, Color);
counter += checkLine(5, 4, 3, 5, 4, square2, square1, Color);
counter += checkLine(6, 7, 8, 6, 7, square1, square2, Color);
counter += checkLine(8, 7, 6, 7, 8, square2, square1, Color);
counter += checkLine(0, 3, 6, 0, 3, square1, square3, Color);
counter += checkLine(6, 3, 0, 6, 3, square3, square1, Color);
counter += checkLine(1, 4, 7, 1, 4, square1, square3, Color);
counter += checkLine(7, 4, 1, 7, 4, square3, square1, Color);
counter += checkLine(2, 5, 8, 2, 5, square1, square3, Color);
counter += checkLine(8, 5, 2, 8, 5, square3, square1, Color);
counter += checkLine(0, 1, 2, 0, 1, square3, square4, Color);
counter += checkLine(2, 1, 0, 2, 1, square4, square3, Color);
counter += checkLine(3, 4, 5, 3, 4, square3, square4, Color);
counter += checkLine(5, 4, 3, 5, 4, square4, square3, Color);
counter += checkLine(6, 7, 8, 6, 7, square3, square4, Color);
counter += checkLine(8, 7, 6, 7, 8, square4, square3, Color);
counter += checkLine(0, 3, 6, 0, 3, square2, square4, Color); /**
counter += checkLine(6, 3, 0, 6, 3, square4, square2, Color); * return square with given number
counter += checkLine(1, 4, 7, 1, 4, square2, square4, Color); * @param num of square
counter += checkLine(7, 4, 1, 7, 4, square4, square2, Color); * @return Array list
counter += checkLine(2, 5, 8, 2, 5, square2, square4, Color); */
counter += checkLine(8, 5, 2, 8, 5, square4, square2, Color); public ArrayList<String> getSquare(int num) {
if (num == 1)
counter += checkLine(2, 4, 6, 2, 4, square2, square3, Color); return square1;
counter += checkLine(6, 4, 2, 6, 4, square3, square2, Color); if (num == 2)
counter += checkLine(0, 4, 8, 0, 4, square1, square4, Color); return square2;
counter += checkLine(8, 4, 0, 8, 4, square4, square1, Color); if (num == 3)
return square3;
if (square2.get(1).equals(square2.get(3)) && square2.get(1).equals(square1.get(8)) && if (num == 4)
square2.get(1).equals(square3.get(1)) && square2.get(1).equals(square3.get(3))) { return square4;
if (square2.get(1).equals(Color)) else
counter += 1; return null;
}
if (square2.get(5).equals(square2.get(7)) && square2.get(5).equals(square4.get(0)) &&
square2.get(5).equals(square3.get(5)) && square2.get(5).equals(square3.get(7))) {
if (square2.get(5).equals(Color))
counter += 1;
}
if (square1.get(1).equals(square1.get(5)) && square1.get(1).equals(square2.get(6)) &&
square1.get(1).equals(square4.get(1)) && square1.get(1).equals(square4.get(5))) {
if (square1.get(1).equals(Color))
counter += 1;
}
if (square1.get(3).equals(square1.get(7)) && square1.get(3).equals(square3.get(2)) &&
square1.get(3).equals(square4.get(3)) && square1.get(3).equals(square4.get(7))) {
if (square1.get(3).equals(Color))
counter += 1;
}
return counter > 0;
} }
public void rotate() { /**
System.out.println("\nEnter number of square and rotate direction like 1 C :"); * set given Array list to given square
Scanner scanner1 = new Scanner(System.in); * @param temp given array list
int square = scanner1.nextInt(); * @param num of square
String dir = scanner1.next(); */
if (square == 1) { public void setSquare(ArrayList<String> temp, int num) {
if (dir.equals("C")) { if (num == 1)
ArrayList<String> temp = new ArrayList(); square1 = temp;
temp.add(0, square1.get(6)); if (num == 2)
temp.add(1, square1.get(3)); square2 = temp;
temp.add(2, square1.get(0)); if (num == 3)
temp.add(3, square1.get(7)); square3 = temp;
temp.add(4, square1.get(4)); if (num == 4)
temp.add(5, square1.get(1)); square4 = temp;
temp.add(6, square1.get(8));
temp.add(7, square1.get(5));
temp.add(8, square1.get(2));
square1 = temp;
}
if (dir.equals("NC")) {
ArrayList<String> temp = new ArrayList();
temp.add(0, square1.get(2));
temp.add(1, square1.get(5));
temp.add(2, square1.get(8));
temp.add(3, square1.get(1));
temp.add(4, square1.get(4));
temp.add(5, square1.get(7));
temp.add(6, square1.get(0));
temp.add(7, square1.get(3));
temp.add(8, square1.get(6));
square1 = temp;
}
} else if (square == 2) {
if (dir.equals("C")) {
ArrayList<String> temp = new ArrayList();
temp.add(0, square2.get(6));
temp.add(1, square2.get(3));
temp.add(2, square2.get(0));
temp.add(3, square2.get(7));
temp.add(4, square2.get(4));
temp.add(5, square2.get(1));
temp.add(6, square2.get(8));
temp.add(7, square2.get(5));
temp.add(8, square2.get(2));
square2 = temp;
}
if (dir.equals("NC")) {
ArrayList<String> temp = new ArrayList();
temp.add(0, square2.get(2));
temp.add(1, square2.get(5));
temp.add(2, square2.get(8));
temp.add(3, square2.get(1));
temp.add(4, square2.get(4));
temp.add(5, square2.get(7));
temp.add(6, square2.get(0));
temp.add(7, square2.get(3));
temp.add(8, square2.get(6));
square2 = temp;
}
} else if (square == 3) {
if (dir.equals("C")) {
ArrayList<String> temp = new ArrayList();
temp.add(0, square3.get(6));
temp.add(1, square3.get(3));
temp.add(2, square3.get(0));
temp.add(3, square3.get(7));
temp.add(4, square3.get(4));
temp.add(5, square3.get(1));
temp.add(6, square3.get(8));
temp.add(7, square3.get(5));
temp.add(8, square3.get(2));
square3 = temp;
}
if (dir.equals("NC")) {
ArrayList<String> temp = new ArrayList();
temp.add(0, square3.get(2));
temp.add(1, square3.get(5));
temp.add(2, square3.get(8));
temp.add(3, square3.get(1));
temp.add(4, square3.get(4));
temp.add(5, square3.get(7));
temp.add(6, square3.get(0));
temp.add(7, square3.get(3));
temp.add(8, square3.get(6));
square3 = temp;
}
} else if (square == 4) {
if (dir.equals("C")) {
ArrayList<String> temp = new ArrayList();
temp.add(0, square4.get(6));
temp.add(1, square4.get(3));
temp.add(2, square4.get(0));
temp.add(3, square4.get(7));
temp.add(4, square4.get(4));
temp.add(5, square4.get(1));
temp.add(6, square4.get(8));
temp.add(7, square4.get(5));
temp.add(8, square4.get(2));
square4 = temp;
}
if (dir.equals("NC")) {
ArrayList<String> temp = new ArrayList();
temp.add(0, square4.get(2));
temp.add(1, square4.get(5));
temp.add(2, square4.get(8));
temp.add(3, square4.get(1));
temp.add(4, square4.get(4));
temp.add(5, square4.get(7));
temp.add(6, square4.get(0));
temp.add(7, square4.get(3));
temp.add(8, square4.get(6));
square4 = temp;
}
}
} }
public void putDisk(String Color) { /**
System.out.println("\nEnter the number of square and circle :"); * check if there is an empty square
Scanner scanner = new Scanner(System.in); * @return true of false
int square = scanner.nextInt(); */
int circle = scanner.nextInt(); public boolean isEmpty() {
if (square > 4 || square < 1 || circle > 9 || circle < 1) //check square to find an empty square - if preset square is not empty check out next square else return true
putDisk(Color); boolean check = true;
else { for (String circle1 : square1) {
if (square == 1) { if (!(circle1.equals(" ⚪ "))) {
if (square1.get(circle - 1).equals(" ⚪ ")) { for (String circle2 : square2) {
square1.remove(circle - 1); if (!(circle2.equals(" ⚪ "))) {
square1.add(circle - 1, Color); for (String circle3 : square3) {
} else { if (!(circle3.equals(" ⚪ "))) {
System.out.println("Already taken"); for (String circle : square4) {
putDisk(Color); if (!(circle.equals(" ⚪ "))) {
} check=false;
} return check;
if (square == 2) { }
if (square2.get(circle - 1).equals(" ⚪ ")) { }
square2.remove(circle - 1); } else
square2.add(circle - 1, Color); return check;
} else { }
System.out.println("Already taken"); }
putDisk(Color); else
} return check;
}
if (square == 3) {
if (square3.get(circle - 1).equals(" ⚪ ")) {
square3.remove(circle - 1);
square3.add(circle - 1, Color);
} else {
System.out.println("Already taken");
putDisk(Color);
}
}
if (square == 4) {
if (square4.get(circle - 1).equals(" ⚪ ")) {
square4.remove(circle - 1);
square4.add(circle - 1, Color);
} else {
System.out.println("Already taken");
putDisk(Color);
} }
} }
else
return check;
} }
return false;
} }
/**
* print map of game
*/
public void print() { public void print() {
System.out.println("Square 1 Square 2"); System.out.println("Square 1 Square 2");
printSquares(square1, square2);
System.out.println(" == == == == == == ");
printSquares(square3, square4);
System.out.print("Square 3 Square 4");
}
/**
* print neighbor squares in a line
* @param square1 left square
* @param square2 right square
*/
private void printSquares(ArrayList<String> square1, ArrayList<String> square2) {
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
if (i == 2 || i == 5 || i == 8) { if (i == 2 || i == 5 || i == 8) {
System.out.print(square1.get(i) + "‖"); System.out.print(square1.get(i) + "‖");
...@@ -281,23 +161,6 @@ public class Map { ...@@ -281,23 +161,6 @@ public class Map {
} else } else
System.out.print(square1.get(i)); System.out.print(square1.get(i));
} }
System.out.println(" == == == == == == ");
for (int i = 0; i < 9; i++) {
if (i == 2 || i == 5 || i == 8) {
System.out.print(square3.get(i) + "‖");
if (i == 2) {
System.out.println(square4.get(0) + square4.get(1) + square4.get(2));
System.out.println();
}
if (i == 5) {
System.out.println(square4.get(3) + square4.get(4) + square4.get(5));
System.out.println();
}
if (i == 8)
System.out.println(square4.get(6) + square4.get(7) + square4.get(8));
} else
System.out.print(square3.get(i));
}
System.out.print("Square 3 Square 4");
} }
} }
\ No newline at end of file
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