Hello there, I am new to this website and this is my first forum post here.
I'm using c# because the FAQ on this site recommended it for beginners though I already know html, css, a little hlsl and very little java. My problem is getting values linked to a class from one method into another.
I just started learning c# yesterday so this may seem like a silly problem.
Here is the code so far.
I want to get all the "player.xxxx" values from the characterCreation method to the runGame method.
namespace TextBasedRPGv0._2
{
class Game
{
public class Character
{
public float maxHealth;
public float currentHealth;
public float maxMana;
public float currentMana;
public float Damage;
public float Defence;
public int level;
public int strength;
public int stamina;
public int agility;
public int speed;
public int intelligence;
public int wisdom;
}
public class Player: Character
{
public string userName;
public string userProf;
public string Warrior;
public string Rogue;
public string Mage;
public float exp;
public float expUntilNextLevel;
public float expNextLevel;
}
public static void characterCreation()
{
int newPlayerLoop = 1;
while (newPlayerLoop != 0)
{
Player player;
player = new Player();
Console.WriteLine("Name your character.");
player.userName = Console.ReadLine();
Console.WriteLine("");
int chooseProf = 1;
Console.WriteLine("Choose your character's profession. (Warrior, Rogue or Mage)");
while (chooseProf != 0)
{
player.userProf = Console.ReadLine();
switch (player.userProf)
{
case "Warrior":
player.level = 1;
player.exp = 0;
player.strength = 7;
player.stamina = 6;
player.agility = 4;
player.speed = 4;
player.intelligence = 3;
player.wisdom = 3;
player.maxHealth = ((player.strength + player.stamina) * (player.level * 2)) + ((player.agility + player.speed + player.intelligence + player.wisdom) / (player.level * 2));
player.currentHealth = player.maxHealth;
player.maxMana = ((player.stamina + player.wisdom) * (player.level * 2)) + ((player.agility + player.speed + player.strength + player.intelligence) / (player.level * 2));
player.currentMana = player.maxMana;
player.Damage = ((player.strength * player.agility) - (player.agility / (player.level * 2) + player.speed)) / 2;
player.Defence = 0.05f;
Console.WriteLine("You are a level " + player.level + " Warrior with:");
chooseProf = 0;
break;
case "Rogue":
player.level = 1;
player.exp = 0;
player.strength = 3;
player.stamina = 5;
player.agility = 7;
player.speed = 6;
player.intelligence = 4;
player.wisdom = 2;
player.maxHealth = ((player.strength + player.speed) * (player.level * 2)) + ((player.agility + player.stamina + player.intelligence + player.wisdom) / (player.level * 2));
player.currentHealth = player.maxHealth;
player.maxMana = ((player.speed + player.wisdom) * (player.level * 2)) + ((player.agility + player.intelligence + player.strength + player.stamina) / (player.level * 2));
player.currentMana = player.maxMana;
player.Damage = ((player.strength * player.agility) + (player.agility / (player.level * 2) + player.speed)) / 2;
player.Defence = 0.04f;
Console.WriteLine("You are a level " + player.level + " Rogue with:");
chooseProf = 0;
break;
case "Mage":
player.level = 1;
player.exp = 0;
player.strength = 2;
player.stamina = 3;
player.agility = 4;
player.speed = 5;
player.intelligence = 6;
player.wisdom = 7;
player.maxHealth = ((player.strength + player.wisdom) * (player.level * 2)) + ((player.agility + player.speed + player.intelligence + player.stamina) / (player.level * 2));
player.currentHealth = player.maxHealth;
player.maxMana = ((player.intelligence + player.wisdom) * (player.level * 2)) + ((player.agility + player.speed + player.strength + player.stamina) / (player.level * 2));
player.currentMana = player.maxMana;
player.Damage = ((player.intelligence * player.agility) - (player.agility / (player.level * 2)) + player.wisdom) / 2;
player.Defence = 0.03f;
Console.WriteLine("You are a level " + player.level + " Mage with:");
chooseProf = 0;
break;
}
}
Console.WriteLine(player.strength + " strength");
Console.WriteLine(player.stamina + " stamina");
Console.WriteLine(player.agility + " agility");
Console.WriteLine(player.speed + " speed");
Console.WriteLine(player.intelligence + " intelligence");
Console.WriteLine(player.wisdom + " wisdom");
Console.WriteLine("Your max health is " + player.maxHealth + ".");
Console.WriteLine("Your max mana is " + player.maxMana + ".");
Console.WriteLine("Your damage is " + player.Damage + ".");
Console.WriteLine("(press enter to continue)");
Console.ReadLine();
Console.Clear();
newPlayerLoop = 0;
}
}
public static void runGame()
{
Console.WriteLine(player.userName);
}
public static void Main(string[] args)
{
characterCreation();
runGame();
Console.ReadLine();
}
}
}
Like I said, I'm new to this so the answer is probably very obvious to someone with c# experience.
Thanks in advance.