Beispiel #1
0
        public HexaModel[][] parse(string mapSize, string mapType, string mapWealth)
        {
            HexaModel[][] map;

            Init();

            //TODO user number parameter
            xDoc.Load("Content/Maps/" + mapSize + ".xml");

            decideProductivity(mapWealth);
            decideMapType(mapType);

            XmlNodeList productivities = xDoc.GetElementsByTagName("productivity");
            XmlNodeList mapTypes = xDoc.GetElementsByTagName("mapType");

            this.parseProductivity(productivities);
            this.parseMapTypes(mapTypes);

            rndIndexTypesIndex = 0;
            rndIndexProductivityIndex = 0;

            if (rndIndexTypes == null)
            {
                rndIndexTypes = new int[200];

                for (int loop1 = 0; loop1 < rndIndexTypes.Length; loop1++)
                {
                    rndIndexTypes[loop1] = loop1 % 6;
                }
                ShuffleArray(rndIndexTypes);

                rndIndexProductivity = new int[200];
                for (int loop1 = 0; loop1 < rndIndexProductivity.Length; loop1++)
                {
                    rndIndexProductivity[loop1] = loop1 % 5;
                }
                ShuffleArray(rndIndexProductivity);
            }

            XmlNodeList rows = xDoc.GetElementsByTagName("row");
            map = new HexaModel[rows.Count][];

            for (int i = 0; i < rows.Count; ++i)
            {
                map[i] = new HexaModel[rows[i].ChildNodes.Count];
                XmlNodeList hexas = rows[i].ChildNodes;

                for (int j = 0; j < hexas.Count; ++j)
                {
                    bool isEmpty = false;
                    bool isWater = false;

                    foreach (XmlAttribute a in hexas[j].Attributes)
                    {
                        if(a.Name == "type" && a.Value == "space") isEmpty = true;
                        if(a.Name == "type" && a.Value == "water") isWater = true;
                    }

                    HexaKind type;
                    int hexanum = 0;

                    if (!isEmpty && !isWater)
                    {
                        type = getRandomType();

                        if (type == HexaKind.Desert)
                        {
                            hexanum = 0;
                        }
                        else
                        {
                            hexanum = getRandomProductivity();
                        }
                    }
                    else
                    {
                        if (isWater)
                            type = HexaKind.Water;
                        else
                            type = HexaKind.Nothing;
                    }

                    map[i][j] = HexaCreator.create(type, hexanum);
                }

            }

            return map;
        }
Beispiel #2
0
        public HexaModel[][] parseCampaignMap(string mapSource)
        {
            HexaModel[][] map;
            xDoc = new XmlDocument();
            xDoc.Load("Content/Maps/" + mapSource);

            XmlNodeList rows = xDoc.GetElementsByTagName("row");
            map = new HexaModel[rows.Count][];

            for (int i = 0; i < rows.Count; ++i)
            {
                map[i] = new HexaModel[rows[i].ChildNodes.Count];
                XmlNodeList hexas = rows[i].ChildNodes;

                for (int loop1 = 0; loop1 < hexas.Count; ++loop1)
                {
                    HexaKind type = HexaKind.Nothing;
                    int hexanum = 0;
                    foreach (XmlAttribute attribute in hexas[loop1].Attributes)
                    {
                        if (attribute.Name == "type")
                            type = decideType(attribute.Value);
                        if (attribute.Name == "productivity")
                            hexanum = Convert.ToInt32(attribute.Value);
                    }

                    map[i][loop1] = HexaCreator.create(type, hexanum);
                }

            }
            return map;
        }
Beispiel #3
0
 public void SetHexaNeighbours(HexaModel hexa1, HexaModel hexa2, HexaModel hexa3)
 {
     hexaNeighbour[0] = hexa1;
     hexaNeighbour[1] = hexa2;
     hexaNeighbour[2] = hexa3;
 }
Beispiel #4
0
        public HexaView(HexaModel model, int x, int y)
        {
            this.x = x;
            this.y = y;

            this.model = model;
            this.hexaID = model.GetID();
            this.kind = model.GetKind();
            hexaRotation = GameMaster.Inst().GetRandomInt(6);

            if (kind != HexaKind.Water)
            {
                this.pickHexaColor = new Color(1.0f - this.hexaID / 256.0f, 0.0f, 0.0f);

                pickVars = new PickVariables(pickHexaColor);

                roadView = new RoadView[(int)RoadPos.Count];
                townView = new TownView[(int)TownPos.Count];
            }
        }
