Commit 5591ec07 authored by amir's avatar amir

What to do (last javadocs)

parent 36de7cba
......@@ -10,8 +10,11 @@ import java.util.Iterator;
public class Graphic extends Display {
JFrame f = new JFrame("othello");// creating instance of JFrame
JLabel l1;
// start button
JButton b = new JButton("start");
// list of buttons do we have
ArrayList<JButton> buttons = new ArrayList<>();
// Creating 64 button in the 64 boxes!!
JButton button11 = new JButton("");
JButton button12 = new JButton("");
JButton button13 = new JButton("");
......@@ -77,6 +80,10 @@ public class Graphic extends Display {
JButton button87 = new JButton("");
JButton button88 = new JButton("");
/**
* Creates the graphic environment for the first time (if the display type == 1)
* @param displayType if equals to 1, constructing is done
*/
public Graphic(byte displayType) {
super(displayType);
l1 = new JLabel(new ImageIcon("untitled.png"));
......@@ -87,16 +94,17 @@ public class Graphic extends Display {
else
f.setVisible(true);
f.add(b);
b.setBounds(300,621,100, 40);//x axis, y axis, width, height
b.setBounds(300,621,180, 40);//x axis, y axis, width, height
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
l1.setBounds(30, 100, 800, 600);
f.add(l1);
b.setVisible(false);
}
});
// all of the buttons except 4 buttons gets the color gray
button11.setBackground(Color.GRAY);
// size and position of each button
button11.setBounds(143, 135, 58, 58);
f.add(button11); buttons.add(button11);
button12.setBackground(Color.GRAY);
......@@ -130,7 +138,6 @@ public class Graphic extends Display {
button23.setBackground(Color.GRAY);
button23.setBounds(143 + 2 * 58, 135 + 58, 58, 58);
f.add(button23); buttons.add(button23);
JButton button24 = new JButton("");
button24.setBackground(Color.GRAY);
button24.setBounds(143 + 3 * 58, 135 + 58, 58, 58);
f.add(button24); buttons.add(button24);
......@@ -298,28 +305,42 @@ public class Graphic extends Display {
f.add(button88); buttons.add(button88);
}
/**
* the overridden version of display in Display class
* this will show the black and white discs and blanks as the colors of buttons
* (gray == blank)
* @param a1 array of the player1's discs
* @param a2 array of the player2's discs
*/
@Override
public void display(int[][] a1, int[][] a2) {
super.display(a1, a2);
for (int i = 1; i <= 8; i++) {
for (int j = 1; j <= 8; j++) {
if (a2[j][i] != 0) {
// the unicode of white circle (there is a player2 disc)
// (there is a player2 disc)
searchInButtons(j, i).setBackground(Color.WHITE);
}
else {
if (a1[j][i] != 0) {
// the unicode of black circle (there is a player1 disc)
// (there is a player1 disc)
searchInButtons(j, i).setBackground(Color.BLACK);
}
else
// the unicode of white square (a blank)
// (a blank)
searchInButtons(j, i).setBackground(Color.GRAY);
}
}
}
}
/**
* gets a coordinate (x and y) and search in the list of buttons to find the buttons
* that is located in that position
* @param x is the x coordinate
* @param y is the y coordinate
* @return the button that locates on that position
*/
public JButton searchInButtons(int x, int y){
Iterator<JButton> buttonIterator = buttons.iterator();
while (buttonIterator.hasNext()){
......@@ -339,7 +360,6 @@ public class Graphic extends Display {
//System.out.println("koft!");
JButton b1 = buttonIterator.next();
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ints[0] = (b1.getX() - 143) / 58 + 1;
ints[1] = (b1.getY() - 135) / 58 + 1;
......@@ -352,7 +372,7 @@ public class Graphic extends Display {
@Override
public String printing(String toPrint, int playerNumber) {
b.setVisible(false);
b.setText(super.printing(toPrint, playerNumber));
b.setText(super.printing(toPrint, playerNumber) + " (click here)");
b.setVisible(true);
return super.printing(toPrint, playerNumber);
}
......
......@@ -4,6 +4,7 @@ package com.company;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
public class Main {
......@@ -22,21 +23,20 @@ public class Main {
else {
graphic.display(play1.getArr1(), play2.getArr2());
}
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)) {
if ((play1.numberOfPlayerPossibleMoves(play2.getArr2(), play1.getArr1()) == 0) &&
(play2.numberOfPlayerPossibleMoves(play1.getArr1(), play2.getArr2()) == 0))
break;
turns++;
if (turns %2 == 1){
if (turns % 2 == 1) {
if (play1.numberOfPlayerPossibleMoves(play2.getArr2(), play1.getArr1()) != 0) {
if (displayType == 0)
console.printing("Player", 1);
else
graphic.printing("Player", 1);
}
else {
} else {
//if there is no possible move prints pass
if (displayType == 0)
console.printing("pass", 1);
......@@ -45,16 +45,13 @@ public class Main {
turns++;
}
}
if (turns %2 == 0){
if (turns % 2 == 0) {
if (play2.numberOfPlayerPossibleMoves(play1.getArr1(), play2.getArr2()) != 0) {
if (play1.numberOfPlayerPossibleMoves(play2.getArr2(), play1.getArr1()) != 0) {
if (displayType == 0)
console.printing("Player", 2);
else
graphic.printing("Player", 2);
}
}
else {
} else {
//if there is no possible move prints pass
if (displayType == 0)
console.printing("pass", 2);
......@@ -66,8 +63,7 @@ public class Main {
int[] inputs = new int[2];
if (displayType == 0) {
inputs = console.getInput();
}
else {
} else {
inputs = graphic.getInput();
}
int y = inputs[1];
......@@ -75,11 +71,10 @@ public class Main {
System.out.println("x = " + x);
System.out.println("y = " + y);
if ((x >= 1) && (x < 9) && (y >= 1) && (y < 9)) {
if ((!play1.containsInArray(play1.getArr1(), x, y)) && (!play2.containsInArray(play2.getArr2(), x, y))){
if (turns %2 == 1){
if ((!play1.containsInArray(play1.getArr1(), x, y)) && (!play2.containsInArray(play2.getArr2(), x, y))) {
if (turns % 2 == 1) {
play1.searchInNeighbors(play2.getArr2(), play1.getArr1(), x, y);
}
else
} else
play2.searchInNeighbors(play1.getArr1(), play2.getArr2(), x, y);
}
......@@ -92,10 +87,10 @@ public class Main {
}
//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()))
System.out.println("Player1 wins!");
else
System.out.println("Player2 wins!");
System.out.println("Player2 wins!");*/
}
......
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