Example #1
0
    /*
     * void step(int i,int j)//visit grids around it from a single step
     * {
     *  if (grids[i, j].isBlock)
     *  { return; }
     *  if (grids[i, j].isInClosedList)
     *  { return; }
     *  if (!grids[i, j].isInOpenList)
     *  { return; }
     *  visit(i + 1, j,i,j);
     *  visit(i, j + 1,i,j);
     *  visit(i - 1, j, i, j);
     *  visit(i, j - 1, i, j);
     *  ClosedList.Add(grids[i,j]);
     *  grids[i, j].isInClosedList = true;
     * }
     */
    void step()//visit grids around it from a single step
    {
        if (OpenList.Count == 0)
        {
            isFinding = false;
            return;
        }
        SingleGrid grid = OpenList[OpenList.Count - 1];

        if (grid.isBlock)
        {
            return;
        }
        if (grid.isInClosedList)
        {
            return;
        }
        if (!grid.isInOpenList)
        {
            return;
        }
        OpenList.RemoveAt(OpenList.Count - 1);
        int i = grid.Position.x;
        int j = grid.Position.y;

        visit(i + 1, j, grid);
        visit(i, j + 1, grid);
        visit(i - 1, j, grid);
        visit(i, j - 1, grid);
        tileManager.Draw(i, j, TileType.Close);
        grid.isInClosedList = true;
        grid.isInOpenList   = false;
    }
Example #2
0
    void GenerateMap(int width, int height, float blockPercent) //m:width ; n:height
    {
        ResetMap();

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                grids[i, j] = new SingleGrid();
                if (Random.Range(0, 1f) < blockPercent)
                {
                    grids[i, j].isBlock = true;
                    tileManager.Draw(i, j, TileType.Block);
                    grids[i, j].Position = new Vector2Int(i, j);
                }
                else
                {
                    grids[i, j].isBlock = false;
                    tileManager.Draw(i, j, TileType.Blank);
                    grids[i, j].Position = new Vector2Int(i, j);
                    grids[i, j].Assume   = endPos.x - i + endPos.y - j;
                }
            }
        }
        grids[0, 0].isBlock   = false;
        grids[0, 0].Assume    = endPos.x + endPos.y;
        grids[0, 0].FromStart = 0;
        //tileManager.Draw(0, 0, TileType.Open);
        AddIntoOpenList(grids[0, 0], grids[0, 0]);

        grids[width - 1, height - 1].isBlock = false;
        tileManager.Draw(width - 1, height - 1, TileType.Blank);
    }
Example #3
0
 void AddGridToMyGroup(SingleGrid grid)
 {
     LastTempDrawGrid = grid;
     if (!mGridGroup.Contains (grid))
     {
         mGridGroup.Add (grid);
         grid.SetLable(mGridGroup.IndexOf(grid).ToString());
     }
 }
Example #4
0
    void TraceBack(SingleGrid grid)
    {
        SingleGrid g = grid;

        while (true)
        {
            tileManager.Draw(g.Position.x, g.Position.y, TileType.Result);
            if (g.Position == new Vector2Int(0, 0))
            {
                break;
            }
            g = g.parent;
        }
    }
Example #5
0
 public void OnDrawGrid(SingleGrid grid)
 {
     if (grid==null||(LastTempDrawGrid != null && LastTempDrawGrid == grid))
     {
         return;
     }
     if(IsNearGrid(grid))
     {
         AddGridToMyGroup(grid);
     }
     else
     {
         AddNearGridGroupToMyGroup(grid);
     }
 }
