Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- int counter = 0;
- char[,] tic = new char[3, 3] { { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'h', 'g', 'k' } };
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- float x0 = this.Width / 5,
- y0 = this.Height / 5,
- x3 = this.Width - x0,
- y3 = this.Height - y0,
- x1 = x0 + (x3 - x0) / 3,
- y1 = y0 + (y3 - y0) / 3,
- x2 = x0 + 2 * (x3 - x0) / 3,
- y2 = y0 + 2 * (x3 - x0) / 3,
- test = x0 + (x3 - x0) / 3;
- g.DrawLine(new Pen(Color.SlateGray, 2.5f), x0, y0, x3, y0);
- g.DrawLine(new Pen(Color.SlateGray, 2.5f), x3, y0, x3, y3);
- g.DrawLine(new Pen(Color.SlateGray, 2.5f), x3, y3, x0, y3);
- g.DrawLine(new Pen(Color.SlateGray, 2.5f), x0, y3, x0, y0);
- g.DrawLine(new Pen(Color.Gray, 2.5f), x1, y0, x1, y3);
- g.DrawLine(new Pen(Color.Gray, 2.5f), x2, y0, x2, y3);
- g.DrawLine(new Pen(Color.Gray, 2.5f), x0, y1, x3, y1);
- g.DrawLine(new Pen(Color.Gray, 2.5f), x0, y2, x3, y2);
- System.IO.File.WriteAllText(@"C:\moves.txt", "");
- }
- private void Form1_MouseClick(object sender, MouseEventArgs e)
- {
- System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
- float x0 = this.Width / 5,
- y0 = this.Height / 5,
- x3 = this.Width - x0,
- y3 = this.Height - y0,
- x1 = x0 + (x3 - x0) / 3,
- y1 = y0 + (y3 - y0) / 3,
- x2 = x0 + 2 * (x3 - x0) / 3,
- y2 = y0 + 2 * (x3 - x0) / 3,
- test = x0 + (x3 - x0) / 3;
- Graphics g = Graphics.FromHwnd(this.Handle);
- Pen redBrush = new Pen(new SolidBrush(Color.Red), 3f);
- Pen blueBrush = new Pen(new SolidBrush(Color.Blue), 3f);
- if (counter < 9)
- {
- if (counter % 2 == 0)
- {
- //РИСУЕМ КРЕСТИКИ
- if (e.X > x1)
- {
- if (e.X < x2)
- {
- if (e.Y > y1)
- {
- if (e.Y < y2)
- {
- g.DrawLine(blueBrush, x1 + 7, y1 + 7, x2 - 7, y2 - 7);
- g.DrawLine(blueBrush, x1 + 7, y2 - 7, x2 - 7, y1 + 7);
- tic[1, 1] = 'X';
- string lines = " X в точке (2; 2)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- g.DrawLine(blueBrush, x1 + 7, y2 + 7, x2 - 7, y3 - 7);
- g.DrawLine(blueBrush, x1 + 7, y3 - 7, x2 - 7, y2 + 7);
- tic[2, 1] = 'X';
- string lines = " X в точке (2; 3)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- g.DrawLine(blueBrush, x1 + 7, y0 + 7, x2 - 7, y1 - 7);
- g.DrawLine(blueBrush, x1 + 7, y1 - 7, x2 - 7, y0 + 7);
- tic[0, 1] = 'X';
- string lines = " X в точке (2; 1)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- if (e.Y > y1)
- {
- if (e.Y < y2)
- {
- g.DrawLine(blueBrush, x2 + 7, y1 + 7, x3 - 7, y2 - 7);
- g.DrawLine(blueBrush, x2 + 7, y2 - 7, x3 - 7, y1 + 7);
- tic[1, 2] = 'X';
- string lines = " X в точке (3; 2)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- g.DrawLine(blueBrush, x2 + 7, y2 + 7, x3 - 7, y3 - 7);
- g.DrawLine(blueBrush, x2 + 7, y3 - 7, x3 - 7, y2 + 7);
- tic[2, 2] = 'X';
- string lines = " X в точке (3; 3)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- g.DrawLine(blueBrush, x2 + 7, y0 + 7, x3 - 7, y1 - 7);
- g.DrawLine(blueBrush, x2 + 7, y1 - 7, x3 - 7, y0 + 7);
- tic[0, 2] = 'X';
- string lines = " X в точке (3; 1)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- }
- else
- {
- if (e.Y > y1)
- {
- if (e.Y < y2)
- {
- g.DrawLine(blueBrush, x0 + 7, y1 + 7, x1 - 7, y2 - 7);
- g.DrawLine(blueBrush, x0 + 7, y2 - 7, x1 - 7, y1 + 7);
- tic[1, 0] = 'X';
- string lines = " X в точке (1; 2)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- g.DrawLine(blueBrush, x0 + 7, y2 + 7, x1 - 7, y3 - 7);
- g.DrawLine(blueBrush, x0 + 7, y3 - 7, x1 - 7, y2 + 7);
- tic[2, 0] = 'X';
- string lines = " X в точке (1; 3)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- g.DrawLine(blueBrush, x0 + 7, y0 + 7, x1 - 7, y1 - 7);
- g.DrawLine(blueBrush, x0 + 7, y1 - 7, x1 - 7, y0 + 7);
- tic[0, 0] = 'X';
- string lines = " X в точке (1; 1)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- }
- //РИСУЕМ НОЛИКИ
- else
- {
- if (e.X > x1)
- {
- if (e.X < x2)
- {
- if (e.Y > y1)
- {
- if (e.Y < y2)
- {
- g.DrawEllipse(redBrush, x1 + 7, y1 + 7, x2 - x1 - 14, y2 - y1 - 14);
- tic[1, 1] = 'O';
- string lines = " O в точке (2; 2)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- g.DrawEllipse(redBrush, x1 + 7, y2 + 7, x2 - x1 - 14, y3 - y2 - 14);
- tic[2, 1] = 'O';
- string lines = " O в точке (2; 3)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- g.DrawEllipse(redBrush, x1 + 7, y0 + 7, x2 - x1 - 14, y1 - y0 - 14);
- tic[0, 1] = 'O';
- string lines = " O в точке (2; 1)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- if (e.Y > y1)
- {
- if (e.Y < y2)
- {
- g.DrawEllipse(redBrush, x2 + 7, y1 + 7, x3 - x2 - 14, y2 - y1 - 14);
- tic[1, 2] = 'O';
- string lines = " O в точке (3; 2)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- g.DrawEllipse(redBrush, x2 + 7, y2 + 7, x3 - x2 - 14, y3 - y2 - 14);
- tic[2, 2] = 'O';
- string lines = " O в точке (3; 3)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- g.DrawEllipse(redBrush, x2 + 7, y0 + 7, x3 - x2 - 14, y1 - y0 - 14);
- tic[0, 2] = 'O';
- string lines = " O в точке (3; 1)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- }
- else
- {
- if (e.Y > y1)
- {
- if (e.Y < y2)
- {
- g.DrawEllipse(redBrush, x0 + 7, y1 + 7, x1 - x0 - 14, y2 - y1 - 14);
- tic[1, 0] = 'O';
- string lines = " O в точке (1; 2)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- g.DrawEllipse(redBrush, x0 + 7, y2 + 7, x1 - x0 - 14, y3 - y2 - 14);
- tic[2, 0] = 'O';
- string lines = " O в точке (1; 3)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- else
- {
- g.DrawEllipse(redBrush, x0 + 7, y0 + 7, x1 - x0 - 14, y1 - y0 - 14);
- tic[0, 0] = 'O';
- string lines = " O в точке (1; 1)\r\n";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- }
- }
- }
- if (tic[0, 0] == tic[1, 1] && tic[1, 1] == tic[2, 2] ||
- tic[1, 0] == tic[1, 1] && tic[1, 1] == tic[1, 2] ||
- tic[2, 0] == tic[1, 1] && tic[1, 1] == tic[0, 2] ||
- tic[2, 1] == tic[1, 1] && tic[1, 1] == tic[0, 1])
- {
- if (counter % 2 == 0)
- {
- string lines = " Игра окончена. \r\n Исход: Победа X.";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- string lines = " Игра окончена. \r\n Исход: Победа O.";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- counter = 8;
- messageBoxCS.AppendFormat(" Победили {0}\n", tic[1, 1]);
- MessageBox.Show(messageBoxCS.ToString(), "Report");
- }
- else if (tic[0, 0] == tic[0, 1] && tic[0, 1] == tic[0, 2] ||
- tic[0, 0] == tic[1, 0] && tic[1, 0] == tic[2, 0] )
- {
- if (counter % 2 == 0)
- {
- string lines = " Игра окончена. \r\n Исход: Победа X.";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- string lines = " Игра окончена. \r\n Исход: Победа O.";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- counter = 8;
- messageBoxCS.AppendFormat(" Победили {0}\n", tic[0, 0]);
- MessageBox.Show(messageBoxCS.ToString(), "Report");
- }
- else if (tic[2, 2] == tic[2, 1] && tic[2, 1] == tic[2, 0] ||
- tic[2, 2] == tic[1, 2] && tic[1, 2] == tic[0, 2])
- {
- if (counter % 2 == 0)
- {
- string lines = " Игра окончена. \r\n Исход: Победа X.";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- else
- {
- string lines = " Игра окончена. \r\n Исход: Победа O.";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- }
- counter = 8;
- messageBoxCS.AppendFormat(" Победили {0}\n", tic[2, 2]);
- MessageBox.Show(messageBoxCS.ToString(), "Report");
- }
- else if (counter == 8)
- {
- string lines = " Игра окончена. \r\n Исход: Ничья.";
- System.IO.File.AppendAllText(@"C:\moves.txt", lines);
- messageBoxCS.AppendFormat(" Игра окончена\n Ничья");
- MessageBox.Show(messageBoxCS.ToString(), "Report");
- }
- counter++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement