示例#1
0
 public void InitializeP1ships() //doljnji mali
 {
     for (int i = 0; i < 152; i += 38)
     {
         for (int j = 0; j < 190; j += 38)
         {
             Squaredown squareP1ships = new Squaredown(count_P1ships, i, j);
             l_P1ships.Add(squareP1ships);
             count_P1ships++;
         }
     }
 }
示例#2
0
 public void Initializepbdown() //doljnji veliki
 {
     for (int i = 0; i < 456; i += 38)
     {
         for (int j = 0; j < 228; j += 38)
         {
             Squaredown squaredown = new Squaredown(count_down_p1, i, j);
             l_down_p1.Add(squaredown);
             count_down_p1++;
         }
     }
 }
示例#3
0
        private void PCShoot()
        {
            int    i, j, y = 0;
            Random rnd = new Random();

            id = rnd.Next(1, 72);
            while (y < temp)
            {
                if (arr[y] == id)
                {
                    id     = rnd.Next(1, 72);
                    arr[x] = id;
                    x++;
                }
                else
                {
                    arr[x] = id;
                    y++;
                }
            }

            temp++;
            if (id % 6 == 0)
            {
                i = 5;
                j = id / 6 - 1;
            }
            else
            {
                i = id % 6 - 1;
                j = id / 6;
            }
            i *= 38;
            j *= 38;
            shots_PC++;
            Squaredown sqd = new Squaredown(id, j, i);

            foreach (Squaredown squareP1ship in l_down_p1)
            {
                if (sqd.id == squareP1ship.id && squareP1ship.full == true)
                {
                    hits_PC++;
                    sqd.FillH(gdown);
                    l_down_p1.Where(w => w.id == id).ToList().ForEach(s => s.shot = true);
                    break;
                }
                else
                {
                    sqd.FillM(gdown);
                    l_down_p1.Where(w => w.id == id).ToList().ForEach(s => s.shot = true);
                }
            }
        }
示例#4
0
        public void pb_down_p1_MouseUp(object sender, MouseEventArgs e)
        {
            int k = 0, l = 0;
            int flen = 0, slen = 0;
            int counti = 0, countj = 0, countid = 0;

            for (int i = 0; i <= e.X; i += 38)
            {
                counti++;
                for (int j = 0; j <= e.Y; j += 38)
                {
                    countj++;
                    k = i;
                    l = j;
                }
            }
            countj  = countj / counti;
            countid = counti * 6 - (6 - countj);
            if (e.Button == MouseButtons.Left) //crta brodic horizontalno
            {
                if (CheckEdgeH(k) == true && CheckPlaceH(countid, k, l) == true)
                {
                    for (int i = 0; i < len; i++)
                    {
                        Squaredown squareP1ships = new Squaredown(countid + flen, k + slen, l);
                        squareP1ships.Fill(gdown);
                        l_down_p1.Where(w => w.id == countid + flen).ToList().ForEach(s => s.full = true);
                        flen += 6;
                        slen += 38;
                    }
                }
            }
            if (e.Button == MouseButtons.Right) //crta brodic vertikalno
            {
                if (CheckEdgeV(l) == true && CheckPlaceV(countid, k, l) == true)
                {
                    for (int i = 0; i < len; i++)
                    {
                        Squaredown squareP1ships = new Squaredown(countid + flen, k, l + slen);
                        squareP1ships.Fill(gdown);
                        l_down_p1.Where(w => w.id == countid + flen).ToList().ForEach(s => s.full = true);
                        flen += 1;
                        slen += 38;
                    }
                }
            }
            len = 0;
        }
示例#5
0
        private bool CheckPlaceV(int b, int k, int l)
        {
            int count = 0, flen = 0, slen = 0;

            foreach (Squaredown sqd in l_down_p1)
            {
                Squaredown squareP1ships = new Squaredown(b + flen, k, l + slen);
                if (sqd.id == squareP1ships.id && flen < len)
                {
                    if (sqd.full == false)
                    {
                        count++;
                    }
                    flen += 1;
                    slen += 38;
                }
            }
            if (count == len)
            {
                return(true);
            }
            else
            {
                MessageBox.Show("That place is taken. Try another one");
                if (len == 2)
                {
                    flag2++;
                }
                else if (len == 3)
                {
                    flag3++;
                }
                else if (len == 4)
                {
                    flag4++;
                }
                return(false);
            }
        }