Beispiel #1
0
        void PrepareBattleMap()
        {
            if (currentData == null)
            {
                Debug.Log("prepare battle map failed:no battle data");
                return;
            }
            gridUnits = new GridUnit[currentData.mapWidth, currentData.mapHeight];

            for (int row = 0; row < currentData.mapHeight; row++)
            {
                for (int column = 0; column < currentData.mapWidth; column++)
                {
                    GridUnitData gud = currentData.mapGrids[column, row];
                    gud.col = column;
                    gud.row = row;
                    if (gud != null)
                    {
                        GridUnit gu = CreateGrid();//创建一个用于显示的格子对象
                        if (gu != null)
                        {
                            gridUnits[column, row]     = gu;
                            gu.transform.localPosition = gud.localPosition;
                            gu.name     = string.Format("Grid_{0}_{1}", row, column);
                            gu.gridData = gud;
                            gu.Refresh();
                            gu.gameObject.SetActive(true);
                        }
                    }
                }
            }
        }
Beispiel #2
0
    //战场中铺设格子(信息,不做显示)
    public void Init(int width, int height)
    {
        if (width <= 0 || height <= 0)
        {
            return;
        }

        MapWidth  = width;
        MapHeight = height;
        MapGrids  = new GridUnit[MapWidth, MapHeight];

        for (int i = 0; i < MapHeight; i++)
        {
            for (int j = 0; j < MapWidth; j++)
            {
                GridUnit gridUnit = new GridUnit(MapId, i, j);
                gridUnit.LocalPosition = new Vector3(
                    j * GameConst.Map_GridWith + (((i & 1) == 1) ? GameConst.Map_GridWith * 0.5f : 0f),
                    0,
                    -i * GameConst.Map_GridOffsetY);
                gridUnit.GridType = GridType.Normal;
                MapGrids[j, i]    = gridUnit;
            }
        }

        GenerateBorn();
        TidyGridList();
    }
