Exemplo n.º 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();
    }
Exemplo n.º 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);
        }
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        List <GameObject> templates = Reference.Asset.monsterTemplate;
        Vector3           offset    = new Vector3(0, 3f);

        bool empty = false;

        for (int i = 0; i < templates.Count - 2; i++)
        {
            GameObject go = null;

            if (i % 2 == 0)
            {
                go = (GameObject)Instantiate(areaDot,
                                             new Vector3(-2, -i, 0) + offset,
                                             Quaternion.identity);
            }
            else
            {
                go = (GameObject)Instantiate(areaDot,
                                             new Vector3(2, -i, 0) + offset,
                                             Quaternion.identity);
            }

            go.transform.localScale = new Vector3(0.7f, 0.7f);
            go.transform.parent     = this.transform;

            if (empty)
            {
                go.GetComponent <SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
            }

            FieldStatus fs = PlayerField.Get(i);
            switch (fs)
            {
            case FieldStatus.FIELD_EMPTY:
                if (!empty)
                {
                    fs = FieldStatus.FIELD_FAILED;
                }
                empty = true;
                break;

            case FieldStatus.FIELD_FAILED:
                Instantiate(starFailedTemplate,
                            go.transform.position + new Vector3(0, 0.75f),
                            Quaternion.identity);
                break;

            case FieldStatus.FIELD_1STAR:
                Instantiate(star1Template,
                            go.transform.position + new Vector3(0, 0.75f),
                            Quaternion.identity);
                break;

            case FieldStatus.FIELD_2STAR:
                Instantiate(star2Template,
                            go.transform.position + new Vector3(0, 0.75f),
                            Quaternion.identity);
                break;

            case FieldStatus.FIELD_3STAR:
                Instantiate(star3Template,
                            go.transform.position + new Vector3(0, 0.75f),
                            Quaternion.identity);
                break;
            }

            fieldStats.Add(fs);
            areaList.Add(go);

            GameObject collider = (GameObject)Instantiate(colliderTemplate,
                                                          go.transform.position,
                                                          Quaternion.identity);
            collider.transform.parent = this.transform;
            colliderList.Add(collider);
        }

        // Generate path
        for (int i = 0; i < areaList.Count - 1; i++)
        {
            GameObject from      = areaList[i];
            GameObject to        = areaList[i + 1];
            Vector3    direction = to.transform.position - from.transform.position;

            for (int j = 2; j < 11; j++)
            {
                float      randomVar    = 0.2f * Mathf.Sin(Mathf.PI * (j + 2) / 10);
                Vector3    randomOffset = new Vector3(randomVar, -randomVar);
                GameObject go           = (GameObject)Instantiate(connectorDot,
                                                                  from.transform.position + (direction.normalized * j) / 3 + randomOffset,
                                                                  Quaternion.identity);
                go.transform.parent = this.transform;
            }
        }
    }