/// <summary> /// Attacks another creature, comparing strength to defence and moving towards the other creature if it is not adjacent /// </summary> /// <param name="otherCreature">The creature to attack</param> public void attack(Creature otherCreature) { if (isAdjacent(otherCreature)) { int winnerEnergy = 10; int loserEnergy = 20; otherCreature.attacked(this); inCombat = true; inCombatWith = otherCreature; int attackVal = this.getStrength() + rand(10); int defVal = otherCreature.getDefence() + rand(10); if (attackVal > defVal) { otherCreature.damage(attackVal - defVal); this.drainEnergy(winnerEnergy); otherCreature.drainEnergy(loserEnergy); } else if (attackVal < defVal) { this.damage((defVal - attackVal) / 2); this.drainEnergy(loserEnergy); otherCreature.drainEnergy(winnerEnergy); } else { this.drainEnergy(loserEnergy); otherCreature.drainEnergy(loserEnergy); } } else { moveTowards(otherCreature); } }
/// <summary> /// Gets an array of strings that contain information about the creature /// </summary> /// <param name="c">The creature to get information about</param> /// <returns>An array of strings containing a set of information about the creature</returns> public string[] getCreatureInfo(Creature c) { string[] status = new string[1]; switch (DataViewed) { case 0: status = new string[] { "Health: " + c.getHealth(), "Energy :" + c.getEnergy(), "Current Scenario: " + c.CurrentScenario, "Response: " + c.CurrentResponse, "Stamina: " + c.getStamina() + "/" + c.getMaxStamina(), "Location: (" + c.getLocationXY()[0] + "," + c.getLocationXY()[1] + ")" }; break; case 1: int[] colours = c.getDna().getColourCount(); status = new string[] { "Number of...", "0s: " + colours[0], "1s: " + colours[1], "2s: " + colours[2], "3s: " + colours[3], "4s: " + colours[4], "5s: " + colours[5], "6s: " + colours[6] }; break; case 2: Color[] cols = Simulation.getColours(); status = new string[cols.Length]; for (int i = 0; i < cols.Length; i++ ) { status[i] = i + ": " + cols[i].ToString(); } break; case 3: string dietString = "Diet: " + c.getDiet(); if (c.getDiet() < 0.5) { dietString += " (HERBIVORE)"; } else { dietString += " (CARNIVORE)"; } status = new string[] { "Stats:", "STR: " + c.getStrength(), "SPD: " + c.getSpeed(), "STL: " + c.getStealthVal(), "AWA: " + c.getAwareness(), "DEF: " + c.getDefence(), dietString }; break; } return status; }