Esempio n. 1
0
        private void button41_Click(object sender, EventArgs e)
        {
            HouseLogic HouseLogic = new HouseLogic();

            if (houseDebtTextBox.Text == "")
            {
                MessageBox.Show("Please, fill the House Debt field!");
            }
            else
            {
                if (!int.TryParse(houseDebtTextBox.Text, out int result))
                {
                    MessageBox.Show("Value entered is too large!");
                }
                else
                {
                    if (HouseLogic.IsHouseExists(result) == -1)
                    {
                        MessageBox.Show("House does not exist!");
                    }

                    else
                    {
                        houseDebtLabel.Text = HouseLogic.HouseDebtSum(result).ToString();
                    }
                }
            }
        }
Esempio n. 2
0
    public void ShowHouseUI(HouseLogic localHouseScript)
    {
        houseUI.enabled            = true;
        residentCount.text         = "Residents: " + localHouseScript.residents;
        residentHappinessText.text = "Resident Happiness: " + localHouseScript.specificResidentHappiness + "%";
        string houseName = localHouseScript.gameObject.name;

        if (houseName == "House1(Clone)")
        {
            houseUITitle.text = "Level 1 House";
        }
        else if (houseName == "House2(Clone)")
        {
            houseUITitle.text = "Level 2 House";
        }
    }
    public void ObjectUI()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 100.0f))
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (hit.transform.tag == "Build")
                {
                    houseScript = hit.transform.GetComponent <HouseLogic>();
                    tabsScript.ShowHouseUI(houseScript);
                }
            }
        }
    }
    public void Place()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 100.0f))
        {
            hoverObject = GameObject.Find(hit.transform.name);
            hoverName   = hit.transform.name;

            if (hoverObject.tag == "Ground")
            {
                int i = System.Convert.ToInt32(hit.transform.name);
                if (worldScript.objects[i] == "Empty")
                {
                    canPlace = true;
                }
                else
                {
                    canPlace = false;
                }
            }
            else
            {
                canPlace = false;
            }
        }
        else
        {
            hoverName   = "";
            hoverObject = null;
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(ray, out hit, 100.0f))
            {
                if (canPlace == true)
                {
                    transform.SetPositionAndRotation(new Vector3(hit.transform.position.x, hit.transform.position.y + 0.5030645f, hit.transform.position.z), transform.rotation);

                    int i = System.Convert.ToInt32(hit.transform.name);
                    Debug.Log(i);
                    worldScript.Xpositions[i] = transform.position.x;
                    worldScript.Ypositions[i] = transform.position.y;
                    worldScript.Zpositions[i] = transform.position.z;


                    currentObject          = Instantiate(prefab);
                    worldScript.objects[i] = prefab.name;
                    currentObject.transform.SetPositionAndRotation(transform.position, transform.rotation);

                    if (currentObject.tag == "Build")
                    {
                        houseScript             = currentObject.GetComponent <HouseLogic>();
                        houseScript.houseNumber = i;
                        houseScript.capacity    = houseCapacity;
                        houses++;

                        currentObject.name = prefab.name;
                    }



                    goldScript.gold -= price;
                }
            }

            placeCalled = false;
        }
    }
    public void LoadWorld()
    {
        WorldData data = SaveLogic.LoadWorld();

        worldScript.objects    = data.objects;
        worldScript.Xpositions = data.Xpositions;
        worldScript.Ypositions = data.Ypositions;
        worldScript.Zpositions = data.Zpositions;

        goldScript.gold                    = data.gold;
        populationScript.population        = data.population;
        populationScript.residentHappiness = data.residenthappiness;

        placementScript.houses = data.houses;

        worldScript.residents = data.residents;

        existingHouses = GameObject.FindGameObjectsWithTag("Build");

        for (int i = 0; i < existingHouses.Length; i++)
        {
            Destroy(existingHouses[i]);
        }
        existingRoads = GameObject.FindGameObjectsWithTag("Road");

        for (int i = 0; i < existingRoads.Length; i++)
        {
            Destroy(existingRoads[i]);
        }
        existingTerrain = GameObject.FindGameObjectsWithTag("Terrain");

        for (int i = 0; i < existingHouses.Length; i++)
        {
            Destroy(existingTerrain[i]);
        }

        for (int i = 0; i < worldScript.objects.Length; i++)
        {
            if (data.objects[i] == "House1")
            {
                prefab        = House1;
                houseCapacity = 5;
            }
            else if (data.objects[i] == "House2")
            {
                prefab        = House2;
                houseCapacity = 8;
            }
            else if (data.objects[i] == "tree")
            {
                prefab = tree;
            }
            else if (data.objects[i] == "tree1")
            {
                prefab = tree1;
            }
            else if (data.objects[i] == "tree2")
            {
                prefab = tree2;
            }
            else if (data.objects[i] == "road")
            {
                prefab = road;
            }
            else if (data.objects[i] == "cornerRoad")
            {
                prefab = cornerRoad;
            }
            else if (data.objects[i] == "cornerRoadLeftBottom")
            {
                prefab = cornerRoadLeftBottom;
            }
            else if (data.objects[i] == "cornerRoadRightTop")
            {
                prefab = cornerRoadRightTop;
            }
            else if (data.objects[i] == "cornerRoadRightBottom")
            {
                prefab = cornerRoadRightBottom;
            }
            else if (data.objects[i] == "3wayRoad")
            {
                prefab = threeWayRoad;
            }
            else if (data.objects[i] == "3wayRoadLeft")
            {
                prefab = threeWayRoadLeft;
            }
            else if (data.objects[i] == "3wayRoadUpwards")
            {
                prefab = threeWayRoadUpwards;
            }
            else if (data.objects[i] == "3wayRoadDown")
            {
                prefab = threeWayRoadDown;
            }
            else if (data.objects[i] == "4cornerRoad")
            {
                prefab = fourCornerRoad;
            }
            else if (data.objects[i] == "roadVertical")
            {
                prefab = roadVertical;
            }
            else
            {
                prefab = null;
            }

            if (prefab != null)
            {
                currentObject = Instantiate(prefab);
                currentObject.transform.SetPositionAndRotation(new Vector3(data.Xpositions[i], data.Ypositions[i], data.Zpositions[i]), currentObject.transform.rotation);
                if (prefab == House1 || prefab == House2)
                {
                    HouseLogic houseScript = currentObject.GetComponent <HouseLogic>();
                    houseScript.capacity    = houseCapacity;
                    houseScript.houseNumber = i;
                }
                if (prefab.tag == "Road")
                {
                    currentObject.name = "Road" + i;
                }
                if (currentObject.tag == "Terrain")
                {
                    currentObject.name = "Tree" + i;
                }
            }
        }
    }