Пример #1
0
    private void RotorLeftBoard(GameEntity rotorEntity, RotorDirection direction, Vector2 pos)
    {
        foreach (var e in _cellGroup.GetEntities())
        {
            if (direction == RotorDirection.Left || direction == RotorDirection.Right)
            {
                if (e.gridPosition.value.y != (int)pos.y)
                {
                    continue;
                }
            }

            if (direction == RotorDirection.Up || direction == RotorDirection.Down)
            {
                if (e.gridPosition.value.x != (int)pos.x)
                {
                    continue;
                }
            }

            CellHelper.UnBlockFallAt(e);
        }

        WaitHelper.Reduce(WaitType.Input, WaitType.Turn, WaitType.CriticalAnimation);

        rotorEntity.isOutsideTheBoard = true;
    }
Пример #2
0
 public void CommitPiece(IPiece piece)
 {
     //if (piece.PosX < 1 || piece.PosX > Width)
     //    return;
     //if (piece.PosY < 1 || piece.PosY > Height)
     //    return;
     for (int i = 1; i <= piece.TotalCells; i++)
     {
         // Get piece position in board
         int x, y;
         piece.GetCellAbsolutePosition(i, out x, out y);
         // Check out of board
         if (x < 1)
         {
             return;
         }
         if (x > Width)
         {
             return;
         }
         if (y < 1)
         {
             return;
         }
         if (y > Height)
         {
             return;
         }
         // Add piece in board
         this[x, y] = CellHelper.SetColor(piece.Value); // indexer will handle cell out of board
     }
 }
Пример #3
0
    protected override void Execute(List <GameEntity> entities)
    {
        foreach (var tntTnt in entities)
        {
            tntTnt.isSpawnAnimationStarted = false;
            tntTnt.isSpawnAnimationEnded   = false;

            var pos       = tntTnt.gridPosition.value;
            var radius    = tntTnt.tntTnt.Radius;
            var removerId = IdHelper.GetNewRemoverId();

            for (int x = pos.x - radius; x <= pos.x + radius; x++)
            {
                for (int y = pos.y - radius; y <= pos.y + radius; y++)
                {
                    CellHelper.UnBlockFallAt(new Vector2Int(x, y));

                    ActivatorHelper.TryActivateItemWithPositive(new Vector2Int(x, y), removerId,
                                                                ActivationReason.Tnt);
                }
            }

            tntTnt.isWillBeDestroyed = true;

            WaitHelper.Reduce(WaitType.Input, WaitType.Turn, WaitType.CriticalAnimation);
        }
    }
Пример #4
0
        private static List <LocationWithValue> GetRowFieldsForFill(Row rowTemplate, WorkbookPart workbookPart, string[] tableNames)
        {
            var fields = new List <LocationWithValue>();

            foreach (var cell in rowTemplate.Descendants <Cell>())
            {
                var cellValue = CellHelper.GetCellValue(cell, workbookPart);
                if (String.IsNullOrWhiteSpace(cellValue) || cellValue.Length <= 4)
                {
                    continue;
                }
                if (!cellValue.StartsWith("{{") || !cellValue.EndsWith("}}"))
                {
                    continue;
                }
                cellValue = cellValue.Substring(2, cellValue.Length - 4);

                foreach (var tableName in tableNames)
                {
                    if (cellValue.IndexOf($"{tableName}.", StringComparison.Ordinal) != -1)
                    {
                        var rowIndex    = CellReferenceHelper.GetRowIndex(cell.CellReference.Value);
                        var columnIndex = CellReferenceHelper.GetColumnIndex(cell.CellReference.Value);
                        fields.Add(new LocationWithValue(rowIndex, columnIndex, cellValue));
                    }
                }
            }
            return(fields);
        }
Пример #5
0
        // Associated with Specials
        public void SpawnSpecialBlocks(int count, Func <Specials> randomFunc)
        {
            // Build list of cells without any specials
            List <int> cellsOccupiedWithoutSpecials = Cells.Select((cell, index) => new
            {
                cell,
                index
            })
                                                      .Where(x => x.cell != CellHelper.EmptyCell && !CellHelper.IsSpecial(x.cell))
                                                      .Select(x => x.index)
                                                      .ToList();

            // Transform 'count' cells into special
            for (int i = 0; i < count; i++)
            {
                int n = cellsOccupiedWithoutSpecials.Count;
                if (n > 0) // if there is at least one non-special piece
                {
                    // get random piece without specials
                    int randomCell = Randomizer.Instance.Next(n);
                    int cellIndex  = cellsOccupiedWithoutSpecials[randomCell];
                    // get random special
                    Specials special = randomFunc();
                    // add special
                    Cells[cellIndex] = CellHelper.SetSpecial(special);

                    // remove piece from available list
                    cellsOccupiedWithoutSpecials.RemoveAt(randomCell);
                }
                else
                {
                    break; // no more cells without specials
                }
            }
        }
Пример #6
0
        public void contentsExpress(Cell cell)
        {
            CellHelper cellOne = cell as CellHelper; //create new cells
            Cell       cellTwo;
            string     formula = "";

            if (cellOne.Texter[0] == '=')              //if there's a formula
            {
                formula = cellOne.Texter.Substring(1); //get whatever's after the '=' sign
                cellTwo = getLetterLocation(formula);  //get the location that's after the '=' sign
                cellOne.setValue(cellTwo.Texter);      //then set the value of the cell that has the formula to the value of the cell it's asking
            }

            else if (string.IsNullOrEmpty(cellOne.Texter)) //if cell is empty set it to empty
            {
                cellOne.setValue("");
            }
            else
            {
                cellOne.setValue(cellOne.Texter); //set value
            }
            if (CellPropertyChanged != null)
            {
                CellPropertyChanged(cell, new PropertyChangedEventArgs("Value")); //fire if changed
            }
        }
    private void ActivateRotorRotor(GameEntity entity)
    {
        WaitHelper.Increase(WaitType.CriticalAnimation);
        CellHelper.BlockFallAt(entity.gridPosition.value);

        entity.isSpawnAnimationStarted = true;
    }
Пример #8
0
 public void DisplayBoard(IBoard board)
 {
     for (int y = board.Height; y >= 1; y--)
     {
         StringBuilder sb = new StringBuilder(String.Format("{0:00}|", y));
         for (int x = 1; x <= board.Width; x++)
         {
             byte cellValue = board[x, y];
             if (cellValue == CellHelper.EmptyCell)
             {
                 sb.Append(".");
             }
             else
             {
                 Pieces   cellPiece   = CellHelper.GetColor(cellValue);
                 Specials cellSpecial = CellHelper.GetSpecial(cellValue);
                 if (cellSpecial == Specials.Invalid)
                 {
                     sb.Append((int)cellPiece);
                 }
                 else
                 {
                     sb.Append(ConvertSpecial(cellSpecial));
                 }
             }
         }
         sb.Append("|");
         Console.SetCursorPosition(0 + 0, board.Height - y + 0);
         Console.Write(sb.ToString());
     }
     Console.SetCursorPosition(0 + 2, board.Height + 0);
     Console.Write("".PadLeft(board.Width + 2, '-'));
 }
    private IEnumerator ActivatePuzzleCombo(GameEntity puzzleCombo)
    {
        CellHelper.BlockFallAt(puzzleCombo.gridPosition.value);

        yield return(null);

        yield return(new WaitWhile(() => WaitHelper.Has(WaitType.FallingItem)));

        WaitHelper.Increase(WaitType.Hint, WaitType.Input, WaitType.Fall, WaitType.Turn, WaitType.CriticalAnimation);

        var cubes = GetColorCubes(puzzleCombo.color.Value);

        puzzleCombo.AddPuzzleTargetedCubes(cubes);

        yield return(new WaitWhile(() => puzzleCombo.hasPuzzleTargetedCubes));

        yield return(new WaitUntil(() => puzzleCombo.hasPosItemsToActivate));

        CellHelper.UnBlockFallAt(puzzleCombo.gridPosition.value);

        puzzleCombo.isWillBeDestroyed = true;

        yield return(ActivatePositiveItemsSequentially(puzzleCombo.posItemsToActivate.PosItemIds));

        WaitHelper.Reduce(WaitType.Hint, WaitType.Input, WaitType.Fall, WaitType.Turn, WaitType.CriticalAnimation);
    }
Пример #10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            newSplit = new SplitItem();

            CellHelper.CircleTheView(GrovealeImage, UIColor.White, 2);

            totalAmount     = TotalAmount;
            splitBetween    = SplitNumber;
            tipSwitch       = TipSwitch;
            tipPercentage   = TipPercentage;
            percentageLabel = PercentageLabel;
            splitButton     = CalculateSplit;
            splitTotal      = TotalSplitAmount;
            saveButton      = SaveSplit;

            totalAmount.KeyboardType   = UIKeyboardType.DecimalPad;
            splitBetween.KeyboardType  = UIKeyboardType.DecimalPad;
            tipPercentage.KeyboardType = UIKeyboardType.DecimalPad;

            tipSwitch.ValueChanged += TipSwitch_ValueChanged;

            splitButton.TouchUpInside += SplitButton_TouchUpInside;

            saveButton.TouchUpInside += SaveButton_TouchUpInside;
        }
Пример #11
0
 public void FillWithRandomCells(Func <Pieces> randomFunc)
 {
     for (int i = 0; i < Width * Height; i++)
     {
         Cells[i] = CellHelper.SetColor(randomFunc());
     }
 }
Пример #12
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var cellSideLength = GetCellSideLength();

            _cells = CellHelper.InitializeCells(cellSideLength,
                                                CommonVariables.Size);
            InitializeGameFiled();
        }
Пример #13
0
        private static void GenerateTemplate(WorkbookPart workbookPart, string sheetId, List <ColumnBlockToInsert> columnsBlockToInsert)
        {
            var worksheetPart  = (WorksheetPart)workbookPart.GetPartById(sheetId);
            var lastColumnName = "A";

            foreach (var columnBlockToInsert in columnsBlockToInsert)
            {
                var startColumnIndex = CellHelper.GetColumnIndex(columnBlockToInsert.FirstColumnName);
                for (int i = 0; i < columnBlockToInsert.ColumnsWidths.Length; i++)
                {
                    AddColumns(worksheetPart.Worksheet, startColumnIndex + i, columnBlockToInsert.ColumnsWidths[i]);
                }
                foreach (var blockToInsert in columnBlockToInsert.RowBlocksToInsert)
                {
                    var fromIndex = 0;
                    foreach (var cellToInsert in blockToInsert.CellsToInsert)
                    {
                        var column1Name    = CellHelper.ColumnIndexToColumnLetter(startColumnIndex + fromIndex);
                        var row1Index      = blockToInsert.RowId;
                        var cell1Reference = new CellReference($"{column1Name}{row1Index}");

                        var column2Name    = CellHelper.ColumnIndexToColumnLetter(startColumnIndex + fromIndex + cellToInsert.RowSize - 1);
                        var row2Index      = blockToInsert.RowId;
                        var cell2Reference = new CellReference($"{column2Name}{row2Index}");
                        lastColumnName = column2Name;

                        if (cellToInsert.RowSize > 1)
                        {
                            MergeCellHelper.MergeTwoCells(worksheetPart.Worksheet, cell1Reference.Reference, cell2Reference.Reference);
                        }
                        else
                        {
                            CellHelper.CreateSpreadsheetCellIfNotExist(worksheetPart.Worksheet, cell1Reference.Reference);
                        }

                        if (!string.IsNullOrEmpty(cellToInsert.FieldName))
                        {
                            var valueToInsert = new ValueToInsert
                            {
                                FieldName = null,
                                IsFormula = false,
                                Type      = typeof(string),
                                Value     = cellToInsert.FieldName,
                            };
                            SetCellValues(worksheetPart.Worksheet, column1Name, blockToInsert.RowId, valueToInsert);
                        }

                        CellHelper.CopyCellStyle(worksheetPart.Worksheet,
                                                 new CellReference(cellToInsert.StyleCellReference).ColumnName,
                                                 new CellReference(cellToInsert.StyleCellReference).RowIndex,
                                                 column1Name, row1Index);
                        fromIndex++;
                    }
                }
            }
            MergeCellHelper.MergeTwoCells(worksheetPart.Worksheet, "B3", $"{lastColumnName}3");
        }
Пример #14
0
 /// <summary>
 /// Removes all special cells from a players field
 /// </summary>
 public void ClearSpecialBlocks(Func <Pieces> randomFunc)
 {
     for (int i = 0; i < Width * Height; i++)
     {
         if (CellHelper.IsSpecial(Cells[i]))
         {
             Cells[i] = CellHelper.SetColor(randomFunc()); // set random piece
         }
     }
 }
Пример #15
0
        public void TestFillWithRandomCells()
        {
            const int width  = 11;
            const int height = 9;
            IBoard    board  = CreateBoard(width, height);

            board.FillWithRandomCells(() => Pieces.TetriminoO);

            Assert.IsTrue(board.Cells.All(x => CellHelper.GetColor(x) == Pieces.TetriminoO));
        }
Пример #16
0
 public override void OnUseSpecial(int playerId, string playerTeam, IReadOnlyBoard playerBoard, int targetId, string targetTeam, IReadOnlyBoard targetBoard, Specials special)
 {
     if (special == Specials.BlockBomb)
     {
         int targetBomb = targetBoard.ReadOnlyCells.Count(x => CellHelper.GetSpecial(x) == Specials.BlockBomb);
         if (targetBomb >= 3)
         {
             Achieve();
         }
     }
 }
Пример #17
0
        private void SizeSlider_ValueChanged(object sender,
                                             RoutedPropertyChangedEventArgs <double> e)
        {
            CommonVariables.Size = Convert.ToInt32(SizeSlider.Value);
            GameField.Children.Clear();
            var cellSideLength = GetCellSideLength();

            _cells = CellHelper.InitializeCells(cellSideLength,
                                                CommonVariables.Size);
            InitializeGameFiled();
        }
Пример #18
0
 public void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Text") //PropertyChanged events, lets them know when properties for each cell has changed
     {
         CellHelper tmpCell = sender as CellHelper;
     }
     else
     {
         CellPropertyChanged(sender, new PropertyChangedEventArgs("Value")); //fires if changed
     }
     contentsExpress(sender as Cell);
 }
Пример #19
0
 private static bool HasNukeGravitySwitchOnBottomLine(IBoard board)
 {
     for (int x = 1; x <= board.Width; x++)
     {
         Specials cellSpecial = CellHelper.GetSpecial(board[x, 0]);
         if (cellSpecial == Specials.BlockGravity || cellSpecial == Specials.NukeField || cellSpecial == Specials.SwitchFields)
         {
             return(true);
         }
     }
     return(false);
 }
    protected override void Execute(List <GameEntity> entities)
    {
        foreach (var entity in entities)
        {
            entity.isSpawnAnimationStarted = false;
            entity.isSpawnAnimationEnded   = false;

            entity.isWillBeDestroyed = true;
            CreateActivateRotors(entity);
            CellHelper.UnBlockFallAt(entity.gridPosition.value);
            WaitHelper.Reduce(WaitType.CriticalAnimation);
        }
    }
        private Row CreateLabel(GeneratingRow item, uint count)
        {
            var row = item.Row;

            row.RowIndex = new UInt32Value(item.Row.RowIndex + (count - 1));
            foreach (var cell in item.Cells)
            {
                cell.Cell.CellReference = CellHelper.GetCellReference(cell.Cell, row.RowIndex);
                cell.Cell.CellValue     = new CellValue(cell.Value);
                cell.Cell.DataType      = new EnumValue <CellValues>(CellValues.String);
                row.Append(cell.Cell);
            }
            return(row);
        }
