Beispiel #1
0
        private UnitPrototype DecodeUnitByName(string file)
        {
            UnitPrototype UT = new UnitPrototype();

            using (FileStream fs = new FileStream(file, FileMode.Open))
            {
                fs.Seek(0, SeekOrigin.Begin);
                StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                while (!sr.EndOfStream)
                {
                    if (!RecognizeUnitData(sr.ReadLine(), UT))
                    {
                        ConsoleBox.WriteLineToConsole("File " + file + " is corrupt or cant be opened!");
                        UT = null;
                        break;
                    }
                }
                sr.Close();
                fs.Close();
            }
            return(UT);
        }
Beispiel #2
0
 private void listBox_units_SelectedIndexChanged(object sender, EventArgs e)
 {
     SelectedUnit      = (UnitPrototype)listBox_units.SelectedItem;
     unitInfo_box.Text = SelectedUnit.getUnitInfo();
 }
Beispiel #3
0
        private bool RecognizeUnitData(string data, UnitPrototype UT)
        {
            string [] parseData = data.Split(new char[] { '=' });
            if (parseData.Length > 2)
            {
                return(false);
            }

            if (parseData[0] == "NAME")
            {
                UT.UnitName = parseData[1];
            }
            if (parseData[0] == "INFO")
            {
                UT.UnitInfo = parseData[1];
            }
            if (parseData[0] == "TYPE")
            {
                string tmp = parseData[1];
                UT.Type = (TypesEnums.UnitType)tmp[0];
            }
            if (parseData[0] == "FORCE")
            {
                UT.UnitForce = ConvertStringToInt(parseData[1]);
            }
            if (parseData[0] == "INC")
            {
                UT.INC = ConvertStringToInt(parseData[1]);
            }
            if (parseData[0] == "MOV")
            {
                UT.MOV = ConvertStringToInt(parseData[1]);
            }
            if (parseData[0] == "LIFE")
            {
                UT.LIFE = ConvertStringToInt(parseData[1]);
            }
            if (parseData[0] == "ATACK")
            {
                UT.ATACK = ConvertStringToInt(parseData[1]);
            }
            if (parseData[0] == "DEF")
            {
                UT.DEF = ConvertStringToInt(parseData[1]);
            }
            if (parseData[0] == "LEVEL")
            {
                UT.LEVEL = ConvertStringToInt(parseData[1]);
            }
            if (UT.Type == TypesEnums.UnitType.Cavalerly)
            {
                if (parseData[0] == "MOV_HORSE")
                {
                    UT.MOV_HORSE = ConvertStringToInt(parseData[1]);
                }
                if (parseData[0] == "LIFE_HORSE")
                {
                    UT.LIFE_HORSE = ConvertStringToInt(parseData[1]);
                }
                if (parseData[0] == "DEF_HORSE")
                {
                    UT.DEF_HORSE = ConvertStringToInt(parseData[1]);
                }
            }
            if (UT.Type == TypesEnums.UnitType.Archers)
            {
                if (parseData[0] == "RANGE")
                {
                    UT.RANGE = ConvertStringToInt(parseData[1]);
                }
            }
            return(true);
        }