Exemplo n.º 1
0
    /// <summary>
    /// Построить здание
    /// </summary>
    /// <param name="coordinate">позиция строения</param>
    /// <param name="building">здание</param>
    /// <returns>true если успешно построили</returns>
    public bool ConstructBuilding(Vector2Int coordinate)
    {
        Vector2Int position = new Vector2Int(coordinate.x - levelManager.resourceData.tilemap.cellBounds.min.x, coordinate.y - levelManager.resourceData.tilemap.cellBounds.min.y);

        if (!IsCanBeBuild(coordinate))
        {
            return(false);
        }

        if (resourceManager.Oil < GetPrice())
        {
            return(false);
        }
        Position = coordinate;
        levelManager.availibleBuildingData.IsAvailibleBuilding[coordinate.x - levelManager.offset.x, coordinate.y - levelManager.offset.y] = false;
        levelManager.buildingData.SetTile(new Vector3Int(coordinate.x, coordinate.y, 0), this.GetTile());
        levelManager.resourceData.tilemap.SetTile(new Vector3Int(coordinate.x, coordinate.y, 0), null);

        float priceBuilding = GetPrice();

        resourceManager.Oil -= priceBuilding;
        buildingManager.AddBuilding(this);
        OnBuilding();
        // TurnController.TurnEndEvent += OnEndTurn;
        return(true);
    }
        public async Task <int> CreateBuilding(string Name, int numberofUnits)
        {
            BuildingManager buildingManager = new BuildingManager(tableGatwayFactory);
            var             buildingDto     = new BuildingDTO {
                Name = Name, NumberOfUnits = numberofUnits
            };
            await buildingManager.AddBuilding(buildingDto);

            return(buildingDto.Id);
        }
        public async Task Building_Added_Successfuly()
        {
            //A => Arange

            BuildingManager buildingManager = new BuildingManager(new MyFakes.TableGatewyFactory());
            BuildingDTO     building        = new BuildingDTO {
                Id = 0, Name = "My Building", NumberOfUnits = 10
            };
            //A => Act
            await buildingManager.AddBuilding(building);

            //A => Assert
            Assert.AreEqual(1, building.Id);
        }
Exemplo n.º 4
0
        void Start()
        {
            buildingManager = BuildingManager.Instance;
            buildingManager.AddBuilding(this);

            health              = GetComponent <Health>();
            health.onEmpty     += OnHealthEmpty;
            health.MaxValue     = 50;
            health.MinValue     = 0;
            health.CurrentValue = health.MaxValue;

            dropPickup = Random.Range(0.0f, 1.0f) > INV_DROP_FREQ;
            Worth      = Random.Range(100, 200);
        }
        public async Task Building_Name_Cannot_Be_Null_Or_Empty()
        {
            //A => Arange

            BuildingManager buildingManager = new BuildingManager(new MyFakes.TableGatewyFactory());
            BuildingDTO     building        = new BuildingDTO {
                Id = 0, Name = string.Empty, NumberOfUnits = 10
            };

            //A => Act
            //A => Assert
            Assert.CatchAsync(() => buildingManager.AddBuilding(building));

            //AsyncTestDelegate asyncTestDelegate = DoMyAcgtion;
            //Assert.CatchAsync(asyncTestDelegate);
        }
Exemplo n.º 6
0
    void OnMouseUp()
    {
        PlayerProperties   pp = GameObject.FindObjectOfType <PlayerProperties>();
        BuildingManager    bm = GameObject.FindObjectOfType <BuildingManager>();
        BuildingProperties bp = GameObject.FindObjectOfType <BuildingProperties>();

        if ((bm.selectedTower != null) && (transform.childCount == 0))                 //If a building is selected and there isn't a building placed on this square
        {
            if (pp.money >= bm.selectedTower.GetComponent <BuildingProperties>().cost) //If the player has enough money
            {
                GameObject b = Instantiate(bm.selectedTower, new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z), transform.rotation, transform);
                bm.AddBuilding(b); //Instantiate the building and add it to the building list
                if (bm.selectedTower != null)
                {
                    pp.money -= bm.selectedTower.GetComponent <BuildingProperties>().cost; //Remove the cost from the player's money
                }
            }
        }
    }
Exemplo n.º 7
0
        public void Confirm(object sender, RoutedEventArgs e)
        {
            if (IsValid())
            {
                if (!_isEdit)
                {
                    var buildingCreated = _buildingManager.AddBuilding(GetBuilding());

                    if (buildingCreated)
                    {
                        MessageBoxResult result = MessageBox.Show("Building has been created. You will be navigated to the buildings window.", "Creation Result", MessageBoxButton.OK);

                        if (result == MessageBoxResult.OK)
                        {
                            Back(null, null);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Building creation has been failed.", "Creation Result", MessageBoxButton.OK);
                    }
                }
                else
                {
                    var buildingUpdated = _buildingManager.UpdateBuilding(GetUpdatedBuilding());

                    if (buildingUpdated)
                    {
                        MessageBoxResult result = MessageBox.Show("Building has been updated. You will be navigated to the buildings window.", "Update Result", MessageBoxButton.OK);

                        if (result == MessageBoxResult.OK)
                        {
                            Back(null, null);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Building update has been failed.", "Update Result", MessageBoxButton.OK);
                    }
                }
            }
        }
        public async Task Building_Added_Successfuly_With_Moq()
        {
            //A => Arange

            Mock <ITableGatwayFactory> mock_ITableGatwayFactory = new Mock <ITableGatwayFactory>();

            Mock <IBuildingTableGateway> mock_IBuildingTableGateway = new Mock <IBuildingTableGateway>();
            int myId = 10;

            mock_IBuildingTableGateway.Setup(x => x.InsertBuildingAsync(It.IsAny <BuildingDTO>())).ReturnsAsync(myId);
            mock_ITableGatwayFactory.Setup(x => x.CreateBuildingTableGateway()).Returns(mock_IBuildingTableGateway.Object);

            BuildingManager buildingManager = new BuildingManager(mock_ITableGatwayFactory.Object);
            BuildingDTO     building        = new BuildingDTO {
                Id = 0, Name = "My Building", NumberOfUnits = 10
            };

            //A => Act
            await buildingManager.AddBuilding(building);

            //A => Assert
            Assert.AreEqual(myId, building.Id);
        }
Exemplo n.º 9
0
    public void Create(float cx, float cy)
    {
        bool able  = true;
        int  price = 0;

        if (num == 1)
        {
            xul   = 0;
            xdl   = 0;
            yul   = 1;
            ydl   = -1;
            sz    = 5;
            price = 100;
        }
        else if (num == 2)
        {
            xul   = 1;
            xdl   = -1;
            yul   = 0;
            ydl   = 0;
            sz    = 5;
            price = 100;
        }
        else if (num == 3)
        {
            xul   = 0;
            xdl   = 0;
            yul   = 0;
            ydl   = 0;
            sz    = 5;
            price = 200;
        }
        else if (num == 4)
        {
            xul   = 1;
            xdl   = 0;
            yul   = 0;
            ydl   = -1;
            sz    = 4;
            price = 150;
        }
        if (ps.money < price)
        {
            able = false;
        }
        for (int i = Mathf.RoundToInt(cx) + xdl; i <= Mathf.RoundToInt(cx) + xul; i++)
        {
            for (int j = Mathf.RoundToInt(cy) + ydl; j <= Mathf.RoundToInt(cy) + yul; j++)
            {
                if (GameObject.Find("center").GetComponent <MapScr>().Map[i + 15, 12 - j].GetComponent <Tiles>().able == false)
                {
                    able = false;
                }
            }
        }

        if (able == true)
        {
            ps.money -= price;
            GameObject tmp = Instantiate(creation, new Vector3(cx, cy, sz), Quaternion.Euler(0, 0, 0));
            tmp.GetComponent <WallScr>().xul = xul;
            tmp.GetComponent <WallScr>().xdl = xdl;
            tmp.GetComponent <WallScr>().yul = yul;
            tmp.GetComponent <WallScr>().ydl = ydl;

            Building.BuildingType targetBuildingType = Building.BuildingType.NONE;
            if (num == 2)
            {
                targetBuildingType = Building.BuildingType.WIDTHWALL;
            }
            else if (num == 3)
            {
                targetBuildingType = Building.BuildingType.TOWER;
            }
            else if (num == 4)
            {
                targetBuildingType = Building.BuildingType.FARM;
            }
            else if (num == 0)
            {
                targetBuildingType = Building.BuildingType.NONE;
            }
            else if (num == 1)
            {
                targetBuildingType = Building.BuildingType.HEIGHTWALL;
            }


            buildingManager.AddBuilding(tmp, Mathf.RoundToInt(cx + 15.5f) - xdl, Mathf.RoundToInt(cy + 15.5f) - ydl, targetBuildingType);
            Debug.Log(cx + " " + cy);
            //buildingManager.AddBuilding(Mathf.RoundToInt(cx) - xdl, Mathf.RoundToInt(cy) - ydl, targetBuildingType, xul - xdl + 1, yul - ydl + 1);
            Off();
        }
    }