private Dictionary <long, CellPosition> _LotLifePositions() { int setNum = 0; var idToCellPositionDict = new Dictionary <long, CellPosition>(); while (setNum < TREASURE_NUM) { var x = UnityEngine.Random.Range(0, CellManager.CELL_MAX_NUM); var y = UnityEngine.Random.Range(0, CellManager.CELL_MAX_NUM); var canSet = true; foreach (var cellPos in idToCellPositionDict.Values) { if (cellPos.X == x && cellPos.Y == y) { canSet = false; break; } } if (!canSet) { continue; } idToCellPositionDict.Add(LifeUniqueId.GetUniqueId(), new CellPosition(x, y)); setNum++; } return(idToCellPositionDict); }
public void RandomSetTreasure(GameTypes.PlayerType playerType) { var player = GetPlayer(playerType); int setNum = 0; var idToCellPositionDict = new Dictionary <long, CellPosition>(); while (setNum < TREASURE_NUM) { var r = new System.Random(); var x = r.Next(CellManager.CELL_MAX_NUM); r = new System.Random(); var y = r.Next(CellManager.CELL_MAX_NUM); var canSet = true; foreach (var cellPos in idToCellPositionDict.Values) { if (cellPos.X == x && cellPos.Y == y) { canSet = false; break; } } if (!canSet) { continue; } idToCellPositionDict.Add(LifeUniqueId.GetUniqueId(), new CellPosition(x, y)); setNum++; } player.SetTreasures(idToCellPositionDict); Locator.CellManager.SetTreasures(playerType, idToCellPositionDict); }
public static long GetUniqueId() { if (_instance == null) { _instance = new LifeUniqueId(); } _instance._IncrementId(); return(_instance._id); }