/// <summary> /// Runs a battle against an easy AI /// </summary> /// <param name="player"></param> /// <param name="computer"></param> public override void StartFight(Pokemon player, Pokemon computer) { //Prepare for the fight Console.WriteLine("You have selected... " + player.GetType().Name + "!"); player.PrintStats(); Console.WriteLine(); Console.WriteLine("And you're going to be fighting... " + computer.GetType().Name + "!"); computer.PrintStats(); Console.WriteLine(); Console.WriteLine("Good luck! Hit enter to begin!"); Console.ReadLine(); Console.Clear(); //Generate available moves player.SetMoves(); computer.SetMoves(); //Simiulate the battle until there's a winner! do { //Print out the status of both pokemon Console.WriteLine("{0,45}: {1}/{2}", computer.GetType().Name, computer.HP, computer.MaxHP); Console.WriteLine("{0,45}: {1}/{2}", player.GetType().Name, player.HP, player.MaxHP); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); int userAttack = GetUserAttack(player); int computerAttack = Utilities.Utilities.getRandomUniqueIndexArray(computer.Moves.Length, 1)[0]; OrderAttacks(player, computer, userAttack, computerAttack); } while(player.HP != 0 && computer.HP != 0); if(0 == player.HP) Console.WriteLine("It looks like you lost! Better luck next time"); else Console.WriteLine("You won! Congratulations!"); Console.ReadLine(); }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { if(0 == GetModifier(user, opponent)) { this.Damage = 0; } else { if(user.Speed >= opponent.Speed) { if(new Random().Next(100) < 30) { this.Damage = opponent.HP; } else { this.Damage = 0; } } else { this.Damage = 0; } } if(0 == this.Damage) Console.WriteLine(user.GetType().Name + " missed!"); else { this.Attacker = user.GetType().Name + " uses " + this.GetType().Name + ". It's an instant KO!"; opponent.TakeDamage(this); } }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { this.Damage = -(user.MaxHP / 2); this.WasEffective = null; this.WasCritical = false; this.Attacker = user.GetType().Name + " uses " + this.GetType().Name; user.TakeDamage(this); }
/// <summary> /// Orders and executes the attacks /// </summary> /// <param name="playerOne"></param> /// <param name="playerTwo"></param> /// <param name="playerAttackOne"></param> /// <param name="playerAttackTwo"></param> protected void OrderAttacks(Pokemon playerOne, Pokemon playerTwo, int playerAttackOne, int playerAttackTwo) { Console.Clear(); //Purely for UI reasons //TODO Generate who goes first properly Pokemon first = new Random().Next(2) == 0 ? playerOne : playerTwo; Pokemon second = first == playerOne ? playerTwo : playerOne; //Make the first player take their turn if(first == playerOne) first.Moves[playerAttackOne].ImplementAttack(first, second); else first.Moves[playerAttackTwo].ImplementAttack(first, second); if(0 == playerOne.HP || 0 == playerTwo.HP) return; //Make the second player take their turn if(second == playerOne) second.Moves[playerAttackOne].ImplementAttack(second, first); else second.Moves[playerAttackTwo].ImplementAttack(second, first); }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { if(IsAHit(user, opponent)) { this.Damage = GenerateDamage(user.Attack, opponent.Defense, GetModifier(user, opponent)); this.Attacker = user.GetType().Name + " uses " + this.GetType().Name; opponent.TakeDamage(this); } else { Console.WriteLine(user.GetType().Name + " missed!"); this.Attacker = user.GetType().Name + " keeps going and crashes!"; this.Damage = 1; this.WasCritical = false; this.WasEffective = null; user.TakeDamage(this); } }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { if(IsAHit(user, opponent)) { this.Damage = GenerateDamage(user.Attack, opponent.Defense, GetModifier(user, opponent)); this.Attacker = user.GetType().Name + " uses " + this.GetType().Name; opponent.TakeDamage(this); if(0 != RecoilDivider) this.Damage /= RecoilDivider; else this.Damage = user.HP; this.WasEffective = null; this.WasCritical = false; this.Attacker = "The attack recoiled!"; user.TakeDamage(this); } else { Console.WriteLine(user.GetType().Name + " missed!"); } }
/// <summary> /// Gets the index of the attack the user wants to use /// </summary> /// <param name="user">The pokemon to display the attacks of</param> /// <returns>Index of the user's intended attack</returns> protected int GetUserAttack(Pokemon user) { //Generate list of acceptable answers to which move the user wants to use List<BaseAnswer> acceptedAnswers = new List<BaseAnswer>(); Console.WriteLine("Available moves:"); for(int i = 0; i < user.Moves.Length; i++) { Move m = user.Moves[i]; if(null == m) break; string name = m.GetType().Name; Console.WriteLine(i + 1 + ": " + name); acceptedAnswers.Add(new BaseAnswer((i + 1).ToString(), i)); acceptedAnswers.Add(new BaseAnswer(name, i)); } //Standard get the answer from the user BaseAnswer result = ClosedAnswers.AskQuestion("What do you want to use?", acceptedAnswers.ToArray()); Console.Clear(); return (int)result.Attachment; }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { int attacks = new Random().Next(8); if(attacks < 3) attacks = 2; else if(attacks < 6) attacks = 3; else if(6 == attacks) attacks = 4; else if(7 == attacks) attacks = 5; this.Damage = GenerateDamage(user.Attack, opponent.Defense, GetModifier(user, opponent)); for(int i = 0; i < attacks; i++) { this.Attacker = user.GetType().Name + " uses " + this.GetType().Name; opponent.TakeDamage(this); } }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { if(IsAHit(user, opponent)) { this.Damage = opponent.HP / 2; this.WasEffective = null; this.WasCritical = false; this.Attacker = user.GetType().Name + " uses " + this.GetType().Name; opponent.TakeDamage(this); } else { Console.WriteLine(user.GetType().Name + " missed!"); } }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { this.Damage = 40; //This one always does 40 damage no matter what. (A little OP for this game!) this.Attacker = user.GetType().Name + " uses " + this.GetType().Name; opponent.TakeDamage(this); }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { Console.WriteLine(user.GetType().Name + " uses " + this.GetType().Name); Console.WriteLine("It has no effect whatsoever"); }
protected void CommonDamageAttack(Pokemon user, Pokemon opponent) { if(IsAHit(user, opponent)) { this.Damage = GenerateDamage(user.Attack, opponent.Defense, GetModifier(user, opponent)); this.Attacker = user.GetType().Name + " uses " + this.GetType().Name; opponent.TakeDamage(this); } else { Console.WriteLine(user.GetType().Name + " missed!"); } }
public abstract void ImplementAttack(Pokemon user, Pokemon opponent);
protected bool IsAHit(Pokemon user, Pokemon target) { //Return on sure hit/miss moves if(this.Accuracy >= 100) return true; if(this.Accuracy <= 0) return false; //Calculate the percentage chance of this move hitting int chance = (int)(this.Accuracy * (float)user.Accuracy / (float)target.Evasion); if(chance >= 100) return true; //Return sure hit //Generate a random int to determine if the attack will actually land Random r = new Random(); if(chance > r.Next(100)) return true; else return false; }
protected float GetModifier(Pokemon user, Pokemon opponent) { float sameTypeBonus, critical, opponentWeakness, random; Random r = new Random(); //First find the same type attack bonus if(this.AttackType == user.PrimaryType || this.AttackType == user.SecondaryType) sameTypeBonus = 1.5f; else sameTypeBonus = 1; if(r.Next(100) < 5) { WasCritical = true; critical = 2; } else { WasCritical = false; critical = 1; } opponentWeakness = opponent.GetWeaknessToRating(this.AttackType); WasEffective = null; if(opponentWeakness < 1) { WasEffective = false; } else if(opponentWeakness > 1) { WasEffective = true; } //Generate 15% varience so attack damage can vary random = (float)(100 - r.Next(16)) / 100; return (sameTypeBonus * critical * opponentWeakness * random); }
public override void ImplementAttack(Pokemon user, Pokemon opponent) { Type[] types = (Type[])Assembly.GetAssembly(typeof(Move)).GetTypes(); Random r = new Random(); Move proposed = null; do { int index = r.Next(types.Length); if(types[index].IsClass && types[index] != this.GetType() && types[index] != typeof(RepeatedMove) && types[index] != typeof(StandardAttack) && types[index] != typeof(OneHitAttack) && types[index] != typeof(AbsorbAttack) && types[index] != typeof(DoubleHitAttack) && types[index] != typeof(RecoveryAttack) && types[index] != typeof(RecoilAttack) && types[index].IsSubclassOf(typeof(Move))) { proposed = (Move)Activator.CreateInstance(types[index]); } } while(null == proposed); proposed.ImplementAttack(user, opponent); }
/// <summary> /// Runs the fight /// </summary> /// <param name="playerOne">The first combattant</param> /// <param name="playerTwo">The second combattant</param> public abstract void StartFight(Pokemon playerOne, Pokemon playerTwo);