|)PS&{v=OWPS0$r&huizcaJ9&=)t^IsZMEIp6>H
z|IXQD=)GX#=SSb(0nms=9RYOf@T13#Ui7Kx*Wp07h5^wY)DgoW5gpcX1TSegs^OT1
zmsK>0-a!q=#lVnw4C@#{T*C%_3#7YzpTkNI?UyV_x)@
zt5`7b1}@zEQh6Ym-#agxpE-kOmuoEUXL91BLjpJAa~FR_*h*}j;Z;aC7|00n>9RUq
z2r)M738+9Nf4NbGC)gtv|IVz%;%nwTHRALnZ$TE3L$QN~Ryq4dFXsY9#O!5i#kh)+
zoVQ=YlX%K{`_r~G^PINNr+f#;&?=l>*9z3|Eof|3;9h}l{-lKxnc=*x!(v;-N~8iB
z<5KKK83y3PF;;h+Bu+7&;a2Z55s~C}CLSY~YJ{26ZX8DqYS~}MZvh-h#8lKvUS%Cl
zB8Ui)35&rM<|T7dvuE!qKvJgls13(&Q~Z5`~8lw*pehIZ~l`N>LYWIv6GZT
zWL!eQ|=d^+hq5127*-5^*7~MDWunz9D6yg8SqroDui=enf#8
z$g9psstGjgtY1N)*ORV$(UL-HYoxpa?~=^;MwVbb^7x)-skMM-~AU>{e7X&5&TZZ+D%Rzc&O7Um08E~w#B$?`%8TuHc96i6Fz
zNhQv8RIGDfjeG48DSc#AW%PT61!{9`n-y!9dq21D-~sEThz@%20J(H!gt^!&a4J?>
zEtVRQ;9f=&S4J$vvZc#%fXi}#fkNtO#dAWBdEE$A7Y8n%nfM^K
z(UO(Fjq?41e+h#C1N-b{lW0ahrS(usFNycD`n`1U0NEZyJ6U(&5c+W#C&+b{@dA$G
z6XFzpiPG;X52HxX!Nen}h|4}rkq4tTD_0Rc&q(G})5==0vMz&`glhZVw}A@D+bJ2H
zJOnNhh_bGNz-InPBFG&Z2pSmT1vt!Tgo@+XL2c!1t1yasjIqq4!WKdkYC9ikh-s}lTa0B&`u$8pQeVsxvKfpS?8;~iu*!9pl
z8NB_4Xiof-znv8PFsERT9bx}fROO6sPgiUQ1FKp^%ee0UB8b79S*7V&Wtmy##ln_A
z=IZi2HbFOkEu=H-J6O*;V3?)_PP6h;2x6KPW?0L!m|(r9F^75nC%w(*CARPLPwEQ$
zKgR{EVi7;^{#e7C_ziF254QI>^FI6kMgkA;j>Y~6>$u31Y_ad=i+14!f>v;ncZdKj
n<1TM@yEJROI_=SK=pcKP{8D8Q(E+Pmb>=Ug8nuhUWxV(whW9(%
From 61a03d07a6fea63903262314c9241f94a79a4fdf Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Fri, 16 Apr 2021 17:40:37 +0300
Subject: [PATCH 5/8] Version6
---
src/main/java/Lesson6/Animal.java | 13 +++++++++++++
src/main/java/Lesson6/Cat.java | 23 +++++++++++++++++++++++
src/main/java/Lesson6/Dog.java | 24 ++++++++++++++++++++++++
src/main/java/Lesson6/homeWorkApp6.java | 15 +++++++++++++++
4 files changed, 75 insertions(+)
create mode 100644 src/main/java/Lesson6/Animal.java
create mode 100644 src/main/java/Lesson6/Cat.java
create mode 100644 src/main/java/Lesson6/Dog.java
create mode 100644 src/main/java/Lesson6/homeWorkApp6.java
diff --git a/src/main/java/Lesson6/Animal.java b/src/main/java/Lesson6/Animal.java
new file mode 100644
index 0000000..49dff25
--- /dev/null
+++ b/src/main/java/Lesson6/Animal.java
@@ -0,0 +1,13 @@
+package Lesson6;
+
+public abstract class Animal {
+ private final int MAX_RUN_LENGTH = 0;
+ private final int MAX_SWIM_LENGTH = 0;
+ private final double MAX_JUMP_HEIGTH = 0;
+
+ abstract void run(int length);
+
+ abstract void swim(int length);
+
+ abstract void jump(double height);
+}
diff --git a/src/main/java/Lesson6/Cat.java b/src/main/java/Lesson6/Cat.java
new file mode 100644
index 0000000..2c881a1
--- /dev/null
+++ b/src/main/java/Lesson6/Cat.java
@@ -0,0 +1,23 @@
+package Lesson6;
+
+public class Cat extends Animal {
+ private final int MAX_RUN_LENGTH = 200;
+ private final double MAX_JUMP_HEIGTH = 2;
+
+ @Override
+ void run(int length) {
+ if ((length >= 0) && (length <= MAX_RUN_LENGTH)) System.out.println("run: true");
+ else System.out.println("run: false");
+ }
+
+ @Override
+ void swim(int length) {
+ System.out.println("swim: false");
+ }
+
+ @Override
+ void jump(double height) {
+ if ((height >= 0) && (height <= MAX_JUMP_HEIGTH)) System.out.println("jump: true");
+ else System.out.println("jump: false");
+ }
+}
diff --git a/src/main/java/Lesson6/Dog.java b/src/main/java/Lesson6/Dog.java
new file mode 100644
index 0000000..b5c0a59
--- /dev/null
+++ b/src/main/java/Lesson6/Dog.java
@@ -0,0 +1,24 @@
+package Lesson6;
+
+public class Dog extends Animal {
+ private final int MAX_RUN_LENGTH = 500;
+ private final int MAX_SWIM_LENGTH = 10;
+ private final double MAX_JUMP_HEIGTH = 0.5;
+
+ @Override
+ void run(int length) {
+ if ((length >= 0) && (length <= MAX_RUN_LENGTH)) System.out.println("run: true");
+ }
+
+ @Override
+ void swim(int length) {
+ if ((length >= 0) && (length <= MAX_SWIM_LENGTH)) System.out.println("swim: true");
+ else System.out.println("swim: false");
+ }
+
+ @Override
+ void jump(double height) {
+ if ((height >= 0) && (height <= MAX_JUMP_HEIGTH)) System.out.println("jump: true");
+ else System.out.println("jump: false");
+ }
+}
diff --git a/src/main/java/Lesson6/homeWorkApp6.java b/src/main/java/Lesson6/homeWorkApp6.java
new file mode 100644
index 0000000..91b0084
--- /dev/null
+++ b/src/main/java/Lesson6/homeWorkApp6.java
@@ -0,0 +1,15 @@
+package Lesson6;
+
+public class homeWorkApp6 {
+ public static void main(String[] args) {
+ Cat cat = new Cat();
+ cat.run(201);
+ cat.swim(1);
+ cat.jump(1.9);
+
+ Dog dog = new Dog();
+ dog.run(500);
+ dog.swim(10);
+ dog.jump(0.4);
+ }
+}
From e4336b8afba613ee0e8a63d77a9243681b462cc8 Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Mon, 19 Apr 2021 21:45:56 +0300
Subject: [PATCH 6/8] Version6
---
src/main/java/Lesson6/Animal.java | 15 +++++++++++++++
src/main/java/Lesson6/Cat.java | 22 +++++++++++++++++-----
src/main/java/Lesson6/Dog.java | 24 +++++++++++++++++++-----
src/main/java/Lesson6/homeWorkApp6.java | 14 ++++++++++++--
4 files changed, 63 insertions(+), 12 deletions(-)
diff --git a/src/main/java/Lesson6/Animal.java b/src/main/java/Lesson6/Animal.java
index 49dff25..ab61a78 100644
--- a/src/main/java/Lesson6/Animal.java
+++ b/src/main/java/Lesson6/Animal.java
@@ -1,13 +1,28 @@
package Lesson6;
public abstract class Animal {
+ private static int counterAnimal = 0;
private final int MAX_RUN_LENGTH = 0;
private final int MAX_SWIM_LENGTH = 0;
private final double MAX_JUMP_HEIGTH = 0;
+ private String name;
+
+ public Animal(String name) {
+ this.name = name;
+ counterAnimal++;
+ }
+
+ public static int getCountAnimal() {
+ return counterAnimal;
+ }
abstract void run(int length);
abstract void swim(int length);
abstract void jump(double height);
+
+ public String getName() {
+ return name;
+ }
}
diff --git a/src/main/java/Lesson6/Cat.java b/src/main/java/Lesson6/Cat.java
index 2c881a1..3f40d1b 100644
--- a/src/main/java/Lesson6/Cat.java
+++ b/src/main/java/Lesson6/Cat.java
@@ -3,21 +3,33 @@
public class Cat extends Animal {
private final int MAX_RUN_LENGTH = 200;
private final double MAX_JUMP_HEIGTH = 2;
+ private static int countCat = 0;
+
+ public Cat(String name) {
+ super(name);
+ countCat++;
+ }
+
+ public static int getCountCat() {
+ return countCat;
+ }
@Override
void run(int length) {
- if ((length >= 0) && (length <= MAX_RUN_LENGTH)) System.out.println("run: true");
- else System.out.println("run: false");
+ if ((length >= 0) && (length <= MAX_RUN_LENGTH))
+ System.out.println("Кошка " + getName() + " пробежала " + length + " м");
+ else System.out.println("Кошка " + getName() + " может пробежать максимум " + MAX_RUN_LENGTH + " м");
}
@Override
void swim(int length) {
- System.out.println("swim: false");
+ System.out.println("Кошка " + getName() + " не умеет плавать");
}
@Override
void jump(double height) {
- if ((height >= 0) && (height <= MAX_JUMP_HEIGTH)) System.out.println("jump: true");
- else System.out.println("jump: false");
+ if ((height >= 0) && (height <= MAX_JUMP_HEIGTH))
+ System.out.println("Кошка " + getName() + " прыгнула на " + height + " м");
+ else System.out.println("Кошка " + getName() + " может прыгнуть максимум " + MAX_JUMP_HEIGTH + " м");
}
}
diff --git a/src/main/java/Lesson6/Dog.java b/src/main/java/Lesson6/Dog.java
index b5c0a59..57b80bc 100644
--- a/src/main/java/Lesson6/Dog.java
+++ b/src/main/java/Lesson6/Dog.java
@@ -4,21 +4,35 @@ public class Dog extends Animal {
private final int MAX_RUN_LENGTH = 500;
private final int MAX_SWIM_LENGTH = 10;
private final double MAX_JUMP_HEIGTH = 0.5;
+ private static int countDog = 0;
+
+ public Dog(String name) {
+ super(name);
+ countDog++;
+ }
+
+ public static int getCountDog() {
+ return countDog;
+ }
@Override
void run(int length) {
- if ((length >= 0) && (length <= MAX_RUN_LENGTH)) System.out.println("run: true");
+ if ((length >= 0) && (length <= MAX_RUN_LENGTH))
+ System.out.println("Собака " + getName() + " пробежала " + length + " м");
+ else System.out.println("Собака " + getName() + " может пробежать максимум " + MAX_RUN_LENGTH + " м");
}
@Override
void swim(int length) {
- if ((length >= 0) && (length <= MAX_SWIM_LENGTH)) System.out.println("swim: true");
- else System.out.println("swim: false");
+ if ((length >= 0) && (length <= MAX_SWIM_LENGTH))
+ System.out.println("Собака " + getName() + " проплыла " + length + " м");
+ else System.out.println("Собака " + getName() + " может проплыть максимум " + MAX_SWIM_LENGTH + " м");
}
@Override
void jump(double height) {
- if ((height >= 0) && (height <= MAX_JUMP_HEIGTH)) System.out.println("jump: true");
- else System.out.println("jump: false");
+ if ((height >= 0) && (height <= MAX_JUMP_HEIGTH))
+ System.out.println("Собака " + getName() + " прыгнула на " + height + " м");
+ else System.out.println("Собака " + getName() + " может прыгнуть максимум " + MAX_JUMP_HEIGTH + " м");
}
}
diff --git a/src/main/java/Lesson6/homeWorkApp6.java b/src/main/java/Lesson6/homeWorkApp6.java
index 91b0084..3fb7a40 100644
--- a/src/main/java/Lesson6/homeWorkApp6.java
+++ b/src/main/java/Lesson6/homeWorkApp6.java
@@ -2,14 +2,24 @@
public class homeWorkApp6 {
public static void main(String[] args) {
- Cat cat = new Cat();
+ Cat cat = new Cat("Котюля");
cat.run(201);
cat.swim(1);
cat.jump(1.9);
- Dog dog = new Dog();
+
+ Dog dog = new Dog("Собачюля");
dog.run(500);
dog.swim(10);
dog.jump(0.4);
+
+ Dog dog1 = new Dog("Собакевич");
+ dog1.run(501);
+ dog1.swim(50);
+ dog1.jump(2);
+
+ System.out.println("Животных в итоге " + Animal.getCountAnimal() + " шт.");
+ System.out.println("Кошачьих в итоге " + Cat.getCountCat() + " шт.");
+ System.out.println("Собачек в итоге " + Dog.getCountDog() + " шт.");
}
}
From 3c064fe929d74739de5581fd3353698a7ded4d5d Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Mon, 19 Apr 2021 22:57:53 +0300
Subject: [PATCH 7/8] Version7
---
src/main/java/lesson7/Cat.java | 26 ++++++++++++++++++++++++++
src/main/java/lesson7/Main.java | 26 ++++++++++++++++++++++++++
src/main/java/lesson7/Plate.java | 28 ++++++++++++++++++++++++++++
3 files changed, 80 insertions(+)
create mode 100644 src/main/java/lesson7/Cat.java
create mode 100644 src/main/java/lesson7/Main.java
create mode 100644 src/main/java/lesson7/Plate.java
diff --git a/src/main/java/lesson7/Cat.java b/src/main/java/lesson7/Cat.java
new file mode 100644
index 0000000..fd1b00b
--- /dev/null
+++ b/src/main/java/lesson7/Cat.java
@@ -0,0 +1,26 @@
+package lesson7;
+
+public class Cat {
+ private String name;
+ private int appetite;
+ private String isFull;
+
+ Cat(String name, int appetite) {
+ this.name = name;
+ this.appetite = appetite;
+ this.isFull = "остался голодным";
+ }
+
+ @Override
+ public String toString() {
+ return name + " ест с аппетитом: " + appetite + " и поэтому он " + isFull;
+ }
+
+ void eat(Plate plate) {
+ if (plate.getAmountOfFood() > appetite) {
+ isFull = "наелся";
+ plate.decreaseFood(appetite);
+ } else plate.decreaseFood(plate.getAmountOfFood());
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/lesson7/Main.java b/src/main/java/lesson7/Main.java
new file mode 100644
index 0000000..9106972
--- /dev/null
+++ b/src/main/java/lesson7/Main.java
@@ -0,0 +1,26 @@
+package lesson7;
+
+public class Main {
+ public static void main(String[] args) {
+ System.out.println("Список котов:");
+ Cat[] x = {new Cat("Матроскин", 207), new Cat("Полосатый", 175), new Cat("Рыжий", 150)};
+ Plate plate = new Plate(100);
+ for (Cat c : x) {
+ System.out.println(c);
+ }
+ System.out.println(plate);
+ System.out.println("***********************************************");
+
+
+ plate.increaseFood(250);
+ System.out.println("Добавим ещё 250 гр.");
+ System.out.println(plate);
+ System.out.println("***********************************************");
+ System.out.println("Кошары начинают есть:");
+ for (Cat c : x) {
+ c.eat(plate);
+ System.out.println(c);
+ System.out.println(plate);
+ }
+ }
+}
diff --git a/src/main/java/lesson7/Plate.java b/src/main/java/lesson7/Plate.java
new file mode 100644
index 0000000..ea425ba
--- /dev/null
+++ b/src/main/java/lesson7/Plate.java
@@ -0,0 +1,28 @@
+package lesson7;
+
+public class Plate {
+ private int amountOfFood;
+
+ Plate(int amountOfFood) {
+ this.amountOfFood = amountOfFood;
+ }
+
+ @Override
+ public String toString() {
+ return "В тарелке: " + amountOfFood + " гр.";
+ }
+
+ void decreaseFood(int appetite) {
+ if (amountOfFood >= appetite) {
+ amountOfFood -= appetite;
+ }
+ }
+
+ int getAmountOfFood() {
+ return amountOfFood;
+ }
+
+ void increaseFood(int amount) {
+ amountOfFood += amount;
+ }
+}
\ No newline at end of file
From 86fb0cfb1ba6eb6e7df36beecea07ede07b65c90 Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Thu, 22 Apr 2021 21:33:12 +0300
Subject: [PATCH 8/8] =?UTF-8?q?Version8=20-=20=D0=98=D0=B3=D1=80=D0=B0=20?=
=?UTF-8?q?=D0=BA=D1=80=D0=B5=D1=81=D1=82=D0=B8=D0=BA=D0=B8-=D0=BD=D0=BE?=
=?UTF-8?q?=D0=BB=D0=B8=D0=BA=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lesson8/TicTacToe.java | 333 +++++++++++++++++++++++++++
1 file changed, 333 insertions(+)
create mode 100644 src/main/java/lesson8/TicTacToe.java
diff --git a/src/main/java/lesson8/TicTacToe.java b/src/main/java/lesson8/TicTacToe.java
new file mode 100644
index 0000000..5c2623b
--- /dev/null
+++ b/src/main/java/lesson8/TicTacToe.java
@@ -0,0 +1,333 @@
+package lesson8;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.Random;
+
+public class TicTacToe extends JFrame {
+ final int SIZE = 3;
+ JPanel panel = new JPanel(new GridLayout(SIZE, SIZE));
+ JButton[][] buttons = new JButton[SIZE][SIZE];
+
+ //FORM CONSTRUCTOR
+ public TicTacToe() {
+ super("Крестики-нолики");
+ setContentPane(panel);
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ setSize(300, 300);
+ setLocationRelativeTo(null);
+ setResizable(false);
+ panel.setOpaque(true);
+ panel.setBackground(Color.DARK_GRAY);
+
+ for (int i = 0; i < SIZE; i++) {
+ for (int j = 0; j < SIZE; j++) {
+ buttons[i][j] = new JButton();
+ buttons[i][j].setBackground(Color.GREEN);
+ buttons[i][j].setFont(new Font("Шериф", Font.BOLD, (200 / SIZE)));
+ buttons[i][j].setText("");
+ panel.add(buttons[i][j]);
+ }
+ }
+
+ buttons[0][0].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[0][0].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[0][0].setText("X");
+ buttons[0][0].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[0][1].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[0][1].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[0][1].setText("X");
+ buttons[0][1].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[0][2].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[0][2].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[0][2].setText("X");
+ buttons[0][2].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[1][0].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[1][0].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[1][0].setText("X");
+ buttons[1][0].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[1][1].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[1][1].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[1][1].setText("X");
+ buttons[1][1].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[1][2].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[1][2].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[1][2].setText("X");
+ buttons[1][2].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[2][0].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[2][0].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[2][0].setText("X");
+ buttons[2][0].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[2][1].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[2][1].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[2][1].setText("X");
+ buttons[2][1].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+ buttons[2][2].addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (buttons[2][2].getText().equals("") && !checkWin() && !isFull()) {
+ buttons[2][2].setText("X");
+ buttons[2][2].setBackground(new Color(128, 111, 255));
+ if (!checkWin() && !isFull()) aiTurn();
+ }
+ }
+ });
+
+ setVisible(true);
+ }
+
+ public static void main(String[] args) {
+ //NIMBUS STYLE
+ try {
+ for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
+ if ("Нимбус".equals(info.getName())) {
+ UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (Exception e) {
+ try {
+ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
+ } catch (Exception ex) {
+
+ }
+ }
+
+ //VIEW FORM
+ TicTacToe game = new TicTacToe();
+ }
+
+ public void startNew() {
+ for (int i = 0; i < SIZE; i++) {
+ for (int j = 0; j < SIZE; j++) {
+ buttons[i][j].setText("");
+ buttons[i][j].setBackground(Color.ORANGE);
+ }
+ }
+ }
+
+ boolean isFull() {
+ for (int i = 0; i < SIZE; i++) {
+ for (int j = 0; j < SIZE; j++) {
+ if (buttons[i][j].getText().equals("")) return false;
+ }
+ }
+ //JOptionPane.showMessageDialog(null, "Map is full");
+ int reply = JOptionPane.showConfirmDialog(null, "ПЕРЕЗАПУСТИТЬ игру?", "Поле заполнено", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+
+ return true;
+ }
+
+ void aiTurn() {
+ Random r = new Random();
+ int i = r.nextInt(SIZE);
+ int j = r.nextInt(SIZE);
+ while (!isCellValid(i, j)) {
+ i = r.nextInt(SIZE);
+ j = r.nextInt(SIZE);
+ }
+ buttons[i][j].setText("O");
+ buttons[i][j].setBackground(new Color(255, 111, 120));
+ checkWin();
+ }
+
+ boolean isCellValid(int i, int j) {
+ if (buttons[i][j].getText().equals("")) {
+ return true;
+ }
+ return false;
+ }
+
+ boolean checkWin() {
+ int countXH = 0;
+ int countOH = 0;
+ int countXV = 0;
+ int countOV = 0;
+ int countXD = 0;
+ int countOD = 0;
+ int countXD2 = 0;
+ int countOD2 = 0;
+ for (int i = 0; i < SIZE; i++) {
+ countXH = 0;
+ countOH = 0;
+ countXV = 0;
+ countOV = 0;
+ for (int j = 0; j < SIZE; j++) {
+ if (buttons[i][j].getText().equals("X")) {
+ countXH += 1;
+ if (countXH == SIZE) {
+ //JOptionPane.showMessageDialog(null, "You Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы выйграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+ if (buttons[i][j].getText().equals("O")) {
+ countOH += 1;
+ if (countOH == SIZE) {
+ //JOptionPane.showMessageDialog(null, "AI Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы проиграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+
+ if (buttons[j][i].getText().equals("X")) {
+ countXV += 1;
+ if (countXV == SIZE) {
+ //JOptionPane.showMessageDialog(null, "You Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы выйграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+ if (buttons[j][i].getText().equals("O")) {
+ countOV += 1;
+ if (countOV == SIZE) {
+ //JOptionPane.showMessageDialog(null, "AI Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы проиграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+ }
+
+ if (buttons[i][i].getText().equals("X")) {
+ countXD += 1;
+ if (countXD == SIZE) {
+ //JOptionPane.showMessageDialog(null, "You Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы выйграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+ if (buttons[i][i].getText().equals("O")) {
+ countOD += 1;
+ if (countOD == SIZE) {
+ //JOptionPane.showMessageDialog(null, "AI Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы проиграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+
+ if (buttons[i][SIZE - i - 1].getText().equals("X")) {
+ countXD2 += 1;
+ if (countXD2 == SIZE) {
+ //JOptionPane.showMessageDialog(null, "You Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы выйграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+ if (buttons[i][SIZE - i - 1].getText().equals("O")) {
+ countOD2 += 1;
+ if (countOD2 == SIZE) {
+ //JOptionPane.showMessageDialog(null, "AI Win");
+ int reply = JOptionPane.showConfirmDialog(null, "Вы проиграли! ПЕРЕЗАПУСТИТЬ игру?", "Игра окончена", JOptionPane.YES_NO_OPTION);
+ if (reply == JOptionPane.YES_OPTION) {
+ startNew();
+ } else {
+ System.exit(0);
+ }
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+}
\ No newline at end of file