Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Need help creating a character system

So I just finished Brackey's C# tutorial and am making a game where you pick two characters and battle each other. I finished creating the characters and their stats, with a simple attack message, and tried to create a system using if statements to create the character class in character slot one. I'm not sure if this is the best way I should do it, but it's the only way I could think of. The problem comes in when I am creating a character type inside the if statement and trying to now call it in other classes. (I'm pretty new to programming, learned some swift a year ago, and just recently got into C#)


Here is the code:


using System;

namespace Program

{

  public class Battle

  {

    public static bool Stuns;

    public static bool Critical;

    public static bool Miss;

    public string Char1;

    public string Char2;


    public void getchar1()

    {

      Console.WriteLine("Please enter the first character:");

      Char1 = Console.ReadLine();

      if (Char1 == "Knight")

      {

        knight character1 = new knight();

      } else if (Char1 == "Mage")

      {

        mage character1 = new mage();

      } else if (Char1 == "Hammer")

      {

        hammer character1 = new hammer();

      } else if (Char1 == "Archer")

      {

        archer character1 = new archer();

      }

       

    }

  }

  public class knight

  {

    public int knightHealth = 15;

    public int knightAttack = 4;

    public int knightDefence = 4;

    public int knightSpeed = 7;

    public int knightRegeneration = 10;

    public void Slash()

    {

      Console.WriteLine("Knight attacked using 'Slash'");

      Console.WriteLine("'Slash' did " + knightAttack + " damage.");


    }

  }

  public class mage

  {

    public int mageHealth = 17;

    public int mageAttack = 5;

    public int mageDefense = 0;

    public int mageSpeed = 4;

    public int mageRegeneration = 7;

    public void Cast()

    {

      Console.WriteLine("Mage attacked using 'Cast'");

      Console.WriteLine("'Cast' did " + mageAttack + " damage.");

    }

  }

  public class hammer

  {

    public int hammerHealth = 20;

    public int hammerAttack = 7;

    public int hammerDefense = 2;

    public int hammerSpeed = 3;

    public int hammerRegeneration = 3;

    public void Smash()

    {

      Console.WriteLine("Hammer attacked using 'Smash'");

      Console.WriteLine("'Smash' did " + hammerAttack + " damage.");

    }

  }

  public class archer

  {

    public int archerHealth = 13;

    public int archerAttack = 3;

    public int archerDefense = 3;

    public int archerSpeed = 5;

    public int archerRegeneration = 5;

    public void Shoot()

    {

      Console.WriteLine("Archer attacked using 'Shoot'");

      Console.WriteLine("'Shoot' did " + archerAttack + " damage.");

    }

  }

  class program

  {

    static void Main()

    {

      Battle start = new Battle();

      start.getchar1();

      Console.WriteLine("Player One is a " + start.Char1);

       

       

      Console.ReadKey();

    }

  }

}

Sign In or Register to comment.