Example #1
0
 public void MidclickPos(IndexOfList2D pos)
 {
     if (Singleton.GamePart.flipBoard[pos] == 1)
     {
         FlipAround(pos);
     }
 }
Example #2
0
    public void FlipAround(IndexOfList2D pos)
    {
        int flagCount = 0;

        flagMap.ChangeAround(pos.x, pos.y,
                             (int aroundX, int aroundY, int get) => {
            if (get == 1)
            {
                flagCount++;
            }
            return(get);
        }
                             );
        if (Singleton.MainData.mineDatas[pos] == flagCount)
        {
            flagMap.ChangeAround(pos.x, pos.y,
                                 (int aroundX, int aroundY, int get) => {
                if (get != 1)
                {
                    Singleton.GamePart.AreaClick(aroundX, aroundY);
                }
                return(get);
            }
                                 );
        }
    }
Example #3
0
 void CreateNewGb(IndexOfList2D pos)
 {
     areaGbs[pos] = GameObject.Instantiate(originPrefab, transform);
     areaGbs[pos].transform.localPosition = AreaPosLocal(pos);
     areaGbs[pos].GetComponentInChildren <AreaView>().x = pos.x;
     areaGbs[pos].GetComponentInChildren <AreaView>().y = pos.y;
 }
Example #4
0
 public Area(IndexOfList2D _pos, ConnectedAreas _father)
 {
     Debug.Assert(_father != null);
     pos        = _pos;
     neighbours = new List <Area>(8);
     father     = _father;
 }
Example #5
0
 public void RclickPos(IndexOfList2D pos)
 {
     if (Singleton.GamePart.flipBoard[pos] != 1)
     {
         flagMap[pos] = 1 - flagMap[pos];
         RefreshView();
     }
 }
Example #6
0
 public T this[IndexOfList2D index] {
     get{
         return(this[index.x, index.y]);
     }
     set{
         this[index.x, index.y] = value;
     }
 }
Example #7
0
    public Area CreateOutside(IndexOfList2D pos, ConnectedAreas father)
    {
        Area area = new Area(pos, father);

        map[pos] = area;
        father.outsides.Add(area);
        return(area);
    }
Example #8
0
    public Area CreateNumber(IndexOfList2D pos, ConnectedAreas father)
    {
        Area area = new Area(pos, father);

        map[pos] = area;
        father.numbers.Add(area);
        return(area);
    }
Example #9
0
 public ChangeMap(IndexOfList2D _clickPos, Dictionary<ConnectedAreas, SearchForCa> _sfcas, PrecacTableBase _tableBase) {
     //Debug.Assert(_sfcas.Count != 0);
     clickPos = _clickPos;
     sfcas = _sfcas;
     mineData = Singleton.MainData.mineDatas;
     flipBoard = Singleton.GamePart.flipBoard;
     tableBase = _tableBase;
 }
Example #10
0
 public void ProcessAfterClick(IndexOfList2D clickPos)
 {
     if (isHappy)
     {
         if (clickAction != null)
         {
             clickAction.Invoke(clickPos);
         }
     }
 }
Example #11
0
 public static void DrawABeaultifulButton(IndexOfList2D pos, Color color, System.Action pushButton)
 {
     Handles.color = color;
     if (Handles.Button(Singleton.MainData.AreaPosWorld(pos), Quaternion.identity, 0.5f, 0.5f, Handles.CylinderHandleCap))
     {
         if (pushButton != null)
         {
             pushButton();
         }
     }
 }
Example #12
0
    public void CreateFlagGb(IndexOfList2D pos)
    {
        GameObject flagFather = GameObject.Find("Flags");

        if (flagFather == null)
        {
            flagFather = new GameObject("Flags");
        }
        var flagPrefab = Resources.Load <GameObject>("flag");

        flagGbs[pos] = Instantiate(flagPrefab);
        flagGbs[pos].transform.parent = flagFather.transform;
    }
Example #13
0
 public void Flip(List <FlipNode> flipNodes)
 {
     foreach (var node in flipNodes)
     {
         var area = tableBase.map.GetArea(node.pos);
         if (area != null)
         {
             area.father.RemoveOutsides(area);
         }
         ConnectedAreas ca = tableBase.cas.CreateCa();
         area = tableBase.map.CreateNumber(node.pos, ca);
         gamePart.flipBoard.ChangeAround(node.x, node.y,
                                         (int aroundX, int aroundY, int get) => {
             IndexOfList2D pos = new IndexOfList2D(aroundX, aroundY);
             Area neighbour    = tableBase.map.GetArea(pos);
             if (get == 0)
             {
                 if (neighbour == null)
                 {
                     neighbour = tableBase.map.CreateOutside(pos, ca);
                 }
                 else
                 {
                     tableBase.cas.MergeCas(neighbour.father, ca);
                     ca = neighbour.father;
                 }
                 neighbour.neighbours.Add(area);
                 area.neighbours.Add(neighbour);
             }
             return(get);
         }
                                         );
         if (area.neighbours.Count == 0)
         {
             tableBase.map.RemovePos(area.pos);
             tableBase.cas.Remove(ca);
         }
     }
     problemsAndResults = new Dictionary <ConnectedAreas, SearchForCa>();
     foreach (var ca in tableBase.cas.list)
     {
         problemsAndResults[ca] = new SearchForCa(ca);
         problemsAndResults[ca].Process();
     }
     visualizedData();
     if (afterPrecacAction != null)
     {
         afterPrecacAction();
     }
 }
Example #14
0
 public void ReverseRandomInsideTarget(int count, IndexOfList2D exceptPos = null) {
     int setValue = -1 - insideTargetValue;
     List<IndexOfList2D> randomList = new List<IndexOfList2D>(insideTargets);
     if(exceptPos != null) {
         foreach(IndexOfList2D pos in randomList) {
             if(pos.x == exceptPos.x && pos.y == exceptPos.y) {
                 randomList.Remove(pos);
                 break;
             }
         }
     }
    for(int i = 0; i < count; i++) {
         IndexOfList2D randomPos = randomList[(int)(Random.value * randomList.Count)];
         randomList.Remove(randomPos);
         result.Add(new SetMap(randomPos, setValue));
     }
 }
Example #15
0
 public void AfterClick(IndexOfList2D clickPos)
 {
     if (precalculate.problemsAndResults != null && precalculate.tableBase != null)
     {
         foreach (var search in precalculate.problemsAndResults.Values)
         {
             if (!search.isDead)
             {
                 return;
             }
         }
         changeMap = new ChangeMap(clickPos, precalculate.problemsAndResults, precalculate.tableBase);
         changeMap.Calculate();
         List <SetMap> setMaps = changeMap.result;
         visualizedData(setMaps);
         changeMap.ChangeMineData();
     }
 }
Example #16
0
    public void RandomGenerate(int randomGenerateCount)
    {
        int tempCount = randomGenerateCount;

        ResetMineData();
        List <IndexOfList2D> positions = new List <IndexOfList2D>();

        foreach (var pos in mineDatas.Positions())
        {
            positions.Add(pos);
        }
        while (tempCount != 0)
        {
            int           index = (int)(Random.value * positions.Count);
            IndexOfList2D pos   = positions[index];
            positions.Remove(pos);
            ReverseMineData(pos.x, pos.y);
            tempCount--;
        }
    }
Example #17
0
 public void RefreshView()
 {
     for (int i = 0; i < flagMap.XSize; i++)
     {
         for (int j = 0; j < flagGbs.YSize; j++)
         {
             var pos = new IndexOfList2D(i, j);
             if (flagMap[pos] == 0 && flagGbs[pos] != null)
             {
                 Destroy(flagGbs[pos]);
                 flagGbs[pos] = null;
             }
             else
             if (flagMap[pos] == 1 && flagGbs[pos] == null)
             {
                 CreateFlagGb(pos);
             }
             if (flagGbs[pos] != null)
             {
                 flagGbs[pos].transform.position = Singleton.MainData.AreaPosWorld(pos);
             }
         }
     }
 }
Example #18
0
 public SetMap(IndexOfList2D _pos, int _value) {
     pos  = _pos;
     value = _value;
 }
Example #19
0
 public Area GetArea(IndexOfList2D pos)
 {
     return(map[pos]);
 }
Example #20
0
 public HCArea(int _value, IndexOfList2D _pos, List <HCArea> _neighbours)
 {
     pos        = _pos;
     neighbours = _neighbours;
     value      = _value;
 }
Example #21
0
 public bool Inside(IndexOfList2D index)
 {
     return(Inside(index.x, index.y));
 }
Example #22
0
 public void RemovePos(IndexOfList2D pos)
 {
     map[pos] = null;
 }
Example #23
0
 public IndexOfList2D(IndexOfList2D other)
 {
     x = other.x;
     y = other.y;
 }
Example #24
0
 public Vector3 AreaPosLocal(IndexOfList2D pos)
 {
     return(AreaPosLocal(pos.x, pos.y));
 }
Example #25
0
 public Vector3 AreaPosWorld(IndexOfList2D pos)
 {
     return(AreaPosWorld(pos.x, pos.y));
 }
Example #26
0
    public void changeMineDataForHappy(IndexOfList2D clickPos)
    {
        List2DInt map = new List2DInt(Singleton.MainData.XSize, Singleton.MainData.YSize, 0);

        outsideUfas = new List <IndexOfList2D>();
        insideUfas  = new List <IndexOfList2D>();
        foreach (var ufa in happyCheck.unFlipAreaList)
        {
            outsideUfas.Add(ufa.pos);
        }
        foreach (var pos in happyCheck.unFlipAreaInsideList)
        {
            if (pos.x != clickPos.x || pos.y != clickPos.y)
            {
                insideUfas.Add(pos);
            }
        }
        List <int> trueResult       = null;
        var        results          = happyCheckStep.checkResults;
        int        needPutMineCount = 0;

        if (map[clickPos] != -1)
        {
            if (results.Count > 0)
            {
                for (int i = 0; i < results.Count; i++)
                {
                    needPutMineCount = Singleton.MainData.mineCount - results[i].Count;
                    if (needPutMineCount <= insideUfas.Count)
                    {
                        trueResult = results[i];
                        break;
                    }
                }
            }
            else
            {
                trueResult       = new List <int>();
                needPutMineCount = Singleton.MainData.mineCount;
            }
        }
        else
        {
            for (int i = 0; i < results.Count; i++)
            {
                var  result = results[i];
                bool flag   = true;
                foreach (int index in result)
                {
                    var ufa = happyCheckStep.GetUfa(index);
                    if (ufa.pos.x == clickPos.x && ufa.pos.y == clickPos.y)
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    trueResult = result;
                }
            }
        }
        if (trueResult == null)
        {
            return;
        }
        foreach (int index in trueResult)
        {
            var ufa = happyCheckStep.GetUfa(index);
            map[ufa.pos] = -1;
        }
        for (int i = 0; i < needPutMineCount; i++)
        {
            IndexOfList2D pos = insideUfas[(int)(Random.Range(0, insideUfas.Count))];
            insideUfas.Remove(pos);
            map[pos] = -1;
        }
        watchList.list = map;
        var mainData = Singleton.MainData;

        foreach (var ufa in happyCheck.unFlipAreaList)
        {
            mainData.SetMineData(ufa.pos.x, ufa.pos.y, map[ufa.pos]);
        }
        foreach (var pos in happyCheck.unFlipAreaInsideList)
        {
            mainData.SetMineData(pos.x, pos.y, map[pos]);
        }
    }
Example #27
0
 public Area(Area other)
 {
     pos        = new IndexOfList2D(other.pos);
     neighbours = new List <Area>(other.neighbours);
 }
Example #28
0
 public static void DrawABeaultifulLabel(IndexOfList2D pos, string text)
 {
     Handles.Label(Singleton.MainData.AreaPosWorld(pos), text);
 }