public void ShipDestroyTest()
        {
            //arrange
            var shipType    = ShipTypeEnum.Battleship;
            var ship        = new Ship(shipType);
            var tileFactory = new TileFactory();
            var tile1       = tileFactory.Create(new Coordinate(0, 1), OwnerTypeEnum.Player) as PlayerTile;
            var tile2       = tileFactory.Create(new Coordinate(0, 2), OwnerTypeEnum.Player) as PlayerTile;
            var tile3       = tileFactory.Create(new Coordinate(0, 3), OwnerTypeEnum.Player) as PlayerTile;
            var tile4       = tileFactory.Create(new Coordinate(0, 4), OwnerTypeEnum.Player) as PlayerTile;
            var tile5       = tileFactory.Create(new Coordinate(0, 5), OwnerTypeEnum.Player) as PlayerTile;

            //act
            tile1.AssignShip(ship);
            tile2.AssignShip(ship);
            tile3.AssignShip(ship);
            tile4.AssignShip(ship);
            tile5.AssignShip(ship);

            tile1.Shoot();
            tile2.Shoot();
            tile3.Shoot();
            tile4.Shoot();
            tile5.Shoot();
            //Assert
            Assert.True(ship.IsDestroyed);
        }
Exemple #2
0
    public override Tile[][] SpawnBoard(int[] rowLengths, TileFactory tileFactory)
    {
        var board = new Tile[rowLengths.Length][];

        for (var row = 0; row < rowLengths.Length; row++)
        {
            board[row] = new Tile[rowLengths[row]];

            var zPos = ((rowLengths.Length * _tileOffset) / 2) - (_tileOffset * row) - (_tileOffset / 2.0f);

            for (var column = 0; column < rowLengths[row]; column++)
            {
                var tile = tileFactory.Create(column, row);

                var xPos = (-(rowLengths[row] * _tileOffset) / 2) + (_tileOffset * column) + (_tileOffset / 2.0f);

                tile.transform.position = new Vector3(xPos, YPos, zPos);
                tile.transform.rotation = new Quaternion(-90.0f, 0.0f, 0.0f, tile.transform.rotation.w);

                board[row][column] = tile;
            }
        }

        ConnectBoard(board);

        return(board);
    }
Exemple #3
0
        private void SetBuildList()
        {
            var tileFactroy         = new TileFactory();
            var buildingNodeFactory = new BuildingNodeFactory();
            var buildings           = PhotonNetwork.CurrentRoom.GetBuild();

            foreach (int buildId in buildings)
            {
                var tileObj         = tileFactroy.Create(buildId.ToString());
                var buildingNodeObj = buildingNodeFactory.Create();
                var tile            = tileObj.GetComponent <Tile>();
                var buildingNode    = buildingNodeObj.GetComponent <BuildingNode>();
                var tmp             = buildingNode.OwnerNameObj.transform.GetChild(0).gameObject;
                Nodes.Add(buildingNode);
                buildingNode.Tile      = tile;
                buildingNode.OwnerName = "勝利点:" + tile.Points + "\nコスト\n";
                foreach (var cost in tile.BuildCost)
                {
                    var go = Instantiate(tmp);
                    go.GetComponent <Image>().sprite = Resources.Load("Textures/" + Enum.GetName(typeof(ResourceType), cost), typeof(Sprite)) as Sprite;
                    go.transform.SetParent(buildingNode.OwnerNameObj.transform);
                    go.SetActive(true);
                }
                buildingNode.ExecuteButton.onClick.AddListener(() => Builder.BuildSetup(tile));
                buildingNodeObj.transform.SetParent(Contents.transform);
                Destroy(tileObj);
            }
        }
Exemple #4
0
 public TileView GetObject()
 {
     if (PoolQueue.Count > 0)
     {
         return(PoolQueue.Dequeue());
     }
     return(_tileFactory.Create());
 }
        public void ClickTestEmptyField()
        {
            //arrange
            var tileFactory = new TileFactory();
            var gameTile    = tileFactory.Create(new Coordinate(0, 0), OwnerTypeEnum.Player) as PlayerTile;

            //act
            gameTile.Click();
            //assert
            Assert.True(gameTile.IsShoot);
        }
        public void ShotOnShip()
        {
            //arrange
            var tileFactory = new TileFactory();
            var gameTile1   = tileFactory.Create(new Coordinate(0, 0), OwnerTypeEnum.Player) as PlayerTile;
            var gameTile2   = tileFactory.Create(new Coordinate(0, 1), OwnerTypeEnum.Player) as PlayerTile;
            var ship        = new Ship(ShipTypeEnum.Battleship);

            //act
            gameTile1.AssignShip(ship);
            gameTile2.AssignShip(ship);
            gameTile1.Shoot();
            //assert
            Assert.IsTrue(gameTile1.IsShip);
            Assert.IsTrue(gameTile1.IsShoot);
            Assert.IsFalse(gameTile2.IsShoot);
            Assert.IsFalse(gameTile1.IsShipDestroyed);
            Assert.IsFalse(gameTile2.IsShipDestroyed);
            Assert.AreEqual(gameTile1.Ship, ship);
            Assert.True(gameTile1.IsShipHit);
        }
        public void DoubleClickTestWithShip()
        {
            //arrange
            var tileFactory = new TileFactory();
            var gameTile    = tileFactory.Create(new Coordinate(0, 0), OwnerTypeEnum.Player) as PlayerTile;
            var ship        = new Ship(ShipTypeEnum.Submarine);

            gameTile.AssignShip(ship);
            //act
            gameTile.Click();

            //assert
            Assert.IsTrue(gameTile.IsShoot);
        }
        public void CreationTest()
        {
            //arrange
            var tileFactory = new TileFactory();
            var gameTile    = tileFactory.Create(new Coordinate(0, 0), OwnerTypeEnum.Player) as PlayerTile;

            //act
            //assert
            Assert.IsFalse(gameTile.IsShip);
            Assert.IsFalse(gameTile.IsShoot);
            Assert.IsFalse(gameTile.IsShipDestroyed);
            Assert.Null(gameTile.Ship);
            Assert.False(gameTile.IsShipHit);
        }
        public static Tile GetWillBuild(this Player player)
        {
            if (player == null || player.CustomProperties[WillBuildPropKey] == null || !player.CustomProperties.ContainsKey(WillBuildPropKey))
            {
                return(null);
            }

            IFactory <GameObject> tileFactory = new TileFactory();
            int        id   = (int)player.CustomProperties[WillBuildPropKey];
            GameObject go   = tileFactory.Create(id.ToString());
            Tile       tile = go.GetComponent <Tile>();

            Object.Destroy(go);
            return(tile);
        }
    public void Draw(string levelName)
    {
        // TODO: Choose the level art!
        _currentSpriteSet = frankenstein;

        var level = TileFactory.Create(levelName);

        PlayerStart = level.PlayerSpawn;

        float cw = level.TileWidth / cellWidth;
        float ch = level.TileHeight / cellHeight;

        float starty = screenHeightInBlocks / 2;
        float startx = -screenWidthInBlocks / 2;

        //BlockDraw(level.Background, SortingLayer.NameToID("Background"), level.Height, level.Width, cw, ch, startx, starty, true);
        BlockDraw(level.Platforms, SortingLayer.NameToID("Platforms"), level.Height, level.Width, cw, ch, startx, starty);
    }
Exemple #11
0
        public static GameObject GetTileData(this RoomInfo room)
        {
            if (room == null || room.CustomProperties[TilePropKey] == null || !room.CustomProperties.ContainsKey(TilePropKey))
            {
                return(null);
            }

            IFactory <GameObject> TileFactory = new TileFactory();
            string        data  = (string)room.CustomProperties[TilePropKey];
            List <string> tileD = data.Split(',').ToList();
            GameObject    go    = TileFactory.Create(tileD[0]);
            Tile          tile  = go.GetComponent <Tile>();

            tile.Pos       = new Vector2(int.Parse(tileD[1]), int.Parse(tileD[2]));
            tile.IsBuilded = true;
            tile.Owner     = PhotonNetwork.CurrentRoom.GetTurnPlayer();
            return(go);
        }
Exemple #12
0
 public static ITile ParseTile(char ch)
 {
     return(TileFactory.Create(ch));
 }