Example #6
0
    void AddIntoOpenList(SingleGrid grid, SingleGrid parent)  //val从大到小排序(小即高优先级在最后)
    {
        int index = OpenList.Count - 1;

        grid.FromStart = parent.FromStart + 1;

        for (; index > -1; index--)
        {
            if (grid.Val <= OpenList[index].Val)
            {
                break;
            }
        }
        OpenList.Insert(index + 1, grid);
        grid.isInOpenList = true;
        grid.parent       = parent;
        tileManager.Draw(grid.Position.x, grid.Position.y, TileType.Open);
    }
        private void Core_ProxyCountChanged(int proxyCount)
        {
            Action method = delegate
            {
                try
                {
                    if (SelectedHeaderButton == CoreRadioButton)
                    {
                        SingleGrid.Refresh();
                    }
                }
                catch (Exception exception)
                {
                    ShowOverlayError(exception);
                }
            };

            TryBeginInvoke(method);
        }
        private void Core_IsInitializedChanged(bool isInitialized)
        {
            Action method = delegate
            {
                try
                {
                    if (SelectedHeaderButton == CoreRadioButton)
                    {
                        SingleGrid.Refresh();
                    }
                }
                catch (Exception exception)
                {
                    ShowOverlayError(exception);
                }
            };

            TryBeginInvoke(method);
        }
Example #9
0
 public void EndDrawGrid(SingleGrid grid)
 {
     if (mGridGroup.Count == 0)
             return;
     if (grid!=null&&grid != mGridGroup [0])
     {
         float dis = Vector3.Distance(mGridGroup [0].transform.position,grid.transform.position);
         if(dis<0.5f)
         {
             AddNearGridGroupToMyGroup (mGridGroup [0]);
         }
     }
     for (int i = 0; i<mGridGroup.Count; i++)
     {
         mGridGroup[i].SetLable("");
     }
     //		NGUIDebug.Log("SleectGrid:"+mGridGroup.Count);
     mParent.mGridSelectMgr.OnSelectGridGroup(mGridGroup);
     LastTempDrawGrid = null;
 }
Example #10
0
 public SingleGrid GetGrid(SingleGrid grid,Side side)
 {
     int rowIndex = grid.mRowIndex;
     int lineIndex = grid.mLineIndex;
     switch (side)
     {
     case Side.Down:
         rowIndex--;
         break;
     case Side.Left:
         lineIndex--;
         break;
     case Side.Right:
         lineIndex++;
         break;
     case Side.Up:
         rowIndex++;
         break;
     }
     return GetGrid(rowIndex,lineIndex);
 }
Example #11
0
 void visit(int i, int j, SingleGrid from)
 {
     if (i < 0 || i >= width)
     {
         return;
     }
     if (j < 0 || j >= height)
     {
         return;
     }
     if (grids[i, j].isBlock)
     {
         return;
     }
     //reach end
     if (grids[i, j].Assume == 0)
     {
         grids[i, j].parent = from;
         isFinding          = false;
         StartCoroutine(callTraceBack(grids[i, j]));
         //TraceBack(grids[i,j]);
         return;
     }
     if (grids[i, j].isInClosedList)
     {
         return;
     }
     if (grids[i, j].isInOpenList)
     {
         if (grids[i, j].FromStart > from.FromStart + 1)
         {
             OpenList.Remove(grids[i, j]);
             AddIntoOpenList(grids[i, j], from);
         }
     }
     else
     {
         AddIntoOpenList(grids[i, j], from);
     }
 }
