Anyone here know a thing or two about C#?

Recommended Videos

DigitalAtlas

New member
Mar 31, 2011
836
0
0
I'm trying to teach myself C#, however, in a console application that lets users build a character in an RPG I'm trying to make I am beyond stuck. Coding is in the spoiler below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



class MakeACharacter
{
public static void Main()
{
Character c1 = new Character();
c1.Name = "Ralph";
c1.Race = "Human";
c1.Classes = "Hunter";
Console.WriteLine("Ralph, Human, Hunter", "Name, Race, Classes");
Display(c1);
}
public static void Display(Character c1);
{
Console.WriteLine("Ralph, Human, Hunter", "Name, Race, Classes");
}

}


public class Character
{//start character class

//Fields
string name, race, classes;

int intellect, strength, agility, cunning, stealth;







//constructor
public Character(string x,string y,string z)
{
Name = x;
Race = y;
Classes = z;
}

public string Name
{//start name prop

get
{
return name;
}
set
{
name = value;
}


}//end name prop

public string Race
{//start race prop


get
{
return race;
}
set
{
race = value;
}


}//end name prop

public string Classes
{//start classes prop

get
{
return classes;
}
set
{
classes = value;


if (classes == "Hunter" && race == "Human")
intellect = 40;
strength = 35;
agility = 30;
cunning = 40;
stealth = 30;

if (classes == "Warrior" && race == "Human")
intellect = 40;
strength = 35;
agility = 40;
cunning = 40;
stealth = 20;

if (classes == "Cleric" && race == "Human")
intellect = 55;
strength = 30;
agility = 30;
cunning = 45;
stealth = 15;

if (classes == "Hunter" && race == "Dwarf")
intellect = 30;
strength = 70;
agility = 35;
cunning = 15;
stealth = 25;

if (classes == "Warrior" && race == "Dwarf")
intellect = 30;
strength = 60;
agility = 55;
cunning = 20;
stealth = 10;

if (classes == "Cleric" && race == "Dwarf")
intellect = 45;
strength = 70;
agility = 35;
cunning = 25;
stealth = 0;

if (classes == "Hunter" && race == "Elf")
intellect = 35;
strength = 30;
agility = 45;
cunning = 25;
stealth = 40;

if (classes == "Warrior" && race == "Elf")
intellect = 35;
strength = 20;
agility = 45;
cunning = 35;
stealth = 40;

if (classes == "Cleric" && race == "Elf")
intellect = 55;
strength = 15;
agility = 45;
cunning = 20;
stealth = 40;
}
}

public int Intellect
{//start intellect prop

get
{
return intellect;
}


}//end intellect prop

public int Strength
{//start strength prop

get
{
return strength;
}


}//end strength prop

public int Agility
{//start agility prop

get
{
return agility;
}


}//end agility prop

public int Cunning
{//start cunning prop

get
{
return cunning;
}


}//end cunning prop


public int Stealth
{//start stealth prop

get
{
return stealth;
}


}//end stealth prop



public void Output()
{
Console.WriteLine (Name);
Console.WriteLine (Race);
Console.WriteLine (Classes);
Console.WriteLine(Intellect);
Console.WriteLine (Strength);
Console.WriteLine (Agility);
Console.WriteLine (Cunning);
Console.WriteLine (Stealth);


}


}//end character

Can anyone offer assistance?
 

An Inferior

Regular Member
Jun 7, 2010
30
0
11
Where exactly are you stuck? Give us a starting point to go off of...
(also, you forgot to close your /spoiler tag)
 

Tharwen

Ep. VI: Return of the turret
May 7, 2009
9,145
0
41
You haven't actually said what's wrong with it. Why are you stuck?
 

TheIronRuler

New member
Mar 18, 2011
4,283
0
0
It's a bit difficult to read in one line...
Last time I checked you should get an error description and line number when you fail to run this.
Why would you try and make a text rpg? Do people seriously enjoy playing in a DoS-like console system?
Advice - set the stats in the beggining and have the race/class bull make changes to it.
Did you balance the classes-races prior to writing this down?
What is the point in this?
 

DigitalAtlas

New member
Mar 31, 2011
836
0
0
Tharwen said:
You haven't actually said what's wrong with it. Why are you stuck?
The beginning bit needs to 'create a character.' The site I'm working with told me to use the following sample code to go by but i'm just lost.

{
public static void Main()
{
Circle c1 = new Circle();
Circle c2 = new Circle();
Circle c3 = new Circle();
c1.Radius = 2;
c2.Radius = 150;
Console.WriteLine("{0,10}{1,10}{2,10}",
"Radius", "Diameter", "Area");
Display(c1);
Display(c2);
Display(c3);
}
 

DigitalAtlas

New member
Mar 31, 2011
836
0
0
TheIronRuler said:
It's a bit difficult to read in one line...
Last time I checked you should get an error description and line number when you fail to run this.
Why would you try and make a text rpg? Do people seriously enjoy playing in a DoS-like console system?
Advice - set the stats in the beggining and have the race/class bull make changes to it.
Did you balance the classes-races prior to writing this down?
What is the point in this?
It's just a sample exercise from this tutorial site I'm working with. Obviously, I don't give a flying sh*t about the rpg. however, I do want to succeed in learning the program.

Instructions below:

You will, in MakeACharacter, create a method that displays your characters info as follows:
Name: Ralph
Race: Human
Class: Hunter


Intellect

Strength

Agility

Cunning

Stealth
40

35

30

34

30
 

TheIronRuler

New member
Mar 18, 2011
4,283
0
0
DigitalAtlas said:
TheIronRuler said:
It's a bit difficult to read in one line...
Last time I checked you should get an error description and line number when you fail to run this.
Why would you try and make a text rpg? Do people seriously enjoy playing in a DoS-like console system?
Advice - set the stats in the beggining and have the race/class bull make changes to it.
Did you balance the classes-races prior to writing this down?
What is the point in this?
It's just a sample exercise from this tutorial site I'm working with. Obviously, I don't give a flying sh*t about the rpg. however, I do want to succeed in learning the program.
I truely think this is bullshit.
You can't 'learn' this way, but using this type of imitating what you see. You need to understadn what every line says and how it affects the program.
EDIT: would you mind giving me a link to that site?
 

Tharwen

Ep. VI: Return of the turret
May 7, 2009
9,145
0
41
DigitalAtlas said:
Tharwen said:
You haven't actually said what's wrong with it. Why are you stuck?
The beginning bit needs to 'create a character.' The site I'm working with told me to use the following sample code to go by but i'm just lost.

{
public static void Main()
{
Circle c1 = new Circle();
Circle c2 = new Circle();
Circle c3 = new Circle();
c1.Radius = 2;
c2.Radius = 150;
Console.WriteLine("{0,10}{1,10}{2,10}",
"Radius", "Diameter", "Area");
Display(c1);
Display(c2);
Display(c3);
}
As far as I can tell by just reading it, the code in the OP should display the following:

Code:
Ralph, Human, Hunter
Ralph, Human, Hunter

It doesn't show the "Name, Race, Classes" bit because that's after the comma, and the comma tells the program that you're giving it two strings instead of one (when the function only asks for one). Also, you've got that same line written twice - once in the main function and once in
Code:
Display()
.

What I suspect you want is for it to show something like this:

Code:
Name: Ralph
Race: Human
Class: Hunter

For that you'd need to use:

Code:
public void Display(Character c1) //Note that there shouldn't be a semicolon on this line
{
    Console.WriteLine("Name: " + c1.Name);
    Console.WriteLine("Race: " + c1.Race);
    Console.WriteLine("Class: " + c1.Class);
}

There are some other things I would personally choose to clean up too, but I'll not mention them for now or it might get too confusing for just a single lesson :p

EDIT: Modified it a bit after noticing a slight error I made.

EDIT 2: Looking over your program again, most of it won't work. I don't think you understand Object-Oriented Programming very well at all and this is possibly too advanced.
 

Smooth Operator

New member
Oct 5, 2010
8,162
0
0
WTH... you picked the worst possible way of learning anything, don't ever jump into specific programs until you know all the basics.

So find some proper step by step tutorials, there are tons of stuff out there on every language imaginable.
 

Lukeje

New member
Feb 6, 2008
4,048
0
0
Tharwen said:
Lukeje said:
DonMartin said:


You're welcome, my good man.
Unfortunately that's C♯, not C#.
C# is usually pronounced C-Sharp, though...

I don't know. I just don't know.
Yeah, I know. It's supposed to be written with a sharp sign instead of a hash where possible as well, but no-one ever does.