示例#1
0
文件: Matrix.cs 项目: nkazban/SOLE
 public double this[int row, int column]
 {
     get
     {
         if (row < 0 && row >= Size)
         {
             throw new ArgumentOutOfRangeException();
         }
         if (column < 0 && column >= Size)
         {
             throw new ArgumentOutOfRangeException();
         }
         return(data[row, column]);
     }
     set
     {
         if (row < 0 && row >= Size)
         {
             throw new ArgumentOutOfRangeException();
         }
         if (column < 0 && column >= Size)
         {
             throw new ArgumentOutOfRangeException();
         }
         data[row, column] = value;
         CellChanged?.Invoke(row, column, value);
     }
 }
示例#2
0
        int RemoveResource(string resourceType, CPos cell, int amount = 1)
        {
            if (!Content.Contains(cell))
            {
                return(0);
            }

            var content = Content[cell];

            if (content.Type == null || content.Type != resourceType)
            {
                return(0);
            }

            var oldDensity = content.Density;
            var density    = Math.Max(0, oldDensity - amount);

            if (density == 0)
            {
                Content[cell]           = ResourceLayerContents.Empty;
                Map.CustomTerrain[cell] = byte.MaxValue;
                --resCells;

                CellChanged?.Invoke(cell, null);
            }
            else
            {
                Content[cell] = new ResourceLayerContents(content.Type, density);
                CellChanged?.Invoke(cell, content.Type);
            }

            return(oldDensity - density);
        }
示例#3
0
        public ResourceType Harvest(CPos cell)
        {
            var c = Content[cell];

            if (c.Type == null)
            {
                return(null);
            }

            if (--c.Density < 0)
            {
                Content[cell] = ResourceLayerContents.Empty;
                world.Map.CustomTerrain[cell] = byte.MaxValue;
                --resCells;

                foreach (var rl in resourceLogicLayers)
                {
                    rl.UpdatePosition(cell, c.Type, 0);
                }
            }
            else
            {
                Content[cell] = c;

                foreach (var rl in resourceLogicLayers)
                {
                    rl.UpdatePosition(cell, c.Type, c.Density);
                }
            }

            CellChanged?.Invoke(cell, c.Type);

            return(c.Type);
        }
示例#4
0
        void OnMouseMove(int x, int y)
        {
            var id = Mouse.HitEntityId;

            Previous = Current;
            Current  = EntitySystem.EntityFramework.GetEntity(id) as ConstructionPoint;

            if (Previous != Current)
            {
                CellChanged?.Invoke(Current);
            }

            if (Current == null)
            {
                NoCell?.Invoke();
            }
            else if (!Current.Controller.Occupied && CanSelect())
            {
                EnterUnoccupiedCell?.Invoke(Current);
            }
            else
            {
                EnterOccupiedCell?.Invoke(Current);
            }
        }
 protected virtual void OnCellChanged(int i_RowNumber, int i_ColNumber)
 {
     if (CellChanged != null)
     {
         CellChanged.Invoke(i_RowNumber, i_ColNumber);
     }
 }
示例#6
0
        public void UpdateCell(CPos cell)
        {
            var uv = cell.ToMPos(Map);

            if (!Map.Resources.Contains(uv))
            {
                return;
            }

            var tile = Map.Resources[uv];
            var t    = Tiles[uv];

            var newTile    = ResourceLayerContents.Empty;
            var newTerrain = byte.MaxValue;

            if (Resources.TryGetValue(tile.Type, out var type))
            {
                newTile = new ResourceLayerContents
                {
                    Type    = type,
                    Density = CalculateCellDensity(type, cell)
                };

                newTerrain = Map.Rules.TerrainInfo.GetTerrainIndex(type.Info.TerrainType);
            }

            // Nothing has changed
            if (newTile.Type == t.Type && newTile.Density == t.Density)
            {
                return;
            }

            UpdateNetWorth(t.Type, t.Density, newTile.Type, newTile.Density);
            Tiles[uv]             = newTile;
            Map.CustomTerrain[uv] = newTerrain;
            CellChanged?.Invoke(cell, type);

            // Neighbouring cell density depends on this cell
            foreach (var d in CVec.Directions)
            {
                var neighbouringCell = cell + d;
                if (!Tiles.Contains(neighbouringCell))
                {
                    continue;
                }

                var neighbouringTile = Tiles[neighbouringCell];
                var density          = CalculateCellDensity(neighbouringTile.Type, neighbouringCell);
                if (neighbouringTile.Density == density)
                {
                    continue;
                }

                UpdateNetWorth(neighbouringTile.Type, neighbouringTile.Density, neighbouringTile.Type, density);
                neighbouringTile.Density = density;
                Tiles[neighbouringCell]  = neighbouringTile;

                CellChanged?.Invoke(neighbouringCell, type);
            }
        }
