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.Windows.Forms;
- namespace Морской_бой
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- PictureBox[,] pict = new PictureBox[10, 10];
- int[,] mas = new int[10, 10];
- int[,] ship = new int[10, 4];
- int n = 0, i = 0, z, s;
- Random rnd = new Random();
- private void Form1_Load(object sender, EventArgs e)
- {
- pict[0, 0] = pictureBox0;
- pict[0, 1] = pictureBox1;
- pict[0, 2] = pictureBox2;
- pict[0, 3] = pictureBox3;
- pict[0, 4] = pictureBox4;
- pict[0, 5] = pictureBox5;
- pict[0, 6] = pictureBox6;
- pict[0, 7] = pictureBox7;
- pict[0, 8] = pictureBox8;
- pict[0, 9] = pictureBox9;
- pict[1, 0] = pictureBox10;
- pict[1, 1] = pictureBox11;
- pict[1, 2] = pictureBox12;
- pict[1, 3] = pictureBox13;
- pict[1, 4] = pictureBox14;
- pict[1, 5] = pictureBox15;
- pict[1, 6] = pictureBox16;
- pict[1, 7] = pictureBox17;
- pict[1, 8] = pictureBox18;
- pict[1, 9] = pictureBox19;
- pict[2, 0] = pictureBox20;
- pict[2, 1] = pictureBox21;
- pict[2, 2] = pictureBox22;
- pict[2, 3] = pictureBox23;
- pict[2, 4] = pictureBox24;
- pict[2, 5] = pictureBox25;
- pict[2, 6] = pictureBox26;
- pict[2, 7] = pictureBox27;
- pict[2, 8] = pictureBox28;
- pict[2, 9] = pictureBox29;
- pict[3, 0] = pictureBox30;
- pict[3, 1] = pictureBox31;
- pict[3, 2] = pictureBox32;
- pict[3, 3] = pictureBox33;
- pict[3, 4] = pictureBox34;
- pict[3, 5] = pictureBox35;
- pict[3, 6] = pictureBox36;
- pict[3, 7] = pictureBox37;
- pict[3, 8] = pictureBox38;
- pict[3, 9] = pictureBox39;
- pict[4, 0] = pictureBox40;
- pict[4, 1] = pictureBox41;
- pict[4, 2] = pictureBox42;
- pict[4, 3] = pictureBox43;
- pict[4, 4] = pictureBox44;
- pict[4, 5] = pictureBox45;
- pict[4, 6] = pictureBox46;
- pict[4, 7] = pictureBox47;
- pict[4, 8] = pictureBox48;
- pict[4, 9] = pictureBox49;
- pict[5, 0] = pictureBox50;
- pict[5, 1] = pictureBox51;
- pict[5, 2] = pictureBox52;
- pict[5, 3] = pictureBox53;
- pict[5, 4] = pictureBox54;
- pict[5, 5] = pictureBox55;
- pict[5, 6] = pictureBox56;
- pict[5, 7] = pictureBox57;
- pict[5, 8] = pictureBox58;
- pict[5, 9] = pictureBox59;
- pict[6, 0] = pictureBox60;
- pict[6, 1] = pictureBox61;
- pict[6, 2] = pictureBox62;
- pict[6, 3] = pictureBox63;
- pict[6, 4] = pictureBox64;
- pict[6, 5] = pictureBox65;
- pict[6, 6] = pictureBox66;
- pict[6, 7] = pictureBox67;
- pict[6, 8] = pictureBox68;
- pict[6, 9] = pictureBox69;
- pict[7, 0] = pictureBox70;
- pict[7, 1] = pictureBox71;
- pict[7, 2] = pictureBox72;
- pict[7, 3] = pictureBox73;
- pict[7, 4] = pictureBox74;
- pict[7, 5] = pictureBox75;
- pict[7, 6] = pictureBox76;
- pict[7, 7] = pictureBox77;
- pict[7, 8] = pictureBox78;
- pict[7, 9] = pictureBox79;
- pict[8, 0] = pictureBox80;
- pict[8, 1] = pictureBox81;
- pict[8, 2] = pictureBox82;
- pict[8, 3] = pictureBox83;
- pict[8, 4] = pictureBox84;
- pict[8, 5] = pictureBox85;
- pict[8, 6] = pictureBox86;
- pict[8, 7] = pictureBox87;
- pict[8, 8] = pictureBox88;
- pict[8, 9] = pictureBox89;
- pict[9, 0] = pictureBox90;
- pict[9, 1] = pictureBox91;
- pict[9, 2] = pictureBox92;
- pict[9, 3] = pictureBox93;
- pict[9, 4] = pictureBox94;
- pict[9, 5] = pictureBox95;
- pict[9, 6] = pictureBox96;
- pict[9, 7] = pictureBox97;
- pict[9, 8] = pictureBox98;
- pict[9, 9] = pictureBox99;
- int v = newgame(0, 0);
- }
- private void pictureBox0_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox2_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox3_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox4_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox5_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox6_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox7_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox8_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox9_Click(object sender, EventArgs e)
- {
- n = 0;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox10_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox11_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox12_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox13_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox14_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox15_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox16_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox17_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox18_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox19_Click(object sender, EventArgs e)
- {
- n = 1;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox20_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox21_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox22_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox23_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox24_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox25_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox26_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox27_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox28_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox29_Click(object sender, EventArgs e)
- {
- n = 2;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox30_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox31_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox32_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox33_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox34_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox35_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox36_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox37_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox38_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox39_Click(object sender, EventArgs e)
- {
- n = 3;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox40_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox41_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox42_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox43_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox44_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox45_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox46_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox47_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox48_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox49_Click(object sender, EventArgs e)
- {
- n = 4;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox50_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox51_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox52_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox53_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox54_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox55_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox56_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox57_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox58_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox59_Click(object sender, EventArgs e)
- {
- n = 5;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox60_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox61_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox62_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox63_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox64_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox65_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox66_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox67_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox68_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox69_Click(object sender, EventArgs e)
- {
- n = 6;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox70_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox71_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox72_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox73_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox74_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox75_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox76_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox77_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox78_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox79_Click(object sender, EventArgs e)
- {
- n = 7;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox80_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox81_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox82_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox83_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox84_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox85_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox86_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox87_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox88_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox89_Click(object sender, EventArgs e)
- {
- n = 8;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox90_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 0;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox91_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 1;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox92_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 2;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox93_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 3;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox94_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 4;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox95_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 5;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox96_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 6;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox97_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 7;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox98_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 8;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- private void pictureBox99_Click(object sender, EventArgs e)
- {
- n = 9;
- i = 9;
- mas[n, i] = sw(n, i);
- pole(0, 0);
- }
- int sw(int n, int i)
- {
- z = mas[n, i];
- s++;
- switch (z)
- {
- case 0:
- z = 3;
- l1.Text = "Мимо";
- break;
- case 1:
- z = 3;
- l1.Text = "Мимо";
- break;
- case 2:
- z = f2(n, i);
- if (z == 5) l1.Text = "Попали";
- if (z == 6) l1.Text = "Убит";
- break;
- case 3:
- l1.Text = "Сюда стреляли";
- break;
- case 4:
- z = 3;
- l1.Text = "Мимо";
- break;
- case 5:
- l1.Text = "Сюда стреляли";
- break;
- case 6:
- l1.Text = "Сюда стреляли";
- break;
- }
- l2.Text = Convert.ToString(s);
- win(0);
- return z;
- }
- void win(int y)
- {
- for (int a = 0; a <= 9; a++)
- {
- for (int b = 0; b <= 9; b++)
- { if (mas[a, b] == 2) y++; }
- }
- if (y == 0)
- {
- MessageBox.Show("Поздравляем! Вы выиграли!", "Морской бой");
- for (int a = 0; a <= 9; a++)
- {
- for (int b = 0; b <= 9; b++)
- pict[a, b].Enabled = false;
- }
- }
- }
- void rad2(int a, int b, int c, int d)
- {
- if (b > 0 & c > 0) mas[b - 1, c - 1] = 4;
- if (c > 0) mas[b, c - 1] = 4;
- if (b > 0) mas[b - 1, c] = 4;
- if (d == 0)
- {
- if (b > 0 & c + a <= 9) mas[b - 1, c + a] = 4;
- if (c + a <= 9) mas[b, c + a] = 4;
- if (b < 9 & c + a <= 9) mas[b + 1, c + a] = 4;
- if (b < 9 & c > 0) mas[b + 1, c - 1] = 4;
- for (int y = 0; y <= a - 1; y++)
- {
- if (b > 0) mas[b - 1, c + y] = 4;
- if (b < 9) mas[b + 1, c + y] = 4;
- }
- }
- if (d == 1)
- {
- if (b + a <= 9) mas[b + a, c] = 4;
- if (b + a <= 9 & c > 0) mas[b + a, c - 1] = 4;
- if (b + a <= 9 & c < 9) mas[b + a, c + 1] = 4;
- if (b > 0 & c < 9) mas[b - 1, c + 1] = 4;
- for (int y = 0; y <= a - 1; y++)
- {
- if (c > 0) mas[b + y, c - 1] = 4;
- if (c < 9) mas[b + y, c + 1] = 4;
- }
- }
- }
- int f2(int n, int i)
- {
- int y = 0;
- for (y = 0; !((ship[y, 3] == 0 & ship[y, 1] == n & ship[y, 2] <= i & i <= ship[y, 2] + ship[y, 0] - 1) | (ship[y, 3] == 1 & ship[y, 2] == i & ship[y, 1] <= n & n <= ship[y, 1] + ship[y, 0] - 1)) & y <= 5; y++) ;
- for (int b = 6; b <= 9; b++)
- {
- if (ship[b, 1] == n & ship[b, 2] == i) y = b;
- }
- if (ship[y, 0] == 1)
- {
- mas[n, i] = 6;
- rad2(ship[y, 0], ship[y, 1], ship[y, 2], ship[y, 3]);
- }
- if (ship[y, 0] != 1) mas[n, i] = 5;
- if (ship[y, 0] == 2 & ship[y, 3] == 0)
- {
- if (mas[ship[y, 1], ship[y, 2]] == 5 & mas[ship[y, 1], ship[y, 2] + 1] == 5)
- {
- mas[ship[y, 1], ship[y, 2]] = 6;
- mas[ship[y, 1], ship[y, 2] + 1] = 6;
- rad2(ship[y, 0], ship[y, 1], ship[y, 2], ship[y, 3]);
- }
- }
- if (ship[y, 0] == 2 & ship[y, 3] == 1)
- {
- if (mas[ship[y, 1], ship[y, 2]] == 5 & ship[y, 3] == 1 & mas[ship[y, 1] + 1, ship[y, 2]] == 5)
- {
- mas[ship[y, 1], ship[y, 2]] = 6;
- mas[ship[y, 1] + 1, ship[y, 2]] = 6;
- rad2(ship[y, 0], ship[y, 1], ship[y, 2], ship[y, 3]);
- }
- }
- if (ship[y, 0] == 3 & ship[y, 3] == 0)
- {
- if (mas[ship[y, 1], ship[y, 2]] == 5 & mas[ship[y, 1], ship[y, 2] + 1] == 5 & mas[ship[y, 1], ship[y, 2] + 2] == 5)
- {
- mas[ship[y, 1], ship[y, 2]] = 6;
- mas[ship[y, 1], ship[y, 2] + 1] = 6;
- mas[ship[y, 1], ship[y, 2] + 2] = 6;
- rad2(ship[y, 0], ship[y, 1], ship[y, 2], ship[y, 3]);
- }
- }
- if (ship[y, 0] == 3 & ship[y, 3] == 1)
- {
- if (mas[ship[y, 1], ship[y, 2]] == 5 & mas[ship[y, 1] + 1, ship[y, 2]] == 5 & mas[ship[y, 1] + 2, ship[y, 2]] == 5)
- {
- mas[ship[y, 1], ship[y, 2]] = 6;
- mas[ship[y, 1] + 1, ship[y, 2]] = 6;
- mas[ship[y, 1] + 2, ship[y, 2]] = 6;
- rad2(ship[y, 0], ship[y, 1], ship[y, 2], ship[y, 3]);
- }
- }
- if (ship[y, 0] == 4 & ship[y, 3] == 0)
- {
- if (mas[ship[y, 1], ship[y, 2]] == 5 & mas[ship[y, 1], ship[y, 2] + 1] == 5 & mas[ship[y, 1], ship[y, 2] + 2] == 5 & mas[ship[y, 1], ship[y, 2] + 3] == 5)
- {
- mas[ship[y, 1], ship[y, 2]] = 6;
- mas[ship[y, 1], ship[y, 2] + 1] = 6;
- mas[ship[y, 1], ship[y, 2] + 2] = 6;
- mas[ship[y, 1], ship[y, 2] + 3] = 6;
- rad2(ship[y, 0], ship[y, 1], ship[y, 2], ship[y, 3]);
- }
- }
- if (ship[y, 0] == 4 & ship[y, 3] == 1)
- {
- if (mas[ship[y, 1], ship[y, 2]] == 5 & ship[y, 3] == 1 & mas[ship[y, 1] + 1, ship[y, 2]] == 5 & mas[ship[y, 1] + 2, ship[y, 2]] == 5 & mas[ship[y, 1] + 3, ship[y, 2]] == 5)
- {
- mas[ship[y, 1], ship[y, 2]] = 6;
- mas[ship[y, 1] + 1, ship[y, 2]] = 6;
- mas[ship[y, 1] + 2, ship[y, 2]] = 6;
- mas[ship[y, 1] + 3, ship[y, 2]] = 6;
- rad2(ship[y, 0], ship[y, 1], ship[y, 2], ship[y, 3]);
- }
- }
- z = mas[n, i];
- return z;
- }
- int newgame(int a, int b)
- {
- s = 0;
- for (n = 0; n <= 9; n++)
- {
- for (i = 0; i <= 9; i++)
- {
- mas[n, i] = 0;
- pict[n, i].Enabled = true;
- pict[n, i].BackColor = Color.SteelBlue;
- }
- }
- int l = rnd.Next(0, 2);
- ship[0, 0] = 4;
- if (l == 0)
- {
- do
- {
- a = rnd.Next(0, 10);
- b = rnd.Next(0, 7);
- }
- while (mas[a, b] == 2 | mas[a, b + 1] == 2 | mas[a, b + 2] == 2 | mas[a, b + 3] == 2 | mas[a, b] == 1 | mas[a, b + 1] == 1 | mas[a, b + 2] == 1 | mas[a, b + 3] == 1);
- mas[a, b] = 2;
- mas[a, b + 1] = 2;
- mas[a, b + 2] = 2;
- mas[a, b + 3] = 2;
- ship[0, 1] = a;
- ship[0, 2] = b;
- ship[0, 3] = l;
- rad(4, a, b, l);
- }
- if (l == 1)
- {
- do
- {
- a = rnd.Next(0, 7);
- b = rnd.Next(0, 10);
- }
- while (mas[a, b] == 2 | mas[a + 1, b] == 2 | mas[a + 2, b] == 2 | mas[a + 3, b] == 2 | mas[a, b] == 1 | mas[a + 1, b] == 1 | mas[a + 2, b] == 1 | mas[a + 3, b] == 1);
- mas[a, b] = 2;
- mas[a + 1, b] = 2;
- mas[a + 2, b] = 2;
- mas[a + 3, b] = 2;
- ship[0, 1] = a;
- ship[0, 2] = b;
- ship[0, 3] = l;
- rad(4, a, b, l);
- }
- for (int y = 0; y <= 1; y++)
- {
- l = rnd.Next(0, 2);
- if (l == 0)
- {
- do
- {
- a = rnd.Next(0, 10);
- b = rnd.Next(0, 8);
- }
- while (mas[a, b] == 2 | mas[a, b + 1] == 2 | mas[a, b + 2] == 2 | mas[a, b] == 1 | mas[a, b + 1] == 1 | mas[a, b + 2] == 1);
- mas[a, b] = 2;
- mas[a, b + 1] = 2;
- mas[a, b + 2] = 2;
- ship[1 + y, 0] = 3;
- ship[1 + y, 1] = a;
- ship[1 + y, 2] = b;
- ship[1 + y, 3] = l;
- rad(3, a, b, l);
- }
- if (l == 1)
- {
- do
- {
- a = rnd.Next(0, 8);
- b = rnd.Next(0, 10);
- }
- while (mas[a, b] == 2 | mas[a + 1, b] == 2 | mas[a + 2, b] == 2 | mas[a, b] == 1 | mas[a + 1, b] == 1 | mas[a + 2, b] == 1);
- mas[a, b] = 2;
- mas[a + 1, b] = 2;
- mas[a + 2, b] = 2;
- ship[1 + y, 0] = 3;
- ship[1 + y, 1] = a;
- ship[1 + y, 2] = b;
- ship[1 + y, 3] = l;
- rad(3, a, b, l);
- }
- }
- for (int y = 0; y <= 2; y++)
- {
- l = rnd.Next(0, 2);
- if (l == 0)
- {
- do
- {
- a = rnd.Next(0, 10);
- b = rnd.Next(0, 9);
- }
- while (mas[a, b] == 2 | mas[a, b + 1] == 2 | mas[a, b] == 1 | mas[a, b + 1] == 1);
- mas[a, b] = 2;
- mas[a, b + 1] = 2;
- ship[3 + y, 0] = 2;
- ship[3 + y, 1] = a;
- ship[3 + y, 2] = b;
- ship[3 + y, 3] = l;
- rad(2, a, b, l);
- }
- if (l == 1)
- {
- do
- {
- a = rnd.Next(0, 8);
- b = rnd.Next(0, 9);
- }
- while (mas[a, b] == 2 | mas[a + 1, b] == 2 | mas[a, b] == 1 | mas[a + 1, b] == 1);
- mas[a, b] = 2;
- mas[a + 1, b] = 2;
- ship[3 + y, 0] = 2;
- ship[3 + y, 1] = a;
- ship[3 + y, 2] = b;
- ship[3 + y, 3] = l;
- rad(2, a, b, l);
- }
- }
- for (int y = 0; y <= 3; y++)
- {
- do
- {
- a = rnd.Next(0, 10);
- b = rnd.Next(0, 10);
- }
- while (mas[a, b] == 2 | mas[a, b] == 1);
- mas[a, b] = 2;
- ship[6 + y, 0] = 1;
- ship[6 + y, 1] = a;
- ship[6 + y, 2] = b;
- ship[6 + y, 3] = 0;
- rad(1, a, b, 0);
- }
- string p = "";
- for (int d = 0; d <= 3; d++)
- {
- p = p + Convert.ToString(ship[0, d]);
- }
- MessageBox.Show(p);
- return a;
- }
- void rad(int a, int b, int c, int d)
- {
- if (b > 0 & c > 0) mas[b - 1, c - 1] = 1;
- if (c > 0) mas[b, c - 1] = 1;
- if (b > 0) mas[b - 1, c] = 1;
- if (d == 0)
- {
- if (b > 0 & c + a <= 9) mas[b - 1, c + a] = 1;
- if (c + a <= 9) mas[b, c + a] = 1;
- if (b < 9 & c + a <= 9) mas[b + 1, c + a] = 1;
- if (b < 9 & c > 0) mas[b + 1, c - 1] = 1;
- for (int y = 0; y <= a - 1; y++)
- {
- if (b > 0) mas[b - 1, c + y] = 1;
- if (b < 9) mas[b + 1, c + y] = 1;
- }
- }
- if (d == 1)
- {
- if (b + a <= 9) mas[b + a, c] = 1;
- if (b + a <= 9 & c > 0) mas[b + a, c - 1] = 1;
- if (b + a <= 9 & c < 9) mas[b + a, c + 1] = 1;
- if (b > 0 & c < 9) mas[b - 1, c + 1] = 1;
- for (int y = 0; y <= a - 1; y++)
- {
- if (c > 0) mas[b + y, c - 1] = 1;
- if (c < 9) mas[b + y, c + 1] = 1;
- }
- }
- }
- void pole(int a, int b)
- {
- for (a = 0; a <= 9; a++)
- {
- for (b = 0; b <= 9; b++)
- {
- switch (mas[a, b])
- {
- case 0:
- pict[a, b].BackColor = Color.SteelBlue;
- break;
- case 1:
- pict[a, b].BackColor = Color.SteelBlue;
- break;
- case 2:
- pict[a, b].BackColor = Color.SteelBlue;
- break;
- case 3:
- pict[a, b].BackColor = Color.Blue;
- break;
- case 4:
- pict[a, b].BackColor = Color.Blue;
- break;
- case 5:
- pict[a, b].BackColor = Color.Violet;
- break;
- case 6:
- pict[a, b].BackColor = Color.Red;
- break;
- }
- }
- }
- }
- private void начатьСНачалаToolStripMenuItem_Click(object sender, EventArgs e)
- {
- int v = newgame(0, 0);
- }
- private void выходToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement