// EmptyCell和ItemCell相关操作
    public void UpdateBackPackCell(ItemInformation itemInfo, int count)
    {
        if (count == 0)//删除道具格子
        {
        }
        else if (count == 1)//添加道具格子
        {
            if (emptyCellList.Count <= itemCellList.Count)
            {
                for (int i = 0; i < cellCountPerRow; i++)
                {
                    emptyCellList.Add(Instantiate(emptyCellPrefab, gridLayoutGroup.transform));
                }
                UpdateGridLayoutGroupRectSize();
            }

            EmptyCell emptyCell = emptyCellList.Find(targetCell => targetCell.isEmpty);
            ItemCell  itemCell  = Instantiate(itemCellPrefab);
            itemCell.Initialization(this, emptyCell, itemInfo);
            BindingBackPackCell(emptyCell, itemCell);
            itemCellList.Add(itemCell);
        }
        else if (count > 1)//更新道具数量显示
        {
            ItemCell itemCell = itemCellList.Find(targetCell => targetCell.itemInfo.ID == itemInfo.ID);
            itemCell.UpdateItemCount(count);
        }
    }
Пример #2
0
 public void SetEmpty()
 {
     for (var i = 0; i < grid.Length; i++)
     {
         grid[i] = new EmptyCell();
     }
 }
Пример #3
0
        public void BeNotEqualToOtherCell()
        {
            var first  = new EmptyCell(position);
            var second = new EmptyCell(position + CellPosition.DeltaDown);

            first.Equals(second).Should().BeFalse();
        }
Пример #4
0
        public ICell[,] GenerateBoard(int size, IList <ShipType> ships)
        {
            // generate an empty board ...
            var board = new ICell[size, size];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    board[i, j] = new EmptyCell();
                }
            }

            // ...and place ships on it
            foreach (var ship in ships)
            {
                bool placedShip;
                do
                {
                    var direction       = (Direction)(randomizer.Next() % 2);
                    var a               = randomizer.Next(0, size - ship.ShipSize());
                    var b               = randomizer.Next(0, size);
                    var initialPosition = direction == Direction.Horizontal ? new Point(a, b) : new Point(b, a);
                    placedShip = PlaceShip(board, ship, direction, initialPosition);
                } while (!placedShip);
            }

            return(board);
        }
Пример #5
0
        public EmptyCell GetValueEmptyCell( )
        {
            int       v   = GetValueInt((int)EmptyCell.BlindsJpn);
            EmptyCell Ret = EmptyCell.BlindsJpn;

            switch (v)
            {
            case (int)EmptyCell.BlindsJpn:
                Ret = EmptyCell.BlindsJpn;
                break;

            case (int)EmptyCell.BlindsEng:
                Ret = EmptyCell.BlindsEng;
                break;

            case (int)EmptyCell.LastFrame:
                Ret = EmptyCell.LastFrame;
                break;

            case (int)EmptyCell.Opacity:
                Ret = EmptyCell.Opacity;
                break;
            }

            return(Ret);
        }
Пример #6
0
        protected override void PostSetup()
        {
            if (!this._goal)
            {
                this._goal = FindObjectOfType <EmptyCell>();
            }

            if (!this._actor)
            {
                this._actor = FindObjectOfType <Actor>();
            }

            if (this._goal)
            {
                NeodroidUtilities.RegisterCollisionTriggerCallbacksOnChildren(
                    this,
                    this._goal.transform,
                    null,
                    this.OnTriggerEnterChild,
                    debug: this.Debugging);
            }

            if (this._actor)
            {
                NeodroidUtilities.RegisterCollisionTriggerCallbacksOnChildren(
                    this,
                    this._actor.transform,
                    null,
                    this.OnTriggerEnterChild,
                    debug: this.Debugging);
            }
        }
Пример #7
0
        swf.Control CreateEmptyCell(int x, int y)
        {
            var c = new EmptyCell();

            c.Margin = GetMargin(x, y);
            return(c);
        }
Пример #8
0
        /// <summary>
        /// Inits cells on the map
        /// </summary>
        /// <param name="size">The map size</param>
        private void InitCells(int size)
        {
            if (!CheckSize(size))
            {
                throw new ArgumentOutOfRangeException();
            }

            Cells = new Cell[size, size];

            var cards = new Stack <Card>(GenerateAvailableCards(size));

            for (var row = 0; row < Cells.GetLength(0); row++)
            {
                for (var column = 0; column < Cells.GetLength(1); column++)
                {
                    if (column % 2 == 0)
                    {
                        Cells[row, column] = cards.Pop();
                    }
                    else
                    {
                        if (row % 2 == 0)
                        {
                            Cells[row, column] = new Block();
                        }
                        else
                        {
                            Cells[row, column] = new EmptyCell();
                        }
                    }
                }
            }
        }
Пример #9
0
        public void Should_Change_Index()
        {
            var cell = new EmptyCell(1);

            cell.SetIndex(3);
            Assert.True(cell.Index == 3);
        }
Пример #10
0
        public void TestMinerEmpty()
        {
            Piece att = new Miner(Ownership.FirstPlayer);
            ICell def = new EmptyCell();

            Assert.True(att == ConflictHandler.Handle(att, def));
        }
Пример #11
0
        public void TestFailOnAttackerFlag_ThrowsPieceConflictHandlerException()
        {
            Piece att = new Flag(Ownership.SecondPlayer);
            ICell def = new EmptyCell();

            TestDelegate code = () => ConflictHandler.Handle(att, def);

            Assert.Throws(typeof(PieceConflictHandlerException), code);
        }
 public void Initialization(BackPack backpack, EmptyCell emptyCell, ItemInformation itemInfo)
 {
     this.itemInfo   = itemInfo;
     this.backpack   = backpack;
     this.emptyCell  = emptyCell;
     image.sprite    = itemInfo.Sprite;
     gameObject.name = itemInfo.Name;
     UpdateItemCount(1);
 }
Пример #13
0
        public void BeEqualToSameCell()
        {
            var first  = new EmptyCell(position);
            var second = new EmptyCell(position);
            var third  = new EmptyCell(position + CellPosition.DeltaDown);

            first.Equals(second).Should().BeTrue();
            first.Equals(third).Should().BeFalse();
        }
Пример #14
0
        public void TestEmptyCell()
        {
            var emptyCell = new EmptyCell(new Point {
                X = 1, Y = 1
            });

            Assert.AreEqual(emptyCell.Name, "EmptyCell");
            Assert.IsFalse(emptyCell.Destructible);
            Assert.IsTrue(emptyCell.Permeability);
        }
    public void OnEndDrag(PointerEventData eventData)
    {
        enableDraw          = false;
        enableCheckDistance = false;
        image.raycastTarget = true;

        EmptyCell newEmptycCell = UIUnit.GetFirstPickUI <EmptyCell>(eventData.position);

        backpack.SwapBackPackCell(this, newEmptycCell);
    }
Пример #16
0
        public void HaveDifferentHashWithDifferentCell()
        {
            var first  = new EmptyCell(position);
            var second = new EmptyCell(position + CellPosition.DeltaDown);

            var firstHash  = first.GetHashCode();
            var secondHash = second.GetHashCode();

            firstHash.Should().NotBe(secondHash);
        }
Пример #17
0
        public void HaveSameHashWithSameCell()
        {
            var first  = new EmptyCell(position);
            var second = new EmptyCell(position);

            var firstHash  = first.GetHashCode();
            var secondHash = second.GetHashCode();

            firstHash.Should().Be(secondHash);
        }
Пример #18
0
 private static void DecideFutureOfEmptyCell(EmptyCell emptyCell, int neighbouringAmebaCount)
 {
     if (neighbouringAmebaCount == 3)
     {
         emptyCell.SpawnAmeba();
     }
     else
     {
         emptyCell.Maintain();
     }
 }
Пример #19
0
        internal static IGameboard GenerateFieldWithSizeTwo()
        {
            var gameboard = new Gameboard(2);

            gameboard[0, 0] = new Mine(MineRadius.MineRadiusOne);
            gameboard[0, 1] = new EmptyCell();
            gameboard[0, 1].Explode();
            gameboard[1, 0] = new EmptyCell();
            gameboard[1, 1] = new EmptyCell();
            return(gameboard);
        }
Пример #20
0
        private void GenerateEmptyField(IGameboard gameboard)
        {
            int size = gameboard.Size;

            for (int row = 0; row < size; row++)
            {
                for (int col = 0; col < size; col++)
                {
                    gameboard[row, col] = new EmptyCell();
                }
            }
        }
Пример #21
0
        private ICell[,] GenerateEmptyBoard(int size)
        {
            var board = new ICell[size, size];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    board[i, j] = new EmptyCell();
                }
            }
            return(board);
        }
Пример #22
0
        public void ConsumedGameElementIsLifeless()
        {
            //Given a game element
            EmptyCell emptyCell     = new EmptyCell();
            int       remainingLife = 0;

            //When it is consumed by main character of the game
            emptyCell.MarkAsConsumed();

            //Then is should no longer have life (it should not provide
            //additional value if is being visited second time)
            Assert.Equal(remainingLife, emptyCell.Life);
        }
Пример #23
0
        internal static IGameboard GenerateFieldWithSizeTenWithEmptyCells()
        {
            var gameboard = new Gameboard(10);

            for (int i = 0; i < gameboard.Size; i++)
            {
                for (int k = 0; k < gameboard.Size; k++)
                {
                    gameboard[i, k] = new EmptyCell();
                }
            }

            return(gameboard);
        }
Пример #24
0
        // Grid renderer.
        public void RenderGrid()
        {
            for (int y = 1; y <= GridArray.GetLength(0); y++)
            {
                for (int x = 1; x <= GridArray.GetLength(1); x++)
                {
                    EmptyCell emptyCell = new EmptyCell();
                    Console.Write(emptyCell.GetCellFormatter() + " ");
                }

                // Write y-axis labels.
                Console.Write(Convert.ToChar(y + 64) + Environment.NewLine);
            }
        }
Пример #25
0
    private void ResetCells()
    {
        lCells.Clear();
        lSnakeCells.Clear();

        int r = Screen.height / Cell.isize - 2;
        int c = Screen.width / Cell.isize - 2;

        for (int i = 0; i < r; i++)
        {
            lCells.Add(new List <Cell>());
            for (int j = 0; j < c; j++)
            {
                if (i == 0 || j == 0 || i == r - 1 || j == c - 1)
                {
                    WallCell wc = new WallCell();
                    wc.ix = j;
                    wc.iy = i;
                    lCells[i].Add(wc);
                }
                else
                {
                    EmptyCell wc = new EmptyCell();
                    wc.ix = j;
                    wc.iy = i;
                    lCells[i].Add(wc);
                }
            }
        }

        for (int i = 0; i < 5; i++)
        {
            int       ix = 5 + i;
            int       iy = 5;
            SnakeCell sc = new SnakeCell();
            sc.ix = ix;
            sc.iy = iy;
            lSnakeCells.Insert(0, sc);
            lCells[iy][ix] = sc;
        }

        RandomOneFood();

        bGameOver = false;

        iDirectX = 1;
        iDirectY = 0;
        moveSep  = 1;
    }
Пример #26
0
        public void Should_Draw_Itself_Correctly()
        {
            var testStr = "{99}";

            var cell = new EmptyCell(1);

            cell.SetIndex(99);

            Assert.True(cell.DrawYourselfInTable(testStr) == testStr.ToSpaces());

            cell.SetIndex(8);
            testStr = "{8}";

            Assert.True(cell.DrawYourselfInTable(testStr) == testStr.ToSpaces());
        }
Пример #27
0
 public override void OnClick(GameObject cell)
 {
     Count--;
     if (Count == 0)
     {
         EmptyCell e = null;
         switch (type)
         {
             case (MaterialType.Forrest): e = new EmptyCell(EmptyCell.EmptyCellType.Grass); break;
             case (MaterialType.Mountain): e = new EmptyCell(EmptyCell.EmptyCellType.Ground); break;
         }
         cell.GetComponent<CellContent>().SetEntity(e);
     }
     Debug.Log("Tap");
 }
Пример #28
0
    override public void OnClick(GameObject cell)
    {
        Count--;
        if (Count == 0)
        {
            EmptyCell e = null;
            switch (type)
            {
            case (MaterialType.Forrest): e = new EmptyCell(EmptyCell.EmptyCellType.Grass); break;

            case (MaterialType.Mountain): e = new EmptyCell(EmptyCell.EmptyCellType.Ground); break;
            }
            cell.GetComponent <CellContent>().SetEntity(e);
        }
        Debug.Log("Tap");
    }
 private void BindingBackPackCell(EmptyCell emptyCell, ItemCell itemCell)
 {
     if (itemCell != null)
     {
         emptyCell.isEmpty  = false;
         emptyCell.itemCell = itemCell;
         itemCell.emptyCell = emptyCell;
         itemCell.transform.SetParent(emptyCell.transform);
         itemCell.transform.localPosition = Vector3.zero;
     }
     else
     {
         emptyCell.isEmpty  = true;
         emptyCell.itemCell = null;
     }
 }
Пример #30
0
        public void DoMove_WhenAllShipsDown_ReturnsGameFinished()
        {
            for (int i = 0; i < currentBoard.GetLength(0); i++)
            {
                currentBoard[0, i] = new EmptyCell();
            }

            gameEngine.DoMove(new Point(0, 1), 0).Item1
            .ShouldBe(MoveResult.Hit);
            gameEngine.DoMove(new Point(1, 1), 0).Item1
            .ShouldBe(MoveResult.Hit);
            gameEngine.DoMove(new Point(2, 1), 0).Item1
            .ShouldBe(MoveResult.Hit);
            gameEngine.DoMove(new Point(3, 1), 0).Item1
            .ShouldBe(MoveResult.PlayerWon);
        }
Пример #31
0
        public void CellsTestIfEmptyCellIsCloned()
        {
            EmptyCell emptyCell = new EmptyCell();

            emptyCell.X        = 2;
            emptyCell.Y        = 3;
            emptyCell.Color    = Color.White;
            emptyCell.CellView = CellView.Bomb1;

            ICell clonedEmptyCell = emptyCell.Clone();

            Assert.AreEqual(emptyCell.X, clonedEmptyCell.X, "X coordinate has not cloned.");
            Assert.AreEqual(emptyCell.Y, clonedEmptyCell.Y, "Y coordinate has not cloned.");
            Assert.AreEqual(emptyCell.Color, clonedEmptyCell.Color, "Cell Color has not cloned.");
            Assert.AreEqual(emptyCell.CellView, clonedEmptyCell.CellView, "CellView Color has not cloned.");
        }
Пример #32
0
        public void CheckIfGenerateFieldMethodSetsACellToAnEmptyOneInsideField()
        {
            var testFieldSize = 9;
            var field = new Field(testFieldSize);

            field.GenerateField();
            var testCell = field.FieldPositions[2, 3];
            var testEmptyCell = new EmptyCell();

            Assert.AreEqual(testCell.ToString(), testEmptyCell.ToString());
        }