示例#7
0
        int AddResource(string resourceType, CPos cell, int amount = 1)
        {
            if (!Content.Contains(cell))
            {
                return(0);
            }

            if (resourceType == null || !info.ResourceTypes.TryGetValue(resourceType, out var resourceInfo))
            {
                return(0);
            }

            var content = Content[cell];

            if (content.Type == null)
            {
                content = CreateResourceCell(resourceType, cell, 0);
            }

            if (content.Type != resourceType)
            {
                return(0);
            }

            var oldDensity = content.Density;
            var density    = Math.Min(resourceInfo.MaxDensity, oldDensity + amount);

            Content[cell] = new ResourceLayerContents(content.Type, density);

            CellChanged?.Invoke(cell, content.Type);

            return(density - oldDensity);
        }
示例#8
0
 protected virtual void OnCellChanged(CellChangedEventArgs e)
 {
     // check if someone is listening
     if (CellChanged != null)
     {
         // raise the event:
         CellChanged.Invoke(this, e);
     }
 }
示例#9
0
文件: Area.cs 项目: waverma/TheRooms
 public void ChangeCell(Vector cellVector, Cell newCell)
 {
     if (!InBounds(cellVector))
     {
         return;
     }
     Map[cellVector.X, cellVector.Y] = newCell;
     CellChanged?.Invoke(cellVector);
 }
示例#10
0
        private void SendCellInfo(int column, int row, Element element, ChangeType changeType)
        {
            var eventArgs = new CellChangedArgs();

            eventArgs.column     = column;
            eventArgs.row        = row;
            eventArgs.changeType = changeType;
            eventArgs.element    = element;
            CellChanged?.Invoke(eventArgs);
        }
        private void DrawManually(MouseEventArgs e)
        {
            var coords = _coordinatesTranslator.FindCell(e.X, e.Y);

            coords.X--;
            coords.Y--;
            if (_painter.TryChangeCell(coords.X, coords.Y, PaintMode))
            {
                CellChanged?.Invoke(coords.X, coords.Y, PaintMode);
            }
        }
示例#12
0
文件: Grid.cs 项目: vzabavnov/Sudoku
        private void OnCellValueChanged(Cell cell)
        {
            Contract.Requires(cell != null);
            Contract.Requires(!cell.IsEmpty);

            if (Disabled)
            {
                return;
            }

            CellChanged?.Invoke(cell);
        }
示例#13
0
        public void AddResource(ResourceType t, CPos p, int n)
        {
            var cell = Content[p];
            if (cell.Type == null)
                cell = CreateResourceCell(t, p);

            if (cell.Type != t)
                return;

            cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n);
            Content[p] = cell;

            CellChanged?.Invoke(p, cell.Type);
        }
示例#14
0
        public void Destroy(CPos cell)
        {
            // Don't break other users of CustomTerrain if there are no resources
            var c = Content[cell];
            if (c.Type == null)
                return;

            --resCells;

            // Clear cell
            Content[cell] = ResourceLayerContents.Empty;
            world.Map.CustomTerrain[cell] = byte.MaxValue;

            CellChanged?.Invoke(cell, c.Type);
        }
示例#15
0
        void SudokuBoard_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (selected == null)
            {
                return;
            }

            if (e != null && ((e.KeyChar == 48 && board[selected] != 0) || (e.KeyChar > 48 && e.KeyChar <= 57)))
            {
                board[selected].ChangeOriginal(e.KeyChar - 48);
                Logger.Log("Changed cell", new Cell[] { board[selected] }, board[selected].ToString());
                CellChanged?.Invoke(board[selected]);
            }
            selected = null;
            ReDraw(false);
        }
示例#16
0
        void SudokuBoard_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (selectedCell == null)
            {
                return;
            }

            if (e != null && ((e.KeyChar == 48 && selectedCell.Value != 0) || (e.KeyChar > 48 && e.KeyChar <= 57)))
            {
                selectedCell.ChangeOriginalValue(e.KeyChar - 48);
                puzzle.LogAction("Changed cell", new Cell[] { selectedCell }, selectedCell.ToString());
                CellChanged?.Invoke(selectedCell);
            }
            selectedCell = null;
            ReDraw(false);
        }
示例#17
0
        private void SudokuBoard_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (_selectedCell == null)
            {
                return;
            }

            if (e != null && ((e.KeyChar == '0' && _selectedCell.Value != 0) || (e.KeyChar > '0' && e.KeyChar <= '9')))
            {
                _selectedCell.ChangeOriginalValue(e.KeyChar - '0');
                _puzzle.LogAction(Puzzle.TechniqueFormat("Changed cell", _selectedCell.ToString()), _selectedCell, (Cell)null);
                CellChanged?.Invoke(_selectedCell);
            }
            _selectedCell = null;
            ReDraw(false);
        }