Example #12
0
    public void GetNextPipe(int clickedX, int clickedY, Image img, SingleGrid g)
    {
        // ridObjs[clickedX + width*clickedY].GetComponent<Image>().sprite
        img.sprite = nextT.GetChild(nextT.childCount - 1).GetComponent <Image>().sprite;
        img.material.SetTexture("_GradientTex", nextT.GetChild(nextT.childCount - 1).GetComponent <Image>().material.GetTexture("_GradientTex"));
        g.SetLogic((int)nextT.GetChild(nextT.childCount - 1).GetComponent <SingleGrid>().currentPipe);
        for (int i = 0; i < nextT.GetChild(nextT.childCount - 1).GetComponent <SingleGrid>().numOfRotations; i++)
        {
            g.RotatePipe();
        }
        Destroy(nextT.GetChild(nextT.childCount - 1).gameObject);
        // nextObjs.RemoveAt(nextObjs.Count - 1);

        // Add one to end, change it to start and change rest to +1
        GameObject newGridObj = Instantiate(gridObj, nextT);

        gridBlocks.Add(newGridObj.GetComponent <SingleGrid>());
        // nextObjs.Add(newGridObj);
        int random = Random.Range(0, pipes.Length);

        newGridObj.GetComponent <Image>().sprite = pipes[random];
        newGridObj.GetComponent <Image>().material.SetTexture("_GradientTex", pipeGradients[random]);
        newGridObj.GetComponent <SingleGrid>().SetLogic(random);
        int randRot = Random.Range(0, 4);

        for (int j = 0; j < randRot; j++)
        {
            newGridObj.GetComponent <SingleGrid>().RotatePipe();
        }
        newGridObj.GetComponent <SingleGrid>().numOfRotations = randRot;

        nextT.GetChild(nextT.childCount - 1).transform.SetAsFirstSibling();
        // GameObject firstObj = nextObjs[0];
        // // nextObjs[0] = nextObjs[nextObjs.Count-1];
        // for(int i = 0; i < nextObjs.Count-1; i++)
        // {
        //     nextObjs[i] = nextObjs[i+1];
        // }
        // nextObjs[0] = firstObj;
    }
Example #13
0
 SingleGrid GetNextGrid(SingleGrid fromGrid,SingleGrid targetGrid)
 {
     GridDisGroup.Clear ();
     AddGridDisToGroup (fromGrid,targetGrid,Side.Down);
     AddGridDisToGroup (fromGrid,targetGrid,Side.Up);
     AddGridDisToGroup (fromGrid,targetGrid,Side.Left);
     AddGridDisToGroup (fromGrid,targetGrid,Side.Right);
     SingleGrid minDisGrid = null;
     float minDis = 10000f;
     foreach (var child in GridDisGroup)
     {
         if(child.Value<minDis)
         {
             minDis = child.Value;
             minDisGrid = child.Key;
         }
     }
     return minDisGrid;
 }
        public GridStamp(List <MyCubeGrid> Grids)
        {
            float  DisassembleRatio = 0;
            double EstimatedValue   = 0;

            BlockTypeCount.Add("Reactors", 0);
            BlockTypeCount.Add("Turrets", 0);
            BlockTypeCount.Add("StaticGuns", 0);
            BlockTypeCount.Add("Refineries", 0);
            BlockTypeCount.Add("Assemblers", 0);

            foreach (MyCubeGrid SingleGrid in Grids)
            {
                if (SingleGrid.GridSizeEnum == MyCubeSize.Large)
                {
                    if (SingleGrid.IsStatic)
                    {
                        StaticGrids    += 1;
                        EstimatedValue += SingleGrid.BlocksCount * Config.StaticGridMarketMultiplier;
                    }
                    else
                    {
                        LargeGrids     += 1;
                        EstimatedValue += SingleGrid.BlocksCount * Config.LargeGridMarketMultiplier;
                    }
                }
                else
                {
                    SmallGrids     += 1;
                    EstimatedValue += SingleGrid.BlocksCount * Config.SmallGridMarketMultiplier;
                }


                foreach (MyCubeBlock SingleBlock in SingleGrid.GetFatBlocks())
                {
                    var Block = (IMyCubeBlock)SingleBlock;


                    if (SingleBlock.BuiltBy != 0)
                    {
                        UpdatePCUCounter(SingleBlock.BuiltBy, SingleBlock.BlockDefinition.PCU);
                    }

                    if (Block as IMyLargeTurretBase != null)
                    {
                        BlockTypeCount["Turrets"] += 1;
                    }
                    if (Block as IMySmallGatlingGun != null)
                    {
                        BlockTypeCount["Turrets"] += 1;
                    }

                    if (Block as IMyGunBaseUser != null)
                    {
                        BlockTypeCount["StaticGuns"] += 1;
                    }

                    if (Block as IMyRefinery != null)
                    {
                        BlockTypeCount["Refineries"] += 1;
                    }
                    if (Block as IMyAssembler != null)
                    {
                        BlockTypeCount["Assemblers"] += 1;
                    }


                    //Main.Debug("Block:" + Block.BlockDefinition + " ratio: " + Block.BlockDefinition.);
                    DisassembleRatio += SingleBlock.BlockDefinition.DeformationRatio;
                    NumberofBlocks   += 1;
                }

                BlockTypeCount["Reactors"] += SingleGrid.NumberOfReactors;
                NumberOfGrids += 1;
                GridMass      += SingleGrid.Mass;
                GridPCU       += SingleGrid.BlocksPCU;
            }

            if (Grids[0].BigOwners.Count > 0)
            {
                Grids[0].GridSystems.JumpSystem.GetMaxJumpDistance(Grids[0].BigOwners[0]);
            }

            //Get Total Build Percent
            GridBuiltPercent = DisassembleRatio / NumberofBlocks;
            MarketValue      = EstimatedValue;
        }
