Commit 13f1fbcc authored by amir's avatar amir

Finalized

parent cac6a3c1
package com.company; package com.company;
public class Console extends Display { public class Console {
public Console(byte displayType) {
super(displayType);
}
@Override
public void visualize() {
super.visualize();
System.out.println(" A B C D E F G H");
}
} }
package com.company; package com.company;
public class Graphic { public class Graphic{
} }
...@@ -6,10 +6,13 @@ public class Main { ...@@ -6,10 +6,13 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
int turns = 0; int turns = 0;
System.out.println("What type of game do you want? 0)console 1)graphic");
Scanner scanner = new Scanner(System.in);
byte displayType = scanner.nextByte();
Players players = new Players(); Players players = new Players();
Player1 play1 = new Player1(); Player1 play1 = new Player1();
Player2 play2 = new Player2(); Player2 play2 = new Player2();
players.display(play1.getArr1(), play2.getArr2()); players.display(play1.getArr1(), play2.getArr2(), displayType);
while ((play1.getNumberOfDisks(play1.getArr1()) + play2.getNumberOfDisks(play2.getArr2()) < 64) && while ((play1.getNumberOfDisks(play1.getArr1()) + play2.getNumberOfDisks(play2.getArr2()) < 64) &&
(play1.getNumberOfDisks(play1.getArr1()) != 0) && (play2.getNumberOfDisks(play2.getArr2()) != 0)) (play1.getNumberOfDisks(play1.getArr1()) != 0) && (play2.getNumberOfDisks(play2.getArr2()) != 0))
{ {
...@@ -36,7 +39,6 @@ public class Main { ...@@ -36,7 +39,6 @@ public class Main {
continue; continue;
} }
} }
Scanner scanner = new Scanner(System.in);
String nl = scanner.nextLine(); String nl = scanner.nextLine();
char[] f = nl.toCharArray(); char[] f = nl.toCharArray();
// scanning the x and y coordinates from user // scanning the x and y coordinates from user
...@@ -52,7 +54,7 @@ public class Main { ...@@ -52,7 +54,7 @@ public class Main {
} }
} }
players.display(play1.getArr1(), play2.getArr2()); players.display(play1.getArr1(), play2.getArr2(), displayType);
//System.out.println("player1: "+play1.getNumberOfDisks1()+" player2:"+play2.getNumberOfDisks2()); //System.out.println("player1: "+play1.getNumberOfDisks1()+" player2:"+play2.getNumberOfDisks2());
} }
if (play1.getNumberOfDisks(play1.getArr1()) > play2.getNumberOfDisks(play2.getArr2())) if (play1.getNumberOfDisks(play1.getArr1()) > play2.getNumberOfDisks(play2.getArr2()))
......
package com.company; package com.company;
public class Player1 extends Players { public class Player1 extends Players {
// the array of the player 1's coordinate
int[][] arr1; int[][] arr1;
/**
* Creates player1 with an initial deceleration
*/
public Player1(){ public Player1(){
arr1 = new int[9][9]; arr1 = new int[9][9];
arr1[4][5] = 1; arr1[4][5] = 1;
arr1[5][4] = 1; arr1[5][4] = 1;
} }
/**
* returns the array of player1's coordinates
* @return the array of player1's coordinates
*/
public int[][] getArr1() { public int[][] getArr1() {
return arr1; return arr1;
} }
......
package com.company; package com.company;
public class Player2 extends Players { public class Player2 extends Players {
// the array of the player 2's coordinate
int[][] arr2; int[][] arr2;
/**
* Creates player2 with an initial deceleration
*/
public Player2(){ public Player2(){
arr2 = new int[9][9]; arr2 = new int[9][9];
arr2[4][4] = 1; arr2[4][4] = 1;
arr2[5][5] = 1; arr2[5][5] = 1;
} }
/**
* returns the array of player2's coordinates
* @return the array of player2's coordinates
*/
public int[][] getArr2() { public int[][] getArr2() {
return arr2; return arr2;
} }
......
...@@ -84,11 +84,15 @@ public class Players { ...@@ -84,11 +84,15 @@ public class Players {
* displays the place of black and white discs and blanks * displays the place of black and white discs and blanks
* @param a1 array of the player1's discs * @param a1 array of the player1's discs
* @param a2 array of the player2's discs * @param a2 array of the player2's discs
* @param displayType type of display
*/ */
public void display(int[][] a1, int[][] a2){ public void display(int[][] a1, int[][] a2, byte displayType){
System.out.println(" A B C D E F G H"); if (displayType == 0) {
System.out.println(" A B C D E F G H");
}
for (int i = 1; i <= 8; i++){ for (int i = 1; i <= 8; i++){
System.out.print(i+ " "); if (displayType == 0)
System.out.print(i+ " ");
for (int j = 1; j <= 8; j++) { for (int j = 1; j <= 8; j++) {
if (containsInArray(a2, j, i)) { if (containsInArray(a2, j, i)) {
// the unicode of white circle (there is a player2 disc) // the unicode of white circle (there is a player2 disc)
...@@ -166,12 +170,13 @@ public class Players { ...@@ -166,12 +170,13 @@ public class Players {
} }
/** /**
* * checks the sides of the blank to see if there is an opponent disk or not
* @param arrOpponent * and then goes to the "checkTheMoveIfPossible" method
* @param arr * @param arrOpponent the coordinates of opponent's discs
* @param x * @param arr the coordinates of player's discs
* @param y * @param x the x coordinate of blank
* @return * @param y the x coordinate of blank
* @return true if any of sides is allowed and false if none them
*/ */
public boolean checkSides(int[][] arrOpponent, int[][] arr, int x, int y){ public boolean checkSides(int[][] arrOpponent, int[][] arr, int x, int y){
if (x != 1){ if (x != 1){
...@@ -223,14 +228,14 @@ public class Players { ...@@ -223,14 +228,14 @@ public class Players {
} }
/** /**
* * checks the move if possible :))
* @param arrOpponent * @param arrOpponent the coordinates of opponent's discs
* @param arr * @param arr the coordinates of player's discs
* @param x * @param x the x coordinate of blank
* @param y * @param y the x coordinate of blank
* @param moveX * @param moveX the direction in the x axis (0, 1 or -1)
* @param moveY * @param moveY the direction in the x axis (0, 1 or -1)
* @return * @return if there is a possible move returns true and else returns false
*/ */
public boolean checkTheMoveIfPossible(int[][] arrOpponent, int[][]arr, int x, int y, int moveX, int moveY){ public boolean checkTheMoveIfPossible(int[][] arrOpponent, int[][]arr, int x, int y, int moveX, int moveY){
int x1 = x; int y1 = y; int x1 = x; int y1 = y;
......
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