Commit 62981b03 authored by amir's avatar amir

Finish I dont care anymore about it!!

parent 5591ec07
......@@ -8,6 +8,11 @@ public class Console extends Display {
super(displayType);
}
/**
* display (console version)
* @param a1 array of the player1's discs
* @param a2 array of the player2's discs
*/
public void display(int[][] a1, int[][] a2) {
super.display(a1, a2);
System.out.println(" A B C D E F G H");
......@@ -33,6 +38,11 @@ public class Console extends Display {
}
}
/**
* (Overridden frm Display Class)
* will gets inputs from user in console version and returns the (x, y) as a two index array of int
* @return an array that contains x and y
*/
@Override
public int[] getInput() {
Scanner scanner = new Scanner(System.in);
......@@ -45,6 +55,12 @@ public class Console extends Display {
return inputs;
}
/**
* prints whose turn is it (console version prints)
* @param toPrint the string whose turn
* @param playerNumber the number of player
* @return this is not important!(only because I want to override)
*/
@Override
public String printing(String toPrint, int playerNumber) {
System.out.println(super.printing(toPrint, playerNumber));
......
package com.company;
public class Display {
// type of display
private byte displayType;
public Display(byte displayType){
this.displayType = displayType;
}
......@@ -15,11 +17,13 @@ public class Display {
}
// this method will be override in Console and Graphic
public int[] getInput(){
int[] input = new int[2];
return input;
}
// this method will be override in Console and Graphic
public String printing(String toPrint, int playerNumber){
if (toPrint.equals("Player"))
return "Player" + playerNumber + ", it's your turn";
......
......@@ -6,6 +6,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
public class Graphic extends Display {
JFrame f = new JFrame("othello");// creating instance of JFrame
......@@ -352,9 +354,15 @@ public class Graphic extends Display {
return null;
}
/**
* searches all of the buttons to see which button is pressed and then
* gets it's x and y and converts it to the players' coordinates
* @return x and y as a two index array(x and y)
*/
@Override
public int[] getInput() {
int [] ints = new int[2];
Iterator<JButton> buttonIterator = buttons.iterator();
while (buttonIterator.hasNext()) {
//System.out.println("koft!");
......@@ -369,11 +377,25 @@ public class Graphic extends Display {
return ints;
}
/**
* prints whose turn is it (graphic version on the start button)
* @param toPrint the string whose turn
* @param playerNumber the number of player
* @return this is not important!(only because I want to override)
*/
@Override
public String printing(String toPrint, int playerNumber) {
b.setVisible(false);
b.setText(super.printing(toPrint, playerNumber) + " (click here)");
b.setVisible(true);
String s = super.printing(toPrint, playerNumber);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
b.setVisible(false);
b.setText(s);
b.setVisible(true);
}
};
Timer timer = new Timer();
timer.scheduleAtFixedRate(timerTask, 10000, 10000);
return super.printing(toPrint, playerNumber);
}
}
package com.company;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
public class Main {
......@@ -87,10 +83,12 @@ public class Main {
}
//System.out.println("player1: "+play1.getNumberOfDisks1()+" player2:"+play2.getNumberOfDisks2());
}
/*if (play1.getNumberOfDisks(play1.getArr1()) > play2.getNumberOfDisks(play2.getArr2()))
System.out.println("Player1 wins!");
else
System.out.println("Player2 wins!");*/
if (displayType == 1) {
if (play1.getNumberOfDisks(play1.getArr1()) > play2.getNumberOfDisks(play2.getArr2()))
System.out.println("Player1 wins!");
else
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