Exemple #1
0
        private Cell CreateCells(string input)
        {
            string[] cellTypes = input.Split(',');

            Cell currentCell = _cellFactory.CreateCell(cellTypes[0].ToString());
            Cell head        = currentCell;

            foreach (string item in cellTypes.Skip(1))
            {
                Cell cell = _cellFactory.CreateCell(item);;
                currentCell.Next = cell;
                currentCell      = cell;
            }
            currentCell.Next = head;
            return(head);

            //Cell previousCell = null;
            //foreach (string item in cellTypes)
            //{
            //    currentCell = _cellFactory.CreateCell(item.ToString());
            //    if (previousCell != null)
            //    {
            //        previousCell.Next = currentCell;
            //    }
            //    else
            //    {
            //        head = currentCell;
            //    }
            //    previousCell = currentCell;
            //}
            //currentCell.Next = head;
            //return head;
        }
Exemple #2
0
        /// <summary>
        /// Places mines on the field
        /// </summary>
        public void PlaceMines()
        {
            if (cells == null)
            {
                throw new ArgumentNullException("Error: playfiled array cannot be null (not initialized)");
            }

            int totalCellsCount = this.PlayfieldSize * this.PlayfieldSize;

            //CellView cellView;
            int fifteenPercentCellsCount = (int)Math.Floor(totalCellsCount * 0.15);
            int thirtyPercentCellsCount  = (int)Math.Floor(totalCellsCount * 0.30);

            int minesCount = RandomGenerator.GetRandomNumber(fifteenPercentCellsCount, thirtyPercentCellsCount + 1);

            for (int i = 0; i < minesCount; i++)
            {
                int mineRowPosition = RandomGenerator.GetRandomNumber(0, PlayfieldSize);
                int mineColPosition = RandomGenerator.GetRandomNumber(0, PlayfieldSize);

                ICell bombCell = CellFactory.CreateCell(CellType.Bomb);
                bombCell.X = mineRowPosition;
                bombCell.Y = mineColPosition;
                this.cells[mineRowPosition, mineColPosition] = bombCell;
                //Console.WriteLine(this.playfield[mineRowPosition, mineColPosition].CellView);
            }
        }
Exemple #3
0
    public void RemoveRoom(RoomCell roomCell)
    {
        var cellsToReplace = new List <Cell>();

        for (int i = 0; i < roomCell.roomInfo.size; i++)
        {
            cellsToReplace.Add(CellFactory.CreateCell(roomCell.id + i, roomCell.transform.position - Vector3.right * roomCell.size * 0.5f * Cell.defaultCellWidth + Vector3.right * i * Cell.defaultCellWidth + Vector3.right * Cell.defaultCellWidth * 0.5f, 1, CellState.Corridor));
            //Setting neighbours
            if (i > 0)
            {
                cellsToReplace[i - 1].rightNeighbour = cellsToReplace[i];
                cellsToReplace[i].leftNeighbour      = cellsToReplace[i - 1];
            }
        }
        cellsToReplace[0].leftNeighbour = roomCell.leftNeighbour;
        cellsToReplace[roomCell.roomInfo.size - 1].rightNeighbour = roomCell.rightNeighbour;
        cells.Remove(roomCell);
        cells.InsertRange(roomCell.id, cellsToReplace);
        foreach (var o in cellsToReplace)
        {
            o.UpdateView();
        }
        UpdateCellIds();
        Destroy(roomCell.gameObject);
    }
        public void CreateCell()
        {
            ICellFactory            factory   = new CellFactory();
            IMinePositionsGenerator generator = Substitute.For <IMinePositionsGenerator>();
            IMinefield field = new Minefield(factory, generator);

            ICell cell = factory.CreateCell(field, 0, 0);

            Assert.AreEqual(new Cell(field, 0, 0), cell);
        }
Exemple #5
0
    public static Cell CreateAndSetCell(int _x, int _y, int value, bool doAnimate)
    {
        GameField[_y, _x]   = CellFactory.CreateCell(value, doAnimate);
        GameField[_y, _x].x = _x;
        GameField[_y, _x].y = _y;

        RegisterCell(GameField[_y, _x]);

        return(GameField[_y, _x]);
    }
Exemple #6
0
    //First create items
    //ALWAYS USE CLONE ASSIGNING ITEM TO CHARACTER
    //Create character by setting his startItems and startSkills
    //Then create cells with the characters
    public List <BattleCell> AddChars()
    {
        //creating items
        Item shovel = new Item("Shovel", 1);
        Item gloves = new Item("Gloves", 1);
        Item knife  = new Item("Knife", 1);

        //creating characters
        Character first = characterFactory.CreateCharacter(
            startItems:  new List <Item> {
            shovel.Clone().SetAmount(10)
        },
            startSkills: new Skills(med: 0, str: 22));

        Character second = characterFactory.CreateCharacter(
            startItems:  new List <Item> {
            shovel.Clone(), knife.SetAmount(2)
        },
            startSkills: new Skills(med: 5, str: 5));

        Character third = characterFactory.CreateCharacter(
            startItems:  new List <Item> {
            gloves, knife.Clone().SetAmount(1)
        },
            startSkills: new Skills(med: 10, str: 2));

        //assigning characters to cells
        return(new List <BattleCell>()
        {
            cellFactory.CreateCell(s.holded, first),
            cellFactory.CreateCell(s.holded, second),
            cellFactory.CreateCell(s.holded, third),
        });
    }
Exemple #7
0
        private void GetResult(Board.Cell coords, Player player)
        {
            var         panel          = GameBoard.Panels.At(coords.Row, coords.Column);
            CellFactory objCellFactory = new CellFactory();
            var         result         = objCellFactory.CreateCell(panel.CellType);

            if (result != null)
            {
                Bank objBank = new Bank();
                player.AddMoneyEarned(result.Amount);
                objBank.AddMoneyEarned(result.Amount);
            }
        }
Exemple #8
0
        /// <summary>
        /// Changes the cell to BlownCell.
        /// </summary>
        /// <param name="posX">X position of the cell.</param>
        /// <param name="posY">Y position of the cell.</param>
        private void MakeCellBlown(int posX, int posY)
        {
            ICell cell = CellFactory.CreateCell(CellType.BlownCell);

            cell.X = posX;
            cell.Y = posY;
            this.PlayField[posX, posY] = cell;

            ////Raise event to update the cell view.
            CellEventArgs e = new CellEventArgs(cell);

            this.OnCellRedefined(e);
        }
Exemple #9
0
        /// <summary>
        /// Initializes new empty field
        /// </summary>
        public void InitializeEmptyField()
        {
            if (cells == null)
            {
                throw new ArgumentNullException("Error: playfiled array cannot be null (not initialized)");
            }

            for (int i = 0; i < this.cells.GetLength(0); i++)
            {
                for (int j = 0; j < this.cells.GetLength(1); j++)
                {
                    ICell cell = CellFactory.CreateCell(CellType.EmptyCell);
                    cell.X           = i;
                    cell.Y           = j;
                    this.cells[i, j] = cell;
                }
            }
        }
Exemple #10
0
    private Cell[] Compressor(Cell[] row, Direction direction)
    {
        int changes;

        if (direction == Direction.Down || direction == Direction.Right)
        {
            Array.Reverse(row);
        }

        do
        {
            changes = 0;
            for (int i = 1; i < row.Length; i++)
            {
                if (row[i] != null && row[i - 1] == null)
                {
                    switch (direction)
                    {
                    case Direction.Up:
                        row[i].offsetY--;
                        break;

                    case Direction.Down:
                        row[i].offsetY++;
                        break;

                    case Direction.Left:
                        row[i].offsetX--;
                        break;

                    case Direction.Right:
                        row[i].offsetX++;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("direction", direction, null);
                    }

                    row[i - 1] = row[i];
                    row[i]     = null;


                    changes++;
                    continue;
                }

                if (row[i] != null && row[i - 1] != null &&
                    !(row[i].isMultiply || row[i - 1].isMultiply) &&
                    row[i - 1].value == row[i].value)
                {
                    row[i - 1].isReadyToDestroy = true;
                    row[i].isReadyToDestroy     = true;
                    Debug.Log("READY TO DESTROY: " + row[i].ToString());
                    Debug.Log("READY TO DESTROY: " + row[i - 1].ToString());
                    var newCell = CellFactory.CreateCell(row[i].value *= 2, false);
                    GameModel.RegisterCell(newCell);

                    newCell.isMultiply = true;

                    switch (direction)
                    {
                    case Direction.Up:
                        row[i].offsetY--;
                        break;

                    case Direction.Down:
                        row[i].offsetY++;
                        break;

                    case Direction.Left:
                        row[i].offsetX--;
                        break;

                    case Direction.Right:
                        row[i].offsetX++;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("direction", direction, null);
                    }

                    row[i - 1]           = newCell;
                    row[i]               = null;
                    GameModel.GameScore += row[i - 1].value;
                    changes++;
                }
            }
        } while (changes != 0);

        if (direction == Direction.Down || direction == Direction.Right)
        {
            Array.Reverse(row);
        }


        return(row);
    }
