Advertisement
Georgiy031

Untitled

Oct 14th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 38.03 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. using System.Threading;
  11. namespace SeaBattle
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         int[,] field1 = new int[10, 10];
  20.         int[,] field2 = new int[10, 10];
  21.         bool start = false;
  22.         int n1, n2;
  23.         /*
  24.          0:  пусто
  25.          1:  корабль
  26.          2:  промах
  27.          3:  попадание
  28.          4:  убит
  29.          */
  30.         private bool Check(int[,] field1)
  31.         {
  32.             bool check = true;
  33.             int n = 0;
  34.             int[] mass_boat = new int[5];
  35.             for (int i = 0; i < 10; i++)
  36.             {
  37.                 int k = 0;
  38.                 for (int j = 0; j < 10; j++)
  39.                 {
  40.                     if (field1[i, j] == 0 || j == 9)
  41.                     {
  42.                         if (field1[i, j] == 1)
  43.                         {
  44.                             k++;
  45.                             n++;
  46.                         }
  47.                         if (k > 4)
  48.                         {
  49.                             check = false;
  50.                             goto TheEnd;
  51.                         }
  52.                         else
  53.                         {
  54.                             if (k != 0)
  55.                             {
  56.                                 mass_boat[k]++;
  57.                                 k = 0;
  58.                             }
  59.                         }
  60.                     }
  61.                     else if (field1[i, j] == 1)
  62.                     {
  63.                         k++;
  64.                         n++;
  65.                     }
  66.                 }
  67.             }
  68.  
  69.             //MessageBox.Show(mass_boat[1].ToString());
  70.             for (int j = 0; j < 10; j++)
  71.             {
  72.                 int k = 0;
  73.                 for (int i = 0; i < 10; i++)
  74.                 {
  75.                     if (field1[i, j] == 0 || i == 9)
  76.                     {
  77.                         if (field1[i, j] == 1)
  78.                         {
  79.                             k++;
  80.                             n++;
  81.                         }
  82.                         if (k > 4)
  83.                         {
  84.                             check = false;
  85.                             goto TheEnd;
  86.                         }
  87.                         else
  88.                         {
  89.                             if (k != 0)
  90.                             {
  91.                                 mass_boat[k]++;
  92.                                 k = 0;
  93.                             }
  94.                         }
  95.                     }
  96.                     else if (field1[i, j] == 1)
  97.                     {
  98.                         k++;
  99.                         n++;
  100.                     }
  101.                 }
  102.             }
  103.             if (n != 40 || mass_boat[1] != 24 || mass_boat[2] != 3 || mass_boat[3] != 2 || mass_boat[4] != 1)
  104.             {
  105.                 check = false;
  106.             }
  107.             for (int i = 0; i < 10; i++)
  108.             {
  109.                 for (int j = 0; j < 10; j++)
  110.                 {
  111.                     if (field1[i, j] == 1)
  112.                     {
  113.                         for (int x = -1; x <= 1; x += 2)
  114.                         {
  115.                             for (int y = -1; y <= 1; y += 2)
  116.                             {
  117.                                 if (i + x >= 0 && i + x < 10 && j + y >= 0 && j + y < 10)
  118.                                 {
  119.                                     if (field1[i + x, j + y] == 1)
  120.                                     {
  121.                                         check = false;
  122.                                         goto TheEnd;
  123.                                     }
  124.                                 }
  125.                             }
  126.                         }
  127.                     }
  128.                 }
  129.             }
  130.             TheEnd:
  131.             if (check) return true;
  132.             else return false;
  133.         }
  134.  
  135.         private void Placement(int f)
  136.         {
  137.             for (int length = 4; length > 0; length--)
  138.             {
  139.                 for (int k = 0; k <= 4 - length; k++)
  140.                 {
  141.                     bool place = false;
  142.                     while (!place)
  143.                     {
  144.                         Random rnd = new Random();
  145.                         int value = rnd.Next(0, 2);
  146.                         int l = length + 2;
  147.                         int w = 3;
  148.                         if (value == 1)
  149.                         {
  150.                             int temp = l;
  151.                             l = w;
  152.                             w = temp;
  153.                         }
  154.                         int x = rnd.Next(0, 10);
  155.                         int y = rnd.Next(0, 10);
  156.                         bool clear = true;
  157.                         if (x + l - 3 >= 10 || y + w - 3 >= 10)
  158.                         {
  159.                             clear = false;
  160.                         }
  161.                         else
  162.                         {
  163.                             for (int i = x - 1; i < x + l - 1; i++)
  164.                             {
  165.                                 for (int j = y - 1; j < y + w - 1; j++)
  166.                                 {
  167.                                     if (i >= 0 && i < 10 && j >= 0 && j < 10)
  168.                                     {
  169.                                         if (Field(f)[i, j] == 1)
  170.                                         {
  171.                                             clear = false;
  172.                                             goto Flag;
  173.                                         }
  174.                                     }
  175.                                 }
  176.                             }
  177.                         }
  178.                         Flag:
  179.                         if (clear)
  180.                         {
  181.                             place = true;
  182.                             for (int i = x; i < x + l - 2; i++)
  183.                             {
  184.                                 for (int j = y; j < y + w - 2; j++)
  185.                                 {
  186.                                     Field(f)[i, j] = 1;
  187.                                 }
  188.                             }
  189.  
  190.                         }
  191.                     }
  192.                 }
  193.             }
  194.  
  195.         }
  196.  
  197.         private Button Colorize(int x, int y, int f)
  198.         {
  199.             if (f == 1) return Button(x * 10 + y);
  200.             else return Button1(x * 10 + y + 100);
  201.         }
  202.  
  203.         private Button Button(int position)
  204.         {
  205.             switch (position)
  206.             {
  207.                 case 0: return button1;
  208.                 case 1: return button2;
  209.                 case 2: return button3;
  210.                 case 3: return button4;
  211.                 case 4: return button5;
  212.                 case 5: return button6;
  213.                 case 6: return button7;
  214.                 case 7: return button8;
  215.                 case 8: return button9;
  216.                 case 9: return button10;
  217.                 case 10: return button11;
  218.                 case 11: return button12;
  219.                 case 12: return button13;
  220.                 case 13: return button14;
  221.                 case 14: return button15;
  222.                 case 15: return button16;
  223.                 case 16: return button17;
  224.                 case 17: return button18;
  225.                 case 18: return button19;
  226.                 case 19: return button20;
  227.                 case 20: return button21;
  228.                 case 21: return button22;
  229.                 case 22: return button23;
  230.                 case 23: return button24;
  231.                 case 24: return button25;
  232.                 case 25: return button26;
  233.                 case 26: return button27;
  234.                 case 27: return button28;
  235.                 case 28: return button29;
  236.                 case 29: return button30;
  237.                 case 30: return button31;
  238.                 case 31: return button32;
  239.                 case 32: return button33;
  240.                 case 33: return button34;
  241.                 case 34: return button35;
  242.                 case 35: return button36;
  243.                 case 36: return button37;
  244.                 case 37: return button38;
  245.                 case 38: return button39;
  246.                 case 39: return button40;
  247.                 case 40: return button41;
  248.                 case 41: return button42;
  249.                 case 42: return button43;
  250.                 case 43: return button44;
  251.                 case 44: return button45;
  252.                 case 45: return button46;
  253.                 case 46: return button47;
  254.                 case 47: return button48;
  255.                 case 48: return button49;
  256.                 case 49: return button50;
  257.                 case 50: return button51;
  258.                 case 51: return button52;
  259.                 case 52: return button53;
  260.                 case 53: return button54;
  261.                 case 54: return button55;
  262.                 case 55: return button56;
  263.                 case 56: return button57;
  264.                 case 57: return button58;
  265.                 case 58: return button59;
  266.                 case 59: return button60;
  267.                 case 60: return button61;
  268.                 case 61: return button62;
  269.                 case 62: return button63;
  270.                 case 63: return button64;
  271.                 case 64: return button65;
  272.                 case 65: return button66;
  273.                 case 66: return button67;
  274.                 case 67: return button68;
  275.                 case 68: return button69;
  276.                 case 69: return button70;
  277.                 case 70: return button71;
  278.                 case 71: return button72;
  279.                 case 72: return button73;
  280.                 case 73: return button74;
  281.                 case 74: return button75;
  282.                 case 75: return button76;
  283.                 case 76: return button77;
  284.                 case 77: return button78;
  285.                 case 78: return button79;
  286.                 case 79: return button80;
  287.                 case 80: return button81;
  288.                 case 81: return button82;
  289.                 case 82: return button83;
  290.                 case 83: return button84;
  291.                 case 84: return button85;
  292.                 case 85: return button86;
  293.                 case 86: return button87;
  294.                 case 87: return button88;
  295.                 case 88: return button89;
  296.                 case 89: return button90;
  297.                 case 90: return button91;
  298.                 case 91: return button92;
  299.                 case 92: return button93;
  300.                 case 93: return button94;
  301.                 case 94: return button95;
  302.                 case 95: return button96;
  303.                 case 96: return button97;
  304.                 case 97: return button98;
  305.                 case 98: return button99;
  306.                 case 99: return button100;
  307.                 default: return button1;
  308.             }
  309.         }  //return button
  310.  
  311.         private Button Button1(int position)
  312.         {
  313.             switch (position)
  314.             {
  315.                 case 100: return button101;
  316.                 case 101: return button102;
  317.                 case 102: return button103;
  318.                 case 103: return button104;
  319.                 case 104: return button105;
  320.                 case 105: return button106;
  321.                 case 106: return button107;
  322.                 case 107: return button108;
  323.                 case 108: return button109;
  324.                 case 109: return button110;
  325.                 case 110: return button111;
  326.                 case 111: return button112;
  327.                 case 112: return button113;
  328.                 case 113: return button114;
  329.                 case 114: return button115;
  330.                 case 115: return button116;
  331.                 case 116: return button117;
  332.                 case 117: return button118;
  333.                 case 118: return button119;
  334.                 case 119: return button120;
  335.                 case 120: return button121;
  336.                 case 121: return button122;
  337.                 case 122: return button123;
  338.                 case 123: return button124;
  339.                 case 124: return button125;
  340.                 case 125: return button126;
  341.                 case 126: return button127;
  342.                 case 127: return button128;
  343.                 case 128: return button129;
  344.                 case 129: return button130;
  345.                 case 130: return button131;
  346.                 case 131: return button132;
  347.                 case 132: return button133;
  348.                 case 133: return button134;
  349.                 case 134: return button135;
  350.                 case 135: return button136;
  351.                 case 136: return button137;
  352.                 case 137: return button138;
  353.                 case 138: return button139;
  354.                 case 139: return button140;
  355.                 case 140: return button141;
  356.                 case 141: return button142;
  357.                 case 142: return button143;
  358.                 case 143: return button144;
  359.                 case 144: return button145;
  360.                 case 145: return button146;
  361.                 case 146: return button147;
  362.                 case 147: return button148;
  363.                 case 148: return button149;
  364.                 case 149: return button150;
  365.                 case 150: return button151;
  366.                 case 151: return button152;
  367.                 case 152: return button153;
  368.                 case 153: return button154;
  369.                 case 154: return button155;
  370.                 case 155: return button156;
  371.                 case 156: return button157;
  372.                 case 157: return button158;
  373.                 case 158: return button159;
  374.                 case 159: return button160;
  375.                 case 160: return button161;
  376.                 case 161: return button162;
  377.                 case 162: return button163;
  378.                 case 163: return button164;
  379.                 case 164: return button165;
  380.                 case 165: return button166;
  381.                 case 166: return button167;
  382.                 case 167: return button168;
  383.                 case 168: return button169;
  384.                 case 169: return button170;
  385.                 case 170: return button171;
  386.                 case 171: return button172;
  387.                 case 172: return button173;
  388.                 case 173: return button174;
  389.                 case 174: return button175;
  390.                 case 175: return button176;
  391.                 case 176: return button177;
  392.                 case 177: return button178;
  393.                 case 178: return button179;
  394.                 case 179: return button180;
  395.                 case 180: return button181;
  396.                 case 181: return button182;
  397.                 case 182: return button183;
  398.                 case 183: return button184;
  399.                 case 184: return button185;
  400.                 case 185: return button186;
  401.                 case 186: return button187;
  402.                 case 187: return button188;
  403.                 case 188: return button189;
  404.                 case 189: return button190;
  405.                 case 190: return button191;
  406.                 case 191: return button192;
  407.                 case 192: return button193;
  408.                 case 193: return button194;
  409.                 case 194: return button195;
  410.                 case 195: return button196;
  411.                 case 196: return button197;
  412.                 case 197: return button198;
  413.                 case 198: return button199;
  414.                 case 199: return button200;
  415.                 default: return button101;
  416.  
  417.             }
  418.         } //return button
  419.  
  420.         private void Restart()
  421.         {
  422.             button203.Visible = true;
  423.             button201.Visible = true;
  424.             n = 0;
  425.             listBox1.Items.Clear();
  426.             textBox1.Clear();
  427.             start = false;
  428.             step = true;
  429.             for (int i = 0; i < 100; i++)
  430.             {
  431.                 Button(i).FlatAppearance.BorderSize = 0;
  432.                 Button(i).FlatStyle = FlatStyle.Flat;
  433.                 Button(i).BackColor = Color.LightSkyBlue;
  434.                 Button1(i + 100).FlatAppearance.BorderSize = 0;
  435.                 Button1(i + 100).FlatStyle = FlatStyle.Flat;
  436.                 Button1(i + 100).BackColor = Color.LightSkyBlue;
  437.             }
  438.             for (int i = 0; i < 10; i++)
  439.             {
  440.                 for (int j = 0; j < 10; j++)
  441.                 {
  442.                     field1[i, j] = 0;
  443.                     field2[i, j] = 0;
  444.                 }
  445.             }
  446.         } //Restart
  447.  
  448.         private void Button1(object sender, EventArgs e) //placement field1
  449.         {
  450.             if (!start)
  451.             {
  452.                 int position = Convert.ToInt16(((Button)sender).Tag);
  453.                 int x = position / 10;
  454.                 int y = position % 10;
  455.                 field1[x, y] = Math.Abs(field1[x, y] - 1);
  456.                 if (field1[x, y] == 1)
  457.                 {
  458.                     Button(position).BackColor = Color.SlateGray;
  459.                 }
  460.                 else Button(position).BackColor = Color.LightSkyBlue;
  461.             }
  462.         }
  463.  
  464.         private void button202_Click(object sender, EventArgs e) // restart
  465.         {
  466.             Restart();
  467.         }
  468.  
  469.         private void Button101(object sender, EventArgs e)
  470.         {
  471.  
  472.         } //-
  473.  
  474.         private void button203_Click(object sender, EventArgs e)
  475.         {
  476.             for(int i = 0; i < 10; i++)
  477.             {
  478.                 for(int j = 0; j < 10; j++)
  479.                 {
  480.                     if(Field(1)[i, j] == 1)
  481.                     {
  482.                         Field(1)[i, j] = 0;
  483.                         Colorize(i, j, 1).BackColor = Color.LightSkyBlue;
  484.                     }
  485.                 }
  486.             }
  487.             Placement(1);
  488.             for(int i = 0; i < 10; i++)
  489.             {
  490.                 for(int j = 0; j < 10; j++)
  491.                 {
  492.                     if (Field(1)[i, j] == 1)
  493.                     {
  494.                         Colorize(i, j, 1).BackColor = Color.SlateGray;
  495.                     }
  496.                 }
  497.             }
  498.         }
  499.  
  500.         private void output(string str)
  501.         {
  502.             listBox1.Items.Insert(n++, str);
  503.             listBox1.SelectedIndex = listBox1.Items.Count - 1;
  504.             listBox1.SelectedIndex = -1;
  505.         }
  506.  
  507.         private void button201_Click(object sender, EventArgs e)   //start
  508.         {
  509.             if (!Check(field1) && start == false)
  510.             {
  511.                 MessageBox.Show("    Корабли раставлены неверно");
  512.             }
  513.             else if (start == false)
  514.             {
  515.                 button201.Visible = false;
  516.                 button203.Visible = false;
  517.                 listBox1.Items.Clear();
  518.                 n1 = 10; n2 = 10;
  519.                 start = true;
  520.                 Placement(2);
  521.                 str = "       ***[ Игра началась ]***";
  522.                 output(str);
  523.                 str = "Ваш ход первый";
  524.                 output(str);
  525.                 textBox1.Clear();
  526.                 str = (10 - n1) + ":" + (10 - n2);
  527.                 textBox1.Text = str;
  528.             }
  529.         }
  530.  
  531.         bool step = false;
  532.         bool trigger = false;
  533.         string str;
  534.         int n = 0;
  535.         int R = 0;
  536.  
  537.         private void Pause()
  538.         {
  539.             Thread.Sleep(250);
  540.             Task.Factory.StartNew(() => {
  541.  
  542.             });
  543.         }
  544.  
  545.         private int[,] Field (int i)
  546.         {
  547.             if (i == 1) return field1;
  548.             else return field2;
  549.         }
  550.  
  551.         private void Buttons_field2(object sender, EventArgs e)// GAME
  552.         {
  553.             void Game_cheak()
  554.             {
  555.                 textBox1.Clear();
  556.                 str = (10 - n1) + ":" + (10 - n2);
  557.                 textBox1.Text = str;
  558.                 if (n1 < 1)
  559.                 {
  560.                     for (int i = 0; i < 10; i++)
  561.                     {
  562.                         for (int j = 0; j < 10; j++)
  563.                         {
  564.                             if (Field(2)[i, j] == 1)
  565.                             {
  566.                                 Colorize(i, j, 2).BackColor = Color.SlateGray;
  567.                             }
  568.                         }
  569.                     }
  570.                     MessageBox.Show("Вы проиграли");
  571.                     Restart();
  572.                 }
  573.                 if (n2 < 1)
  574.                 {
  575.                     MessageBox.Show("Вы победили");
  576.                     Restart();
  577.                 }
  578.             }
  579.             bool Dfs(int x, int y, int x1, int y1, int f)
  580.             {
  581.                 if (Field(f)[x, y] == 1 && (x != x1 || y != y1)) return true;
  582.                 bool t1 = false, t2 = false, t3 = false, t4 = false;
  583.                 if ((x - 1 != x1 || y != y1) && x - 1 >= 0) if (Field(f)[x - 1, y] != 2 && Field(f)[x - 1, y] != 0) t1 = Dfs(x - 1, y, x, y, f);
  584.                 if ((x + 1 != x1 || y != y1) && x + 1 < 10) if (Field(f)[x + 1, y] != 2 && Field(f)[x + 1, y] != 0) t2 = Dfs(x + 1, y, x, y, f);
  585.                 if ((x != x1 || y + 1 != y1) && y + 1 < 10) if (Field(f)[x, y + 1] != 2 && Field(f)[x, y + 1] != 0) t3 = Dfs(x, y + 1, x, y, f);
  586.                 if ((x != x1 || y - 1 != y1) && y - 1 >= 0) if (Field(f)[x, y - 1] != 2 && Field(f)[x, y - 1] != 0) t4 = Dfs(x, y - 1, x, y, f);
  587.                 return t1 || t2 || t3 || t4;
  588.             }
  589.             void Kill(int x, int y, int f)
  590.             {
  591.                 for (int i = -1; i < 2; i++)
  592.                 {
  593.                     for (int j = -1; j < 2; j++)
  594.                     {
  595.                         if (x + i >= 0 && x + i < 10 && y + j >= 0 && y + j < 10)
  596.                         {
  597.                             if (Field(f)[x + i, y + j] == 0)
  598.                             {
  599.                                 Field(f)[x + i, y + j] = 2;
  600.                                 Colorize((x + i),(y + j), f).BackColor = Color.DeepSkyBlue;
  601.                             }
  602.                             else if (Field(f)[x + i, y + j] == 1 || Field(f)[x + i, y + j] == 3)
  603.                             {
  604.                                 Field(f)[x + i, y + j] = 4;
  605.                                 Colorize((x + i), (y + j), f).BackColor = Color.Red;
  606.                                 Kill(x + i, y + j, f);
  607.                             }
  608.                         }
  609.                     }
  610.                 }
  611.             }
  612.             void Shoot(int f, int x, int y, int t)
  613.             {
  614.                 if(t != 4) Field(f)[x, y] = t;
  615.                 if (f == 1) Pause();
  616.                 int x1 = x;
  617.                 if (x1 == 9) x1 = 10;
  618.  
  619.                 if (f == 1) str = "Он: ";
  620.                 else str = "Вы: ";
  621.  
  622.                 str = str + Convert.ToChar(x1 + 'А') + (y + 1);
  623.                 if (t == 2)
  624.                 {
  625.                     str += " - мимо";
  626.                     Colorize(x, y, f).BackColor = Color.DeepSkyBlue;
  627.                 }
  628.                 else if (t == 3)
  629.                 {
  630.                     str += " - ранил";
  631.                     Colorize(x, y, f).BackColor = Color.Orange;
  632.                 }
  633.                 else
  634.                 {
  635.                     str += " - убил";
  636.                     Colorize(x, y, f).BackColor = Color.Red;
  637.                 }
  638.                 output(str);
  639.                 Colorize(x, y, f).Refresh();
  640.             }
  641.             if (start)
  642.             {
  643.                 Game_cheak();
  644.                 int position = Convert.ToInt16(((Button)sender).Tag);
  645.                 int x = (position - 100) / 10;
  646.                 int y = position % 10;
  647.                 if (field2[x, y] != 0 && field2[x, y] != 1)
  648.                 {
  649.                     return;
  650.                 }
  651.                 if (field2[x, y] == 0)
  652.                 {
  653.                     Shoot(2, x, y, 2);
  654.  
  655.                 }
  656.                 else if (field2[x, y] == 1)
  657.                 {
  658.                     if (Dfs(x, y, x, y, 2))
  659.                     {
  660.                         Shoot(2, x, y, 3);
  661.                         return;
  662.                     }
  663.                     else
  664.                     {
  665.                         Shoot(2, x, y, 4);
  666.                         Kill(x, y, 2);
  667.                         n2--;
  668.                         Game_cheak();
  669.                         return;
  670.                     }
  671.                 }
  672.                 Game_cheak();
  673.                 //==============================================================================================================================
  674.                 Random rnd = new Random();
  675.                 step = false;
  676.                 while (!step)
  677.                 {
  678.                     if (trigger)
  679.                     {                                              
  680.                         if (R == 0)
  681.                         {
  682.                             for (int i = 0; i < 10; i++)
  683.                             {
  684.                                 for (int j = 0; j < 10; j++)
  685.                                 {
  686.                                     if (field1[i, j] == 3)
  687.                                     {
  688.                                         int t = rnd.Next(0, 4);
  689.                                         int r = rnd.Next(0, 2);
  690.                                         if (r == 0) r = -1;
  691.                                         for (int k = 0; k < 4; k++)
  692.                                         {
  693.                                             if (t == 0) { x = i + 1; y = j; };
  694.                                             if (t == 1) { x = i - 1; y = j; };
  695.                                             if (t == 2) { x = i; y = j + 1; };
  696.                                             if (t == 3) { x = i; y = j - 1; };
  697.                                             if (x >= 0 && x < 10 && y >= 0 && y < 10)
  698.                                             {
  699.                                                 if (field1[x, y] == 1)
  700.                                                 {
  701.                                                     if (t == 0 || t == 1) R = 1;
  702.                                                     else R = 2;
  703.                                                     if (Dfs(x, y, x, y, 1))
  704.                                                     {
  705.                                                         Shoot(1, x, y, 3);
  706.                                                         goto Break1;
  707.                                                     }
  708.                                                     else
  709.                                                     {
  710.                                                         Shoot(1, x, y, 4);
  711.                                                         Kill(x, y, 1);
  712.                                                         trigger = false;
  713.                                                         R = 0;
  714.                                                         n1--;
  715.                                                         goto Break1;
  716.                                                     }
  717.                                                 }
  718.                                                 else if (field1[x, y] == 0)
  719.                                                 {
  720.                                                     Shoot(1, x, y, 2);
  721.                                                     step = true;
  722.                                                     goto Break1;
  723.                                                 }
  724.                                                 else { }
  725.                                             }
  726.                                             t = (t + r + 4) % 4;
  727.                                         }
  728.                                     }
  729.                                 }
  730.                             }
  731.                         }
  732.                         else if (R == 1) //// R 1
  733.                         {
  734.                             for (int i = 0; i < 10; i++)
  735.                             {
  736.                                 for (int j = 0; j < 10; j++)
  737.                                 {
  738.                                     if (field1[i, j] == 3)
  739.                                     {
  740.                                         x = i;
  741.                                         y = j;
  742.                                         int r = rnd.Next(0, 2);
  743.                                         if (r == 0) r = -1;
  744.                                         int x2 = x;
  745.                                         while (start)
  746.                                         {
  747.                                             x2 += r;
  748.                                             if (x2 < 0 || x2 > 9) break;
  749.                                             if (field1[x2, y] == 3) continue;
  750.                                             if (field1[x2, y] == 2) break;
  751.                                             else
  752.                                             {
  753.                                                 if (field1[x2, y] == 0)
  754.                                                 {
  755.                                                     Shoot(1, x2, y, 2);
  756.                                                     step = true;
  757.                                                     goto Break1;
  758.                                                 }
  759.                                                 else if (field1[x2, y] == 1)
  760.                                                 {
  761.                                                     if (Dfs(x2, y, x2, y, 1))
  762.                                                     {
  763.                                                         Shoot(1, x2, y, 3);
  764.                                                         goto Break1;
  765.                                                     }
  766.                                                     else
  767.                                                     {
  768.                                                         Shoot(1, x2, y, 4);
  769.                                                         Kill(x2, y, 1);
  770.                                                         trigger = false;
  771.                                                         R = 0;
  772.                                                         n1--;
  773.                                                         goto Break1;
  774.                                                     }
  775.                                                 }
  776.                                             }
  777.                                         }
  778.                                         x2 = x;
  779.                                         while (start)
  780.                                         {
  781.                                             x2 -= r;
  782.                                             if (x2 < 0 || x2 > 9) break;
  783.                                             if (field1[x2, y] == 3) continue;
  784.                                             if (field1[x2, y] == 2) break;
  785.                                             else
  786.                                             {
  787.                                                 if (field1[x2, y] == 0)
  788.                                                 {
  789.                                                     Shoot(1, x2, y, 2);
  790.                                                     step = true;
  791.                                                     goto Break1;
  792.                                                 }
  793.                                                 else if (field1[x2, y] == 1)
  794.                                                 {
  795.                                                     if (Dfs(x2, y, x2, y, 1))
  796.                                                     {
  797.                                                         Shoot(1, x2, y, 3);
  798.                                                         goto Break1;
  799.                                                     }
  800.                                                     else
  801.                                                     {
  802.                                                         Shoot(1, x2, y, 4);
  803.                                                         Kill(x2, y, 1);
  804.                                                         trigger = false;
  805.                                                         R = 0;
  806.                                                         n1--;
  807.                                                         goto Break1;
  808.                                                     }
  809.                                                 }
  810.                                             }
  811.                                         }
  812.                                     }
  813.                                 }
  814.                             }
  815.                         }
  816.                         else if (R == 2) //// R 2
  817.                         {
  818.                             for (int i = 0; i < 10; i++)
  819.                             {
  820.                                 for (int j = 0; j < 10; j++)
  821.                                 {
  822.                                     if (field1[i, j] == 3)
  823.                                     {
  824.                                         x = i;
  825.                                         y = j;
  826.                                         int r = rnd.Next(0, 2);
  827.                                         if (r == 0) r = -1;
  828.                                         int y2 = y;
  829.                                         while (start)
  830.                                         {
  831.                                             y2 += r;
  832.                                             if (y2 < 0 || y2 > 9) break;
  833.                                             if (field1[x, y2] == 3) continue;
  834.                                             if (field1[x, y2] == 2) break;
  835.                                             else
  836.                                             {
  837.                                                 if (field1[x, y2] == 0)
  838.                                                 {
  839.                                                     Shoot(1, x, y2, 2);
  840.                                                     step = true;
  841.                                                     goto Break1;
  842.                                                 }
  843.                                                 else if (field1[x, y2] == 1)
  844.                                                 {
  845.                                                     if (Dfs(x, y2, x, y2, 1))
  846.                                                     {
  847.                                                         Shoot(1, x, y2, 3);
  848.                                                         goto Break1;
  849.                                                     }
  850.                                                     else
  851.                                                     {
  852.                                                         Shoot(1, x, y2, 4);
  853.                                                         Kill(x, y2, 1);
  854.                                                         trigger = false;
  855.                                                         R = 0;
  856.                                                         n1--;
  857.                                                         goto Break1;
  858.                                                     }
  859.                                                 }
  860.                                             }
  861.                                         }
  862.                                         y2 = y;
  863.                                         while (start)
  864.                                         {
  865.                                             y2 -= r;
  866.                                             if (y2 < 0 || y2 > 9) break;
  867.                                             if (field1[x, y2] == 3) continue;
  868.                                             if (field1[x, y2] == 2) break;
  869.                                             else
  870.                                             {
  871.                                                 if (field1[x, y2] == 0)
  872.                                                 {
  873.                                                     Shoot(1, x, y2, 2);
  874.                                                     step = true;
  875.                                                     goto Break1;
  876.                                                 }
  877.                                                 else if (field1[x, y2] == 1)
  878.                                                 {
  879.                                                     if (Dfs(x, y2, x, y2, 1))
  880.                                                     {
  881.                                                         Shoot(1, x, y2, 3);
  882.                                                         goto Break1;
  883.                                                     }
  884.                                                     else
  885.                                                     {
  886.                                                         Shoot(1, x, y2, 4);
  887.                                                         Kill(x, y2, 1);
  888.                                                         trigger = false;
  889.                                                         R = 0;
  890.                                                         n1--;
  891.                                                         goto Break1;
  892.                                                     }
  893.                                                 }
  894.                                             }
  895.                                         }
  896.                                     }
  897.                                 }
  898.                             }
  899.                         }
  900.                     }
  901.                     ////////////////////
  902.                     x = rnd.Next(0, 10);
  903.                     y = rnd.Next(0, 10);
  904.                     if(field1[x, y] != 0 && field1[x, y] != 1)
  905.                     {
  906.                         continue;
  907.                     }
  908.                     else if(field1[x, y] == 0)
  909.                     {
  910.                         Shoot(1, x, y, 2);
  911.                         step = true;
  912.                     }
  913.                     else if(field1[x, y] == 1)
  914.                     {
  915.                         if(Dfs(x, y, x, y, 1))
  916.                         {
  917.                             Shoot(1, x, y, 3);
  918.                             trigger = true;
  919.                             R = 0;
  920.                         }
  921.                         else
  922.                         {
  923.                             Shoot(1, x, y, 4);
  924.                           Kill(x, y, 1);
  925.                             n1--;
  926.                         }
  927.                     }
  928.                     Break1:
  929.                     Game_cheak();
  930.                 }
  931.             }
  932.         }
  933.  
  934.         private void Form1_Load(object sender, EventArgs e)
  935.         {
  936.             button203.Visible = true;
  937.             Restart();
  938.             button202.FlatAppearance.BorderSize = 0;
  939.             button202.FlatStyle = FlatStyle.Flat;
  940.             button202.BackColor = Color.LightGray;
  941.             button203.FlatAppearance.BorderSize = 0;
  942.             button203.FlatStyle = FlatStyle.Flat;
  943.             button203.BackColor = Color.LightGray;
  944.             button201.BackColor = Color.LightGray;
  945.             button201.FlatAppearance.BorderSize = 0;
  946.             button201.FlatStyle = FlatStyle.Flat;
  947.         }
  948.     }
  949. }
  950.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement