Пример #1
0
    public void SaveDeck()
    {
        CalculTotal();

        Deck d = new Deck();

        d.InitDeck();

        for (int i = 0; i < allCards.Length; i++)
        {
            Actions action = null;

            switch (allCards[i].GetCardType() - 1)
            {
            case 0:
                action = new Arrow();
                break;

            case 1:
                action = new Magic();
                break;

            case 2:
                action = new Sword();
                break;

            case 3:
                action = new Move();
                break;

            case 4:
                action = new Shield();
                break;
            }

            action.InitAction();
            action.SetCardAmount(allCards[i].GetStrength());

            Card1 c = new Card1();
            c.SetCard(action);
            d.AddCard(c, i);
        }

        if (lastCalcul < 100 && deckText.text != "")
        {
            FileReader.GetInstance().SaveDeck(deckText.text, d);
        }
    }
Пример #2
0
    public void RecoverActions(bool isLeft, int actionIndex, int actionAmount)
    {
        Actions lAction = null;
        Actions rAction = null;

        switch (actionIndex)
        {
        case 0:
            if (isLeft)
            {
                lAction = new Arrow();
            }
            else
            {
                rAction = new Arrow();
            }
            break;

        case 1:
            if (isLeft)
            {
                lAction = new Magic();
            }
            else
            {
                rAction = new Magic();
            }
            break;

        case 2:
            if (isLeft)
            {
                lAction = new Move();
            }
            else
            {
                rAction = new Move();
            }
            break;

        case 3:
            if (isLeft)
            {
                lAction = new Shield();
            }
            else
            {
                rAction = new Shield();
            }
            break;

        case 4:
            if (isLeft)
            {
                lAction = new Sword();
            }
            else
            {
                rAction = new Sword();
            }
            break;
        }

        if (isLeft)
        {
            _leftAction.SetCard(lAction);
            _leftAction.GetSelectedAction().InitAction();
            _leftAction.GetSelectedAction().SetCardAmount(actionAmount);
        }
        else
        {
            _rightAction.SetCard(rAction);
            _rightAction.GetSelectedAction().InitAction();
            _rightAction.GetSelectedAction().SetCardAmount(actionAmount);
        }
    }
Пример #3
0
    public Card1[] ReadFile(string deckName)
    {
        fileName = deckName + ".txt";

        Card1[] newDeck = new Card1[10];
        int     index   = 0;

        StreamReader sr           = new StreamReader(fullPath + "/" + fileName);
        string       fileContents = sr.ReadToEnd();

        sr.Close();

        List <string> infos = new List <string>();

        string[] lines = fileContents.Split("\n"[0]);
        foreach (string line in lines)
        {
            // not a comment line
            if (!line.Contains("#"))
            {
                infos.Add(line);
            }
        }

        for (int i = 0; i < infos.Count; i++)
        {
            if (!infos[i].Contains("="))
            {
                // white line
            }
            else
            {
                string[] action1s = infos[i].Split('=');

                int id1     = int.Parse(action1s[0]);
                int amount1 = int.Parse(action1s[1]);

                Actions action1 = null;

                switch (id1)
                {
                case 0:
                    action1 = new Arrow();
                    break;

                case 1:
                    action1 = new Magic();
                    break;

                case 2:
                    action1 = new Sword();
                    break;

                case 3:
                    action1 = new Move();
                    break;

                case 4:
                    action1 = new Shield();
                    break;
                }

                action1.InitAction();
                action1.SetCardAmount(amount1);

                Card1 c = new Card1();
                c.SetCard(action1);
                newDeck[index] = c;
                index++;
            }
        }

        return(newDeck);
    }