Ejemplo n.º 1
0
    private void Buy()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            //Buy
            PlayerCoin playerCoinComponent = playerCoin.GetComponent <PlayerCoin>();
            TotalBuy   totalComponent      = total.GetComponent <TotalBuy>();

            float playerMoney = playerCoinComponent.coin;
            float totalMoney  = totalComponent.total;
            if (totalMoney <= playerMoney && totalMoney != 0)
            {
                //Debug.Log("CONSEGUE COMPRAR");
                total.GetComponent <TotalBuy>().setTotalValue((playerMoney - totalMoney), playerMoney);
                playerCoin.GetComponent <PlayerCoin>().setCoinValue((playerMoney - totalMoney));
                setPlayerSkin();

                seletedItensArray = new ArrayList();
                seletedIDSArray   = new ArrayList();

                total.GetComponent <TotalBuy>().setTotalValue((0), playerMoney);
                Shop.gameObject.active = false;
            }
        }
    }
Ejemplo n.º 2
0
 void OnMouseUp()
 {
     if (currentItem != null)
     {
         PlayerCoin.Add((int)(currentItem.GetComponent <Item>().Cost *quantity * 0.1f));
         PlayerItems.Add(currentItem.name, -quantity);
         SetItem(currentItem.name);
     }
 }
Ejemplo n.º 3
0
    public static void Load()
    {
        if (!File.Exists(savePath))
        {
            return;
        }

        string       line;
        StreamReader file = new StreamReader(savePath);

        while ((line = file.ReadLine()) != null)
        {
            string[] exp = line.Split(';');

            if (exp[0] == "gold")
            {
                PlayerCoin.Set(int.Parse(exp[1]));
            }
            else if (exp[0] == "monster")
            {
                PlayerMonster.Add(exp[1], int.Parse(exp[2]));
            }
            else if (exp[0] == "item")
            {
                PlayerItems.Add(exp[1], int.Parse(exp[2]));
            }
            else if (exp[0] == "field")
            {
                if (exp[2] == "0")
                {
                    PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_FAILED);
                }
                else if (exp[2] == "1")
                {
                    PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_1STAR);
                }
                else if (exp[2] == "2")
                {
                    PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_2STAR);
                }
                else if (exp[2] == "3")
                {
                    PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_3STAR);
                }
                else
                {
                    PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_EMPTY);
                }
            }

            PlayerMonster.Load();
        }

        file.Close();
    }
Ejemplo n.º 4
0
    private bool Buy(string name, int cost)
    {
        if (PlayerCoin.Get() > cost)
        {
            Debug.Log("Player buy: " + name + " at cost " + cost);
            PlayerMonster.Add(name, 0);
            PlayerCoin.Spend(cost);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 5
0
    public static void Save()
    {
        StreamWriter file = new StreamWriter(savePath);

        file.WriteLine("gold;" + PlayerCoin.Get());

        for (int i = 0; i < PlayerMonster.Count; i++)
        {
            file.WriteLine("monster;" + PlayerMonster.Get(i).monsterName + ";" + PlayerMonster.Get(i).exp);
        }

        foreach (KeyValuePair <string, int> pair in PlayerItems.Items)
        {
            file.WriteLine("item;" + pair.Key + ";" + pair.Value);
        }

        for (int i = 0; PlayerField.Has(i); i++)
        {
            switch (PlayerField.Get(i))
            {
            case FieldStatus.FIELD_EMPTY:
                file.WriteLine("field;" + i.ToString() + ";-1");
                break;

            case FieldStatus.FIELD_FAILED:
                file.WriteLine("field;" + i.ToString() + ";0");
                break;

            case FieldStatus.FIELD_1STAR:
                file.WriteLine("field;" + i.ToString() + ";1");
                break;

            case FieldStatus.FIELD_2STAR:
                file.WriteLine("field;" + i.ToString() + ";2");
                break;

            case FieldStatus.FIELD_3STAR:
                file.WriteLine("field;" + i.ToString() + ";3");
                break;
            }
        }

        file.Close();
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition),
                                                 Vector2.zero);

            if (hit.transform != null)
            {
                for (int i = 0; i < colliderList.Count; i++)
                {
                    if (hit.transform.gameObject == colliderList[i].gameObject)
                    {
                        if (PlayerCoin.Get() >= itemList[i].GetComponent <Item>().Cost)
                        {
                            PlayerCoin.Spend(itemList[i].GetComponent <Item>().Cost);
                            PlayerItems.Add(itemList[i].name, 1);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 7
0
 void OnGUI()
 {
     GUI.Label(new Rect(screenPos.x, Screen.height - screenPos.y, 40, 25),
               PlayerCoin.Get().ToString(),
               textStyle);
 }
Ejemplo n.º 8
0
    private void ShowGameEnd()
    {
        if (!messageBox.activeSelf)
        {
            int bonusMin = (PlayerMonster.IndexEnemy + 1) * 9;
            int bonusMax = (PlayerMonster.IndexEnemy + 1) * 12;

            if (playerHealth <= 0)
            {
                bonusMin = (PlayerMonster.IndexEnemy + 1) * 1;
                bonusMax = (PlayerMonster.IndexEnemy + 1) * 3;
            }

            int goldBonus = Random.Range(bonusMin, bonusMax);

            PlayerCoin.Add(goldBonus);
            GameObject gold = messageBox.transform.FindChild("GoldDisplay").gameObject;
            gold.GetComponent <TextMesh>().text = "+" + goldBonus;

            // Apply database
            foreach (GameObject go in activeMonster)
            {
                PlayerMonster.Get(go.GetComponent <Monster>().StorageIndex).exp =
                    go.GetComponent <Monster>().Exp;
            }

            List <GameObject> dropItem = new List <GameObject>();
            foreach (GameObject item in Reference.Asset.itemTemplate)
            {
                int rand = Random.Range(0, 100);

                if (rand <= item.GetComponent <Item>().DropWeight)
                {
                    PlayerItems.Add(item.name, 1);
                    dropItem.Add(item);
                }
            }

            int count = 0;
            foreach (GameObject go in dropItem)
            {
                GameObject item = (GameObject)Instantiate(go,
                                                          new Vector3(count, 0, 0),
                                                          Quaternion.identity);
                item.GetComponent <SpriteRenderer>().sortingOrder = 2;
                count++;
            }

            switch (defeatedEnemy)
            {
            case 0:
                if (PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_3STAR &&
                    PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_2STAR &&
                    PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_1STAR)
                {
                    PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_FAILED);
                }
                break;

            case 1:
                if (PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_3STAR &&
                    PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_2STAR)
                {
                    PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_1STAR);
                }
                break;

            case 2:
                if (PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_3STAR)
                {
                    PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_2STAR);
                }
                break;

            case 3:
                PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_3STAR);
                break;
            }

            messageBox.SetActive(true);
        }

        GameObject title = messageBox.transform.FindChild("TextHelper").gameObject;

        if (playerHealth > 0)
        {
            title.GetComponent <TextMesh>().text  = "Victory";
            title.GetComponent <TextMesh>().color = new Color(255, 226, 0);
        }
        else
        {
            title.GetComponent <TextMesh>().text  = "Defeated";
            title.GetComponent <TextMesh>().color = new Color(233, 0, 0);
        }
    }