Beispiel #1
0
 public void Init()
 {
     CreateMap();
     isPlaying = false;
     bot       = new EnemyBot(enemyMap, myMap, enemyButtons, myButtons);
     enemyMap  = bot.ConfigureShip();
 }
Beispiel #2
0
        public int CountDeck(int x, int y, bool horizontShip)
        {
            int count = 0;

            if (horizontShip)
            {
                while (myMap[x, y] == 1)
                {
                    for (int i = -1; i <= 1; i++)
                    {
                        if ((EnemyBot.IsInsideMap(x + 1, y + i) && myMap[x + 1, y + i] == 1) ||
                            (EnemyBot.IsInsideMap(x - 1, y + i) && myMap[x - 1, y + i] == 1))
                        {
                            return(-1);
                        }
                    }
                    count++;
                    y++;
                    if (EnemyBot.IsInsideMap(x, y))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                while (myMap[x, y] == 1)
                {
                    for (int i = -1; i <= 1; i++)
                    {
                        if (i != 0)
                        {
                            if ((EnemyBot.IsInsideMap(x + i, y + 1) && myMap[x + i, y + 1] == 1) ||
                                (EnemyBot.IsInsideMap(x + i, y - 1) && myMap[x + i, y - 1] == 1))
                            {
                                return(-2);
                            }
                        }
                    }
                    count++;
                    x++;
                    if (EnemyBot.IsInsideMap(x, y))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(count);
        }
Beispiel #3
0
        public bool CheckShips(int[,] myMap, out string txt)
        {
            txt = "";
            List <int> result       = new List <int>();
            bool       horizontShip = true;

            int[] RightArr_ShipsCount = { 1, 1, 1, 1, 2, 2, 2, 3, 3, 4 };
            for (int x = 1; x < mapSize; x++)
            {
                for (int y = 1; y < mapSize; y++)
                {
                    if (myMap[x, y] == 1)
                    {
                        if ((!EnemyBot.IsInsideMap(x - 1, y) || myMap[x - 1, y] != 1) && // vertical ship
                            (!EnemyBot.IsInsideMap(x, y + 1) || myMap[x, y + 1] != 1) &&
                            (!EnemyBot.IsInsideMap(x, y - 1) || myMap[x, y - 1] != 1))
                        {
                            if (CountDeck(x, y, !horizontShip) < 0)
                            {
                                return(false);
                            }
                            else
                            {
                                result.Add(CountDeck(x, y, !horizontShip));
                            }
                        }
                        else if ((!EnemyBot.IsInsideMap(x - 1, y) || myMap[x - 1, y] != 1) && // horizont ship
                                 (!EnemyBot.IsInsideMap(x + 1, y) || myMap[x + 1, y] != 1) &&
                                 (!EnemyBot.IsInsideMap(x, y - 1) || myMap[x, y - 1] != 1))
                        {
                            if (CountDeck(x, y, horizontShip) < 0)
                            {
                                return(false);
                            }
                            else
                            {
                                result.Add(CountDeck(x, y, horizontShip));
                            }
                        }
                    }
                }
            }
            result.Sort();
            return((result.ToArray().Length == 10) ? Enumerable.SequenceEqual(RightArr_ShipsCount, result) : false);
        }
Beispiel #4
0
 public void CheckWreckedShip(int[,] map, Button[,] button)
 {
     if (isPlaying)
     {
         for (int x = 1; x < mapSize; x++)
         {
             for (int y = 1; y < mapSize; y++)
             {
                 if (map[x, y] == 3)
                 {
                     // button[x, y].BackColor = Color.Red;
                     if ((!EnemyBot.IsInsideMap(x - 1, y) || map[x - 1, y] != 3) && // vertical ship
                         (!EnemyBot.IsInsideMap(x, y + 1) || map[x, y + 1] != 3) &&
                         (!EnemyBot.IsInsideMap(x, y - 1) || map[x, y - 1] != 3) &&
                         (!EnemyBot.IsInsideMap(x, y + 1) || map[x, y + 1] != 1) &&
                         (!EnemyBot.IsInsideMap(x - 1, y) || map[x - 1, y] != 1) &&
                         (!EnemyBot.IsInsideMap(x, y - 1) || map[x, y - 1] != 1))
                     {
                         int t = x;
                         while (EnemyBot.IsInsideMap(t, y) && map[t, y] == 3)
                         {
                             t++;
                             if (EnemyBot.IsInsideMap(t, y) && map[t, y] == 1)
                             {
                                 break;
                             }
                             else if (EnemyBot.IsInsideMap(t, y) && map[t, y] == 3 && EnemyBot.IsInsideMap(t + 1, y))
                             {
                                 continue;
                             }
                             else
                             {
                                 // if (!EnemyBot.IsInsideMap(t, y)) t--;
                                 for (int i = x; i < t; i++)
                                 {
                                     button[i, y].BackColor = Color.DarkRed;
                                     button[i, y].Text      = "X";
                                 }
                             }
                         }
                     }
                     else if ((!EnemyBot.IsInsideMap(x - 1, y) || map[x - 1, y] != 3) && // horizont ship
                              (!EnemyBot.IsInsideMap(x + 1, y) || map[x + 1, y] != 3) &&
                              (!EnemyBot.IsInsideMap(x, y - 1) || map[x, y - 1] != 3) &&
                              (!EnemyBot.IsInsideMap(x - 1, y) || map[x - 1, y] != 1) &&
                              (!EnemyBot.IsInsideMap(x, y - 1) || map[x, y - 1] != 1))
                     {
                         int t = y;
                         while (EnemyBot.IsInsideMap(x, t) && map[x, t] == 3)
                         {
                             t++;
                             if (EnemyBot.IsInsideMap(x, t) && map[x, t] == 1)
                             {
                                 break;
                             }
                             else if (EnemyBot.IsInsideMap(x, t) && map[x, t] == 3 && EnemyBot.IsInsideMap(x, t + 1))
                             {
                                 continue;
                             }
                             else
                             {
                                 for (int i = y; i < t; i++)
                                 {
                                     button[x, i].BackColor = Color.DarkRed;
                                     button[x, i].Text      = "X";
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }