public void MoveCreatureTest()
        {
            MapCreator creator = new MapCreator();
            IMap       map     = creator.GenerateFlatMap(2, 2, new Dictionary <TileValues, int> {
                { TileValues.Forest, 1 }
            });
            CreatureGenerator generator = new CreatureGenerator();
            ICreature         creature  = generator.GenerateCreature(CreatureTypes.Human);

            ITile currentTile = map.Tiles[0];
            ITile newTile     = map.Tiles[1];

            currentTile.CreatureList.Add(creature);

            MoveCreatureActionParameter parameter = new MoveCreatureActionParameter()
            {
                Creature            = creature,
                CurrentCreatureTile = currentTile,
                NewCreatureTile     = newTile,
            };

            MoveCreatureAction action = new MoveCreatureAction();
            IActionResult      result = action.Execute(parameter);

            Assert.IsTrue(result.Success);

            Assert.AreEqual(0, currentTile.CreatureList.Count);
            Assert.AreEqual(1, newTile.CreatureList.Count);

            Assert.IsFalse(currentTile.CreatureList.Contains(creature));
            Assert.IsTrue(newTile.CreatureList.Contains(creature));
        }
Exemple #2
0
    void Start()
    {
        pg = PlantGenerator.Instance;
        cg = CreatureGenerator.Instance;

        Camera.main.orthographicSize = (float)height / 2;
        back.transform.localScale    = new Vector3(width, height, 0f);
    }
Exemple #3
0
    //Magic End

    void Start()
    {
        ui = myUI.Instance;
        cg = CreatureGenerator.Instance;
        im = GetComponent <Creature>();

        timer    = Time.time;
        lastTime = timer;

        food  = new List <Transform>();
        enemy = new List <Transform>();
    }
Exemple #4
0
        public TestScene()
        {
            _random = new DotNetRandom();

            MapBuilder builder = new ForestBuilder(64, 64, 0, _random.Next());

            builder.Build();
            _map = builder.Map;
            _fov = new FieldOfView(_map);

            Race playerRace = Engine.Assets.GetAsset <Race>("player");

            _player = new Player(playerRace);
            _map.Add(_player, 32, 32);

            for (int i = 0; i < 10; i++)
            {
                Creature frog = CreatureGenerator.NewCreature("frog");
                _map.Add(frog, _map.RandomEmptyPoint(_random));
            }

            for (int i = 0; i < 10; i++)
            {
                Creature rat = CreatureGenerator.NewCreature("rat");
                _map.Add(rat, _map.RandomEmptyPoint(_random));
            }

            _turnManager = new TurnManager <Creature>(_map.Creatures);

            _tileSelection = Engine.Assets.GetAsset <Sprite>("tile_selection");

            _soundEffectManager.LoadSoundEffect("rain_looped");
            _soundEffectManager.LoadSoundEffect("thunder_01");

            _soundEffectManager.Play("rain_looped", 0.4f, loop: true);

            _camera      = new Camera();
            _camera.Zoom = 1f;

            int w = Engine.Width / 8;
            int h = Engine.Height / 8;

            _camera.Origin = new Vector2(Engine.Width / 2, Engine.Height / 2);
            _camera.X      = _player.RenderX;
            _camera.Y      = _player.RenderY;


            _mapRenderer       = new MapRenderer(_map, _lightingManager, _camera);
            _creatureRenderer  = new CreatureRenderer(_map.Creatures, _map, _lightingManager, _camera);
            _effectsRenderer   = new EffectsRenderer(_map, _lightingManager, _camera);
            _interfaceRenderer = new InterfaceRenderer(_map, _camera);
        }
        public void AttackCreatureTest()
        {
            CreatureGenerator generator      = new CreatureGenerator();
            ICreature         humanCreature  = generator.GenerateCreature(CreatureTypes.Human);
            ICreature         goblinCreature = generator.GenerateCreature(CreatureTypes.Goblin);

            AttackCreatureActionParameter parameter = new AttackCreatureActionParameter()
            {
                AttackingCreature = humanCreature,
                DefendingCreature = goblinCreature,
            };

            AttackCreatureAction attackAction = new AttackCreatureAction();
            IActionResult        result       = attackAction.Execute(parameter);

            Assert.IsTrue(result.Success);

            Assert.IsTrue(humanCreature.Health <= 0 || goblinCreature.Health <= 0);
        }
Exemple #6
0
    // Use this for initialization
    void Start()
    {
        cg = CreatureGenerator.Instance;

        age     = 0;
        isAdult = false;

        size = Mathf.RoundToInt(maxSize * 0.1f);



        if (Random.value < 0.5)
        {
            isMale = true;
        }

        alive = true;

        SendMessage("SetMaxEnergy", maxSize * cg.sizeToEnergy);
        SendMessage("SetMaxHp", maxSize);
    }
Exemple #7
0
 void Start()
 {
     creObj = transform.parent.gameObject;
     cg = CreatureGenerator.Instance;
 }
Exemple #8
0
 void Start()
 {
     cg     = CreatureGenerator.Instance;
     energy = maxEnergy / 2;
     hp     = maxHp;
 }
Exemple #9
0
 void Start()
 {
     cg = CreatureGenerator.Instance;
 }
Exemple #10
0
 void Start()
 {
     creObj = transform.parent.gameObject;
     cg     = CreatureGenerator.Instance;
 }
Exemple #11
0
 void Start()
 {
     cg = CreatureGenerator.Instance;
     energy = maxEnergy / 2;
     hp = maxHp;
 }
Exemple #12
0
 void Start()
 {
     ui = myUI.Instance;
     cg = CreatureGenerator.Instance;
     txt = GetComponent<Text>();
 }
Exemple #13
0
 void Start()
 {
     ui  = myUI.Instance;
     cg  = CreatureGenerator.Instance;
     txt = GetComponent <Text>();
 }
Exemple #14
0
    public GameObject Create(GameObject p1, GameObject p2, bool allowMutation = true, float mutationChance = 0.05f)
    {
        CreatureGenerator c1 = p1.GetComponent <CreatureGenerator> ();
        CreatureGenerator c2 = p2.GetComponent <CreatureGenerator> ();

        GameObject        babyCreature = new GameObject();
        CreatureGenerator c3           = babyCreature.AddComponent <CreatureGenerator>();

        //get the publicly accessible variables
        FieldInfo[] fi = typeof(CreatureGenerator).GetFields(BindingFlags.Public | BindingFlags.Instance);

        foreach (FieldInfo f in fi)
        {
            Debug.Log(f.Name + " Type= " + f.GetValue(c1).GetType().ToString());

            //randomly select certain attibutes from either parent and put into child,
            //chance for mutation of certain variables
            int sel = Random.Range(0, 2);
            //Debug.Log (sel);
            //set values to either parent1 or parent2 values at random
            if (sel == 1)
            {
                typeof(CreatureGenerator).GetField(f.Name).SetValue(c3, typeof(CreatureGenerator).GetField(f.Name).GetValue(c1));
            }
            else
            {
                typeof(CreatureGenerator).GetField(f.Name).SetValue(c3, typeof(CreatureGenerator).GetField(f.Name).GetValue(c2));
            }
        }

        Debug.Log("After attr select");
        //set the name to longest parent name, or a combination of both
        if (p1.name.Length < p2.name.Length && p2.name.Contains(p1.name))
        {
            babyCreature.name = p2.name;
        }
        else if (p2.name.Length < p1.name.Length && p1.name.Contains(p2.name))
        {
            babyCreature.name = p1.name;
        }
        else
        {
            //indexes of the capital letters

            Debug.Log("Getting index");
            int p1index = 0;
            int p2index = 0;

            try{
                p1index = (from ch in p1.name.ToCharArray()
                           where char.IsUpper(ch)
                           select p1.name.IndexOf(ch)).First();

                p2index = (from ch in p2.name.ToCharArray()
                           where char.IsUpper(ch)
                           select p2.name.IndexOf(ch)).First();
            }catch (System.Exception e) {
                Debug.Log(e.ToString());
            }

            Debug.Log("After index");
            //if caps in name else just combine name
            if (p1index > 0 && p2index > 0)
            {
                babyCreature.name = p1.name.Substring(0, p1index) + p2.name.Substring(0, p2index);
            }
            else
            {
                babyCreature.name = p1.name + p2.name;
            }
        }

        Debug.Log("Setting Name");


        //mutate the creature
        if (allowMutation)
        {
            Debug.Log("Check Mutate");
            foreach (FieldInfo f in fi)
            {
                float chance = Random.Range(0, 101) * 0.01f;

                //if the chance is met and the variable is a number, then edit number
                if (chance < mutationChance && (f.GetValue(c3).GetType().ToString() == "System.Single" || f.GetValue(c3).GetType().ToString() == "System.Int32"))
                {
                    //if its greater than one increment or decrement by random percentage of the current value;

                    if ((float)f.GetValue(c3) > 0)
                    {
                        Debug.Log("Mutating");

                        float percent = Random.Range(-150, 150) * 0.01f;
                        float oldVal  = (float)typeof(CreatureGenerator).GetField(f.Name).GetValue(c3);
                        float newVal  = Mathf.Clamp(oldVal + oldVal * percent, 0.1f, float.MaxValue);
                        typeof(CreatureGenerator).GetField(f.Name).SetValue(c3, newVal);
                        //Debug.Log ("mutated " + f.Name + " from " + oldVal.ToString () + " to " + newVal);
                    }
                }
            }
        }



        return(babyCreature);
    }
Exemple #15
0
    //Magic End
    void Start()
    {
        ui = myUI.Instance;
        cg = CreatureGenerator.Instance;
        im = GetComponent<Creature>();

        timer = Time.time;
        lastTime = timer;

        food = new List<Transform>();
        enemy = new List<Transform>();
    }
Exemple #16
0
        private ICreature GetCreature(CreatureTypes creatureType)
        {
            CreatureGenerator generator = new CreatureGenerator();

            return(generator.GenerateCreature(creatureType));
        }
Exemple #17
0
 void Start()
 {
     cg = CreatureGenerator.Instance;
 }