Beispiel #3
0
        //准备加载战场
        private void PrepareBattleMap()
        {
            if (currentData == null)
            {
                EUtilityHelperL.LogError("Prepare battle map failed. No battle data.");
                return;
            }
            gridUnits = new GridUnit[currentData.mapData.mapWidth, currentData.mapData.mapHeight];

            for (int r = 0; r < currentData.mapData.mapHeight; ++r)
            {
                for (int c = 0; c < currentData.mapData.mapWidth; ++c)
                {
                    GridUnitData gud = currentData.mapData.mapGrids[c, r];
                    if (gud != null)
                    {
                        //创建一个用于显示的格子对象
                        GridUnit gridUnit = CreateGrid();
                        if (gridUnit != null)
                        {
                            gridUnits[c, r] = gridUnit;
                            gridUnit.transform.localPosition = gud.localPosition;
                            gridUnit.name     = string.Format("Grid_{0}_{1}", r, c);
                            gridUnit.gridData = gud;
                            gridUnit.RefreshColor();
                            gridUnit.gameObject.SetActive(true);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        //准备加载战场
        private void PrepareBattleMap()
        {
            if (currentData == null)
            {
                EUtilityHelperL.LogError("Prepare battle map failed. No battle data.");
                return;
            }
            gridUnits = new GridUnit[currentData.mapWidth, currentData.mapHeight];

            for (int row = 0; row < currentData.mapHeight; ++row)
            {
                for (int column = 0; column < currentData.mapWidth; ++column)
                {
                    GridUnitData gud = currentData.mapGrids[column, row];
                    if (gud != null)
                    {
                        //创建一个用于显示的格子对象
                        GridUnit gu = CreateGrid();
                        if (gu != null)
                        {
                            gridUnits[column, row]     = gu;
                            gu.transform.localPosition = gud.localPosition;
                            gu.name     = string.Format("Grid_{0}_{1}", row, column);
                            gu.gridData = gud;
                            gu.Refresh();
                            gu.gameObject.SetActive(true);
                        }
                    }
                }
            }
        }
Beispiel #5
0
 public Grid(int width, int height, float cellSize)
 {
     this.width    = width;
     this.height   = height;
     this.cellSize = cellSize;
     units         = new GridUnit[width, height];
 }
Beispiel #6
0
    }         // InitGameGrid()

    // Initialize the internal market grid
    public void InitMarketGrid()
    {
        if (!hasAuthority)
        {
            Debug.Log(debug + "No authority to initialize the internal market grid!");
            return;
        }

        // Market Grid ####################################
        marketGrid = new GridUnit[Mathf.CeilToInt((float)GameManager.masterDeck.marketCardDeck.Count()
                                                  / (float)GameManager.height), GameManager.height];
        maxMarketStack = new int[GameManager.height];

        int marketWidth = Mathf.CeilToInt((float)GameManager.masterDeck.marketCardDeck.Count()
                                          / (float)GameManager.height);

        for (int x = 0; x < marketWidth; x++)
        {
            for (int y = 0; y < GameManager.height; y++)
            {
                // Draw a card from the Market Card deck
                // Card card = Card.CreateInstance<Card>();
                CardData card;
                if (GameManager.DrawCard(GameManager.masterDeckMutable.marketCardDeck,
                                         GameManager.masterDeck.marketCardDeck,
                                         out card, false))
                {
                    // Debug.Log("[GridManager] Saving card at [" + x + ", " + y + "]");
                    // Connect the drawn card to the internal grid
                    marketGrid[x, y] = new GridUnit(card: card, x: x, y: y);
                    // Debug.Log("[GridManager] Card saved: " + marketGrid[x, y].card);
                }
            } // y
        }     // x
    }         // InitMarketGrid()
Beispiel #7
0
    //根据地图数据生成地图
    private void Genrate()
    {
        gridUnits = new GridUnit[currentMapData.mapHeight, currentMapData.mapWidth];

        for (int i = 0; i < currentMapData.mapHeight; ++i)
        {
            for (int j = 0; j < currentMapData.mapWidth; ++j)
            {
                gridUnits[i, j] = InstantiateGridUnit(i, j);
            }
        }
    }
Beispiel #8
0
    /// <summary>
    /// GameBoardを生成する
    /// </summary>
    private void CreateGrid()
    {
        gameBoardUnits = new GridUnit[gridSizeX, gridSizeY];

        for (int y = 0; y < gridSizeY; y++)
        {
            for (int x = 0; x < gridSizeX; x++)
            {
                GridUnit newGridUnit = new GridUnit(gridUnitPrefab, transform, x, y);
                gameBoardUnits[x, y] = newGridUnit;
            }
        }
    }
Beispiel #9
0
 public Grid(int width, int height, System.Func <Grid <GridUnit>, int, int, GridUnit> func, float cellSize = 1)
 {
     this.width    = width;
     this.height   = height;
     this.cellSize = cellSize;
     units         = new GridUnit[width, height];
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             units[x, y] = func.Invoke(this, x, y);
         }
     }
 }
Beispiel #10
0
        //回收所有格子
        private void RecycleAllGrids()
        {
            if (gridPool == null)
            {
                return;
            }

            for (int i = 0; i < gridPool.Count; ++i)
            {
                gridPool[i].transform.localPosition = Vector3.zero;
                gridPool[i].name = "UNUSED";
                gridPool[i].gameObject.SetActive(false);
            }

            gridUnits = null;
        }
Beispiel #11
0
        //战场中铺设格子
        public void Generate(int width, int height, int obstacleCount, int gap)
        {
            //UtilityHelper.TimerStart();

            if (width <= 0 || height <= 0)
            {
                return;
            }

            //记录地图宽高
            mapWidth  = width;
            mapHeight = height;
            //生成格子数组
            mapGrids = new GridUnit[mapWidth, mapHeight];

            //全部生成为普通格子
            for (int r = 0; r < mapHeight; ++r)
            {
                for (int c = 0; c < mapWidth; ++c)
                {
                    GridUnit gridUnitData = new GridUnit(this, r, c);
                    gridUnitData.localPosition = new Vector3(
                        c * EGameConstL.Map_GridWidth + ((r & 1) == (EGameConstL.Map_FirstRowOffset ? 0 : 1) ? (EGameConstL.Map_GridWidth * 0.5f) : 0f),
                        -r * EGameConstL.Map_GridOffsetY,
                        0
                        );

                    //初始设置为普通格子
                    gridUnitData.GridType = GridType.Normal;
                    //保存
                    mapGrids[c, r] = gridUnitData;
                }
            }
            //随机一些出生格子
            GenerateBorn();
            //随机一些障碍格子
            GenerateObstacle(obstacleCount, gap);
            //整理格子列表
            TidyGridList();

            RefreshGridsRuntimePasses();
            //UtilityHelper.Log(string.Format("Generate map {0}, time cost:{1}", mapID, UtilityHelper.TimerEnd()));
        }
Beispiel #12
0
        //战场中铺设格子
        public void Init(
            int width, int height,
            int obstacleCount, int gap,
            int buffCount, int itemCount)
        {
            if (width <= 0 || height <= 0)
            {
                return;
            }

            //记录地图宽高
            mapWidth  = width;
            mapHeight = height;
            //生成格子数组
            mapGrids = new GridUnit[mapWidth, mapHeight];

            this.obstacleCount = obstacleCount;
            this.obstacleGap   = gap;
            this.buffCount     = buffCount;
            this.itemCount     = itemCount;

            //全部生成为普通格子
            for (int r = 0; r < mapHeight; ++r)
            {
                for (int c = 0; c < mapWidth; ++c)
                {
                    GridUnit gridUnitData = new GridUnit(this, r, c);
                    gridUnitData.localPosition = new Vector3(
                        c * EGameConstL.Map_GridWidth,// + ((r & 1) == (EGameConstL.Map_FirstRowOffset ? 0 : 1) ? (EGameConstL.Map_GridWidth * 0.5f) : 0f),
                        -r * EGameConstL.Map_GridOffsetY,
                        0
                        );

                    //保存
                    mapGrids[c, r] = gridUnitData;
                }
            }

            ResetMap();
        }
Beispiel #13
0
    }         // CreateHandObjects()

    // Initialize the internal game grid
    public void InitGameGrid()
    {
        if (!hasAuthority)
        {
            // Debug.Log(debug + "No authority to initialize the internal game grid!");
            return;
        }

        // Game Grid ######################################
        grid     = new GridUnit[GameManager.width, GameManager.height];
        rowPos   = new float[GameManager.height];
        maxStack = new int[GameManager.height];

        for (int x = 0; x < GameManager.width; x++)
        {
            for (int y = 0; y < GameManager.height; y++)
            {
                // Draw a card from the Land Tile deck
                // Card card = Card.CreateInstance<Card>();
                CardData card;

                if (GameManager.DrawCard(GameManager.masterDeckMutable.landTileDeck,
                                         GameManager.masterDeck.landTileDeck,
                                         out card))
                {
                    // Debug.Log("[GridManager] Tile Draw successful!");
                    // Connect the drawn card to the internal grid
                    grid[x, y] = new GridUnit(card: card, x: x, y: y);
                }
                else
                {
                    Debug.Log(debug + "Tile Draw failure!");
                }
            } // y
        }     // x
    }         // InitGameGrid()
Beispiel #14
0
        public static BattleMap ReadBattleMapFromXML(string xmlFilePath)
        {
            TextAsset xmlfile = Resources.Load(xmlFilePath) as TextAsset;

            if (!xmlfile)
            {
                UtilityHelper.LogFormat("Load {0} xml file failed!", xmlFilePath);
                return(null);
            }

            int mapWidth  = 0;
            int mapHeight = 0;

            GridUnit[,] gridMap = null;

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlfile.text);
            XmlNodeList xmlNodeList = xmlDoc.SelectSingleNode("MapBaseMsg").ChildNodes;
            XmlNodeList mapMsgList  = null;

            foreach (XmlElement xmlElement in xmlNodeList)
            {
                switch (xmlElement.Name)
                {
                case ("Width"):
                    mapWidth = Convert.ToInt32(xmlElement.InnerText);
                    break;

                case ("Height"):
                    mapHeight = Convert.ToInt32(xmlElement.InnerText);
                    break;

                case ("GridMsg"):
                    mapMsgList = xmlElement.ChildNodes;
                    break;
                }
            }

            BattleMap battleMap = new BattleMap(mapWidth, mapHeight);

            foreach (XmlElement gridUnitInfo in mapMsgList)
            {
                int           posX = 0, posY = 0;
                GridAttribute gridAttribute = new GridAttribute();
                foreach (XmlElement xmlElement in gridUnitInfo.ChildNodes)
                {
                    switch (xmlElement.Name)
                    {
                    case ("PosX"):
                        posX = Convert.ToInt32(xmlElement.InnerText);
                        break;

                    case ("PosY"):
                        posY = Convert.ToInt32(xmlElement.InnerText);
                        break;

                    case ("Name"):
                        gridAttribute.m_Name = Convert.ToString(xmlElement.InnerText);
                        break;

                    case ("Avoid"):
                        gridAttribute.m_Avoid = Convert.ToSingle(xmlElement.InnerText);
                        break;

                    case ("Defense"):
                        gridAttribute.m_Defense = Convert.ToSingle(xmlElement.InnerText);
                        break;

                    case ("Height"):
                        gridAttribute.m_Height = Convert.ToSingle(xmlElement.InnerText);
                        break;

                    case ("MaxPassVolume"):
                        gridAttribute.m_MaxPassVolume = Convert.ToSingle(xmlElement.InnerText);
                        break;

                    case ("CrossCost"):
                        gridAttribute.m_CrossCost = Convert.ToSingle(xmlElement.InnerText);
                        break;

                    case ("GridType"):
                        gridAttribute.SetGridType(Convert.ToString(xmlElement.InnerText));
                        break;
                    }
                }
                GridUnit gridUnit = battleMap.mapGrids[posX - 1, posY - 1];
                if (gridUnit == null)
                {
                    gridUnit = new GridUnit(battleMap, posY - 1, posX - 1);
                    battleMap.mapGrids[posX - 1, posY - 1] = gridUnit;
                }
                gridUnit.column          = posX - 1;
                gridUnit.row             = posY - 1;
                gridUnit.m_GridAttribute = gridAttribute;
                gridUnit.localPosition   = new Vector3(posX * EGameConstL.Map_GridWidth, -posY * EGameConstL.Map_GridOffsetY, 0);

                if (gridUnit.m_GridAttribute.m_GridType == GridType.Normal)
                {
                    battleMap.normalGrids.Add(gridUnit);
                }
                else if (gridUnit.m_GridAttribute.m_GridType == GridType.Obstacle)
                {
                    battleMap.obstacleGrids.Add(gridUnit);
                }
            }

            return(battleMap);
        }
