public void ClearCell(int column) { if (CellsMap.ContainsKey(column)) { CellsMap.Remove(column); } }
private bool ReplacementPossible(Entity cell1, Entity cell2, out List <MatchResult> result) { CellsMap map = new CellsMap(EntityManager); var cell1Position = EntityManager.GetComponentData <CellPosition>(cell1); var cell1Content = EntityManager.GetComponentData <CellContent>(cell1); var cell2Position = EntityManager.GetComponentData <CellPosition>(cell2); var cell2Content = EntityManager.GetComponentData <CellContent>(cell2); map.Set(cell1Position, cell2, cell2Content); map.Set(cell2Position, cell1, cell1Content); result = new List <MatchResult>(); foreach (var matcher in _matchers) { var matchResult = matcher.Check(map, cell1Position); if (matchResult.Length >= 3) { result.Add(matchResult); } matchResult = matcher.Check(map, cell2Position); if (matchResult.Length >= 3) { result.Add(matchResult); } } return(result.Count > 0); }
private void GenerateTopLine() { bool active = false; Entity refillEntity = Entity.Null; Entities.ForEach((Entity entity, ref GenerateLineRequest request) => { if (request.Status == RequestStatus.New) { refillEntity = entity; active = true; request.Status = RequestStatus.Processing; } }); if (!active) { return; } var process = new ProcessGroup <TimerComponent, GenerateCellData>(EntityManager, Entities); GameFieldSize fieldSize = _helper.GetSize(); Color[] colors = _helper.GetColors(); CellsMap map = new CellsMap(EntityManager); float delay = 0; int y = _helper.Gravity == GravityDirection.Down ? fieldSize.Height - 1 : 0; for (int i = 0; i < fieldSize.Width; i++) { if (!map.GetCell(i, y, out var cell)) { delay += GenerateTimeout; process.Add(new TimerComponent(delay), new GenerateCellData { x = i, y = y, Color = colors.GetRandom() }); } } process.OnItemCompleted += (Entity entity, ref TimerComponent completable, ref GenerateCellData marker) => { AddCellAt(marker.x, marker.y, marker.Color); }; process.OnCompleted += group => { EntityManager.SetComponentData(refillEntity, new GenerateLineRequest { Status = RequestStatus.Completed }); DestroyEntityAfterFrame(refillEntity, 2); }; HoldProcess(process); }
public void Cleanup() { List <int> list = new List <int>(CellsMap.Keys); list.Sort(); foreach (int item in list) { XMLCellModel xMLCellModel = (XMLCellModel)CellsMap[item]; xMLCellModel.Cleanup(); _row.C.Add(xMLCellModel.Data); } CellsMap.Clear(); }
public ICellModel getCell(int col) { if (col < 0 || col > 16383) { throw new FatalException(); } if (CellsMap.TryGetValue(col, out ICellModel value)) { return(value); } CT_Cell cT_Cell = new CT_Cell(); cT_Cell.R_Attr = CellPair.Name(RowNumber, col); value = new XMLCellModel(_worksheetModel, _manager, cT_Cell); CellsMap.Add(col, value); return(value); }
private Dictionary <Entity, int> CalculateCellsOffsets(GameFieldSize gameSettings) { GravityDirection gravityDirection = _helper.Gravity; CellsMap map = new CellsMap(EntityManager); Dictionary <Entity, int> offsettedCells = new Dictionary <Entity, int>(); var i = new IntIterator(new IteratorSettings(0, gameSettings.Width - 1, 1)); while (i.MoveNext()) { var j = new IntIterator(new IteratorSettings(0, gameSettings.Height - 1, -(int)gravityDirection)); while (j.MoveNext()) { if (map.GetCell(i, j, out var cell)) { continue; } var k = new IntIterator(new IteratorSettings( j - (int)gravityDirection, IteratorSettings.GetTo(0, gameSettings.Height - 1, -(int)gravityDirection), -(int)gravityDirection)); while (k.MoveNext()) { if (!map.GetCell(i, k, out var affectedCell)) { continue; } if (!offsettedCells.TryGetValue(affectedCell, out var o)) { offsettedCells[affectedCell] = 0; } offsettedCells[affectedCell] += (int)gravityDirection; } } } return(offsettedCells); }
private void GenerateAll() { Entities.ForEach((Entity entity, ref GenerateAllCellsRequest request) => { if (request.Status != RequestStatus.New) { return; } GameFieldSize size = _helper.GetSize(); Color[] colors = _helper.GetColors(); CellsMap map = new CellsMap(EntityManager); for (int i = 0; i < size.Width; i++) { for (int j = 0; j < size.Height; j++) { AddCellAt(i, j, colors.GetRandom()); } } request.Status = RequestStatus.Completed; }); }