Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         int counter = 0;
  16.         char[,] tic = new char[3, 3] { { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'h', 'g', 'k' } };
  17.  
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void Form1_Paint(object sender, PaintEventArgs e)
  24.         {
  25.             Graphics g = e.Graphics;
  26.             float x0 = this.Width / 5,
  27.                 y0 = this.Height / 5,
  28.                 x3 = this.Width - x0,
  29.                 y3 = this.Height - y0,
  30.                 x1 = x0 + (x3 - x0) / 3,
  31.                 y1 = y0 + (y3 - y0) / 3,
  32.                 x2 = x0 + 2 * (x3 - x0) / 3,
  33.                 y2 = y0 + 2 * (x3 - x0) / 3,
  34.                 test = x0 + (x3 - x0) / 3;
  35.             g.DrawLine(new Pen(Color.SlateGray, 2.5f), x0, y0, x3, y0);
  36.             g.DrawLine(new Pen(Color.SlateGray, 2.5f), x3, y0, x3, y3);
  37.             g.DrawLine(new Pen(Color.SlateGray, 2.5f), x3, y3, x0, y3);
  38.             g.DrawLine(new Pen(Color.SlateGray, 2.5f), x0, y3, x0, y0);
  39.             g.DrawLine(new Pen(Color.Gray, 2.5f), x1, y0, x1, y3);
  40.             g.DrawLine(new Pen(Color.Gray, 2.5f), x2, y0, x2, y3);
  41.             g.DrawLine(new Pen(Color.Gray, 2.5f), x0, y1, x3, y1);
  42.             g.DrawLine(new Pen(Color.Gray, 2.5f), x0, y2, x3, y2);
  43.             System.IO.File.WriteAllText(@"C:\moves.txt", "");
  44.         }
  45.  
  46.         private void Form1_MouseClick(object sender, MouseEventArgs e)
  47.         {
  48.             System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
  49.             float x0 = this.Width / 5,
  50.                 y0 = this.Height / 5,
  51.                 x3 = this.Width - x0,
  52.                 y3 = this.Height - y0,
  53.                 x1 = x0 + (x3 - x0) / 3,
  54.                 y1 = y0 + (y3 - y0) / 3,
  55.                 x2 = x0 + 2 * (x3 - x0) / 3,
  56.                 y2 = y0 + 2 * (x3 - x0) / 3,
  57.                 test = x0 + (x3 - x0) / 3;
  58.             Graphics g = Graphics.FromHwnd(this.Handle);
  59.             Pen redBrush = new Pen(new SolidBrush(Color.Red), 3f);
  60.             Pen blueBrush = new Pen(new SolidBrush(Color.Blue), 3f);
  61.  
  62.  
  63.             if (counter < 9)
  64.             {
  65.  
  66.                 if (counter % 2 == 0)
  67.                 {
  68.                     //РИСУЕМ КРЕСТИКИ
  69.  
  70.                     if (e.X > x1)
  71.                     {
  72.                         if (e.X < x2)
  73.                         {
  74.                             if (e.Y > y1)
  75.                             {
  76.                                 if (e.Y < y2)
  77.                                 {
  78.                                     g.DrawLine(blueBrush, x1 + 7, y1 + 7, x2 - 7, y2 - 7);
  79.                                     g.DrawLine(blueBrush, x1 + 7, y2 - 7, x2 - 7, y1 + 7);
  80.                                     tic[1, 1] = 'X';
  81.                                     string lines = " X в точке (2; 2)\r\n";
  82.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  83.  
  84.                                 }
  85.                                 else
  86.                                 {
  87.                                     g.DrawLine(blueBrush, x1 + 7, y2 + 7, x2 - 7, y3 - 7);
  88.                                     g.DrawLine(blueBrush, x1 + 7, y3 - 7, x2 - 7, y2 + 7);
  89.                                     tic[2, 1] = 'X';
  90.                                     string lines = " X в точке (2; 3)\r\n";
  91.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  92.                                 }
  93.                             }
  94.                             else
  95.                             {
  96.                                 g.DrawLine(blueBrush, x1 + 7, y0 + 7, x2 - 7, y1 - 7);
  97.                                 g.DrawLine(blueBrush, x1 + 7, y1 - 7, x2 - 7, y0 + 7);
  98.                                 tic[0, 1] = 'X';
  99.                                 string lines = " X в точке (2; 1)\r\n";
  100.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  101.                             }
  102.                         }
  103.                         else
  104.                         {
  105.                             if (e.Y > y1)
  106.                             {
  107.                                 if (e.Y < y2)
  108.                                 {
  109.                                     g.DrawLine(blueBrush, x2 + 7, y1 + 7, x3 - 7, y2 - 7);
  110.                                     g.DrawLine(blueBrush, x2 + 7, y2 - 7, x3 - 7, y1 + 7);
  111.                                     tic[1, 2] = 'X';
  112.                                     string lines = " X в точке (3; 2)\r\n";
  113.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  114.                                 }
  115.                                 else
  116.                                 {
  117.                                     g.DrawLine(blueBrush, x2 + 7, y2 + 7, x3 - 7, y3 - 7);
  118.                                     g.DrawLine(blueBrush, x2 + 7, y3 - 7, x3 - 7, y2 + 7);
  119.                                     tic[2, 2] = 'X';
  120.                                     string lines = " X в точке (3; 3)\r\n";
  121.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  122.                                 }
  123.                             }
  124.                             else
  125.                             {
  126.                                 g.DrawLine(blueBrush, x2 + 7, y0 + 7, x3 - 7, y1 - 7);
  127.                                 g.DrawLine(blueBrush, x2 + 7, y1 - 7, x3 - 7, y0 + 7);
  128.                                 tic[0, 2] = 'X';
  129.                                 string lines = " X в точке (3; 1)\r\n";
  130.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  131.                             }
  132.                         }
  133.                     }
  134.                     else
  135.                     {
  136.                         if (e.Y > y1)
  137.                         {
  138.                             if (e.Y < y2)
  139.                             {
  140.                                 g.DrawLine(blueBrush, x0 + 7, y1 + 7, x1 - 7, y2 - 7);
  141.                                 g.DrawLine(blueBrush, x0 + 7, y2 - 7, x1 - 7, y1 + 7);
  142.                                 tic[1, 0] = 'X';
  143.                                 string lines = " X в точке (1; 2)\r\n";
  144.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  145.                             }
  146.                             else
  147.                             {
  148.                                 g.DrawLine(blueBrush, x0 + 7, y2 + 7, x1 - 7, y3 - 7);
  149.                                 g.DrawLine(blueBrush, x0 + 7, y3 - 7, x1 - 7, y2 + 7);
  150.                                 tic[2, 0] = 'X';
  151.                                 string lines = " X в точке (1; 3)\r\n";
  152.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  153.                             }
  154.                         }
  155.                         else
  156.                         {
  157.                             g.DrawLine(blueBrush, x0 + 7, y0 + 7, x1 - 7, y1 - 7);
  158.                             g.DrawLine(blueBrush, x0 + 7, y1 - 7, x1 - 7, y0 + 7);
  159.                             tic[0, 0] = 'X';
  160.                             string lines = " X в точке (1; 1)\r\n";
  161.                             System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  162.                         }
  163.                     }
  164.  
  165.                 }
  166.  
  167.                 //РИСУЕМ НОЛИКИ
  168.  
  169.                 else
  170.                 {
  171.                     if (e.X > x1)
  172.                     {
  173.                         if (e.X < x2)
  174.                         {
  175.                             if (e.Y > y1)
  176.                             {
  177.                                 if (e.Y < y2)
  178.                                 {
  179.                                     g.DrawEllipse(redBrush, x1 + 7, y1 + 7, x2 - x1 - 14, y2 - y1 - 14);
  180.                                     tic[1, 1] = 'O';
  181.                                     string lines = " O в точке (2; 2)\r\n";
  182.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  183.                                 }
  184.                                 else
  185.                                 {
  186.                                     g.DrawEllipse(redBrush, x1 + 7, y2 + 7, x2 - x1 - 14, y3 - y2 - 14);
  187.                                     tic[2, 1] = 'O';
  188.                                     string lines = " O в точке (2; 3)\r\n";
  189.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  190.                                 }
  191.                             }
  192.                             else
  193.                             {
  194.                                 g.DrawEllipse(redBrush, x1 + 7, y0 + 7, x2 - x1 - 14, y1 - y0 - 14);
  195.                                 tic[0, 1] = 'O';
  196.                                 string lines = " O в точке (2; 1)\r\n";
  197.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  198.                             }
  199.                         }
  200.                         else
  201.                         {
  202.                             if (e.Y > y1)
  203.                             {
  204.                                 if (e.Y < y2)
  205.                                 {
  206.                                     g.DrawEllipse(redBrush, x2 + 7, y1 + 7, x3 - x2 - 14, y2 - y1 - 14);
  207.                                     tic[1, 2] = 'O';
  208.                                     string lines = " O в точке (3; 2)\r\n";
  209.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  210.                                 }
  211.                                 else
  212.                                 {
  213.                                     g.DrawEllipse(redBrush, x2 + 7, y2 + 7, x3 - x2 - 14, y3 - y2 - 14);
  214.                                     tic[2, 2] = 'O';
  215.                                     string lines = " O в точке (3; 3)\r\n";
  216.                                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  217.                                 }
  218.                             }
  219.                             else
  220.                             {
  221.                                 g.DrawEllipse(redBrush, x2 + 7, y0 + 7, x3 - x2 - 14, y1 - y0 - 14);
  222.                                 tic[0, 2] = 'O';
  223.                                 string lines = " O в точке (3; 1)\r\n";
  224.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  225.                             }
  226.                         }
  227.                     }
  228.                     else
  229.                     {
  230.                         if (e.Y > y1)
  231.                         {
  232.                             if (e.Y < y2)
  233.                             {
  234.                                 g.DrawEllipse(redBrush, x0 + 7, y1 + 7, x1 - x0 - 14, y2 - y1 - 14);
  235.                                 tic[1, 0] = 'O';
  236.                                 string lines = " O в точке (1; 2)\r\n";
  237.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  238.                             }
  239.                             else
  240.                             {
  241.                                 g.DrawEllipse(redBrush, x0 + 7, y2 + 7, x1 - x0 - 14, y3 - y2 - 14);
  242.                                 tic[2, 0] = 'O';
  243.                                 string lines = " O в точке (1; 3)\r\n";
  244.                                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  245.                             }
  246.                         }
  247.                         else
  248.                         {
  249.                             g.DrawEllipse(redBrush, x0 + 7, y0 + 7, x1 - x0 - 14, y1 - y0 - 14);
  250.                             tic[0, 0] = 'O';
  251.                             string lines = " O в точке (1; 1)\r\n";
  252.                             System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  253.                         }
  254.                     }
  255.  
  256.                 }
  257.  
  258.             }
  259.  
  260.  
  261.  
  262.             if (tic[0, 0] == tic[1, 1] && tic[1, 1] == tic[2, 2] ||
  263.                 tic[1, 0] == tic[1, 1] && tic[1, 1] == tic[1, 2] ||
  264.                 tic[2, 0] == tic[1, 1] && tic[1, 1] == tic[0, 2] ||
  265.                 tic[2, 1] == tic[1, 1] && tic[1, 1] == tic[0, 1])
  266.             {
  267.                 if (counter % 2 == 0)
  268.                 {
  269.                     string lines = " Игра окончена. \r\n Исход: Победа X.";
  270.                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  271.                 }
  272.  
  273.                 else
  274.                 {
  275.                     string lines = " Игра окончена. \r\n Исход: Победа O.";
  276.                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  277.                 }
  278.  
  279.                 counter = 8;
  280.                 messageBoxCS.AppendFormat("    Победили {0}\n", tic[1, 1]);
  281.                 MessageBox.Show(messageBoxCS.ToString(), "Report");
  282.             }
  283.  
  284.             else if (tic[0, 0] == tic[0, 1] && tic[0, 1] == tic[0, 2] ||
  285.                      tic[0, 0] == tic[1, 0] && tic[1, 0] == tic[2, 0] )
  286.             {
  287.                 if (counter % 2 == 0)
  288.                 {
  289.                     string lines = " Игра окончена. \r\n Исход: Победа X.";
  290.                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  291.                 }
  292.  
  293.                 else
  294.                 {
  295.                     string lines = " Игра окончена. \r\n Исход: Победа O.";
  296.                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  297.                 }
  298.  
  299.                 counter = 8;
  300.                 messageBoxCS.AppendFormat("    Победили {0}\n", tic[0, 0]);
  301.                 MessageBox.Show(messageBoxCS.ToString(), "Report");
  302.             }
  303.  
  304.             else if (tic[2, 2] == tic[2, 1] && tic[2, 1] == tic[2, 0] ||
  305.                      tic[2, 2] == tic[1, 2] && tic[1, 2] == tic[0, 2])
  306.             {
  307.                 if (counter % 2 == 0)
  308.                 {
  309.                     string lines = " Игра окончена. \r\n Исход: Победа X.";
  310.                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  311.                 }
  312.  
  313.                 else
  314.                 {
  315.                     string lines = " Игра окончена. \r\n Исход: Победа O.";
  316.                     System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  317.                 }
  318.  
  319.                 counter = 8;
  320.                 messageBoxCS.AppendFormat("    Победили {0}\n", tic[2, 2]);
  321.                 MessageBox.Show(messageBoxCS.ToString(), "Report");
  322.             }
  323.  
  324.             else if (counter == 8)
  325.             {
  326.                 string lines = " Игра окончена. \r\n Исход: Ничья.";
  327.                 System.IO.File.AppendAllText(@"C:\moves.txt", lines);
  328.                 messageBoxCS.AppendFormat("  Игра окончена\n         Ничья");
  329.                 MessageBox.Show(messageBoxCS.ToString(), "Report");
  330.             }
  331.  
  332.  
  333.             counter++;
  334.         }
  335.  
  336.        
  337.  
  338.     }
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement