示例#1
0
        public void ResetCell(IntVect2 cellKey)
        {
            PlayableCell cell = GetCell(cellKey);

            cell.Reset();
            Messenger <PlayableCell> .Broadcast(PlayableCell.EVENT_CELL_UPDATED, cell);
        }
示例#2
0
        public void IncreaseCellBounty(IntVect2 cellKey, int amount)
        {
            PlayableCell cell = GetCell(cellKey);

            cell.Bounty += amount;
            Messenger <PlayableCell> .Broadcast(PlayableCell.EVENT_CELL_UPDATED, cell);
        }
示例#3
0
        public bool GetRandomCell(ref IntVect2 key)
        {
            List <Cell> availableCells = new List <Cell>();

            foreach (List <Cell> row in _Cells)
            {
                foreach (Cell cell in row)
                {
                    if (!cell.HasMission() && cell.IsFree())
                    {
                        availableCells.Add(cell);
                    }
                }
            }

            if (availableCells.Count < 1)
            {
                return(false);
            }
            else
            {
                key = availableCells.ElementAt(Random.Range(0, availableCells.Count)).Key;
                return(true);
            }
        }
示例#4
0
 public Mission(IntVect2 cellKey, string clientID, string targetID, float ttl)
 {
     CellKey  = cellKey;
     ClientID = clientID;
     TargetID = targetID;
     TTL      = ttl;
 }
示例#5
0
        public void CellProgressed(IntVect2 cellKey, float progress)
        {
            Cell cell = GetCell(cellKey);

            cell.Progress = progress;
            Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell);
        }
示例#6
0
        private void FreezeTarget(IntVect2 cellKey)
        {
            Cell cell = _GridModelController.GetCell(cellKey);

            if (cell.Target != null)
            {
                cell.Target.Freeze = true;
            }
        }
示例#7
0
        private void RegenerateSurroundingCells(Cell cell)
        {
            Debug.Log("RegenerateSurroundingCells");
            IntVect2 cellKey = cell.Key;

            AddCellByDeviation(cell.Key, new IntVect2(-1, 0));
            AddCellByDeviation(cell.Key, new IntVect2(1, 0));
            AddCellByDeviation(cell.Key, new IntVect2(0, -1));
            AddCellByDeviation(cell.Key, new IntVect2(0, 1));
        }
示例#8
0
 private bool CellInPath(IntVect2 key, List <IntVect2> path)
 {
     foreach (IntVect2 cellKey in path)
     {
         if (cellKey == key)
         {
             return(true);
         }
     }
     return(false);
 }
示例#9
0
 public Mission GetMissionFromCellKey(IntVect2 key)
 {
     foreach (Mission mission in _Missions)
     {
         if (ShanghaiUtils.KeysMatch(mission.CellKey, key))
         {
             return(mission);
         }
     }
     Debug.Log("ERROR, couldn't get mission from key " + key);
     return(null);
 }
示例#10
0
 private bool CheckPrevCellPositions(IntVect2 key, List <IntVect2> path)
 {
     if (CellInPath(key, path))
     {
         Messenger.Broadcast(EVENT_MISSION_FAILED);
         return(false);
     }
     else if (path.Count > 1 && GetCell(path[path.Count - 1]).HasMission())
     {
         return(false);
     }
     return(true);
 }
示例#11
0
        private void AddCellByDeviation(IntVect2 key, IntVect2 deviation)
        {
            IntVect2 newKey = new IntVect2(key.x + deviation.x, key.y + deviation.y);

            if (newKey.x >= 0 && newKey.x < ShanghaiConfig.Instance.GridSize &&
                newKey.y >= 0 && newKey.y < ShanghaiConfig.Instance.GridSize)
            {
                Cell adjacentCell = _GridModelController.GetCell(newKey);
                if (adjacentCell.State == Cell.CellState.DEAD)
                {
                    _GridModelController.ResetCell(adjacentCell);
                }
            }
        }
示例#12
0
        private void OnCellClicked(IntVect2 cellKey)
        {
            Cell cell = _Model.Grid.GetCell(cellKey);

            if (cell != null &&
                cell.Source != null &&
                cell.Source.PaintColour == ShanghaiUtils.PaintColour.NONE)
            {
                cell.Source.PaintColour = _Model.PaintColour;
                Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell);

                Messenger.Broadcast(EVENT_RESET_COLOUR_INTERVAL);
            }
        }
示例#13
0
        public bool ValidateCellInput(IntVect2 key, List <IntVect2> path)
        {
            PlayableCell cell = GetCell(key);

            if (CellIsConnected(key, path) &&
                GetCell(key).IsFree() &&
                CheckPrevCellPositions(key, path))
            {
                UpdateCellPipeType(cell, path);
                Messenger <PlayableCell> .Broadcast(PlayableCell.EVENT_CELL_UPDATED, cell);

                return(true);
            }
            return(false);
        }