Exemple #11
0
    void InitBasement()
    {
        int cellDepth = 0;
        int cellCount = 0;

        cells = new List <Cell>();

        var lastPos = new Vector3(0f - (int)settings.entranceSize * 0.5f * Cell.defaultCellWidth, 0f - cellDepth * (Cell.defaultCellHeight + floorOffset) + (Cell.defaultCellHeight + floorOffset) * 0.5f, 0f);

        entranceCell = CellFactory.CreateCell(cellCount, lastPos, 1, CellState.Corridor);
        gaperQueue.transform.position = entranceCell.transform.position - new Vector3(Cell.defaultCellWidth, Cell.defaultCellHeight * 0.5f);
        Cell currentCell = entranceCell;

        cells.Add(currentCell);
        cellCount++;
        //initializing entrance level
        for (int i = 1; i < settings.entranceSize; i++)
        {
            lastPos += Vector3.right * Cell.defaultCellWidth;
            Cell c = CellFactory.CreateCell(cellCount, lastPos, 1, CellState.Corridor);
            currentCell.neighbours[1] = c;
            c.neighbours[3]           = currentCell;
            currentCell = c;
            cells.Add(currentCell);
            cellCount++;
        }
        backdoorCell = currentCell;
        consumerQueue.transform.position = backdoorCell.transform.position + new Vector3(Cell.defaultCellWidth, -Cell.defaultCellHeight * 0.5f);
        //Creating basement
        for (int d = 1; d < settings.depth; d++)
        {
            cellDepth++;
            lastPos = new Vector3(0f - (int)(settings.horizontalSize * 0.5f) * Cell.defaultCellWidth, 0f - cellDepth * (Cell.defaultCellHeight + floorOffset) + (Cell.defaultCellHeight + floorOffset) * 0.5f, 0f);
            Cell c = CellFactory.CreateCell(cellCount, lastPos);
            currentCell = c;
            cells.Add(c);
            if (d > 1)
            {
                cells[cellCount - settings.horizontalSize].neighbours[2] = currentCell;
                currentCell.neighbours[0] = cells[cellCount - settings.horizontalSize];
            }
            cellCount++;
            for (int i = 1; i < settings.horizontalSize; i++)
            {
                lastPos += Vector3.right * Cell.defaultCellWidth;
                c        = CellFactory.CreateCell(cellCount, lastPos);
                currentCell.neighbours[1] = c;
                c.neighbours[3]           = currentCell;
                currentCell = c;
                cells.Add(currentCell);
                //neighboursAbove
                if (d > 1)
                {
                    cells[cellCount - settings.horizontalSize].neighbours[2] = currentCell;
                    currentCell.neighbours[0] = cells[cellCount - settings.horizontalSize];
                }
                else if (d == 1 && cellCount == settings.entranceSize + (int)(settings.horizontalSize * 0.5f) + 1)
                {
                    backdoorCell.neighbours[2] = currentCell;
                    currentCell.neighbours[0]  = backdoorCell;
                }
                cellCount++;
            }
        }

        //creating views;
        for (int i = 0; i < cells.Count; i++)
        {
            CellFactory.UpgradeCell(cells[i]);
        }
    }
Exemple #12
0
    public void PlaceRoom(Cell cell, RoomInfo room)
    {
        List <Cell> cellsToReplace = new List <Cell>();

        for (int horizontalOffset = 0; horizontalOffset < room.size; horizontalOffset++)
        {
            cellsToReplace.Clear();
            for (int i = 0; i < room.size; i++)
            {
                int id = cell.id + i - horizontalOffset;
                if (id < cells.Count)
                {
                    if (cells[id].cellState == CellState.Corridor && (!cells[id].bottomNeighbour || cells[id].bottomNeighbour.cellState != CellState.Ladder))
                    {
                        cellsToReplace.Add(cells[id]);
                    }
                }
                else
                {
                    Debug.Log("Trying for id:" + id);
                }
            }

            if (cellsToReplace.Count == room.size)
            {
                Cell left, right;
                Cell newCell = CellFactory.CreateCell(cellsToReplace[0].id, (cellsToReplace[room.size - 1].transform.position + cellsToReplace[0].transform.position) * 0.5f, room.size, CellState.Room);
                left  = cellsToReplace[0].leftNeighbour;
                right = cellsToReplace[room.size - 1].rightNeighbour;
                newCell.leftNeighbour  = left;
                newCell.rightNeighbour = right;

                if (left)
                {
                    left.rightNeighbour = newCell;
                    left.UpdateView();
                }
                if (right)
                {
                    right.leftNeighbour = newCell;
                    right.UpdateView();
                }

                for (int i = 0; i < cellsToReplace.Count; i++)
                {
                    if (cellsToReplace[i].topNeighbour)
                    {
                        if (cellsToReplace[i].topNeighbour.bottomNeighbour)
                        {
                            cellsToReplace[i].topNeighbour.bottomNeighbour = null;
                            cellsToReplace[i].topNeighbour.UpdateView();
                        }
                    }
                    if (cellsToReplace[i].bottomNeighbour)
                    {
                        if (cellsToReplace[i].bottomNeighbour.topNeighbour)
                        {
                            cellsToReplace[i].bottomNeighbour.topNeighbour = null;
                            cellsToReplace[i].bottomNeighbour.UpdateView();
                        }
                    }
                    Destroy(cellsToReplace[i].gameObject);
                }

                cells.RemoveRange(newCell.id, newCell.size);
                cells.Insert(newCell.id, newCell);
                (newCell as RoomCell).roomInfo = room;
                newCell.UpdateView();

                UpdateCellIds();
                Shop.instance.Deselect();
                break;
            }
        }
    }