Пример #22
0
    private bool _canPlace;             // True, when the building can place


    protected override void Created()
    {
        // Adjusting placing listener
        _manager.SelectionManager.PlacingOperation += Placing;
        // Filling the building with tempCells
        _buildingCells = CellHelper.SpawnCells(_buildingData.dimensions, _manager.GameConfig.Cell, CellContainer);

        foreach (var cell in _buildingCells)
        {
            cell.Renderer.sortingOrder = 3;
        }

        AdjustContainerPos();
    }
Пример #23
0
        public Spreadsheet(int Rows, int Columns)
        {
            Arrays = new CellHelper[Rows, Columns];
            //spreadsheet constructor that takes in a # of rows and columns

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Columns; j++)
                {
                    CellHelper Temps = new CellHelper(i, j);
                    Temps.PropertyChanged += OnPropertyChanged;
                    Arrays[i, j]           = Temps;
                }
            }
        }
Пример #24
0
        private static int GetOpponentWithMostSpecials(IEnumerable <IOpponent> opponents) // Search among opponents which one has most specials
        {
            int id           = -1;
            int mostSpecials = 0;

            foreach (IOpponent opponent in opponents)
            {
                int countSpecial = opponent.Board.Cells.Count(x => CellHelper.GetSpecial(x) != Specials.Invalid);
                if (countSpecial > mostSpecials)
                {
                    id           = opponent.PlayerId;
                    mostSpecials = countSpecial;
                }
            }
            return(id);
        }
        private Row CreateRow(Row rowTemplate, uint rowIndex, System.Data.DataTable table, int tableRowIndex, List <LocationWithValue> fields)
        {
            var newRow = (Row)rowTemplate.Clone();

            newRow.RowIndex = new UInt32Value(rowIndex);
            foreach (var cell in newRow.Elements <Cell>())
            {
                cell.CellReference = CellHelper.GetCellReference(cell, new UInt32Value(rowIndex));
                foreach (var field in fields.Where(fil => cell.CellReference == fil.ColumnIndex + rowIndex))
                {
                    cell.CellValue = new CellValue(table.Rows[tableRowIndex][field.ValueName].ToString());
                    cell.DataType  = new EnumValue <CellValues>(CellValues.String);
                }
            }
            return(newRow);
        }