Example #15
0
 void AddNearGridGroupToMyGroup(SingleGrid grid)
 {
     SingleGrid getGrid = LastTempDrawGrid;
     while (getGrid!=grid)
     {
         getGrid = GetNextGrid(getGrid,grid);
         AddGridToMyGroup(getGrid);
     }
 }
Example #16
0
 void GetRoundGridGroup(SingleGrid grid)
 {
     for (int i=0; i<4; i++)
     {
         SingleGrid mGrid = GridPoolManager.Instance.GetGrid (grid, (Side)i);
         RoundGridGroup[i] = mGrid;
     }
 }
Example #17
0
 void AddGridDisToGroup(SingleGrid fromGrid,SingleGrid targetGrid,Side side)
 {
     SingleGrid mSideGrid = GridPoolManager.Instance.GetGrid (fromGrid, side);
     if (mSideGrid != null)
         GridDisGroup [mSideGrid] = Vector2.Distance (new Vector2 (mSideGrid.mRowIndex, mSideGrid.mLineIndex), new Vector2 (targetGrid.mRowIndex, targetGrid.mLineIndex));
 }
Example #18
0
 GridSelectGroupData GetSelectGroupData(SingleGrid grid)
 {
     for (int s = 0; s<selectGroupData.Count; s++) {
         GridSelectGroupData data = selectGroupData[s];
         if(data.SelectGridGroup.Contains(grid))
             return data;
     }
     GridSelectGroupData newData = new GridSelectGroupData ();
     selectGroupData.Add (newData);
     return newData;
 }
Example #19
0
 bool IsNearGrid(SingleGrid grid)
 {
     bool flag = true;
     if(LastTempDrawGrid!=null)
         flag = Mathf.Abs(grid.mRowIndex-LastTempDrawGrid.mRowIndex)<=1&&Mathf.Abs(grid.mLineIndex-LastTempDrawGrid.mLineIndex)<=1;
     return flag;
 }
Example #20
0
 //    int CheckNum = 0;
 void GetNearGridGroup(SingleGrid grid,GridSelectGroupData gridSelectGroupData)
 {
     for (int i=0; i<4; i++)
     {
         SingleGrid mGrid = GridPoolManager.Instance.GetGrid (grid, (Side)i);
         if(mGrid!=null)
         {
             if(!DrawGridGroup.Contains(mGrid)&&!gridSelectGroupData.SelectGridGroup.Contains(mGrid))
             {
                 gridSelectGroupData.SelectGridGroup.Add(mGrid);
                 GetNearGridGroup(mGrid,gridSelectGroupData);
     //					CheckNum++;
             }
         }else
             gridSelectGroupData.isSlect = false;
     }
 }
