Sign in to follow this  

[.net] Head First C#: Lab #1: A Day at the Races

This topic is 3462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi can anyone test out my entry for the contest. racetrack simulator written in C# You need to have .net 3.5 framework installed on your system since the program does use some new C# 2008 stuff like object initializers. I mainly just want to know if it runs without crashing and what you think of the greyhound running speeds. Thanks.

Share this post


Link to post
Share on other sites
Ran just fine on my laptop (which doubles as a .NET dev machine).

As for the running speeds, I'd try to make the races a little more consistent. The first time I raced the dogs #4 didn't even move. Even now, they don't seem to move reliably as I just had a race where the only dog to move was #2.

My recommendation would be to have the dogs have two items related to movement: stamina and speed. Stamina would decrease over time and when the dog is out their speed would be reduced. Each dog would then have different amounts of stamina and the winner would be the one with the greatest amount. This way the races can appear close without the results ever changing.

Share this post


Link to post
Share on other sites
Quote:
Original post by savagemonitor
Ran just fine on my laptop (which doubles as a .NET dev machine).

As for the running speeds, I'd try to make the races a little more consistent. The first time I raced the dogs #4 didn't even move. Even now, they don't seem to move reliably as I just had a race where the only dog to move was #2.

My recommendation would be to have the dogs have two items related to movement: stamina and speed. Stamina would decrease over time and when the dog is out their speed would be reduced. Each dog would then have different amounts of stamina and the winner would be the one with the greatest amount. This way the races can appear close without the results ever changing.

Thanks for taking the time to test it out and thanks for your suggestions for improvement.
I should've mentioned that there are certain guidelines here I had to follow for the contest which kinda limited me somewhat.
But since the I already submitted this for the contest I can add my own improvements now. For example, I know how to fix the transparency issue when the dogs cross the finish line, now that I'm further in the book by using backcolor = Color.transparent which I can fix now.
I've also found out about System.Threading.Thread.Sleep() which I can also use to adjust the speed.

Share this post


Link to post
Share on other sites
Okay I have decided to release the source code to my racetrack simulator game written in C# now that the contest is over and the winning entry doesn't even follow the guidelines and shouldn't have won as far as I can tell.

I guess they really did just pick the first program they recieved that ran without crashing.
Bet class

From class

Greyhound class

Guy class

I'll probably also be posting my RPG game in C# for lab #2 and
invaders game in C# using Linq for lab #3 shortly if anyone is interested.

Share this post


Link to post
Share on other sites
Quote:
Original post by aku_bedul
daviangel...please post the lab#2 Head First c# source code..thanks..

Okay I'll have to find it first since I haven't worked on it for months.
And even if I do find it wasn't complete since I just couldn't get the weapon class right but what I did get working was pretty cool.
I mean the simple enemy AI worked alot better than I thought it would!

Share this post


Link to post
Share on other sites
thanks daviangel..
its okay if you couldn't get the weapon class right..
i still want to see the source code because i still cannot run the game..

the error says..
" Inconsistent accessibility: parameter type 'Lab2.Game' is less accessible than method 'Lab2.Enemy.Enemy(Lab2.Game, System.Drawing.Point, int)' "

why it says that...what i need to do..??
and where do i need to put this code::

private Game game;
private Random random = new Random();
private void Form1_Load(object sender, EventArgs e)
{
game = new Game(new Rectangle(78, 57, 420, 155));
game.NewLevel(random);
UpdateCharacters();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by aku_bedul
" Inconsistent accessibility: parameter type 'Lab2.Game' is less accessible than method 'Lab2.Enemy.Enemy(Lab2.Game, System.Drawing.Point, int)' "


The access specifier (i.e., private, protected, etc.) of a method's parameter cannot be more "strict" than the access level of the method itself, because then you have no way of calling the method.

For example, suppose that a class A is declared as private, and some method called Func() is declared as public and takes an argument of type A. How will you call the method? If you write:

SomeObj.Func(new A());

You'll get an error saying that you can't create an object of type A because it is declared as private.

Hopefully this explains the logic behind the error message.

The solution, then, is to declare Game with an access specifier that is less "strict" or equal to the access specifier with which Enemy is declared.

Share this post


Link to post
Share on other sites
Well I did find the class diagram here
Unlimited Free Image and File Hosting at MediaFire
Okay I found the code and like I said it's not finished but the monster AI is pretty cool!
http://www.mediafire.com/?tmwjjipwxm5
Malaysia is a beautiful country by the way. I'll never forget the images of lighting from the volcanoes at night when I sailed past it anyways!


[Edited by - daviangel on June 23, 2008 5:21:45 AM]

Share this post


Link to post
Share on other sites
thanks daviangel for the code..
the code is very helpful for me to further study and know a lot of things using C#.. thanks..

can u also post your source code for lab# 3 head first C#..? i really need the code...thanks daviangel...

by the way, for your information, Malaysia doesn't have any volcano at all..i think the country that u mean is "Indonesia" not "Malaysia"..but its okay because Indonesia is near to Malaysia..

Share this post


Link to post
Share on other sites

This topic is 3462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this