Beispiel #5
0
        public void CreateTownsAndRoads(HexaModel[] neighboursModel, HexaView hexaView, HexaView[] neighboursView)
        {
            hexaNeighbours = new HexaModel[neighboursModel.Length];
            for (int loop1 = 0; loop1 < neighboursModel.Length; loop1++)
                hexaNeighbours[loop1] = neighboursModel[loop1];

            if (kind == HexaKind.Nothing || kind == HexaKind.Water)
                return;

            ///////////////////////
            // Creating roads -> //
            ///////////////////////
            // Always make owns road or get reference from other roads (not sending reference to other hexas)
            if (neighboursModel[(int)RoadPos.UpLeft] == null ||
                neighboursModel[(int)RoadPos.UpLeft].GetRoad(RoadPos.BottomRight) == null)
            {
                roadOwner[(int)RoadPos.UpLeft] = true;
                roads[(int)RoadPos.UpLeft] = new RoadModel();
                hexaView.CreateRoadView(RoadPos.UpLeft, Matrix.CreateRotationY(-(float)Math.PI / 3.0f) * Matrix.CreateTranslation(new Vector3(-0.25f, 0.0f, 0.14f)));
            }
            else
            {
                roads[(int)RoadPos.UpLeft] = neighboursModel[(int)RoadPos.UpLeft].GetRoad(RoadPos.BottomRight);
                hexaView.SetRoadView(RoadPos.UpLeft, neighboursView[(int)RoadPos.UpLeft].GetRoadView(RoadPos.BottomRight));
            }

            if (neighboursModel[(int)RoadPos.UpRight] == null ||
                neighboursModel[(int)RoadPos.UpRight].GetRoad(RoadPos.BottomLeft) == null)
            {
                roadOwner[(int)RoadPos.UpRight] = true;
                roads[(int)RoadPos.UpRight] = new RoadModel();
                hexaView.CreateRoadView(RoadPos.UpRight, Matrix.CreateRotationY((float)Math.PI / 3.0f) * Matrix.CreateTranslation(new Vector3(-0.25f, 0.0f, -0.14f)));
            }
            else
            {
                roads[(int)RoadPos.UpRight] = neighboursModel[(int)RoadPos.UpRight].GetRoad(RoadPos.BottomLeft);
                hexaView.SetRoadView(RoadPos.UpRight, neighboursView[(int)RoadPos.UpRight].GetRoadView(RoadPos.BottomLeft));
            }

            if (neighboursModel[(int)RoadPos.MiddleLeft] == null ||
                neighboursModel[(int)RoadPos.MiddleLeft].GetRoad(RoadPos.MiddleRight) == null)
            {
                roadOwner[(int)RoadPos.MiddleLeft] = true;
                roads[(int)RoadPos.MiddleLeft] = new RoadModel();
                hexaView.CreateRoadView(RoadPos.MiddleLeft, Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, 0.29f)));
            }
            else
            {
                roads[(int)RoadPos.MiddleLeft] = neighboursModel[(int)RoadPos.MiddleLeft].GetRoad(RoadPos.MiddleRight);
                hexaView.SetRoadView(RoadPos.MiddleLeft, neighboursView[(int)RoadPos.MiddleLeft].GetRoadView(RoadPos.MiddleRight));
            }

            if (neighboursModel[(int)RoadPos.MiddleRight] == null ||
                neighboursModel[(int)RoadPos.MiddleRight].GetRoad(RoadPos.MiddleLeft) == null)
            {
                roadOwner[(int)RoadPos.MiddleRight] = true;
                roads[(int)RoadPos.MiddleRight] = new RoadModel();
                hexaView.CreateRoadView(RoadPos.MiddleRight, Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, -0.28f)));
            }
            else
            {
                roads[(int)RoadPos.MiddleRight] = neighboursModel[(int)RoadPos.MiddleRight].GetRoad(RoadPos.MiddleLeft);
                hexaView.SetRoadView(RoadPos.MiddleRight, neighboursView[(int)RoadPos.MiddleRight].GetRoadView(RoadPos.MiddleLeft));
            }

            if (neighboursModel[(int)RoadPos.BottomLeft] == null ||
                neighboursModel[(int)RoadPos.BottomLeft].GetRoad(RoadPos.UpRight) == null)
            {
                roadOwner[(int)RoadPos.BottomLeft] = true;
                roads[(int)RoadPos.BottomLeft] = new RoadModel();
                hexaView.CreateRoadView(RoadPos.BottomLeft, Matrix.CreateRotationY((float)Math.PI / 3.0f) * Matrix.CreateTranslation(new Vector3(0.25f, 0.0f, 0.14f)));
            }
            else
            {
                roads[(int)RoadPos.BottomLeft] = neighboursModel[(int)RoadPos.BottomLeft].GetRoad(RoadPos.UpRight);
                hexaView.SetRoadView(RoadPos.BottomLeft, neighboursView[(int)RoadPos.BottomLeft].GetRoadView(RoadPos.UpRight));
            }
            if (neighboursModel[(int)RoadPos.BottomRight] == null ||
                neighboursModel[(int)RoadPos.BottomRight].GetRoad(RoadPos.UpLeft) == null)
            {
                roadOwner[(int)RoadPos.BottomRight] = true;
                roads[(int)RoadPos.BottomRight] = new RoadModel();
                hexaView.CreateRoadView(RoadPos.BottomRight, Matrix.CreateRotationY(-(float)Math.PI / 3.0f) * Matrix.CreateTranslation(new Vector3(0.25f, 0.0f, -0.14f)));
            }
            else
            {
                roads[(int)RoadPos.BottomRight] = neighboursModel[(int)RoadPos.BottomRight].GetRoad(RoadPos.UpLeft);
                hexaView.SetRoadView(RoadPos.BottomRight, neighboursView[(int)RoadPos.BottomRight].GetRoadView(RoadPos.UpLeft));
            }

            ///////////////////////
            // Creating tows ->  //
            ///////////////////////
            if ((neighboursModel[(int)RoadPos.UpLeft] == null ||
                 neighboursModel[(int)RoadPos.UpLeft].getTown(TownPos.BottomRight) == null) &&
                (neighboursModel[(int)RoadPos.UpRight] == null ||
                 neighboursModel[(int)RoadPos.UpRight].getTown(TownPos.BottomLeft) == null))
            {
                townOwner[(int)TownPos.Up] = true;
                towns[(int)TownPos.Up] = new TownModel();
                hexaView.CreateTownView(TownPos.Up, Matrix.CreateTranslation(new Vector3(-0.32f, 0.0f, 0.0f)));
            }
            else
            {
                if (neighboursModel[(int)RoadPos.UpLeft] != null && neighboursModel[(int)RoadPos.UpLeft].getTown(TownPos.BottomRight) != null)
                {
                    towns[(int)TownPos.Up] = neighboursModel[(int)RoadPos.UpLeft].getTown(TownPos.BottomRight);
                    hexaView.SetTownView(TownPos.Up, neighboursView[(int)RoadPos.UpLeft].GetTownView(TownPos.BottomRight));
                }
                else
                {
                    towns[(int)TownPos.Up] = neighboursModel[(int)RoadPos.UpRight].getTown(TownPos.BottomLeft);
                    hexaView.SetTownView(TownPos.Up, neighboursView[(int)RoadPos.UpRight].GetTownView(TownPos.BottomLeft));
                }
            }

            if ((neighboursModel[(int)RoadPos.BottomLeft] == null ||
                 neighboursModel[(int)RoadPos.BottomLeft].getTown(TownPos.UpRight) == null) &&
                (neighboursModel[(int)RoadPos.BottomRight] == null ||
                 neighboursModel[(int)RoadPos.BottomRight].getTown(TownPos.UpLeft) == null))
            {
                townOwner[(int)TownPos.Bottom] = true;
                towns[(int)TownPos.Bottom] = new TownModel();
                hexaView.CreateTownView(TownPos.Bottom, Matrix.CreateTranslation(new Vector3(0.32f, 0.0f, 0.0f)));
            }
            else
            {
                towns[(int)TownPos.Bottom] = neighboursModel[(int)RoadPos.BottomLeft].getTown(TownPos.UpRight);
                hexaView.SetTownView(TownPos.Bottom, neighboursView[(int)RoadPos.BottomLeft].GetTownView(TownPos.UpRight));
            }

            if ((neighboursModel[(int)RoadPos.UpRight] == null ||
                neighboursModel[(int)RoadPos.UpRight].getTown(TownPos.Bottom) == null) &&
               (neighboursModel[(int)RoadPos.MiddleRight] == null ||
                neighboursModel[(int)RoadPos.MiddleRight].getTown(TownPos.UpLeft) == null))
            {
                townOwner[(int)TownPos.UpRight] = true;
                towns[(int)TownPos.UpRight] = new TownModel();
                hexaView.CreateTownView(TownPos.UpRight, Matrix.CreateTranslation(new Vector3(-0.16f, 0.0f, -0.28f)));
            }
            else
            {
                if (neighboursModel[(int)RoadPos.UpRight] != null && neighboursModel[(int)RoadPos.UpRight].getTown(TownPos.Bottom) != null)
                {
                    towns[(int)TownPos.UpRight] = neighboursModel[(int)RoadPos.UpRight].getTown(TownPos.Bottom);
                    hexaView.SetTownView(TownPos.UpRight, neighboursView[(int)RoadPos.UpRight].GetTownView(TownPos.Bottom));
                }
                else
                {
                    towns[(int)TownPos.UpRight] = neighboursModel[(int)RoadPos.MiddleRight].getTown(TownPos.UpLeft);
                    hexaView.SetTownView(TownPos.UpRight, neighboursView[(int)RoadPos.MiddleRight].GetTownView(TownPos.UpLeft));
                }
            }

            if ((neighboursModel[(int)RoadPos.UpLeft] == null ||
                 neighboursModel[(int)RoadPos.UpLeft].getTown(TownPos.Bottom) == null) &&
                (neighboursModel[(int)RoadPos.MiddleLeft] == null ||
                 neighboursModel[(int)RoadPos.MiddleLeft].getTown(TownPos.UpRight) == null))
            {
                townOwner[(int)TownPos.UpLeft] = true;
                towns[(int)TownPos.UpLeft] = new TownModel();
                hexaView.CreateTownView(TownPos.UpLeft, Matrix.CreateTranslation(new Vector3(-0.16f, 0.0f, 0.28f)));
            }
            else
            {
                towns[(int)TownPos.UpLeft] = neighboursModel[(int)RoadPos.UpLeft].getTown(TownPos.Bottom);
                hexaView.SetTownView(TownPos.UpLeft, neighboursView[(int)RoadPos.UpLeft].GetTownView(TownPos.Bottom));
            }

            if ((neighboursModel[(int)RoadPos.BottomRight] == null ||
                neighboursModel[(int)RoadPos.BottomRight].getTown(TownPos.Up) == null) &&
               (neighboursModel[(int)RoadPos.MiddleRight] == null ||
                neighboursModel[(int)RoadPos.MiddleRight].getTown(TownPos.BottomLeft) == null))
            {
                townOwner[(int)TownPos.BottomRight] = true;
                towns[(int)TownPos.BottomRight] = new TownModel();
                hexaView.CreateTownView(TownPos.BottomRight, Matrix.CreateTranslation(new Vector3(0.16f, 0.0f, -0.28f)));
            }
            else
            {
                if (neighboursModel[(int)RoadPos.BottomRight] != null && neighboursModel[(int)RoadPos.BottomRight].getTown(TownPos.Bottom) != null)
                {
                    towns[(int)TownPos.BottomRight] = neighboursModel[(int)RoadPos.BottomRight].getTown(TownPos.Up);
                    hexaView.SetTownView(TownPos.BottomRight, neighboursView[(int)RoadPos.BottomRight].GetTownView(TownPos.Up));
                }
                else
                {
                    towns[(int)TownPos.BottomRight] = neighboursModel[(int)RoadPos.MiddleRight].getTown(TownPos.BottomLeft);
                    hexaView.SetTownView(TownPos.BottomRight, neighboursView[(int)RoadPos.MiddleRight].GetTownView(TownPos.BottomLeft));
                }
            }
            if ((neighboursModel[(int)RoadPos.BottomLeft] == null ||
                neighboursModel[(int)RoadPos.BottomLeft].getTown(TownPos.Up) == null) &&
               (neighboursModel[(int)RoadPos.MiddleLeft] == null ||
                neighboursModel[(int)RoadPos.MiddleLeft].getTown(TownPos.BottomRight) == null))
            {
                townOwner[(int)TownPos.BottomLeft] = true;
                towns[(int)TownPos.BottomLeft] = new TownModel();
                hexaView.CreateTownView(TownPos.BottomLeft, Matrix.CreateTranslation(new Vector3(0.16f, 0.0f, 0.28f)));
            }
            else
            {
                if (neighboursModel[(int)RoadPos.BottomLeft] != null && neighboursModel[(int)RoadPos.BottomLeft].getTown(TownPos.Bottom) != null)
                {
                    towns[(int)TownPos.BottomLeft] = neighboursModel[(int)RoadPos.BottomLeft].getTown(TownPos.Up);
                    hexaView.SetTownView(TownPos.BottomLeft, neighboursView[(int)RoadPos.BottomLeft].GetTownView(TownPos.Up));
                }
                else
                {
                    towns[(int)TownPos.BottomLeft] = neighboursModel[(int)RoadPos.MiddleLeft].getTown(TownPos.BottomRight);
                    hexaView.SetTownView(TownPos.BottomLeft, neighboursView[(int)RoadPos.MiddleLeft].GetTownView(TownPos.BottomRight));
                }
            }
        }