Exemplo n.º 1
0
 /// <summary>
 /// 随机生成地图,用于测试
 /// </summary>
 /// <returns>地图数据</returns>
 static MapGridStatus[,] GenerateTestMap()
 {
     MapGridStatus[,] data = new MapGridStatus[2, 100];
     for (int i = 0; i < 2; i++)
     {
         for (int j = 0; j < 100; j++)
         {
             data[i, j] = (MapGridStatus)RandomGenerator.GetNumber(0, 4);
         }
     }
     return(data);
 }
Exemplo n.º 2
0
        static MapGridStatus[,] GenerateMaps()
        {
            MapGridStatus[,] data = new MapGridStatus[2, 100];
            for (int i = 0; i < 2; i++)
            {
                MapGridStatus[] oneMap    = new MapGridStatus[100];
                bool[]          list_used = new bool[100];
                for (int j = 0; j < 100; j++)
                {
                    list_used[j] = false;
                }
                for (int j = 4; j > 0; j--)
                {
                    for (int k = 0; k < 5 - j; k++)
                    {
                        int[] ship = GetShip(list_used, j);
                        while (!IsShipValid(oneMap, ship))
                        {
                            ship = GetShip(list_used, j);
                        }
                        //将找好的船加入字典当中
                        commonData.dict_ship[i][j.ToString() + k.ToString()] = ship;
                        SetShipOnMap(oneMap, ship);
                        for (int l = 0; l < 100; l++)
                        {
                            if (oneMap[l] == MapGridStatus.BlankChosen || oneMap[l] == MapGridStatus.Ship)
                            {
                                list_used[l] = true;
                            }
                        }
                    }
                }
                for (int j = 0; j < 100; j++)
                {
                    if (oneMap[j] != MapGridStatus.Ship)
                    {
                        oneMap[j] = MapGridStatus.Blank;
                    }
                }

                for (int j = 0; j < 100; j++)
                {
                    data[i, j] = oneMap[j];
                }
            }
            return(data);
        }