• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tome Steve Srsan

C++ problems

17 posts in this topic

Hello everyone i was just wondering what i'm doing wrong with my code, as when i try to compile it comes up with what i describe as code dump, there are a few other problems but once i get the code dump out the way i should be able to fix everything else
[CODE]
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Hello everyone and welcome to this game.\n";
cout << "In this game the aim is to attack the wolf with what you think is the best attack, goodluck!\n";
int healthme;
int healthit;
for(healthme=500;healthme<0; ); (healthit=500; healthit<0; ) {
cout << "Your Health is " << healthme << " and the wolfs health is " << healthit << "\n";
cout << "So, what attack do you want to hit the wolf with a weapon or with magic?";
string attack;
cin >> attack;

if(attack=="a weapon" , "weapon" , "the weapon") {
cout << "What part of the wolf do you want to attack, the body or the head?";
string bodypart;
cin >> bodypart;
if(bodypart == "the body" , "body") {
healthit=healthit-50;
cout << "You hit the wolf!\n";
}

else if(bodypart == "the head" , "head") {
healthit = healthit-100;
healthme=healthme-20;
cout << "It was a good hit, but it bites back!\n";
}
else cout << "you missed! (spelt it wrong) \n";
}
else if(attack =="magic" , "with magic"){
cout << "what element would you like to attack with? fire lightning, ice, water, or earth?\n";
string magic;
cin << magic;
if(magic == "fire"){
healthit=healthit-50;
cout << "It does good damage!\n";
}
else if(magic == "lightning"){
healthit=healthit-100;
cout << "It does amazing damage!\n";
}

else if(magic == "earth"){
healthit= healthit-70;
cout << "It hits hard!\n";
}
else if(magic=="ice") {
healthit = healthit-30;
cout << "It doesn't seem to hurt much!\n";
}
else if(magic=="water") {
healthit = healthit - 10;
cout << "It seems unaffected!\n";
}
else cout << "You missed! (spelt it wrong!)\n";
}
else cout << "you took to long! (spelt wrong!)";
if(healthit<=100){
cout << "He is Angry now and doing more damage!\n";
healthme = healthme-75;
}
else {
cout << "The wolf goes out to attack!\n";
healthme= healthme-50;
}
}
if(healthme<=0) cout << "Your Dead... Game over i guess?";
else cout << "The wolf is dead! You Win!";

return 0;
}
[/CODE]

Sorry about the neatness but would be appreciated if someone could tell me what i'm doing wrong, thank you in advance [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Big T06
0

Share this post


Link to post
Share on other sites
Can you post the compilation error which you describe as code dump, or just the beginning and end of the first error it if it's very large.
0

Share this post


Link to post
Share on other sites
You should post the error message. Even if it makes no sense to you, chances are there is some useful information in there.
0

Share this post


Link to post
Share on other sites
You seem to have 2 sets of brackets after for, I don't see the point and as far as my C++ knowledge goes you are suppose to have just one.