示例#14
0
 private bool CellIsConnected(IntVect2 key, List <IntVect2> path)
 {
     if (path.Count < 1)
     {
         // nothing yet
     }
     else
     {
         IntVect2 prevKey = GetCell(path[path.Count - 1]).Key;
         if ((Mathf.Abs(key.x - prevKey.x) == 1 && (key.y == prevKey.y)) ||
             (Mathf.Abs(key.y - prevKey.y) == 1 && (key.x == prevKey.x)))
         {
             return(true);
         }
     }
     return(false);
 }
示例#15
0
        private void OnCellDragged(IntVect2 cellKey)
        {
            if (cellKey == _CurrentCell)
            {
                return;
            }
            _CurrentCell = cellKey;

            if (_Model.Grid.ValidateCellInput(cellKey, _Path))
            {
                _Path.Add(cellKey);
                if (ShanghaiUtils.IsEndPoint(_Model.Grid.GetCell(cellKey)))
                {
                    _Model.CanDraw = false;
                }
            }
        }
示例#16
0
        public bool GenerateSource()
        {
            IntVect2 cellKey = new IntVect2(0, 0);

            if (!_Model.Grid.GetRandomCell(ref cellKey))
            {
                return(false);
            }

            float TTL = _Config.SourceWaitTime;

            Source source = new Source(cellKey, TTL, _Model.PaintColour);

            Messenger <Source> .Broadcast(EVENT_SOURCE_CREATED, source);

            return(true);
        }
示例#17
0
        public bool GenerateTarget()
        {
            IntVect2 cellKey = new IntVect2(0, 0);

            if (!_Model.Grid.GetRandomCell(ref cellKey))
            {
                return(false);
            }

            ShanghaiUtils.PaintColour targetColour = ShanghaiUtils.GetRandomColour(_Model.AvailableColours);
            Debug.Log("targetColour: " + targetColour);
            float  TTL    = _Config.TargetWaitTime;
            Target target = new Target(cellKey, targetColour, TTL);

            Messenger <Target> .Broadcast(EVENT_TARGET_CREATED, target);

            return(true);
        }
示例#18
0
        public bool GenerateMission()
        {
            IntVect2 cellKey = new IntVect2(0, 0);

            if (!_Model.Grid.GetRandomCell(ref cellKey))
            {
                return(false);
            }
            string targetID = _Model.Targets.ElementAt(Random.Range(0, _Model.Targets.Count)).Value.Key;
            string clientID = _Model.Clients.ElementAt(Random.Range(0, _Model.Clients.Count)).Value.Key;
            float  TTL      = _Config.MissionWaitTimeMedium + (Random.Range(0, _Config.MissionWaitTimeDeviance * 2)) - _Config.MissionWaitTimeDeviance;

            Mission mission = new Mission(cellKey, clientID, targetID, TTL);

            Messenger <Mission> .Broadcast(EVENT_MISSION_CREATED, mission);

            return(true);
        }
示例#19
0
        public bool ValidateCellInput(IntVect2 key, List <IntVect2> path)
        {
            Cell cell = GetCell(key);

            /* First point, can only be a valid source */
            if (path.Count == 0 &&
                cell.Source != null &&
                cell.Source.PaintColour != ShanghaiUtils.PaintColour.NONE)
            {
                GameModel.Instance.PathColour = cell.Source.PaintColour;
                cell.Source.Locked            = true;
                return(true);
            }
            else if (CellIsConnected(key, path) &&
                     CanDrawOnCell(GetCell(key), GetCell(path[0])))
            {
                cell.HasPath = true;
                Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell);

                return(true);
            }
            return(false);
        }
示例#20
0
 public Source(IntVect2 cellKey, float ttl, ShanghaiUtils.PaintColour colour)
 {
     CellKey     = cellKey;
     TTL         = ttl;
     PaintColour = colour;
 }
示例#21
0
 public Cell GetCell(IntVect2 key)
 {
     return(_Cells[key.y][key.x]);
 }
示例#22
0
 public UnplayableCell(IntVect2 key) : base(key)
 {
 }
示例#23
0
 private void OnCellProgressed(IntVect2 cellKey, float progress)
 {
     _Grid.CellProgressed(cellKey, progress);
 }
示例#24
0
        public void ResetCell(IntVect2 cellKey)
        {
            Cell cell = GetCell(cellKey);

            ResetCell(cell);
        }
示例#25
0
 public ChanceCells(IntVect2 key) : base(key)
 {
 }
示例#26
0
 public static bool KeysMatch(IntVect2 k1, IntVect2 k2)
 {
     return(k1.x == k2.x && k1.y == k2.y);
 }
示例#27
0
 public GridCell(IntVect2 key)
 {
     Key = key;
 }
示例#28
0
文件: Cell.cs 项目: chrismcmath/Paint
 public Cell(IntVect2 key)
 {
     Key = key;
 }
示例#29
0
 public Target(IntVect2 cellKey, ShanghaiUtils.PaintColour colour, float ttl)
 {
     CellKey     = cellKey;
     PaintColour = colour;
     TTL         = ttl;
 }