Beispiel #15
0
    void Awake()
    {
        if (singleton == null)
        {
            singleton = this;
        }
        grid = new GridUnit[gridSize, gridSize];
        fetchPuzzle();
        spawnBoard();
        if (PuzzleControl.singleton.selectedPuzzle == 0)
        {
            grid [8, 4].output = new Signal(1, 150, "right");

            grid [0, 4].gameObject.GetComponent <Receiver> ().inputDirection  = "right";
            grid [0, 4].gameObject.GetComponent <Receiver> ().inputType       = 1;
            grid [0, 4].gameObject.GetComponent <Receiver> ().inputLowerLimit = 100;
            grid [0, 4].gameObject.GetComponent <Receiver> ().inputUpperLimit = 200;
            clearList.Add(grid [0, 4].gameObject.GetComponent <Receiver> ());
            tutStuff1.SetActive(true);
            convStuff.SetActive(false);
            ampStuff.SetActive(false);
        }

        if (PuzzleControl.singleton.selectedPuzzle == 1)
        {
            grid [9, 4].output = new Signal(1, 200, "up");
            grid [9, 4].gameObject.transform.Rotate(0, 0, 90);

            grid [1, 0].gameObject.GetComponent <Receiver> ().inputDirection  = "up";
            grid [1, 0].gameObject.GetComponent <Receiver> ().inputType       = 1;
            grid [1, 0].gameObject.GetComponent <Receiver> ().inputLowerLimit = 700;
            grid [1, 0].gameObject.GetComponent <Receiver> ().inputUpperLimit = 1000;
            grid [1, 0].gameObject.transform.Rotate(0, 0, 90);
            clearList.Add(grid [1, 0].gameObject.GetComponent <Receiver> ());
            tutStuff2.SetActive(true);
            convStuff.SetActive(false);
        }
        if (PuzzleControl.singleton.selectedPuzzle == 2)
        {
            grid [9, 8].output = new Signal(1, 400, "down");
            grid [9, 8].gameObject.transform.Rotate(0, 0, -90);

            grid [1, 4].gameObject.GetComponent <Receiver> ().inputDirection  = "left";
            grid [1, 4].gameObject.GetComponent <Receiver> ().inputType       = 2;
            grid [1, 4].gameObject.GetComponent <Receiver> ().inputLowerLimit = 100;
            grid [1, 4].gameObject.GetComponent <Receiver> ().inputUpperLimit = 200;
            grid [1, 4].gameObject.transform.Rotate(0, 0, 180);
            clearList.Add(grid [1, 4].gameObject.GetComponent <Receiver> ());
            tutStuff3.SetActive(true);
            ampStuff.SetActive(false);
        }

        if (PuzzleControl.singleton.selectedPuzzle == 3)
        {
            grid [0, 2].output = new Signal(1, 100, "right");

            grid [5, 5].output = new Signal(2, 150, "down");
            grid [5, 5].gameObject.transform.Rotate(0, 0, -90);

            grid [2, 8].gameObject.GetComponent <Receiver> ().inputDirection  = "right";
            grid [2, 8].gameObject.GetComponent <Receiver> ().inputType       = 1;
            grid [2, 8].gameObject.GetComponent <Receiver> ().inputLowerLimit = 225;
            grid [2, 8].gameObject.GetComponent <Receiver> ().inputUpperLimit = 350;
            clearList.Add(grid [2, 8].gameObject.GetComponent <Receiver> ());

            grid [5, 0].gameObject.GetComponent <Receiver> ().inputDirection  = "right";
            grid [5, 0].gameObject.GetComponent <Receiver> ().inputType       = 3;
            grid [5, 0].gameObject.GetComponent <Receiver> ().inputLowerLimit = 75;
            grid [5, 0].gameObject.GetComponent <Receiver> ().inputUpperLimit = 125;
            clearList.Add(grid [5, 0].gameObject.GetComponent <Receiver> ());
        }

        if (PuzzleControl.singleton.selectedPuzzle == 4)
        {
            grid [0, 9].output = new Signal(1, 200, "right");

            grid [1, 0].gameObject.GetComponent <Receiver> ().inputDirection  = "left";
            grid [1, 0].gameObject.GetComponent <Receiver> ().inputType       = 1;
            grid [1, 0].gameObject.GetComponent <Receiver> ().inputLowerLimit = 150;
            grid [1, 0].gameObject.GetComponent <Receiver> ().inputUpperLimit = 300;
            grid [1, 0].gameObject.transform.Rotate(0, 0, 180);
            clearList.Add(grid [1, 0].gameObject.GetComponent <Receiver> ());

            grid [9, 4].gameObject.GetComponent <Receiver> ().inputDirection  = "down";
            grid [9, 4].gameObject.GetComponent <Receiver> ().inputType       = 1;
            grid [9, 4].gameObject.GetComponent <Receiver> ().inputLowerLimit = 200;
            grid [9, 4].gameObject.GetComponent <Receiver> ().inputUpperLimit = 250;
            grid [9, 4].gameObject.transform.Rotate(0, 0, -90);
            clearList.Add(grid [9, 4].gameObject.GetComponent <Receiver> ());
        }
    }
