Пример #1
0
        // Строим список [partOfString -- Lvl]
        static StructureList <MyStruct> ScanArithmeticExpression(string str)
        {
            char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            str = str.Replace('.', ',');
            str = str.Replace(" ", string.Empty);

            MyStruct[] data = {};
            StructureList <MyStruct> list = new StructureList <MyStruct>(data);
            int lvl = 0;

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '(')
                {
                    lvl++;
                    list.Add(new MyStruct {
                        PartOfString = str[i].ToString(), Lvl = lvl
                    });
                }

                if (digits.Contains(str[i]))
                {
                    string number = "";
                    while (digits.Contains(str[i]) || str[i] == ',')
                    {
                        number += str[i];
                        i++;
                    }

                    i--;

                    lvl++;
                    list.Add(new MyStruct {
                        PartOfString = number, Lvl = lvl
                    });
                }

                if (str[i] == '+' || str[i] == '-' || str[i] == '*' ||
                    str[i] == '/' || str[i] == ')')
                {
                    lvl--;
                    list.Add(new MyStruct {
                        PartOfString = str[i].ToString(), Lvl = lvl
                    });
                }
            }

            return(list);
        }
Пример #2
0
        private void generateLakeHouse(int HouseID)
        {
            int Radius = 32;

            int PX = (int)CenterPosition.X;
            int PY = (int)CenterPosition.Y;

            for (int countX = -Radius; countX <= Radius; countX += 2)
            {
                for (int countY = -Radius; countY <= Radius; countY += 2)
                {
                    if (MapUtil.HasSurrounding(PX + countX, PY + countY, IslandMap.lk, 8) && !IslandMap.lk[PX + countX, PY + countY] && !MapUtil.HasSurrounding(PX + countX, PY + countY, IslandMap.m, 1))
                    {
                        Point LakePoint = MapUtil.getClosest(PX + countX, PY + countY, IslandMap.lk, Radius);
                        int   angle     = MapUtil.GetDirectionAngle(PX + countX, PY + countY, IslandMap.lk) + 90;

                        if (angle >= 0)
                        {
                            Point3D Dimensions = VoxelModels.VoxelModels.ModelDimensionLibrary["House_" + HouseID + "_Dimensions"];

                            //Debug.WriteLine(Dimensions);

                            Structure Structure         = new Structure(new Point3D(PX + countX, IslandMap.h[PX + countX, PY + countY], PY + countY), angle, (int)Dimensions.X, (int)Dimensions.Y, (int)Dimensions.Z);
                            Boolean   HasNearbyBuilding = MapUtil.HasStructureSurroundingStructure(Structure, this, 3);

                            if (!HasNearbyBuilding)
                            {
                                Boolean HasLake = MapUtil.HasStructureSurrounding(Structure, IslandMap.lk, 6);

                                if (!HasLake)
                                {
                                    //add system for random houses
                                    IslandMap.StructureNames.Add("House_" + HouseID + "_");

                                    //IslandMap.StructurePoints.Add(new Point3D(PX + countX, IslandMap.h[PX + countX, PY + countY], PX + countX));
                                    IslandMap.StructurePoints.Add(new Point3D(PX + countX, IslandMap.h[PX + countX, PY + countY], PY + countY));
                                    //IslandMap.StructurePoints.Add(new Point3D(512, 2, 512));
                                    //IslandMap.StructureRotations.Add(new Vector3D(dir.X, 1, dir.Y));
                                    IslandMap.StructureRotations.Add(angle);

                                    StructureList.Add(Structure);

                                    //Debug.WriteLine("House added");

                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        // Вычислить значение к скобках
        static StructureList <MyStruct> DeterminateExpression(StructureList <MyStruct> list)
        {
            // Найдем 2 элемента с максимальным уровнем
            int max = GetMaxLvl(list);

            MyStruct element1 = new MyStruct();

            element1.Lvl          = -1;
            element1.PartOfString = "";

            MyStruct element2 = new MyStruct();

            element1.Lvl          = -1;
            element1.PartOfString = "";

            int num = 0;

            foreach (var element in list)
            {
                if (element.Lvl == max)
                {
                    if (element1.Lvl == -1)
                    {
                        element1 = element;
                    }
                    else
                    {
                        element2 = element;
                        break;
                    }
                }

                num++;
            }

            // Номер операции (между двумя элементами)
            num--;
            string operation = list.Data[num].PartOfString;

            // Результат операции
            double res    = 0;
            double value1 = Double.Parse(element1.PartOfString);
            double value2 = Double.Parse(element2.PartOfString);

            if (operation == "+")
            {
                res = value1 + value2;
            }

            if (operation == "-")
            {
                res = value1 - value2;
            }

            if (operation == "*")
            {
                res = value1 * value2;
            }

            if (operation == "/")
            {
                res = Math.Round(value1 / value2, 3);
            }

            list.Remove(num - 2);
            list.Remove(num - 2);
            list.Remove(num - 2);
            list.Remove(num - 2);
            list.Remove(num - 2);

            MyStruct newRes = new MyStruct {
                PartOfString = res.ToString(CultureInfo.InvariantCulture), Lvl = max - 1
            };

            list.Add(newRes, num - 2);

            return(list);
        }