Commit 9e532c5f authored by amir's avatar amir

adding graphic version

parent 13f1fbcc
package com.company;
public class Console {
public class Console extends Display {
public Console(byte displayType) {
super(displayType);
}
@Override
public void display(int[][] a1, int[][] a2) {
super.display(a1, a2);
System.out.println(" A B C D E F G H");
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)
System.out.print('\u25CB');
}
else {
if (a1[j][i] != 0) {
// the unicode of black circle (there is a player1 disc)
System.out.print('\u25CF');
}
else
// the unicode of white square (a blank)
System.out.print('\u25A1');
}
System.out.print(" ");
}
System.out.println();
}
}
}
package com.company;
public class Display {
private byte displayType;
public Display(byte displayType){
this.displayType = displayType;
}
/**
* displays the place of black and white discs and blanks (will be overridden in console and graphic version)
* @param a1 array of the player1's discs
* @param a2 array of the player2's discs
*/
public void display(int[][] a1, int[][] a2){
}
}
package com.company;
public class Graphic{
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Graphic extends Display {
public Graphic(byte displayType) {
super(displayType);
JFrame f = new JFrame("othello");// creating instance of JFrame
JLabel l1;
l1 = new JLabel(new ImageIcon("untitled.png"));
f.setSize(700, 700);
f.setLayout(null);
f.setVisible(true);
JButton b = new JButton("start");
f.add(b);
b.setBounds(300,621,100, 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);
}
});
JButton button11 = new JButton("");
button11.setBackground(Color.GRAY);
button11.setBounds(143, 135, 58, 58);
f.add(button11); buttons.add(button11);
JButton button12 = new JButton("");
button12.setBackground(Color.GRAY);
button12.setBounds(143 + 58, 135, 58, 58);
f.add(button12); buttons.add(button12);
JButton button13 = new JButton("");
button13.setBackground(Color.GRAY);
button13.setBounds(143 + 2 * 58, 135, 58, 58);
f.add(button13); buttons.add(button13);
JButton button14 = new JButton("");
button14.setBackground(Color.GRAY);
button14.setBounds(143 + 3 * 58, 135, 58, 58);
f.add(button14); buttons.add(button14);
JButton button15 = new JButton("");
button15.setBackground(Color.GRAY);
button15.setBounds(143 + 4 * 58, 135, 58, 58);
f.add(button15); buttons.add(button15);
JButton button16 = new JButton("");
button16.setBackground(Color.GRAY);
button16.setBounds(143 + 5 * 58, 135, 58, 58);
f.add(button16); buttons.add(button16);
JButton button17 = new JButton("");
button17.setBackground(Color.GRAY);
button17.setBounds(143 + 6 * 58, 135, 58, 58);
f.add(button17); buttons.add(button17);
JButton button18 = new JButton("");
button18.setBackground(Color.GRAY);
button18.setBounds(143 + 7 * 58, 135, 58, 58);
f.add(button18); buttons.add(button18);
JButton button21 = new JButton("");
button21.setBackground(Color.GRAY);
button21.setBounds(143, 135 + 58, 58, 58);
f.add(button21); buttons.add(button21);
JButton button22 = new JButton("");
button22.setBackground(Color.GRAY);
button22.setBounds(143 + 58, 135 + 58, 58, 58);
f.add(button22); buttons.add(button22);
JButton button23 = new JButton("");
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);
JButton button25 = new JButton("");
button25.setBackground(Color.GRAY);
button25.setBounds(143 + 4 * 58, 135 + 58, 58, 58);
f.add(button25); buttons.add(button25);
JButton button26 = new JButton("");
button26.setBackground(Color.GRAY);
button26.setBounds(143 + 5 * 58, 135 + 58, 58, 58);
f.add(button26); buttons.add(button26);
JButton button27 = new JButton("");
button27.setBackground(Color.GRAY);
button27.setBounds(143 + 6 * 58, 135 + 58, 58, 58);
f.add(button27); buttons.add(button27);
JButton button28 = new JButton("");
button28.setBackground(Color.GRAY);
button28.setBounds(143 + 7 * 58, 135 + 58, 58, 58);
f.add(button28); buttons.add(button28);
JButton button31 = new JButton("");
button31.setBackground(Color.GRAY);
button31.setBounds(143, 135 + 2 * 58, 58, 58);
f.add(button31); buttons.add(button31);
JButton button32 = new JButton("");
button32.setBackground(Color.GRAY);
button32.setBounds(143 + 58, 135 + 2 * 58, 58, 58);
f.add(button32); buttons.add(button32);
JButton button33 = new JButton("");
button33.setBackground(Color.GRAY);
button33.setBounds(143 + 2 * 58, 135 + 2 * 58, 58, 58);
f.add(button33); buttons.add(button33);
JButton button34 = new JButton("");
button34.setBackground(Color.GRAY);
button34.setBounds(143 + 3 * 58, 135 + 2 * 58, 58, 58);
f.add(button34); buttons.add(button34);
JButton button35 = new JButton("");
button35.setBackground(Color.GRAY);
button35.setBounds(143 + 4 * 58, 135 + 2 * 58, 58, 58);
f.add(button35); buttons.add(button35);
JButton button36 = new JButton("");
button36.setBackground(Color.GRAY);
button36.setBounds(143 + 5 * 58, 135 + 2 * 58, 58, 58);
f.add(button36); buttons.add(button36);
JButton button37 = new JButton("");
button37.setBackground(Color.GRAY);
button37.setBounds(143 + 6 * 58, 135 + 2 * 58, 58, 58);
f.add(button37); buttons.add(button37);
JButton button38 = new JButton("");
button38.setBackground(Color.GRAY);
button38.setBounds(143 + 7 * 58, 135 + 2 * 58, 58, 58);
f.add(button38); buttons.add(button38);
JButton button41 = new JButton("");
button41.setBackground(Color.GRAY);
button41.setBounds(143, 135 + 3 * 58, 58, 58);
f.add(button41); buttons.add(button41);
JButton button42 = new JButton("");
button42.setBackground(Color.GRAY);
button42.setBounds(143 + 58, 135 + 3 * 58, 58, 58);
f.add(button42); buttons.add(button42);
JButton button43 = new JButton("");
button43.setBackground(Color.GRAY);
button43.setBounds(143 + 2 * 58, 135 + 3 * 58, 58, 58);
f.add(button43); buttons.add(button43);
JButton button44 = new JButton("");
button44.setBackground(Color.WHITE);
button44.setBounds(143 + 3 * 58, 135 + 3 * 58, 58, 58);
f.add(button44); buttons.add(button44);
JButton button45 = new JButton("");
button45.setBackground(Color.BLACK);
button45.setBounds(143 + 4 * 58, 135 + 3 * 58, 58, 58);
f.add(button45); buttons.add(button45);
JButton button46 = new JButton("");
button46.setBackground(Color.GRAY);
button46.setBounds(143 + 5 * 58, 135 + 3 * 58, 58, 58);
f.add(button46); buttons.add(button46);
JButton button47 = new JButton("");
button47.setBackground(Color.GRAY);
button47.setBounds(143 + 6 * 58, 135 + 3 * 58, 58, 58);
f.add(button47); buttons.add(button47);
JButton button48 = new JButton("");
button48.setBackground(Color.GRAY);
button48.setBounds(143 + 7 * 58, 135 + 3 * 58, 58, 58);
f.add(button48); buttons.add(button48);
JButton button51 = new JButton("");
button51.setBackground(Color.GRAY);
button51.setBounds(143, 135 + 4 * 58, 58, 58);
f.add(button51); buttons.add(button51);
JButton button52 = new JButton("");
button52.setBackground(Color.GRAY);
button52.setBounds(143 + 58, 135 + 4 * 58, 58, 58);
f.add(button52); buttons.add(button52);
JButton button53 = new JButton("");
button53.setBackground(Color.GRAY);
button53.setBounds(143 + 2 * 58, 135 + 4 * 58, 58, 58);
f.add(button53); buttons.add(button53);
JButton button54 = new JButton("");
button54.setBackground(Color.BLACK);
button54.setBounds(143 + 3 * 58, 135 + 4 * 58, 58, 58);
f.add(button54); buttons.add(button54);
JButton button55 = new JButton("");
button55.setBackground(Color.WHITE);
button55.setBounds(143 + 4 * 58, 135 + 4 * 58, 58, 58);
f.add(button55); buttons.add(button55);
JButton button56 = new JButton("");
button56.setBackground(Color.GRAY);
button56.setBounds(143 + 5 * 58, 135 + 4 * 58, 58, 58);
f.add(button56); buttons.add(button56);
JButton button57 = new JButton("");
button57.setBackground(Color.GRAY);
button57.setBounds(143 + 6 * 58, 135 + 4 * 58, 58, 58);
f.add(button57); buttons.add(button57);
JButton button58 = new JButton("");
button58.setBackground(Color.GRAY);
button58.setBounds(143 + 7 * 58, 135 + 4 * 58, 58, 58);
f.add(button58); buttons.add(button58);
JButton button61 = new JButton("");
button61.setBackground(Color.GRAY);
button61.setBounds(143, 135 + 5 * 58, 58, 58);
f.add(button61); buttons.add(button61);
JButton button62 = new JButton("");
button62.setBackground(Color.GRAY);
button62.setBounds(143 + 58, 135 + 5 * 58, 58, 58);
f.add(button62); buttons.add(button62);
JButton button63 = new JButton("");
button63.setBackground(Color.GRAY);
button63.setBounds(143 + 2 * 58, 135 + 5 * 58, 58, 58);
f.add(button63); buttons.add(button63);
JButton button64 = new JButton("");
button64.setBackground(Color.GRAY);
button64.setBounds(143 + 3 * 58, 135 + 5 * 58, 58, 58);
f.add(button64); buttons.add(button64);
JButton button65 = new JButton("");
button65.setBackground(Color.GRAY);
button65.setBounds(143 + 4 * 58, 135 + 5 * 58, 58, 58);
f.add(button65); buttons.add(button65);
JButton button66 = new JButton("");
button66.setBackground(Color.GRAY);
button66.setBounds(143 + 5 * 58, 135 + 5 * 58, 58, 58);
f.add(button66); buttons.add(button66);
JButton button67 = new JButton("");
button67.setBackground(Color.GRAY);
button67.setBounds(143 + 6 * 58, 135 + 5 * 58, 58, 58);
f.add(button67); buttons.add(button67);
JButton button68 = new JButton("");
button68.setBackground(Color.GRAY);
button68.setBounds(143 + 7 * 58, 135 + 5 * 58, 58, 58);
f.add(button68); buttons.add(button68);
JButton button71 = new JButton("");
button71.setBackground(Color.GRAY);
button71.setBounds(143, 135 + 6 * 58, 58, 58);
f.add(button71); buttons.add(button71);
JButton button72 = new JButton("");
button72.setBackground(Color.GRAY);
button72.setBounds(143 + 58, 135 + 6 * 58, 58, 58);
f.add(button72); buttons.add(button72);
JButton button73 = new JButton("");
button73.setBackground(Color.GRAY);
button73.setBounds(143 + 2 * 58, 135 + 6 * 58, 58, 58);
f.add(button73); buttons.add(button73);
JButton button74 = new JButton("");
button74.setBackground(Color.GRAY);
button74.setBounds(143 + 3 * 58, 135 + 6 * 58, 58, 58);
f.add(button74); buttons.add(button74);
JButton button75 = new JButton("");
button75.setBackground(Color.GRAY);
button75.setBounds(143 + 4 * 58, 135 + 6 * 58, 58, 58);
f.add(button75); buttons.add(button75);
JButton button76 = new JButton("");
button76.setBackground(Color.GRAY);
button76.setBounds(143 + 5 * 58, 135 + 6 * 58, 58, 58);
f.add(button76); buttons.add(button76);
JButton button77 = new JButton("");
button77.setBackground(Color.GRAY);
button77.setBounds(143 + 6 * 58, 135 + 6 * 58, 58, 58);
f.add(button77); buttons.add(button77);
JButton button78 = new JButton("");
button78.setBackground(Color.GRAY);
button78.setBounds(143 + 7 * 58, 135 + 6 * 58, 58, 58);
f.add(button78); buttons.add(button78);
JButton button81 = new JButton("");
button81.setBackground(Color.GRAY);
button81.setBounds(143, 135 + 7 * 58, 58, 58);
f.add(button81); buttons.add(button81);
JButton button82 = new JButton("");
button82.setBackground(Color.GRAY);
button82.setBounds(143 + 58, 135 + 7 * 58, 58, 58);
f.add(button82); buttons.add(button82);
JButton button83 = new JButton("");
button83.setBackground(Color.GRAY);
button83.setBounds(143 + 2 * 58, 135 + 7 * 58, 58, 58);
f.add(button83); buttons.add(button83);
JButton button84 = new JButton("");
button84.setBackground(Color.GRAY);
button84.setBounds(143 + 3 * 58, 135 + 7 * 58, 58, 58);
f.add(button84); buttons.add(button84);
JButton button85 = new JButton("");
button85.setBackground(Color.GRAY);
button85.setBounds(143 + 4 * 58, 135 + 7 * 58, 58, 58);
f.add(button85); buttons.add(button85);
JButton button86 = new JButton("");
button86.setBackground(Color.GRAY);
button86.setBounds(143 + 5 * 58, 135 + 7 * 58, 58, 58);
f.add(button86); buttons.add(button86);
JButton button87 = new JButton("");
button87.setBackground(Color.GRAY);
button87.setBounds(143 + 6 * 58, 135 + 7 * 58, 58, 58);
f.add(button87); buttons.add(button87);
JButton button88 = new JButton("");
button88.setBackground(Color.GRAY);
button88.setBounds(143 + 7 * 58, 135 + 7 * 58, 58, 58);
f.add(button88); buttons.add(button88);
}
@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)
}
else {
if (a1[j][i] != 0) {
// the unicode of black circle (there is a player1 disc)
System.out.print('\u25CF');
}
else
// the unicode of white square (a blank)
System.out.print('\u25A1');
}
}
}
}
}
......@@ -80,38 +80,7 @@ public class Players {
}
}
/**
* displays the place of black and white discs and blanks
* @param a1 array of the player1's discs
* @param a2 array of the player2's discs
* @param displayType type of display
*/
public void display(int[][] a1, int[][] a2, byte displayType){
if (displayType == 0) {
System.out.println(" A B C D E F G H");
}
for (int i = 1; i <= 8; i++){
if (displayType == 0)
System.out.print(i+ " ");
for (int j = 1; j <= 8; j++) {
if (containsInArray(a2, j, i)) {
// the unicode of white circle (there is a player2 disc)
System.out.print('\u25CB');
}
else {
if (containsInArray(a1, j, i)) {
// the unicode of black circle (there is a player1 disc)
System.out.print('\u25CF');
}
else
// the unicode of white square (a blank)
System.out.print('\u25A1');
}
System.out.print(" ");
}
System.out.println();
}
}
/**
* this method checks if the move is possible, then equalize the color of the
......
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