08-05-2010, 12:16 PM
I've got this same thread on HF
Hey SupportForums, Simplicity here with my first contribution to this forum.
I'm sure some of you guys have always wondered about game designing with C++. Well To start off you sure do need a good level of knowledge of the Language. This is pretty powerful code if you know what I mean.
I've decided to kind of open this thread as a example and help thread of gaming with C++. I've written a well coded BASIC Battleship game (no graphics). It's a very basic application you can run in cmd.
If you want to learn to Write games and make pimp games with C++ You should be able to write up a code like this in a few hours.
Heres the game source:
http://pastebin.com/V3jWjXtg
Feel free to Edit it anyway you want and play around with it.
You got questions about programming basic games with C++ please post here and or if your serious about programming Games Contact me at
iMiracle@live.com / rl257@yahoo.com / bloddyharry_rsportal@live.com
I've had alot of suggestions to change my code, and alot of people telling me 30k line of code isn't needed.
I agree in that case, here are some of the suggestios I've gotten.
Store ships in arrays of integers like so:
When placing the ship, fill the array as needed:
Now you have the numbers for the spaces the ship is at... When doing checks for hits, your code can be like the following:
Doing this alone will reduce the number of lines by around 18 thousand.
At the end of the function, you have a line "void quitGame();". Remove the "void" from there, otherwise you're just declaring that a function with the name "quitGame()" of type void exists. If you want to call the function, it's just "quitGame();".
2. Next section is where you set 2 spaces to B and A depending on the space targeted. Once again you have a lot of code here where it's not needed.
You can get the row to be used by simple mathematics:
Please give more suggestions and feedback please, thanks.
Hey SupportForums, Simplicity here with my first contribution to this forum.
I'm sure some of you guys have always wondered about game designing with C++. Well To start off you sure do need a good level of knowledge of the Language. This is pretty powerful code if you know what I mean.
I've decided to kind of open this thread as a example and help thread of gaming with C++. I've written a well coded BASIC Battleship game (no graphics). It's a very basic application you can run in cmd.
If you want to learn to Write games and make pimp games with C++ You should be able to write up a code like this in a few hours.
Heres the game source:
http://pastebin.com/V3jWjXtg
Feel free to Edit it anyway you want and play around with it.
You got questions about programming basic games with C++ please post here and or if your serious about programming Games Contact me at
iMiracle@live.com / rl257@yahoo.com / bloddyharry_rsportal@live.com
I've had alot of suggestions to change my code, and alot of people telling me 30k line of code isn't needed.
I agree in that case, here are some of the suggestios I've gotten.
Store ships in arrays of integers like so:
Code:
int p1battleship[5] = { 0, 0, 0, 0, 0 };
When placing the ship, fill the array as needed:
Code:
int startspace = 22;
for (int i = 0; i < 5; i++) {
p1battleship[i] = startspace;
startspace++;
}
Now you have the numbers for the spaces the ship is at... When doing checks for hits, your code can be like the following:
Code:
int target = 22;
for (int i = 0; i < 5; i++) {
if (p1battleship[i] == target) {
printf("Hit!\n");
hit++;
break;
}
}
Doing this alone will reduce the number of lines by around 18 thousand.
At the end of the function, you have a line "void quitGame();". Remove the "void" from there, otherwise you're just declaring that a function with the name "quitGame()" of type void exists. If you want to call the function, it's just "quitGame();".
2. Next section is where you set 2 spaces to B and A depending on the space targeted. Once again you have a lot of code here where it's not needed.
You can get the row to be used by simple mathematics:
Code:
// Tens digit determines the row
switch (target / 10) {
case 1:
// Row 1
case 2:
// Row 2
...
}
Please give more suggestions and feedback please, thanks.