Example #1
0
        public void CanAddValidForager()
        {
            var tempFile = File.Create("temp.csv");

            tempFile.Close();
            ForagerFileRepository repo    = new ForagerFileRepository("temp.csv");
            ForagerService        service = new ForagerService(repo);
            Forager forager = new Forager
            {
                FirstName = "Sally",
                LastName  = "Smith",
                Id        = "abc-123",
                State     = "AL"
            };

            Result <Forager> result = service.Add(forager);


            Assert.IsTrue(result.Success);
            Assert.NotNull(result.Value);
            Assert.AreEqual(36, result.Value.Id.Length);

            File.Delete("temp.csv");
        }
        private Forage Deserialize(string[] fields, DateTime date)
        {
            if (fields.Length != 4)
            {
                return(null);
            }

            Forage result = new Forage();

            result.Id        = fields[0];
            result.Date      = date;
            result.Kilograms = decimal.Parse(fields[3]);

            Forager forager = new Forager();

            forager.Id     = fields[1];
            result.Forager = forager;

            Item item = new Item();

            item.Id     = int.Parse(fields[2]);
            result.Item = item;
            return(result);
        }
Example #3
0
    // Attacking functionality to damage characters/base
    public void Attack()
    {
        // Check if a forager target is identified
        if (AttackTarget_F != null)
        {
            // Check if we are near the target
            if (CheckAround(AttackTarget_F.CurrentPosition))
            {
                // Reduce target health
                AttackTarget_F.GetComponent <Forager>().Health -= 10.0f;

                // Check if target is dead
                if (AttackTarget_F.GetComponent <Forager>().Health <= 0)
                {
                    // No longer being attacked
                    beingAttacked = false;

                    // Destroy and clean-up target
                    Destroy(AttackTarget_F.gameObject);

                    // Remove target from appropriate list and unit count
                    if (OwnedBy == Ownership.Player)
                    {
                        game.GetComponent <Game>().EnemyForagerList.Remove(AttackTarget_F.GetComponent <Forager>());
                        game.GetComponent <Game>().enemyUnitCount--;
                    }
                    else
                    {
                        game.GetComponent <Game>().foragerList.Remove(AttackTarget_F.GetComponent <Forager>());
                        game.GetComponent <Game>().unitCount--;
                    }

                    // Reset target and tile
                    AttackTarget_F = null;
                    tile           = null;
                }
            }
        }
        else if (AttackTarget_W != null) // Otherwise check if a warrior target is identified
        {
            // Check if we are near the target
            if (CheckAround(AttackTarget_W.CurrentPosition))
            {
                // Reduce target health
                AttackTarget_W.GetComponent <Warrior>().Health -= 10.0f;

                // Check if target is dead
                if (AttackTarget_W.GetComponent <Warrior>().Health <= 0)
                {
                    // No longer being attacked
                    beingAttacked = false;

                    // Destroy and clean-up target
                    Destroy(AttackTarget_W.gameObject);

                    // Remove target from appropriate list and unit count
                    if (OwnedBy == Ownership.Player)
                    {
                        game.GetComponent <Game>().EnemyWarriorList.Remove(AttackTarget_W.GetComponent <Warrior>());
                        game.GetComponent <Game>().enemyUnitCount--;
                    }
                    else
                    {
                        game.GetComponent <Game>().warriorList.Remove(AttackTarget_W.GetComponent <Warrior>());
                        game.GetComponent <Game>().unitCount--;
                    }

                    // Reset target and tile
                    AttackTarget_W = null;
                    tile           = null;
                }
            }
        }
        else if (CheckAround(baseTile)) // Otherwise, check if we are near the opposing base tile
        {
            // Attack base dependent on if I'm a player or enemy
            if (this.OwnedBy == Ownership.Enemy)
            {
                game.GetComponent <Game>().AttackPlayerBase();
            }
            else
            {
                game.GetComponent <Game>().AttackEnemyBase();
            }
        }
    }
Example #4
0
    // Target finder func to find closest target for warrior to attack
    private void FindTarget(List <Warrior> warriors, List <Forager> foragers)
    {
        // Define target and assoc vars
        float shortestLength = float.MaxValue;
        float temp;

        AttackTarget_F = null;
        AttackTarget_W = null;

        // Target warriors by default so check if there is any
        if (warriors.Count == 0)
        {
            // No warriors on map so find a forager to attack
            foreach (Forager forager in foragers)
            {
                // Get distance and compare to shortest one
                temp = Vector3.Distance(this.transform.position, forager.transform.position);
                if (temp < shortestLength)
                {
                    // Found a shorter dist target so this is the target
                    shortestLength = temp;
                    tile           = forager.CurrentPosition;
                    AttackTarget_F = forager;
                }
            }
        }
        else // Opposing warrior(s) exist so target them
        {
            foreach (Warrior warrior in warriors)
            {
                // Get distance and compare to shortest one
                temp = Vector3.Distance(this.transform.position, warrior.transform.position);

                if (temp < shortestLength)
                {
                    // Found a shorter dist target so this is the target
                    shortestLength = temp;
                    tile           = warrior.CurrentPosition;
                    AttackTarget_W = warrior;
                }
            }
        }

        // Check if no attack target was found (e.g. no opposing warriors/foragers on map)
        // so attack the base
        if (AttackTarget_F == null && AttackTarget_W == null)
        {
            // Holder for route to the shortest point surrounding the base tile
            List <EnvironmentTile> route = new List <EnvironmentTile>();
            EnvironmentTile        tile2 = game.GetComponent <Game>().CheckAround(baseTile, this.CurrentPosition);

            // Ensure a surrounding tile is found
            if (tile2 != null)
            {
                // Calc route to the base tile
                route = mMap.Solve(this.CurrentPosition, tile2, "warrior");

                // Check if route is possible
                if (route != null)
                {
                    // Follow route and set target
                    GoTo(route);
                    CurrentTarget = tile2;
                }
                else
                {
                    // Impossible to go to base tile so do nothing
                    CurrentTarget = null;
                }
            }
        }
        else
        {
            // We have found a target so set it to the tile
            CurrentTarget = tile;
        }
    }
 Forager IForagerRepository.Add(Forager forager)
 {
     throw new NotImplementedException();
 }