Пример #26
0
        public static void CopyAndInsertRows(int fromRowIndex, int toRowIndex, int rowsCount, int wellIndex,
                                             WorkbookPart workbookPart, string sheetId, List <TableToInsert> dataTables)
        {
            var processedTablesRows = dataTables.ToDictionary(x => x.TableName, y => 0);
            var worksheetPart       = (WorksheetPart)workbookPart.GetPartById(sheetId);
            var mergeCells          = MergeCellHelper.GetMergeCells(workbookPart, sheetId).FirstOrDefault()
                                      .ChildElements.Select(x => x as MergeCell);

            Row oldRow            = null;
            Row generatedRow      = null;
            var mergeCellsForCopy = new List <MergeCell>();

            for (int i = 0; i < rowsCount; i++)
            {
                var oldRowIndex = fromRowIndex + i;
                oldRow       = RowHelper.GetRow(worksheetPart.Worksheet, (uint)oldRowIndex);
                generatedRow = CreateRow(worksheetPart.Worksheet, oldRow, (uint)(toRowIndex + i), dataTables, 0, new List <LocationWithValue>(), processedTablesRows);
                foreach (var cell in generatedRow.Descendants <Cell>())
                {
                    if (cell == null)
                    {
                        continue;
                    }
                    var cellValue = CellHelper.GetCellValue(cell, workbookPart);
                    if (String.IsNullOrWhiteSpace(cellValue) || cellValue.Length <= 4)
                    {
                        continue;
                    }
                    if (!cellValue.StartsWith("{{Well1"))
                    {
                        continue;
                    }
                    cellValue = cellValue.Replace("{{Well1", $"{{{{Well{wellIndex}");
                    SetCellValues(cell, new ValueToInsert(null, typeof(string), cellValue));
                }
                InsertRowHelper.InsertRow((uint)(toRowIndex + i), worksheetPart, generatedRow);

                var rowMergeCellsForCopy = mergeCells.Where(x => new MergeCellReference(x.Reference).CellFrom.RowIndex == oldRowIndex);
                mergeCellsForCopy.AddRange(rowMergeCellsForCopy);
            }
            foreach (var mergeCellForCopy in mergeCellsForCopy)
            {
                var newMergeCell = MergeCellReferenceMoveByRows(new MergeCellReference(mergeCellForCopy.Reference), toRowIndex - fromRowIndex);
                MergeCellHelper.MergeTwoCells(worksheetPart.Worksheet, newMergeCell.CellFrom.Reference, newMergeCell.CellTo.Reference);
            }
        }
Пример #27
0
        public void TestIndexerGetFailedIfWrongIndices2()
        {
            const int width  = 11;
            const int height = 9;
            IBoard    board  = CreateBoard(width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    board.Cells[x + y * width] = CellHelper.SetColor(Pieces.TetriminoL); // different from EmptyCell
                }
            }
            byte value = board[0, 0]; // coordinates are [1, width] and [1, height]

            Assert.AreEqual(value, CellHelper.EmptyCell);
        }
Пример #28
0
    private void ActivateTntTnt(GameEntity tntTnt)
    {
        WaitHelper.Increase(WaitType.Input, WaitType.Turn, WaitType.CriticalAnimation);

        var pos    = tntTnt.gridPosition.value;
        var radius = tntTnt.tntTnt.Radius;

        for (int x = pos.x - radius; x <= pos.x + radius; x++)
        {
            for (int y = pos.y - radius; y <= pos.y + radius; y++)
            {
                CellHelper.BlockFallAt(new Vector2Int(x, y));
            }
        }

        tntTnt.isSpawnAnimationStarted = true;
    }
    private void ActivateTnt(GameEntity tnt)
    {
        WaitHelper.Increase(WaitType.Input, WaitType.Turn, WaitType.CriticalAnimation);

        tnt.isTntExplosionStarted = true;
        tnt.isCanFall             = false;

        var       tntPos = tnt.gridPosition.value;
        const int radius = 1;

        for (var x = tntPos.x - radius; x <= tntPos.x + radius; x++)
        {
            for (var y = tntPos.y - radius; y <= tntPos.y + radius; y++)
            {
                CellHelper.BlockFallAt(new Vector2Int(x, y));
            }
        }
    }
Пример #30
0
        public static void NextIterationGridCalculate(List <List <Rectangle> > cells)
        {
            var copyCells = CellHelper.CopyCells(cells);

            for (var i = 0; i < CommonVariables.Size; ++i)
            {
                for (var j = 0; j < CommonVariables.Size; ++j)
                {
                    var numberOfNeighbors = CountNeighbors(copyCells, i, j);
                    var presentState      = (copyCells[i][j].Fill
                                             == CommonVariables.LifeColorBrush);
                    cells[i][j].Fill = IsAliveInNextIteration(numberOfNeighbors, presentState)
                                                ? CommonVariables.LifeColorBrush : CommonVariables.EmptinessColorBrush;
                }
            }

            CommonVariables.Iteration++;
        }