示例#18
0
        public ResourceType Harvest(CPos cell)
        {
            var c = Content[cell];
            if (c.Type == null)
                return null;

            if (--c.Density < 0)
            {
                Content[cell] = ResourceLayerContents.Empty;
                world.Map.CustomTerrain[cell] = byte.MaxValue;
                --resCells;
            }
            else
                Content[cell] = c;

            CellChanged?.Invoke(cell, c.Type);

            return c.Type;
        }
示例#19
0
        void ClearResources(CPos cell)
        {
            if (!Content.Contains(cell))
            {
                return;
            }

            // Don't break other users of CustomTerrain if there are no resources
            var content = Content[cell];

            if (content.Type == null)
            {
                return;
            }

            Content[cell]           = ResourceLayerContents.Empty;
            Map.CustomTerrain[cell] = byte.MaxValue;
            --resCells;

            CellChanged?.Invoke(cell, null);
        }
示例#20
0
文件: Area.cs 项目: waverma/TheRooms
        public Area(Cell[,] map, Vector playerLocation)
        {
            PlayerLocation = playerLocation;
            Map            = map;

            foreach (var cell in map)
            {
                if (cell?.Creature != null)
                {
                    cell.Creature.StateChanged += (Vector vector) =>
                    {
                        if (cell.Creature.Health <= 0 && cell.Creature.IsMortal)
                        {
                            ChangeCell(vector, cell.RemoveCreature());
                        }
                        CellChanged?.Invoke(vector);
                    }
                }
            }
            ;
        }
示例#21
0
        public void Destroy(CPos cell)
        {
            // Don't break other users of CustomTerrain if there are no resources
            var c = Content[cell];

            if (c.Type == null)
            {
                return;
            }

            --resCells;

            foreach (var rl in resourceLogicLayers)
            {
                rl.UpdatePosition(cell, Content[cell].Type, 0);
            }

            // Clear cell
            Content[cell] = ResourceLayerContents.Empty;
            world.Map.CustomTerrain[cell] = byte.MaxValue;

            CellChanged?.Invoke(cell, c.Type);
        }
示例#22
0
        public void UpdateCell(CPos cell)
        {
            var uv = cell.ToMPos(Map);

            if (!Map.Resources.Contains(uv))
            {
                return;
            }

            var tile = Map.Resources[uv];
            var t    = Tiles[uv];

            var newTile    = ResourceLayerContents.Empty;
            var newTerrain = byte.MaxValue;

            if (Resources.TryGetValue(tile.Type, out ResourceType type))
            {
                newTile = new ResourceLayerContents
                {
                    Type    = type,
                    Density = tile.Index
                };

                newTerrain = Tileset.GetTerrainIndex(type.Info.TerrainType);
            }

            // Nothing has changed
            if (newTile.Type == t.Type && newTile.Density == t.Density)
            {
                return;
            }

            UpdateNetWorth(t.Type, t.Density, newTile.Type, newTile.Density);
            Tiles[uv]             = newTile;
            Map.CustomTerrain[uv] = newTerrain;
            CellChanged?.Invoke(cell, type);
        }
示例#23
0
        public void AddResource(ResourceType t, CPos p, int n)
        {
            var cell = Content[p];

            if (cell.Type == null)
            {
                cell = CreateResourceCell(t, p);
            }

            if (cell.Type != t)
            {
                return;
            }

            cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n);
            Content[p]   = cell;

            CellChanged?.Invoke(p, cell.Type);

            foreach (var rl in resourceLogicLayers)
            {
                rl.UpdatePosition(p, t, cell.Density);
            }
        }
示例#24
0
 public void OnCellChanged(string map, string cell, string pad)
 {
     CellChanged?.Invoke(Bot, map, cell, pad);
 }
示例#25
0
 public void Update()
 {
     CellChanged?.Invoke(this, EventArgs.Empty);
 }
示例#26
0
 /// <summary>
 /// Triggering the cell changed event
 /// </summary>
 /// <param name="x">The x-coordinate of the cell</param>
 /// <param name="y">The y-coordinate of the cell</param>
 /// <param name="cell">The new state of the cell</param>
 private void OnCellChanged(int x, int y, Cell cell)
 {
     CellChanged?.Invoke(this, new CellChangedEventArgs(x, y, cell));
 }
示例#27
0
 private void MakeCell(int x, int y, ICell cell)
 {
     _field[x, y] = cell;
     CellChanged?.Invoke(new CellChangedEventArgs <ICell>(x, y, cell));
 }
示例#28
0
 public void OnMessage(CellChanged message)
 {
     Refresh();
 }
示例#29
0
        //--------------internal method is responsible for raising the event--------------

        protected virtual void OnCellChanged(CellChangeEventArgs e)
        {
            CellChanged?.Invoke(e);
        }