コード例 #1
0
    private string receiveTreasure()
    {
        GameInfo player = BaseSaver.getGame();
        int      pick   = Random.Range(0, 20);

        if (pick == 0)
        {
            Debug.Log("Gained Attribute!");
            CharacterInfo.attributeType newAttrib = GameInfo.getAvailableAttribute(player);
            if (newAttrib != CharacterInfo.attributeType.None)
            {
                List <CharacterInfo.attributeType> attribs = new List <CharacterInfo.attributeType> (player.attributes);
                attribs.Add(newAttrib);
                player.attributes = attribs.ToArray();
            }
            return("Gained Attribute!");
        }
        else if (pick < 8)
        {
            Debug.Log("Gained Gold!");
            player.gold += Random.Range(80, 220);
            return("Gained Gold!");
        }
        else
        {
            Debug.Log("Gained Rations!");
            player.rations += Random.Range(200, 450);
            return("Gained Rations!");
        }
    }
コード例 #2
0
ファイル: GameInfo.cs プロジェクト: BradZzz/Hex
    public static CharacterInfo.attributeType getAvailableAttribute(GameInfo gameI)
    {
        String[] names = Enum.GetNames(typeof(CharacterInfo.attributeType));
        List <CharacterInfo.attributeType> attribs = new List <CharacterInfo.attributeType> (gameI.attributes);

        //Find the enum that matches the name here
        for (int i = 0; i < names.Length; i++)
        {
            CharacterInfo.attributeType thisAttrib = (CharacterInfo.attributeType)Enum.GetValues(typeof(CharacterInfo.attributeType)).GetValue(i);
            if (!attribs.Contains(thisAttrib))
            {
                return(thisAttrib);
            }
        }
        return(CharacterInfo.attributeType.None);
    }