Пример #1
0
        public void AddSpaceSector(int x, int y, SpaceSector ss, Random random, int version)
        {
            //如果存在则删除,
            if (ListSpaceSector.Exists(item => item.Name == ss.Name))
            {
                ListSpaceSector.Remove(ListSpaceSector.SingleOrDefault(item => item.Name == ss.Name));
            }
            //添加
            ss.CenterA = x;
            ss.CenterB = y;
            ListSpaceSector.Add(ss);

            List <Tuple <int, int> > hexList = GetHexList(x, y);

            for (int j = 0; j < ss.TerranHexArray.Count; j++)
            {
                HexArray[hexList[j].Item1, hexList[j].Item2] = ss.TerranHexArray[j];
            }
            if (random != null)
            {
                //手动旋转,不需要检测颜色相邻
                if (!ValidateMap(hexList))
                {
                    //System.Diagnostics.Debug.WriteLine("发现不合法");
                    AddSpaceSector(x, y, ss.RandomRotato(random, version), random, version);
                }
            }
        }
Пример #2
0
        public SpaceSector RandomRotato(Random random, int version)
        {
            //Random  r =
            var time = random.Next(6);
            //System.Diagnostics.Debug.WriteLine("Time is "+time);
            SpaceSector result = this;

            for (int i = 0; i < time; i++)
            {
                result = result.Rotate(isClockwise: true, version: version);
            }
            result.Name = this.Name;
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 旋转
        /// </summary>
        /// <param name="isClockwise">是否顺时针</param>
        /// <returns></returns>
        public SpaceSector Rotate(bool isClockwise = true, int version = 3)
        {
            var newTHA = new List <TerrenHex>();

            //版本低于san,用原地图
            if (version < 3)
            {
                newTHA.Add(TerranHexArray[3]);
                newTHA.Add(TerranHexArray[8]);
                newTHA.Add(TerranHexArray[1]);
                newTHA.Add(TerranHexArray[13]);
                newTHA.Add(TerranHexArray[6]);
                newTHA.Add(TerranHexArray[0]);
                newTHA.Add(TerranHexArray[11]);
                newTHA.Add(TerranHexArray[4]);
                newTHA.Add(TerranHexArray[16]);
                newTHA.Add(TerranHexArray[9]);
                newTHA.Add(TerranHexArray[2]);
                newTHA.Add(TerranHexArray[14]);
                newTHA.Add(TerranHexArray[7]);
                newTHA.Add(TerranHexArray[18]);
                newTHA.Add(TerranHexArray[12]);
                newTHA.Add(TerranHexArray[5]);
                newTHA.Add(TerranHexArray[17]);
                newTHA.Add(TerranHexArray[10]);
                newTHA.Add(TerranHexArray[15]);
            }
            else
            {
                int[] list;
                if (isClockwise)//重新左(顺时针)只旋转一格
                {
                    list = new[] { 3, 8, 1, 13, 6, 0, 11, 4, 16, 9, 2, 14, 7, 18, 12, 5, 17, 10, 15 };
                }
                else//重新右(逆时针)只旋转一格
                {
                    list = new[] { 5, 2, 10, 0, 7, 15, 4, 12, 1, 9, 17, 6, 14, 3, 11, 18, 8, 16, 13 };
                }
                foreach (int i in list)
                {
                    newTHA.Add(TerranHexArray[i]);
                }
            }

            SpaceSector spaceSector = new SpaceSector(newTHA);

            spaceSector.Name = this.Name;
            return(spaceSector);
        }
Пример #4
0
        /// <summary>
        /// 4人完全随机
        /// </summary>
        /// <param name="random"></param>
        /// <returns></returns>
        public Map Get4PAllRandomMap(Random random)
        {
            var result = new Map();

            //0,1,2,3固定

            var randomList = new List <SpaceSector>()
            {
                ssl[0], ssl[1], ssl[2], ssl[3], ssl[4], ssl[5], ssl[6], ssl[7], ssl[8], ssl[9]
            };

            this.centerTuple_4p.ForEach(x =>
            {
                var index = random.Next(randomList.Count);
                SpaceSector spaceSector = randomList[index].RandomRotato(random, gaiaGame.version);
                result.AddSpaceSector(x.Item1, x.Item2, spaceSector, random, this.gaiaGame.version);
                //测试旋转
                //spaceSector = spaceSector.Rotate();
                //result.AddSpaceSector(x.Item1, x.Item2, spaceSector, null);
                randomList.RemoveAt(index);
            });
            return(result);
        }