예제 #1
0
 public static void saveMonsterCanvas(string path_in, MonsterCanvas monsterCanvas_in)
 {
     using (StreamWriter file = File.CreateText(path_in))
     {
         JsonSerializer serializer = new JsonSerializer();
         serializer.Serialize(file, monsterCanvas_in);
     }
 }
예제 #2
0
        //Need Json Package http://www.nuget.org/packages/Newtonsoft.Json

        /*  Exemple :
         *  // Write the contents of the variable someClass to a file.
         *  WriteToBinaryFile<SomeClass>("C:\someClass.txt", object1);
         *
         *  // Read the file contents back into a variable.
         *  SomeClass object1= ReadFromBinaryFile<SomeClass>("C:\someClass.txt");
         */

        public static MonsterCanvas loadMonsterCanvas(string path_in)
        {
            using (StreamReader file = File.OpenText(path_in))
            {
                JsonSerializer serializer = new JsonSerializer();
                MonsterCanvas  mc_out     = (MonsterCanvas)serializer.Deserialize(file, typeof(MonsterCanvas));
                return(mc_out);
            }
        }
예제 #3
0
        public void addMonster(MonsterCanvas mc_in)
        {
            int x = rnd.Next(0, width);
            int y = rnd.Next(0, heigth);

            var m = new Monster(mc_in, x, y, rnd);

            list_monster.Add(m);
            map[x, y] = m;
        }
예제 #4
0
        /// <summary>
        /// Mix DNA (race stat) of two same race monster
        /// </summary>
        /// <param name="m">Monster to compare and maybe replicate</param>
        /// <param name="rnd_in">Random number to blend in :P</param>
        public MonsterCanvas replicate(Monster m, Random rnd_in)
        {
            // Controler le type
            if (name == m.name)
            {
                // Calcul affinite
                if (rnd_in.NextDouble() > 0.5f)
                {
                    // Mix de stats
                    Tuple <int, int> hp_temp  = rnd_tuple(hp, m.hp, rnd_in);
                    Tuple <int, int> atk_temp = rnd_tuple(atk, m.atk, rnd_in);
                    Tuple <int, int> def_temp = rnd_tuple(def, m.def, rnd_in);
                    Tuple <int, int> spd_temp = rnd_tuple(spd, m.spd, rnd_in);

                    MonsterCanvas mc_temp = new MonsterCanvas(name, acronyme, hp_temp, atk_temp, def_temp, spd_temp);
                    return(mc_temp);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        public Monster(MonsterCanvas mc_in, int x_in, int y_in, Random rnd_in)
        {
            coord = new Coordinates(x_in, y_in);

            int birth_hp = rnd_in.Next(mc_in.hp.Item1, mc_in.hp.Item2);

            hp = new Tuple <int, int>(birth_hp, birth_hp);

            int birth_atk = rnd_in.Next(mc_in.atk.Item1, mc_in.atk.Item2);

            atk = new Tuple <int, int>(birth_atk, birth_atk);

            int birth_def = rnd_in.Next(mc_in.def.Item1, mc_in.def.Item2);

            def = new Tuple <int, int>(birth_atk, birth_atk);

            int birth_spd = rnd_in.Next(mc_in.spd.Item1, mc_in.spd.Item2);

            spd = new Tuple <int, int>(birth_atk, birth_atk);

            name     = mc_in.name;
            acronyme = mc_in.acronyme;
        }