[color=#000088]for[/color][color=#666600]([/color][color=#000000]healthme[/color][color=#666600]=[/color][color=#006666]500[/color][color=#666600];[/color][color=#000000]healthme[/color][color=#666600]<[/color][color=#006666]0[/color][color=#666600];[/color][color=#000000] [/color][color=#666600]);[/color][color=#000000] [/color][color=#666600]([/color][color=#000000]healthit[/color][color=#666600]=[/color][color=#006666]500[/color][color=#666600];[/color][color=#000000] healthit[/color][color=#666600]<[/color][color=#006666]0[/color][color=#666600];[/color][color=#000000] [/color][color=#666600])[/color][color=#000000] [/color][color=#666600]{[/color]

I would suggest a while loop that checks if the players health or the wolfs health is 0 or less instead
0

Share this post


Link to post
Share on other sites
Could you explain what you think this line does?
[code] for(healthme=500;healthme<0; ); (healthit=500; healthit<0; ) {[/code]
0

Share this post


Link to post
Share on other sites
You need to describe the problem.

If you are getting a compile time error then you should include the error messages (copy & paste). Note that if there are a lot of messages you should generally ignore all bar the top one or two. Each time the compiler finds some errors, its understanding of the program is going to deviate from your expectations, and these build up into dramatically cascading errors that will be very confusing if you try to understand them.

If the problem is with the code - one trick is to simplify. Don't write too much code at once, write small increments and test them regularly. This will prevent you getting a big build up of errors that generate this "code dump".

If you are getting runtime errors - post the error message, and as much of the program interaction you can.If you are getting strange runtime behaviour, indicate both the expected and desired behaviour. Pasting the output of a sample run of the program might be useful too.
0

Share this post


Link to post
Share on other sites
This line also doesn't do what you think it does:
[code] if(attack=="a weapon" , "weapon" , "the weapon") {[/code]

I am starting to think that you should start with a working "Hello, world!" program and then slowly build more things into it until it does what you want. Make sure you compile and test your program after writing every few lines. If there is some syntax you are uncertain about (like how to check if a string matches one of several strings), write a little test just for that.

That way you won't end up with a long piece of code full of mistakes: You'll catch the mistakes when you write them and you'll know where they are because most of the code has been tested already and is likely to be correct.
2

Share this post


Link to post
Share on other sites
Just now looked your code. Can you describe what this line is trying to do?

[code]
for(healthme=500;healthme<0; ); (healthit=500; healthit<0; ) {
[/code]
0

Share this post


Link to post
Share on other sites
If you're using visual studio your "code dump" most likely comes from this using
[CODE]
cin << magic; // instead of cin >> magic;
[/CODE]

But apart from that your code probably will not run the way you expected it.
Things to help you get started:[list]
[*]You need to initialize your variables (especially healthme and helthit)
[*]Have a look into && and || operators for if-statements
[*]Instead of using a crippled for/loop use a while loop
[/list]
0

Share this post


Link to post
Share on other sites
I am just going to repeat what you have already been told, where you have your if (attack == "a weapon" , should be if (attack == "a weapon" || "weapon" || "the weapon").
Also where you first create healthme and healthit declare the amount there.... int Healthme = 500;

You should really look into the different operator's and method's of calling loops ^_^
-2

Share this post


Link to post
Share on other sites
[quote name='RyuunoShinobi' timestamp='1340980185' post='4953965']
I am just going to repeat what you have already been told, where you have your if (attack == "a weapon" , should be if (attack == "a weapon" || "weapon" || "the weapon").
[/quote]
That, too, will always resolve to 'true'.
0

Share this post


Link to post
Share on other sites
[quote name='RyuunoShinobi' timestamp='1340980185' post='4953965']
I am just going to repeat what you have already been told, where you have your if (attack == "a weapon" , should be if (attack == "a weapon" || "weapon" || "the weapon").
Also where you first create healthme and healthit declare the amount there.... int Healthme = 500;

You should really look into the different operator's and method's of calling loops [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img]
[/quote]

That will simply resolve to 'true' for every execution as his last form would. You are executing attack == "a weapon", which calls std::string's overloaded == operator, and returns true or false. However, it then will execute [true | false] | "weapon". "weapon" is not going to be [i]nullptr[/i], therefor, you are bitwise ORing a [true | false] (generally represented as 0x1 and 0x0) against a guaranteed non-[i]nullptr[/i] value, giving you a value that is guaranteed to NOT be 0. You then do it again with "the weapon".

The way that [i]doesn't[/i] fail is:

[CODE]
if (attack == "a weapon" || attack == "weapon" || attack == "the weapon")
[/CODE]

However, judging by the the set of strings, I wouldn't be surprised if one could get away with

[CODE]
if (attack.find("weapon") != std::string::npos)
[/CODE] Edited by Ameise
0

Share this post


Link to post
Share on other sites
[quote]
However, it then will execute [true | false] | "weapon". "weapon" is not going to be nullptr, therefor, you are bitwise ORing a [true | false] (generally represented as 0x1 and 0x0) against a guaranteed non-nullptr value, giving you a value that is guaranteed to NOT be 0. You then do it again with "the weapon".
[/quote]
Those are logical OR, not bitwise OR. The compiler determines that "weapon" is a non-null pointer, so you have [some boolean] || true, which evaluates to true, short circuiting the final condition.

[quote]
However, judging by the the set of strings, I wouldn't be surprised if one could get away with
[code]
if (attack.find("weapon") != std::string::npos)
[/code]
[/quote]
To nitpick, the user could type something ambiguous, like: "a magical weapon". In this case the program would behave differently if it checked for the presence of "weapon" or "magic" first.

I think your code behaves reasonably for this, but it is nice to be aware of such edge cases. Edited by rip-off
1

Share this post


Link to post
Share on other sites
-Browser is being stupid, double post.- Edited by Ameise
0

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1340985257' post='4953988']
[quote]
However, it then will execute [true | false] | "weapon". "weapon" is not going to be nullptr, therefor, you are bitwise ORing a [true | false] (generally represented as 0x1 and 0x0) against a guaranteed non-nullptr value, giving you a value that is guaranteed to NOT be 0. You then do it again with "the weapon".
[/quote]
Those are logical OR, not bitwise OR. The compiler determines that "weapon" is a non-null pointer, so you have [some boolean] || true, which evaluates to true, short circuiting the final condition.
[/quote]

Whoops. Looked like single-pipes on my screen.

[quote name='rip-off' timestamp='1340985257' post='4953988']
[quote]
However, judging by the the set of strings, I wouldn't be surprised if one could get away with
[code]
if (attack.find("weapon") != std::string::npos)
[/code]
[/quote]
To nitpick, the user could type something ambiguous, like: "a magical weapon". In this case the program would behave differently if it checked for the presence of "weapon" or "magic" first.

I think your code behaves reasonably for this, but it is nice to be aware of such edge cases.
[/quote]

Aye, hence 'get away with'. I'm aware that there is the potential for edge cases, but he would need to handle those separately; there's no clarification in regards to the existence of said edge cases, so I didn't handle them :).
0

Share this post


Link to post
Share on other sites
Never mind, I see what the problem is with the way I did that -.-; Edited by RyuunoShinobi
0

Share this post


Link to post
Share on other sites
[quote name='Codarki' timestamp='1340969899' post='4953927']
Just now looked your code. Can you describe what this line is trying to do?

[code]
for(healthme=500;healthme<0; ); (healthit=500; healthit<0; ) {
[/code]
[/quote]
i know i got that wrong quite badly but all i'm trying to do there is set a for that looks at both of those conditions before going through with the loop.
0

Share this post


Link to post
Share on other sites
Actually don't worry i figured it out i got the game to work [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] i'm cheering, thanks for everyone's input and help [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
0

Share this post


Link to post
Share on other sites

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  
Followers 0