Beispiel #16
0
 public BattleMap(int width, int height)
 {
     mapWidth  = width;
     mapHeight = height;
     mapGrids  = new GridUnit[width, height];
 }
Beispiel #17
0
        public void parseCSV(string input, string output, GridUnit[,] array, List <GridUnit> airportGridUnits, List <GridUnit> activeGridUnits)
        {
            using (StreamWriter outputFile = new StreamWriter(output))
            {
                using (StreamReader inputFile = new StreamReader(input))
                {
                    string[] lineArr;
                    string   line;
                    string   writeLine   = String.Empty;
                    int      lineCounter = 850;
                    bool     oneAdded    = true;

                    while ((line = inputFile.ReadLine()) != null && lineCounter > topLattitude)
                    {
                        lineCounter--; // remove the top data
                    }
                    while ((line = inputFile.ReadLine()) != null && lineCounter > bottomLattitude)
                    {
                        writeLine = String.Empty;
                        lineArr   = line.Split(',');

                        for (int i = 0; i < lineArr.Length; i++)
                        {
                            if (i < westernLongitude)
                            {
                                // do nothing
                            }
                            else if (i > easternLongitude - 1)
                            {
                                break;
                            }
                            else
                            {
                                writeLine += lineArr[i] + ",";

                                if (lineArr[i] != "99999.0" && lineArr[i] != "1.0369266")
                                {
                                    array[i - westernLongitude, lineCounter - bottomLattitude - 1] = new GridUnit(Convert.ToInt64(Convert.ToSingle(lineArr[i]) * 100), 0, 0, Convert.ToInt64(Convert.ToSingle(lineArr[i]) * 100), i - westernLongitude, lineCounter - bottomLattitude - 1);
                                    if (array[i - westernLongitude, lineCounter - bottomLattitude - 1].N > 300000)
                                    {
                                        if (oneAdded)
                                        {
                                            //activeGridUnits.Add(array[i - westernLongitude, lineCounter - bottomLattitude - 1]);
                                            //activeGridUnits.ElementAt(0).i = .01;
                                            oneAdded = false;
                                        }
                                        airportGridUnits.Add(array[i - westernLongitude, lineCounter - bottomLattitude - 1]);
                                    }
                                }
                                else
                                {
                                    array[i - westernLongitude, lineCounter - bottomLattitude - 1] = new GridUnit(0, 0, 0, 0, i - westernLongitude, lineCounter - bottomLattitude - 1);
                                }
                            }
                        }
                        outputFile.WriteLine(writeLine);
                        lineCounter--;
                    }
                }
            }
        }