Ejemplo n.º 1
0
    /// <summary>
    /// Adds a playerobject to the list, for later use.
    /// </summary>
    public void addPlayer(string name, int age, int height, float weight, Gender gender, PawnColor c, bool save)
    {
        Player p = new Player();

        p.setInfo(players.Count, name, age, height, weight, gender, c.getColor(), c.getColorId(), maxInsulin);
        players.Add(p);
        usedColors.Add(c);

        if (save)
        {
            XmlSerializer ser  = new XmlSerializer(typeof(Player));
            StreamWriter  file = new StreamWriter(Path.Combine(Application.persistentDataPath, p.getFileName() + ".xml"));
            ser.Serialize(file, p);
            file.Close();
        }

        if (players.Count == playerCount)
        {
            if (TitleMusic.Instance != null)
            {
                TitleMusic.Instance.Destroy();
            }
            Application.LoadLevel("BoardGame");
        }
        else
        {
            Application.LoadLevel("PlayerInfo");
        }
    }
    public void setPlayer()
    {
        bool error = false;

        error = (nameError.enabled = (pname == "")) || error;
        error = (ageError.enabled = (age == 0)) || error;
        error = (weightError.enabled = (weight == 0)) || error;
        error = (heightError.enabled = (height == -1) || (height == 0)) || error;
        //error = (heightError.enabled = (height == 0)) || error;
        error = (genderError.enabled = (gender == Gender.None)) || error;
        error = (colorError.enabled = (color.getColor() == Color.clear)) || error;

        if (!error)
        {
            InformationManager.instance.addPlayer(pname, age, height, weight, gender, color, saveToggle.isOn);
        }
        else                  //show length error
        {
            if (height == -1) //wrong input
            {
                heightError.text = "Lengte is niet in centimeters";
            }
            else             //no input
            {
                heightError.text = "Vul uw lengte in";
            }
        }
    }