Commit 5a06e374 authored by amir's avatar amir

Displaying in console and graphic version

parent 9e532c5f
...@@ -4,18 +4,85 @@ import javax.swing.*; ...@@ -4,18 +4,85 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
public class Graphic extends Display { public class Graphic extends Display {
JFrame f = new JFrame("othello");// creating instance of JFrame
JLabel l1;
JButton b = new JButton("start");
ArrayList<JButton> buttons = new ArrayList<>();
JButton button11 = new JButton("");
JButton button12 = new JButton("");
JButton button13 = new JButton("");
JButton button14 = new JButton("");
JButton button15 = new JButton("");
JButton button16 = new JButton("");
JButton button17 = new JButton("");
JButton button18 = new JButton("");
JButton button21 = new JButton("");
JButton button22 = new JButton("");
JButton button23 = new JButton("");
JButton button24 = new JButton("");
JButton button25 = new JButton("");
JButton button26 = new JButton("");
JButton button27 = new JButton("");
JButton button28 = new JButton("");
JButton button31 = new JButton("");
JButton button32 = new JButton("");
JButton button33 = new JButton("");
JButton button34 = new JButton("");
JButton button35 = new JButton("");
JButton button36 = new JButton("");
JButton button37 = new JButton("");
JButton button38 = new JButton("");
JButton button41 = new JButton("");
JButton button42 = new JButton("");
JButton button43 = new JButton("");
JButton button44 = new JButton("");
JButton button45 = new JButton("");
JButton button46 = new JButton("");
JButton button47 = new JButton("");
JButton button48 = new JButton("");
JButton button51 = new JButton("");
JButton button52 = new JButton("");
JButton button53 = new JButton("");
JButton button54 = new JButton("");
JButton button55 = new JButton("");
JButton button56 = new JButton("");
JButton button57 = new JButton("");
JButton button58 = new JButton("");
JButton button61 = new JButton("");
JButton button62 = new JButton("");
JButton button63 = new JButton("");
JButton button64 = new JButton("");
JButton button65 = new JButton("");
JButton button66 = new JButton("");
JButton button67 = new JButton("");
JButton button68 = new JButton("");
JButton button71 = new JButton("");
JButton button72 = new JButton("");
JButton button73 = new JButton("");
JButton button74 = new JButton("");
JButton button75 = new JButton("");
JButton button76 = new JButton("");
JButton button77 = new JButton("");
JButton button78 = new JButton("");
JButton button81 = new JButton("");
JButton button82 = new JButton("");
JButton button83 = new JButton("");
JButton button84 = new JButton("");
JButton button85 = new JButton("");
JButton button86 = new JButton("");
JButton button87 = new JButton("");
JButton button88 = new JButton("");
public Graphic(byte displayType) { public Graphic(byte displayType) {
super(displayType); super(displayType);
JFrame f = new JFrame("othello");// creating instance of JFrame
JLabel l1;
l1 = new JLabel(new ImageIcon("untitled.png")); l1 = new JLabel(new ImageIcon("untitled.png"));
f.setSize(700, 700); f.setSize(700, 700);
f.setLayout(null); f.setLayout(null);
f.setVisible(true); f.setVisible(true);
JButton b = new JButton("start");
f.add(b); f.add(b);
b.setBounds(300,621,100, 40);//x axis, y axis, width, height b.setBounds(300,621,100, 40);//x axis, y axis, width, height
b.addActionListener(new ActionListener() { b.addActionListener(new ActionListener() {
...@@ -26,48 +93,37 @@ public class Graphic extends Display { ...@@ -26,48 +93,37 @@ public class Graphic extends Display {
b.setVisible(false); b.setVisible(false);
} }
}); });
JButton button11 = new JButton("");
button11.setBackground(Color.GRAY); button11.setBackground(Color.GRAY);
button11.setBounds(143, 135, 58, 58); button11.setBounds(143, 135, 58, 58);
f.add(button11); buttons.add(button11); f.add(button11); buttons.add(button11);
JButton button12 = new JButton("");
button12.setBackground(Color.GRAY); button12.setBackground(Color.GRAY);
button12.setBounds(143 + 58, 135, 58, 58); button12.setBounds(143 + 58, 135, 58, 58);
f.add(button12); buttons.add(button12); f.add(button12); buttons.add(button12);
JButton button13 = new JButton("");
button13.setBackground(Color.GRAY); button13.setBackground(Color.GRAY);
button13.setBounds(143 + 2 * 58, 135, 58, 58); button13.setBounds(143 + 2 * 58, 135, 58, 58);
f.add(button13); buttons.add(button13); f.add(button13); buttons.add(button13);
JButton button14 = new JButton("");
button14.setBackground(Color.GRAY); button14.setBackground(Color.GRAY);
button14.setBounds(143 + 3 * 58, 135, 58, 58); button14.setBounds(143 + 3 * 58, 135, 58, 58);
f.add(button14); buttons.add(button14); f.add(button14); buttons.add(button14);
JButton button15 = new JButton("");
button15.setBackground(Color.GRAY); button15.setBackground(Color.GRAY);
button15.setBounds(143 + 4 * 58, 135, 58, 58); button15.setBounds(143 + 4 * 58, 135, 58, 58);
f.add(button15); buttons.add(button15); f.add(button15); buttons.add(button15);
JButton button16 = new JButton("");
button16.setBackground(Color.GRAY); button16.setBackground(Color.GRAY);
button16.setBounds(143 + 5 * 58, 135, 58, 58); button16.setBounds(143 + 5 * 58, 135, 58, 58);
f.add(button16); buttons.add(button16); f.add(button16); buttons.add(button16);
JButton button17 = new JButton("");
button17.setBackground(Color.GRAY); button17.setBackground(Color.GRAY);
button17.setBounds(143 + 6 * 58, 135, 58, 58); button17.setBounds(143 + 6 * 58, 135, 58, 58);
f.add(button17); buttons.add(button17); f.add(button17); buttons.add(button17);
JButton button18 = new JButton("");
button18.setBackground(Color.GRAY); button18.setBackground(Color.GRAY);
button18.setBounds(143 + 7 * 58, 135, 58, 58); button18.setBounds(143 + 7 * 58, 135, 58, 58);
f.add(button18); buttons.add(button18); f.add(button18); buttons.add(button18);
JButton button21 = new JButton("");
button21.setBackground(Color.GRAY); button21.setBackground(Color.GRAY);
button21.setBounds(143, 135 + 58, 58, 58); button21.setBounds(143, 135 + 58, 58, 58);
f.add(button21); buttons.add(button21); f.add(button21); buttons.add(button21);
JButton button22 = new JButton("");
button22.setBackground(Color.GRAY); button22.setBackground(Color.GRAY);
button22.setBounds(143 + 58, 135 + 58, 58, 58); button22.setBounds(143 + 58, 135 + 58, 58, 58);
f.add(button22); buttons.add(button22); f.add(button22); buttons.add(button22);
JButton button23 = new JButton("");
button23.setBackground(Color.GRAY); button23.setBackground(Color.GRAY);
button23.setBounds(143 + 2 * 58, 135 + 58, 58, 58); button23.setBounds(143 + 2 * 58, 135 + 58, 58, 58);
f.add(button23); buttons.add(button23); f.add(button23); buttons.add(button23);
...@@ -75,217 +131,165 @@ public class Graphic extends Display { ...@@ -75,217 +131,165 @@ public class Graphic extends Display {
button24.setBackground(Color.GRAY); button24.setBackground(Color.GRAY);
button24.setBounds(143 + 3 * 58, 135 + 58, 58, 58); button24.setBounds(143 + 3 * 58, 135 + 58, 58, 58);
f.add(button24); buttons.add(button24); f.add(button24); buttons.add(button24);
JButton button25 = new JButton("");
button25.setBackground(Color.GRAY); button25.setBackground(Color.GRAY);
button25.setBounds(143 + 4 * 58, 135 + 58, 58, 58); button25.setBounds(143 + 4 * 58, 135 + 58, 58, 58);
f.add(button25); buttons.add(button25); f.add(button25); buttons.add(button25);
JButton button26 = new JButton("");
button26.setBackground(Color.GRAY); button26.setBackground(Color.GRAY);
button26.setBounds(143 + 5 * 58, 135 + 58, 58, 58); button26.setBounds(143 + 5 * 58, 135 + 58, 58, 58);
f.add(button26); buttons.add(button26); f.add(button26); buttons.add(button26);
JButton button27 = new JButton("");
button27.setBackground(Color.GRAY); button27.setBackground(Color.GRAY);
button27.setBounds(143 + 6 * 58, 135 + 58, 58, 58); button27.setBounds(143 + 6 * 58, 135 + 58, 58, 58);
f.add(button27); buttons.add(button27); f.add(button27); buttons.add(button27);
JButton button28 = new JButton("");
button28.setBackground(Color.GRAY); button28.setBackground(Color.GRAY);
button28.setBounds(143 + 7 * 58, 135 + 58, 58, 58); button28.setBounds(143 + 7 * 58, 135 + 58, 58, 58);
f.add(button28); buttons.add(button28); f.add(button28); buttons.add(button28);
JButton button31 = new JButton("");
button31.setBackground(Color.GRAY); button31.setBackground(Color.GRAY);
button31.setBounds(143, 135 + 2 * 58, 58, 58); button31.setBounds(143, 135 + 2 * 58, 58, 58);
f.add(button31); buttons.add(button31); f.add(button31); buttons.add(button31);
JButton button32 = new JButton("");
button32.setBackground(Color.GRAY); button32.setBackground(Color.GRAY);
button32.setBounds(143 + 58, 135 + 2 * 58, 58, 58); button32.setBounds(143 + 58, 135 + 2 * 58, 58, 58);
f.add(button32); buttons.add(button32); f.add(button32); buttons.add(button32);
JButton button33 = new JButton("");
button33.setBackground(Color.GRAY); button33.setBackground(Color.GRAY);
button33.setBounds(143 + 2 * 58, 135 + 2 * 58, 58, 58); button33.setBounds(143 + 2 * 58, 135 + 2 * 58, 58, 58);
f.add(button33); buttons.add(button33); f.add(button33); buttons.add(button33);
JButton button34 = new JButton("");
button34.setBackground(Color.GRAY); button34.setBackground(Color.GRAY);
button34.setBounds(143 + 3 * 58, 135 + 2 * 58, 58, 58); button34.setBounds(143 + 3 * 58, 135 + 2 * 58, 58, 58);
f.add(button34); buttons.add(button34); f.add(button34); buttons.add(button34);
JButton button35 = new JButton("");
button35.setBackground(Color.GRAY); button35.setBackground(Color.GRAY);
button35.setBounds(143 + 4 * 58, 135 + 2 * 58, 58, 58); button35.setBounds(143 + 4 * 58, 135 + 2 * 58, 58, 58);
f.add(button35); buttons.add(button35); f.add(button35); buttons.add(button35);
JButton button36 = new JButton("");
button36.setBackground(Color.GRAY); button36.setBackground(Color.GRAY);
button36.setBounds(143 + 5 * 58, 135 + 2 * 58, 58, 58); button36.setBounds(143 + 5 * 58, 135 + 2 * 58, 58, 58);
f.add(button36); buttons.add(button36); f.add(button36); buttons.add(button36);
JButton button37 = new JButton("");
button37.setBackground(Color.GRAY); button37.setBackground(Color.GRAY);
button37.setBounds(143 + 6 * 58, 135 + 2 * 58, 58, 58); button37.setBounds(143 + 6 * 58, 135 + 2 * 58, 58, 58);
f.add(button37); buttons.add(button37); f.add(button37); buttons.add(button37);
JButton button38 = new JButton("");
button38.setBackground(Color.GRAY); button38.setBackground(Color.GRAY);
button38.setBounds(143 + 7 * 58, 135 + 2 * 58, 58, 58); button38.setBounds(143 + 7 * 58, 135 + 2 * 58, 58, 58);
f.add(button38); buttons.add(button38); f.add(button38); buttons.add(button38);
JButton button41 = new JButton("");
button41.setBackground(Color.GRAY); button41.setBackground(Color.GRAY);
button41.setBounds(143, 135 + 3 * 58, 58, 58); button41.setBounds(143, 135 + 3 * 58, 58, 58);
f.add(button41); buttons.add(button41); f.add(button41); buttons.add(button41);
JButton button42 = new JButton("");
button42.setBackground(Color.GRAY); button42.setBackground(Color.GRAY);
button42.setBounds(143 + 58, 135 + 3 * 58, 58, 58); button42.setBounds(143 + 58, 135 + 3 * 58, 58, 58);
f.add(button42); buttons.add(button42); f.add(button42); buttons.add(button42);
JButton button43 = new JButton("");
button43.setBackground(Color.GRAY); button43.setBackground(Color.GRAY);
button43.setBounds(143 + 2 * 58, 135 + 3 * 58, 58, 58); button43.setBounds(143 + 2 * 58, 135 + 3 * 58, 58, 58);
f.add(button43); buttons.add(button43); f.add(button43); buttons.add(button43);
JButton button44 = new JButton("");
button44.setBackground(Color.WHITE); button44.setBackground(Color.WHITE);
button44.setBounds(143 + 3 * 58, 135 + 3 * 58, 58, 58); button44.setBounds(143 + 3 * 58, 135 + 3 * 58, 58, 58);
f.add(button44); buttons.add(button44); f.add(button44); buttons.add(button44);
JButton button45 = new JButton("");
button45.setBackground(Color.BLACK); button45.setBackground(Color.BLACK);
button45.setBounds(143 + 4 * 58, 135 + 3 * 58, 58, 58); button45.setBounds(143 + 4 * 58, 135 + 3 * 58, 58, 58);
f.add(button45); buttons.add(button45); f.add(button45); buttons.add(button45);
JButton button46 = new JButton("");
button46.setBackground(Color.GRAY); button46.setBackground(Color.GRAY);
button46.setBounds(143 + 5 * 58, 135 + 3 * 58, 58, 58); button46.setBounds(143 + 5 * 58, 135 + 3 * 58, 58, 58);
f.add(button46); buttons.add(button46); f.add(button46); buttons.add(button46);
JButton button47 = new JButton("");
button47.setBackground(Color.GRAY); button47.setBackground(Color.GRAY);
button47.setBounds(143 + 6 * 58, 135 + 3 * 58, 58, 58); button47.setBounds(143 + 6 * 58, 135 + 3 * 58, 58, 58);
f.add(button47); buttons.add(button47); f.add(button47); buttons.add(button47);
JButton button48 = new JButton("");
button48.setBackground(Color.GRAY); button48.setBackground(Color.GRAY);
button48.setBounds(143 + 7 * 58, 135 + 3 * 58, 58, 58); button48.setBounds(143 + 7 * 58, 135 + 3 * 58, 58, 58);
f.add(button48); buttons.add(button48); f.add(button48); buttons.add(button48);
JButton button51 = new JButton("");
button51.setBackground(Color.GRAY); button51.setBackground(Color.GRAY);
button51.setBounds(143, 135 + 4 * 58, 58, 58); button51.setBounds(143, 135 + 4 * 58, 58, 58);
f.add(button51); buttons.add(button51); f.add(button51); buttons.add(button51);
JButton button52 = new JButton("");
button52.setBackground(Color.GRAY); button52.setBackground(Color.GRAY);
button52.setBounds(143 + 58, 135 + 4 * 58, 58, 58); button52.setBounds(143 + 58, 135 + 4 * 58, 58, 58);
f.add(button52); buttons.add(button52); f.add(button52); buttons.add(button52);
JButton button53 = new JButton("");
button53.setBackground(Color.GRAY); button53.setBackground(Color.GRAY);
button53.setBounds(143 + 2 * 58, 135 + 4 * 58, 58, 58); button53.setBounds(143 + 2 * 58, 135 + 4 * 58, 58, 58);
f.add(button53); buttons.add(button53); f.add(button53); buttons.add(button53);
JButton button54 = new JButton("");
button54.setBackground(Color.BLACK); button54.setBackground(Color.BLACK);
button54.setBounds(143 + 3 * 58, 135 + 4 * 58, 58, 58); button54.setBounds(143 + 3 * 58, 135 + 4 * 58, 58, 58);
f.add(button54); buttons.add(button54); f.add(button54); buttons.add(button54);
JButton button55 = new JButton("");
button55.setBackground(Color.WHITE); button55.setBackground(Color.WHITE);
button55.setBounds(143 + 4 * 58, 135 + 4 * 58, 58, 58); button55.setBounds(143 + 4 * 58, 135 + 4 * 58, 58, 58);
f.add(button55); buttons.add(button55); f.add(button55); buttons.add(button55);
JButton button56 = new JButton("");
button56.setBackground(Color.GRAY); button56.setBackground(Color.GRAY);
button56.setBounds(143 + 5 * 58, 135 + 4 * 58, 58, 58); button56.setBounds(143 + 5 * 58, 135 + 4 * 58, 58, 58);
f.add(button56); buttons.add(button56); f.add(button56); buttons.add(button56);
JButton button57 = new JButton("");
button57.setBackground(Color.GRAY); button57.setBackground(Color.GRAY);
button57.setBounds(143 + 6 * 58, 135 + 4 * 58, 58, 58); button57.setBounds(143 + 6 * 58, 135 + 4 * 58, 58, 58);
f.add(button57); buttons.add(button57); f.add(button57); buttons.add(button57);
JButton button58 = new JButton("");
button58.setBackground(Color.GRAY); button58.setBackground(Color.GRAY);
button58.setBounds(143 + 7 * 58, 135 + 4 * 58, 58, 58); button58.setBounds(143 + 7 * 58, 135 + 4 * 58, 58, 58);
f.add(button58); buttons.add(button58); f.add(button58); buttons.add(button58);
JButton button61 = new JButton("");
button61.setBackground(Color.GRAY); button61.setBackground(Color.GRAY);
button61.setBounds(143, 135 + 5 * 58, 58, 58); button61.setBounds(143, 135 + 5 * 58, 58, 58);
f.add(button61); buttons.add(button61); f.add(button61); buttons.add(button61);
JButton button62 = new JButton("");
button62.setBackground(Color.GRAY); button62.setBackground(Color.GRAY);
button62.setBounds(143 + 58, 135 + 5 * 58, 58, 58); button62.setBounds(143 + 58, 135 + 5 * 58, 58, 58);
f.add(button62); buttons.add(button62); f.add(button62); buttons.add(button62);
JButton button63 = new JButton("");
button63.setBackground(Color.GRAY); button63.setBackground(Color.GRAY);
button63.setBounds(143 + 2 * 58, 135 + 5 * 58, 58, 58); button63.setBounds(143 + 2 * 58, 135 + 5 * 58, 58, 58);
f.add(button63); buttons.add(button63); f.add(button63); buttons.add(button63);
JButton button64 = new JButton("");
button64.setBackground(Color.GRAY); button64.setBackground(Color.GRAY);
button64.setBounds(143 + 3 * 58, 135 + 5 * 58, 58, 58); button64.setBounds(143 + 3 * 58, 135 + 5 * 58, 58, 58);
f.add(button64); buttons.add(button64); f.add(button64); buttons.add(button64);
JButton button65 = new JButton("");
button65.setBackground(Color.GRAY); button65.setBackground(Color.GRAY);
button65.setBounds(143 + 4 * 58, 135 + 5 * 58, 58, 58); button65.setBounds(143 + 4 * 58, 135 + 5 * 58, 58, 58);
f.add(button65); buttons.add(button65); f.add(button65); buttons.add(button65);
JButton button66 = new JButton("");
button66.setBackground(Color.GRAY); button66.setBackground(Color.GRAY);
button66.setBounds(143 + 5 * 58, 135 + 5 * 58, 58, 58); button66.setBounds(143 + 5 * 58, 135 + 5 * 58, 58, 58);
f.add(button66); buttons.add(button66); f.add(button66); buttons.add(button66);
JButton button67 = new JButton("");
button67.setBackground(Color.GRAY); button67.setBackground(Color.GRAY);
button67.setBounds(143 + 6 * 58, 135 + 5 * 58, 58, 58); button67.setBounds(143 + 6 * 58, 135 + 5 * 58, 58, 58);
f.add(button67); buttons.add(button67); f.add(button67); buttons.add(button67);
JButton button68 = new JButton("");
button68.setBackground(Color.GRAY); button68.setBackground(Color.GRAY);
button68.setBounds(143 + 7 * 58, 135 + 5 * 58, 58, 58); button68.setBounds(143 + 7 * 58, 135 + 5 * 58, 58, 58);
f.add(button68); buttons.add(button68); f.add(button68); buttons.add(button68);
JButton button71 = new JButton("");
button71.setBackground(Color.GRAY); button71.setBackground(Color.GRAY);
button71.setBounds(143, 135 + 6 * 58, 58, 58); button71.setBounds(143, 135 + 6 * 58, 58, 58);
f.add(button71); buttons.add(button71); f.add(button71); buttons.add(button71);
JButton button72 = new JButton("");
button72.setBackground(Color.GRAY); button72.setBackground(Color.GRAY);
button72.setBounds(143 + 58, 135 + 6 * 58, 58, 58); button72.setBounds(143 + 58, 135 + 6 * 58, 58, 58);
f.add(button72); buttons.add(button72); f.add(button72); buttons.add(button72);
JButton button73 = new JButton("");
button73.setBackground(Color.GRAY); button73.setBackground(Color.GRAY);
button73.setBounds(143 + 2 * 58, 135 + 6 * 58, 58, 58); button73.setBounds(143 + 2 * 58, 135 + 6 * 58, 58, 58);
f.add(button73); buttons.add(button73); f.add(button73); buttons.add(button73);
JButton button74 = new JButton("");
button74.setBackground(Color.GRAY); button74.setBackground(Color.GRAY);
button74.setBounds(143 + 3 * 58, 135 + 6 * 58, 58, 58); button74.setBounds(143 + 3 * 58, 135 + 6 * 58, 58, 58);
f.add(button74); buttons.add(button74); f.add(button74); buttons.add(button74);
JButton button75 = new JButton("");
button75.setBackground(Color.GRAY); button75.setBackground(Color.GRAY);
button75.setBounds(143 + 4 * 58, 135 + 6 * 58, 58, 58); button75.setBounds(143 + 4 * 58, 135 + 6 * 58, 58, 58);
f.add(button75); buttons.add(button75); f.add(button75); buttons.add(button75);
JButton button76 = new JButton("");
button76.setBackground(Color.GRAY); button76.setBackground(Color.GRAY);
button76.setBounds(143 + 5 * 58, 135 + 6 * 58, 58, 58); button76.setBounds(143 + 5 * 58, 135 + 6 * 58, 58, 58);
f.add(button76); buttons.add(button76); f.add(button76); buttons.add(button76);
JButton button77 = new JButton("");
button77.setBackground(Color.GRAY); button77.setBackground(Color.GRAY);
button77.setBounds(143 + 6 * 58, 135 + 6 * 58, 58, 58); button77.setBounds(143 + 6 * 58, 135 + 6 * 58, 58, 58);
f.add(button77); buttons.add(button77); f.add(button77); buttons.add(button77);
JButton button78 = new JButton("");
button78.setBackground(Color.GRAY); button78.setBackground(Color.GRAY);
button78.setBounds(143 + 7 * 58, 135 + 6 * 58, 58, 58); button78.setBounds(143 + 7 * 58, 135 + 6 * 58, 58, 58);
f.add(button78); buttons.add(button78); f.add(button78); buttons.add(button78);
JButton button81 = new JButton("");
button81.setBackground(Color.GRAY); button81.setBackground(Color.GRAY);
button81.setBounds(143, 135 + 7 * 58, 58, 58); button81.setBounds(143, 135 + 7 * 58, 58, 58);
f.add(button81); buttons.add(button81); f.add(button81); buttons.add(button81);
JButton button82 = new JButton("");
button82.setBackground(Color.GRAY); button82.setBackground(Color.GRAY);
button82.setBounds(143 + 58, 135 + 7 * 58, 58, 58); button82.setBounds(143 + 58, 135 + 7 * 58, 58, 58);
f.add(button82); buttons.add(button82); f.add(button82); buttons.add(button82);
JButton button83 = new JButton("");
button83.setBackground(Color.GRAY); button83.setBackground(Color.GRAY);
button83.setBounds(143 + 2 * 58, 135 + 7 * 58, 58, 58); button83.setBounds(143 + 2 * 58, 135 + 7 * 58, 58, 58);
f.add(button83); buttons.add(button83); f.add(button83); buttons.add(button83);
JButton button84 = new JButton("");
button84.setBackground(Color.GRAY); button84.setBackground(Color.GRAY);
button84.setBounds(143 + 3 * 58, 135 + 7 * 58, 58, 58); button84.setBounds(143 + 3 * 58, 135 + 7 * 58, 58, 58);
f.add(button84); buttons.add(button84); f.add(button84); buttons.add(button84);
JButton button85 = new JButton("");
button85.setBackground(Color.GRAY); button85.setBackground(Color.GRAY);
button85.setBounds(143 + 4 * 58, 135 + 7 * 58, 58, 58); button85.setBounds(143 + 4 * 58, 135 + 7 * 58, 58, 58);
f.add(button85); buttons.add(button85); f.add(button85); buttons.add(button85);
JButton button86 = new JButton("");
button86.setBackground(Color.GRAY); button86.setBackground(Color.GRAY);
button86.setBounds(143 + 5 * 58, 135 + 7 * 58, 58, 58); button86.setBounds(143 + 5 * 58, 135 + 7 * 58, 58, 58);
f.add(button86); buttons.add(button86); f.add(button86); buttons.add(button86);
JButton button87 = new JButton("");
button87.setBackground(Color.GRAY); button87.setBackground(Color.GRAY);
button87.setBounds(143 + 6 * 58, 135 + 7 * 58, 58, 58); button87.setBounds(143 + 6 * 58, 135 + 7 * 58, 58, 58);
f.add(button87); buttons.add(button87); f.add(button87); buttons.add(button87);
JButton button88 = new JButton("");
button88.setBackground(Color.GRAY); button88.setBackground(Color.GRAY);
button88.setBounds(143 + 7 * 58, 135 + 7 * 58, 58, 58); button88.setBounds(143 + 7 * 58, 135 + 7 * 58, 58, 58);
f.add(button88); buttons.add(button88); f.add(button88); buttons.add(button88);
...@@ -298,18 +302,29 @@ public class Graphic extends Display { ...@@ -298,18 +302,29 @@ public class Graphic extends Display {
for (int j = 1; j <= 8; j++) { for (int j = 1; j <= 8; j++) {
if (a2[j][i] != 0) { if (a2[j][i] != 0) {
// the unicode of white circle (there is a player2 disc) // the unicode of white circle (there is a player2 disc)
searchInButtons(j, i).setBackground(Color.WHITE);
} }
else { else {
if (a1[j][i] != 0) { if (a1[j][i] != 0) {
// the unicode of black circle (there is a player1 disc) // the unicode of black circle (there is a player1 disc)
System.out.print('\u25CF'); searchInButtons(j, i).setBackground(Color.BLACK);
} }
else else
// the unicode of white square (a blank) // the unicode of white square (a blank)
System.out.print('\u25A1'); searchInButtons(j, i).setBackground(Color.GRAY);
} }
} }
} }
} }
public JButton searchInButtons(int x, int y){
Iterator<JButton> buttonIterator = buttons.iterator();
while (buttonIterator.hasNext()){
JButton b1 = buttonIterator.next();
if (b1.getX() == (x - 1) * 58 + 143 && b1.getY() == (y - 1) * 58 + 135) {
return b1;
}
}
return null;
}
} }
...@@ -9,11 +9,17 @@ public class Main { ...@@ -9,11 +9,17 @@ public class Main {
System.out.println("What type of game do you want? 0)console 1)graphic"); System.out.println("What type of game do you want? 0)console 1)graphic");
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
byte displayType = scanner.nextByte(); byte displayType = scanner.nextByte();
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(), displayType); if (displayType == 0) {
while ((play1.getNumberOfDisks(play1.getArr1()) + play2.getNumberOfDisks(play2.getArr2()) < 64) && Console console = new Console(displayType);
console.display(play1.getArr1(), play2.getArr2());
}
else {
Graphic graphic = new Graphic(displayType);
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) && if ((play1.numberOfPlayerPossibleMoves(play2.getArr2(), play1.getArr1()) == 0) &&
...@@ -54,13 +60,18 @@ public class Main { ...@@ -54,13 +60,18 @@ public class Main {
} }
} }
players.display(play1.getArr1(), play2.getArr2(), displayType); if (displayType == 0) {
console.display(play1.getArr1(), play2.getArr2());
}
else {
graphic.display(play1.getArr1(), play2.getArr2());
}
//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()))
System.out.println("Player1 wins!"); System.out.println("Player1 wins!");
else 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