🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C# Workshop - Week 1 (Ch. 1 - 4) - Beginners

Started by
91 comments, last by CalebGorde 12 years, 10 months ago
Thanks,

this post added great value for me :)

I hope you'll keep up with next chapters !!

great job
Advertisement
nice explanation Dinner, Thank you :D
Wow! Thanks for this, I was stumped when I had a look at the specification, as I've never programmed before :).

I haven't had a chance to think of any questions yet because I've just got home from work, but I'll read through it tomorrow and think of somethings to ask that I don't understand still.

Again, thanks for simplifying things, I didn't know where to start with the specification and all that complicated talk!
Quote: Original post by Washu
Quote: Original post by SamLowry
Quote: Original post by zKarp
Ok I experimented with the code, because that's how I learn.

I tried intergrading this into a GUI interface.

I keep the same code but change the output.

Instead of writeline I have it Textbox1.text.

My question is, how do I convert an int to a string?

because in order to have z.HP be in that textbox, it has to be a string not int.

I tried

z.HP1 = cstr(z.HP)

but than i get errors

Thanks for the help.

-Zac Karpinski

*Sorry if this isn't suppose to be in here but it's related.

int x = 1;string xs = x.ToString();

Or xs = "" + x;


Or xs = string.Empty + x; [wink]

If you want to be really fancy, see Formatting Numeric Results Table (C# Reference) - although the examples use Console.Write, you could use string.Format.
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
Hey

Is JWalsh going to continue that overview of the chapter? I found it very useful, and it cleared up a lot of things for me...

Ben
Quote: Original post by paulecoyote
Quote: Original post by Washu
Quote: Original post by SamLowry
Quote: Original post by zKarp
Ok I experimented with the code, because that's how I learn.

I tried intergrading this into a GUI interface.

I keep the same code but change the output.

Instead of writeline I have it Textbox1.text.

My question is, how do I convert an int to a string?

because in order to have z.HP be in that textbox, it has to be a string not int.

I tried

z.HP1 = cstr(z.HP)

but than i get errors

Thanks for the help.

-Zac Karpinski

*Sorry if this isn't suppose to be in here but it's related.

int x = 1;string xs = x.ToString();

Or xs = "" + x;


Or xs = string.Empty + x; [wink]

If you want to be really fancy, see Formatting Numeric Results Table (C# Reference) - although the examples use Console.Write, you could use string.Format.


Or xs = (int)TypeDescriptor.GetConverter(typeof(int)).ConvertToInvariantString(x);

:)
Mike Popoloski | Journal | SlimDX
Quote: Original post by Mike.Popoloski
Or xs = (int)TypeDescriptor.GetConverter(typeof(int)).ConvertToInvariantString(x);

:)


You sure about that? xs is a string, and you're casting to an int right before assignment.

The type convertor stuff may be a little too advanced right now - but for anyone daring enough to look it up, it basically is a mechanism to allow you to cast between types when you know the types at runtime rather then compile-time.
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
Quote: Original post by InfernoZeus
Hey

Is JWalsh going to continue that overview of the chapter? I found it very useful, and it cleared up a lot of things for me...

Ben


Yes, I will be continuing it. [smile] I'm working on exercises, etc...for next week currently. The rest of the overview will be going up in pieces.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Quote: Original post by paulecoyote
Quote: Original post by Mike.Popoloski
Or xs = (int)TypeDescriptor.GetConverter(typeof(int)).ConvertToInvariantString(x);

:)


You sure about that? xs is a string, and you're casting to an int right before assignment.

The type convertor stuff may be a little too advanced right now - but for anyone daring enough to look it up, it basically is a mechanism to allow you to cast between types when you know the types at runtime rather then compile-time.


Oops! Somehow I just knew that posting something cheeky like that would come back to bite me in the ass. :) The cast should most certainly be (string). Everything else should still work though.

Yes, type converters are gifts from heaven when trying to parse data from a stream or file. For example, if you have a configuration file that defines several colors and their values, instead of trying to parse that data by hand, just use a string->Color type converter. But your right, it is probably way too complicated right now, especially for the beginner thread.
Mike Popoloski | Journal | SlimDX
Quote: Original post by Dinner
Im not a teacher, just learning too, but maybe i can help a lil (or confuse you even more T_T)

I think you mostly have it correct with what your saying

rand.Attack(Semirhage);
is calling rand attack method and naming Semirhage as the target

Semirhage would be a object that is being passed into rand attack method

This line is directly connected to that
public void Attack(Character enemy)
This is defining the method and saying what objects/variable it accepts

So attack takes a object of type Character and calls it enemy for the duration of the method

Your next line confused me, but basically ill use it all in an example

public void Attack(Character enemy) {

int resistance = enemy.Level + enemy.Armor;
int damageBySword = 10;

enemy.takeDamage(damageBySword - resistance);

}

So
rand has a sword that can deal 10 damage
Semirhage level is 3 and he has a armour of 5, so resistance would be 8
if Semirhage has 10 life, then after rand uses

rand.Attack(Semirhage);

Semirhage life would now be 8
10 damage minus the 8 resistance means 2 damage is then taken from Semirhage life

Hope that helps at all


Thanks Dinner,

For some reason my ability to grasp all of this is difficult, however your example really cleared things up.

This topic is closed to new replies.

Advertisement