I got like 15 or more classes total. I guess i can post the whole thing. It's gonna be rough looking through it all in the little code window. This class here selects how many monsters, and which type you fight. Be advised. This code is sloppy and poorly desgined as it is right now. Adding in the new features has messed it up bad. I just want to get it running again so i can start fixing it. This is my first game so it's been difficult. And i just started learning C# on monday so be nice :) lol. It's going well, i think ...
namespace RpgGame
{
class Program
{
static void Main()
{
MainGame maingame = new MainGame();
}
}
}
namespace RpgGame
{
class MainGame
{
Hero myhero;
string answer;
public MainGame()
{
myhero = new Hero();
Hero.Initialize(myhero);
BasicGameLoop();
}
public void BasicGameLoop()
{
//int gold=0, xp=0;
string action;
Fight fight;
Inn inn;
do
{
MainMenu Menu = new MainMenu();
action = Menu.PrintMainMenu();
if (action == "F")
{
fight = new Fight();
fight.fight(myhero);
}
if (action == "R")
{
inn = new Inn();
inn.inn(myhero);
}
answer = Console.ReadLine();
}
while (myhero.isAlive==true);
}
}
}
namespace RpgGame
{
class MainMenu
{
string MenuChoice;
public string PrintMainMenu()
{
Console.Clear();
Console.Write(@"
***********************************************
R(rest/inn) F(fight) B(buy) I(inventory)
************************************************");
Console.WriteLine("");
MenuChoice = Console.ReadLine();
switch (MenuChoice)
{
case "r":
case "R":
MenuChoice = "R";
break;
case "f":
case "F":
MenuChoice = "F";
break;
case "b":
case "B":
MenuChoice = "B";
break;
case "i":
case "I":
MenuChoice = "I";
break;
default:
Console.WriteLine("??????????");
Console.ReadLine();
PrintMainMenu();
break;
}
return MenuChoice;
}
}
}
namespace RpgGame
{
class Fight
{
Battle battle;
int monsterSELECT;
List<Character> Monster;
public void fight(Hero myhero)
{
bool KeepFighting = false;
int NumMonster = 0, NumMonster2;
Random rand = new Random();
NumMonster2 = rand.Next(1, 4);
Monster = new List<Character>();
do
{
monsterSELECT = rand.Next(1, 4);
switch (monsterSELECT)
{
/*case 0:
Monster monster = new Monster();
Monster.Add = new Monster
battle = new Battle(myhero, monster);
break;*/
case 1:
//Barbarian barbarian = new Barbarian();
Barbarian barbarian = new Barbarian();
Monster.Add = barbarian;
break;
case 2:
//Slime slime = new Slime();
Monster.Add = (new Slime());
break;
case 3:
//Mage mage = new Mage();
Monster.Add = (new Mage());
break;
}
NumMonster++;
} while (KeepFighting = false && NumMonster != NumMonster2);
battle = new Battle(myhero, Monster);
}
}
}
namespace RpgGame
{
class Battle
{
int flee = 0;
string userchoice;
string monsterchoice;
public Battle(Hero hero, List<Character> monsters)
{
Console.WriteLine("{0} is facing: ", hero.Identifier);
foreach (Character monster in monsters)
{
Console.WriteLine("{0}, ", monster.Identifier);
}
BattleLoop(hero, monsters);
}
public void BattleLoop(Hero hero, List<Character> monsters)
{
bool someonetofight = true;
do
{
BattleHelper battleHelper = new BattleHelper();
battleHelper.PrintStatus(hero);
userchoice = battleHelper.PrintChoice();
if (userchoice == "f" || userchoice == "F")
continue;
Console.WriteLine();
if (userchoice == "a" || userchoice == "A")
{
int MonsterTarget = 0;
MonsterTarget = Target.target(monsters);
battleHelper.ProcessChoice(userchoice, hero, monsters[MonsterTarget]);
}
if (userchoice == "d" || userchoice == "D")
{
hero.defended = true;
}
if (userchoice == "s" || userchoice == "S")
{
Spell spell = new Spell();
string SpellChoice = "";
SpellChoice = spell.SpellPrint();
if (SpellChoice == "F" || SpellChoice == "M")
{
foreach (Character defender in monsters)
{
battleHelper.ProcessChoice(SpellChoice,hero, defender);
}
}
}
foreach (Character monster in monsters)
{
monster.isAlive = battleHelper.CheckHealth(monster.CurrentHealth);
if (monster.isAlive == true)
{
monsterchoice = monster.AI();
battleHelper.ProcessChoice(monsterchoice, monster, hero);
}
}
hero.isAlive = battleHelper.CheckHealth(hero.CurrentHealth);
Console.ReadLine();
Console.Clear();//This clears our screen so the next turn is a fresh screen
someonetofight = true;
someonetofight = Isalive.isalive(monsters);
} while (hero.isAlive == true && someonetofight == true);
if (hero.isAlive == true)
Console.WriteLine("You won!");
if (hero.isAlive == false)
Console.WriteLine("You Died!");
}
}
}
namespace RpgGame
{
class BattleHelper
{
int damage;
Random rand;
public void PrintStatus(Character hero)
{
Console.Write(@"
********************************
HP/MaxHP MP/MaxMP
{0}: {1}/{2}hp {3}/{4}mp
********************************
", hero.Identifier, hero.CurrentHealth, hero.MaxHealth, hero.CurrentMagic, hero.MaxMagic);
}
public string PrintChoice()
{
string choice;
Console.WriteLine();
Console.Write(@"
_____________________
Please choose an action:
(A)ttack:
(D)efend:
(S)pell:
(F)lee:
_____________________");
Console.WriteLine();
choice = Console.ReadLine();
return choice;
}
public void ProcessChoice(string choice, Character attacker, Character defender)
{
switch (choice)
{
case "A":
case "a":
Console.WriteLine();
Console.WriteLine("{0} attacks!", attacker.Identifier);
DealDamage(attacker, defender);
defender.CurrentHealth -= damage;
Console.WriteLine("{0} hits the {1} for {2}hp of damage"
, attacker.Identifier, defender.Identifier, damage);
attacker.defended = false;
break;
case "D":
case "d":
Console.WriteLine();
Console.WriteLine("{0} defends!", attacker.Identifier);
attacker.defended = true;
break;
case "F":
case "f":
Console.WriteLine();
Console.WriteLine("{0} flees!", attacker.Identifier);
break;
case "S":
case "s":
int SpellDamage;
Spell spell = new Spell();
string SpellChoice="";
if (attacker.Monster == false)
SpellChoice = spell.SpellPrint();
if (attacker.Monster == true)
SpellChoice = attacker.SpellAI();
SpellDamage = spell.SpellProcess(SpellChoice, attacker, defender);
defender.CurrentHealth -= SpellDamage;
break;
default:
Console.WriteLine("I'm sorry, I didn't recognize that.");
Console.WriteLine();
choice = PrintChoice();
Console.WriteLine();
ProcessChoice(choice, attacker, defender);
break;
}
}
public int DealDamage(Character attacker, Character defender)
{
int max;
int min;
rand = new Random();
max = attacker.AttackDamage - defender.Defense;
if (attacker.defended == true)
max = (int)(max * 1.8);
if (defender.defended == true)
max /= (int) 2;
if (max <= 0)
{
max = 1;
}
min = (int)(attacker.AttackDamage * .8) - defender.Defense;
if (attacker.defended == true)
min = (int)(min * 1.2);
if (defender.defended == true)
min = (int)(min / 2);
if (min <= 0)
{
min = 1;
}
damage = rand.Next(min, max);//calculate the damage
return damage;//send it on back
}
public bool CheckHealth(int health)
{
bool alive;
if (health > 0)
{
alive = true;
}
else
{
alive = false;
}
return alive;
}
}
}
}
namespace RpgGame
{
class Inn
{
public void inn(Hero myhero)
{
string answer;
Console.Clear();
Console.Write(@"
************************************
{0}/{1} HP {2}/{3}MP
************************************
(R)Rest for 20 gold?
(E)Eat for 5 gold?
*************************************",myhero.CurrentHealth,myhero.MaxHealth,myhero.CurrentMagic,myhero.MaxMagic);
answer = Console.ReadLine();
switch (answer) {
case "r":
case "R":
Rest(myhero);
break;
case "e":
case"E":
Eat(myhero);
break;
}
}
public void Rest(Hero myhero){
myhero.CurrentHealth = myhero.MaxHealth;
Console.WriteLine("Fully Healed!!!");
Console.ReadLine();
}
public void Eat(Hero myhero){
myhero.CurrentHealth += 6;
Console.WriteLine("Gain 6HP!!");
if (myhero.CurrentHealth > myhero.MaxHealth)
myhero.CurrentHealth = myhero.MaxHealth;
Console.ReadLine();
}
}
}
namespace RpgGame
{
public class Character
{
protected Random rand;
protected int AiAttack, AiDefend, AiSpell;
public int CurrentHealth, MaxHealth, CurrentMagic;
public int MaxMagic, Strength, Defense, Agility;
public int Experience, Gold, AttackDamage;
public string Identifier;
public bool isAlive, defended = false, Monster;
public Character()
{
}
public virtual string AI()
{
string choice = "";
return choice;
}
public virtual string SpellAI()
{
string SpellChoice = "";
return SpellChoice ;
}
}
}
namespace RpgGame
{
class Hero : Character
{
public Hero()
{
}
public static void Initialize(Hero hero)
{
hero.CurrentHealth = 18;
hero.MaxHealth = 18;
hero.CurrentMagic = 8;
hero.MaxMagic = 8;
hero.Strength = 10;
hero.Defense = 3;
hero.Agility = 6;
hero.Experience = 0;
hero.Gold = 0;
Console.WriteLine("What is your Hero's name?");
hero.Identifier = Console.ReadLine();
hero.isAlive = true;
hero.AttackDamage = hero.Strength;
hero.Monster = false;
}
}
}
namespace RpgGame
{
class Barbarian : Character
{
public Barbarian()
{
base.AiAttack = 75;
base.AiDefend = 100;
base.AiSpell = 0;
base.CurrentHealth = 25;
base.MaxHealth = 25;
base.CurrentMagic = 0;
base.MaxMagic = 0;
base.Strength = 8;
base.Defense = 3;
base.Agility = 4;
base.Experience = 10;
base.Gold = 5;
base.Identifier = "Barbarian";
base.isAlive = true;
base.AttackDamage = Strength;
base.Monster = true;
}
public override string AI()
{
string choice;
int ainumberchoice;
rand = new Random();
ainumberchoice = rand.Next(1, 100);
if (ainumberchoice < base.AiAttack)
{
choice = "A";
}
else if (ainumberchoice <= base.AiDefend && ainumberchoice >= base.AiAttack)
{
choice = "D";
}
else if (ainumberchoice < base.AiSpell && ainumberchoice > base.AiDefend)
{
choice = "S";
}
else
{
choice = "F";
}
return choice;
}
}
}
namespace RpgGame
{
class Slime : Character
{
public Slime()
{
base.AiAttack = 80;
base.AiDefend = 100;
base.AiSpell = 0;
base.CurrentHealth = 10;
base.MaxHealth = 10;
base.CurrentMagic = 0;
base.MaxMagic = 0;
base.Strength = 3;
base.Defense = 5;
base.Agility = 4;
base.Experience = 5;
base.Gold = 3;
base.Identifier = "Slime";
base.isAlive = true;
base.AttackDamage = Strength;
base.Monster = true;
}
public override string AI()
{
string choice;
int ainumberchoice;
rand = new Random();
ainumberchoice = rand.Next(1, 100);
if (ainumberchoice < base.AiAttack)
{
choice = "A";
}
else if (ainumberchoice <= base.AiDefend && ainumberchoice >= base.AiAttack)
{
choice = "D";
}
else if (ainumberchoice < base.AiSpell && ainumberchoice > base.AiDefend)
{
choice = "S";
}
else
{
choice = "F";
}
return choice;
}
}
}
namespace RpgGame
{
public partial class Mage : Character
{
public Mage()
{
base.AiAttack = 10;
base.AiDefend = 20;
base.AiSpell = 100;
base.CurrentHealth = 15;
base.MaxHealth = 15;
base.CurrentMagic = 10;
base.MaxMagic = 10;
base.Strength = 5;
base.Defense = 2;
base.Agility = 4;
base.Experience = 7;
base.Gold = 8;
base.Identifier = "Mage";
base.isAlive = true;
base.AttackDamage = Strength;
base.Monster = true;
}
public override string AI()
{
string choice;
int ainumberchoice;
rand = new Random();
ainumberchoice = rand.Next(1, 100);
if (ainumberchoice < base.AiAttack)
{
choice = "A";
}
else if (ainumberchoice <= base.AiDefend && ainumberchoice >= base.AiAttack)
{
choice = "D";
}
else if (ainumberchoice < base.AiSpell && ainumberchoice > base.AiDefend)
{
choice = "S";
}
else
{
choice = "F";
}
return choice;
}
public override string SpellAI()
{
string SpellChoice = "";
Random rand = new Random();
int SC;
SC = rand.Next(0, 3);
switch (SC)
{
case 0:
SpellChoice = "F";
break;
case 1:
SpellChoice = "M";
break;
case 2:
SpellChoice = "H";
break;
}
return SpellChoice;
}
}
}
namespace RpgGame
{
class Target
{
public static int target(List<Character> monsters)
{
int target = 0;
string StringTarget = "";
int count = 0;
foreach (Character monster in monsters)
{
Console.WriteLine(
@"****************************
Pick a target
******************************");
Console.WriteLine("{0} **** {1}", monster.Identifier, count);
count++;
}
StringTarget = Console.ReadLine();
target = int.Parse(StringTarget);
return target;
}
}
}
namespace RpgGame
{
class Isalive
{
public static bool isalive(List<Character> monsters)
{
bool left = false;
foreach (Character monster in monsters)
{
if (monster.CurrentHealth > 0)
{
left = true;
}
}
return left;
}
}
}