Example #21
0
    public IEnumerator WaterFlowLoop()
    {
        yield return(new WaitForSeconds(0.1f));

        bool       firstTime  = false;
        bool       playing    = true;
        SingleGrid nextGrid   = null;
        Material   newPipeMat = Instantiate(waterPipeMat);

        startTile.GetComponent <Image>().material = newPipeMat;
        startTile.GetComponent <Image>().material.SetTexture("_GradientTex", pipeGradients[1]);
        startTile.GetComponent <Image>().material.SetFloat("_WaterValue", 1);
        nextGrid = startTile.GetComponent <SingleGrid>();
        float lerp = 0.0f;

        while (playing)
        {
            lerp = 0.0f;
            nextGrid.activity = GridActivity.HasWater;
            while (lerp < 1.0f)
            {
                nextGrid.gameObject.GetComponent <Image>().material.SetFloat("_WaterValue", 1.0f - lerp);
                lerp += Time.deltaTime * 0.2f * speedMult;
                yield return(null);
            }
            nextGrid.gameObject.GetComponent <Image>().material.SetFloat("_WaterValue", 0.0f);
            if (firstTime)
            {
                if (startTile.GetComponent <SingleGrid>().flowingTo == 1)
                {
                    nextGrid = GetCorrectGrid(startTile.GetComponent <SingleGrid>().x, startTile.GetComponent <SingleGrid>().y - 1);
                }
                else if (startTile.GetComponent <SingleGrid>().flowingTo == 2)
                {
                    nextGrid = GetCorrectGrid(startTile.GetComponent <SingleGrid>().x + 1, startTile.GetComponent <SingleGrid>().y);
                }
                startTile = nextGrid.gameObject;
                Material newPipeMat2 = Instantiate(waterPipeMat);
                Texture  t           = nextGrid.gameObject.GetComponent <Image>().material.GetTexture("_GradientTex");
                nextGrid.gameObject.GetComponent <Image>().material = newPipeMat2;
                nextGrid.gameObject.GetComponent <Image>().material.SetTexture("_GradientTex", pipeGradients[(int)nextGrid.currentPipe]);
                nextGrid.gameObject.GetComponent <Image>().material.SetFloat("_WaterValue", 1);
                firstTime = false;
            }
            else
            {
                startTile = nextGrid.gameObject;

                if (nextGrid.x == winX && nextGrid.y - 1 == winY)
                {
                    AudioManager.instance.Play("Toilet");
                    AudioManager.instance.Stop("Glitch");
                    Debug.Log("Win!");
                    victoryCanvas.SetActive(true);
                    playing = false;
                    break;
                }

                if (playing)
                {
                    if (nextGrid.GetComponent <SingleGrid>().flowingTo == 0)
                    {
                        nextGrid = GetCorrectGrid(nextGrid.GetComponent <SingleGrid>().x - 1, nextGrid.GetComponent <SingleGrid>().y);
                    }
                    else if (nextGrid.GetComponent <SingleGrid>().flowingTo == 1)
                    {
                        nextGrid = GetCorrectGrid(nextGrid.GetComponent <SingleGrid>().x, nextGrid.GetComponent <SingleGrid>().y - 1);
                    }
                    else if (nextGrid.GetComponent <SingleGrid>().flowingTo == 2)
                    {
                        nextGrid = GetCorrectGrid(nextGrid.GetComponent <SingleGrid>().x + 1, nextGrid.GetComponent <SingleGrid>().y);
                    }
                    else if (nextGrid.GetComponent <SingleGrid>().flowingTo == 3)
                    {
                        nextGrid = GetCorrectGrid(nextGrid.GetComponent <SingleGrid>().x, nextGrid.GetComponent <SingleGrid>().y + 1);
                    }

                    if (nextGrid.x < 0 || nextGrid.x > width - 1 || nextGrid.y < 0 || nextGrid.y > height - 1)
                    {
                        Debug.Log("Game over!");
                        LevelManager.LevelMaster.AddToGrade(-0.5f);
                        loseCanvas.SetActive(true);
                        playing = false;
                        break;
                    }

                    Material newPipeMat2 = Instantiate(waterPipeMat);
                    nextGrid.gameObject.GetComponent <Image>().material = newPipeMat2;
                    nextGrid.gameObject.GetComponent <Image>().material.SetTexture("_GradientTex", pipeGradients[(int)nextGrid.currentPipe]);
                    nextGrid.gameObject.GetComponent <Image>().material.SetFloat("_WaterValue", 1);
                }

                if ((nextGrid.sides[3] > 0 && startTile.GetComponent <SingleGrid>().sides[1] > 0))
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (i != 3)
                        {
                            if (nextGrid.sides[i] > 0)
                            {
                                nextGrid.flowingTo = i;
                                if (nextGrid.flowingTo == 2 && nextGrid.currentPipe == Pipe.Straight && nextGrid.GetComponent <RectTransform>().eulerAngles.z > 170.0f && nextGrid.GetComponent <RectTransform>().eulerAngles.z < 190.0f)
                                {
                                    nextGrid.gameObject.GetComponent <Image>().material.SetInt("_Direction", 1);
                                }
                                if (nextGrid.flowingTo == 2 && nextGrid.currentPipe == Pipe.Curve)
                                {
                                    nextGrid.gameObject.GetComponent <Image>().material.SetInt("_Direction", 1);
                                }
                            }
                        }
                    }
                }
                else if (nextGrid.sides[0] > 0 && startTile.GetComponent <SingleGrid>().sides[2] > 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (i != 0)
                        {
                            if (nextGrid.sides[i] > 0)
                            {
                                nextGrid.flowingTo = i;
                                if (nextGrid.flowingTo == 3 && nextGrid.currentPipe == Pipe.Curve)
                                {
                                    nextGrid.gameObject.GetComponent <Image>().material.SetInt("_Direction", 1);
                                }
                            }
                        }
                    }
                }
                else if (nextGrid.sides[1] > 0 && startTile.GetComponent <SingleGrid>().sides[3] > 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (i != 1)
                        {
                            if (nextGrid.sides[i] > 0)
                            {
                                nextGrid.flowingTo = i;
                                if (nextGrid.flowingTo == 0 && nextGrid.currentPipe == Pipe.Curve)
                                {
                                    nextGrid.gameObject.GetComponent <Image>().material.SetInt("_Direction", 1);
                                }
                            }
                        }
                    }
                }
                else if (nextGrid.sides[2] > 0 && startTile.GetComponent <SingleGrid>().sides[0] > 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (i != 2)
                        {
                            if (nextGrid.sides[i] > 0)
                            {
                                nextGrid.flowingTo = i;
                                if (nextGrid.flowingTo == 1 && nextGrid.currentPipe == Pipe.Straight && nextGrid.GetComponent <RectTransform>().eulerAngles.z > -80.0f && nextGrid.GetComponent <RectTransform>().eulerAngles.z < -100.0f)
                                {
                                    nextGrid.gameObject.GetComponent <Image>().material.SetInt("_Direction", 1);
                                }
                                if (nextGrid.flowingTo == 1 && nextGrid.currentPipe == Pipe.Curve)
                                {
                                    nextGrid.gameObject.GetComponent <Image>().material.SetInt("_Direction", 1);
                                }
                            }
                        }
                    }
                }
                else
                {
                    playing = false;
                    LevelManager.LevelMaster.AddToGrade(-0.5f);
                    loseCanvas.SetActive(true);
                }
            }
        }
    }
Example #22
0
    IEnumerator callTraceBack(SingleGrid grid)
    {
        yield return(null);

        TraceBack(grid);
    }