예제 #1
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();
    }
예제 #2
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);
        }
    }