• 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++ not initilizing

6 posts in this topic

i only have one problem and i have one problem why its not working, and i can't figure out what is wrong
[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=500;
int healthit=500;
while(healthme>0 && 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.find("weapon") != std::string::npos) {
cout << "What part of the wolf do you want to attack, the body or the head?\n";
string bodypart;
cin >> bodypart;
if(bodypart.find("body") != std::string::npos) {
healthit-= getdamage(50, 10);
cout << "You hit the wolf!\n";
}

else if(bodypart.find("head") != std::string::npos) {
healthit -= getdamage(100, 20);
healthme -= getdamage(20, 5);
cout << "It was a good hit, but it bites back!\n";
}

else cout << "you missed! (spelt it wrong) \n";
}
else if (attack.find("magic") != std::string::npos){
cout << "what element would you like to attack with? fire lightning, ice, water, or earth?\n";
string magic;
cin >> magic;
if(magic == "fire"){
healthit-= getdamage(50, 10);
cout << "It does good damage!\n";
}
else if(magic == "lightning"){
healthit-= getdamage(100, 10);
cout << "It does amazing damage!\n";
}

else if(magic == "earth"){
healthit-= getdamage(70, 10);
cout << "It hits hard!\n";
}
else if(magic=="ice") {
healthit -= getdamage(30, 5);
cout << "It doesn't seem to hurt much!\n";
}
else if(magic=="water") {
healthit -= getdamage(10, 2);
cout << "It seems unaffected!\n";
}
else cout << "You missed! (spelt it wrong!)\n";
}
else cout << "you took to long! (spelt wrong!)";
if(healthit>=0){
if(healthit<=100){

cout << "He is Angry now and doing more damage!\n";
healthme -= getdamage(75, 10);
}
else {
cout << "The wolf goes out to attack!\n";
healthme-= getdamage(50, 10);
}
}
}
if(healthme<=0) cout << "Your Dead... Game over i guess?";
else cout << "The wolf is dead! You Win!";

return 0;
}
// Returns a random value within DamageRange of Damagebase
int getdamage(int damagebase, int damagerange)
{
// if DamageBase is 50, and DamageRange is 10, DamageBase will be 40 here
int damagedealt = damagebase - damagerange;
// if DamageRange is 10, then this will add anywhere from 0 to 20 damage*
damagedealt += (rand() % (damagerange*2));
return damagedealt;
}


[/CODE]

when compiling the program the error
'getdamage' identifier not found
i can't figure out whats wrong its probably something stupid but still thanks for any help anyway [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
0

Share this post


Link to post
Share on other sites
Look up [url="http://en.wikipedia.org/wiki/Forward_declaration"]http://en.wikipedia....ard_declaration[/url] [size=3]([color=#000000][font=sans-serif]Forward declaration)[/font][/color][/size]
1

Share this post


Link to post
Share on other sites
Everything in C++ must be declared before it is used or the compiler has no idea about what it's trying to use. Function declarations are simple because they just the function header (the header must be identical to the header in the definition).

The brilliant this about declarations is that you could move your function to a different source file and, as long as the function is declared, you are free to use it as much as you like.[source lang="cpp"]# include <stdlib.h>

int getdamage(int, int);

/* entry point */
int main(int argc, char *argv[])
{
/* function body */

return 0;
}

/* return damage */
int getdamage(int damagebase, int damagerange)
{
return damagebase - damagerange += rand() % (damagerange * 2); /* we need to seed rand with a call to srand */
}
[/source]Also remember that identifiers for arguments in declarations don't necessarily need to be the same (or even exist at all).

You never call to change the seed for the random number function either. With that code you'll get the same effects over and over...

Anddd if you use the standard namespace at the beginning of the source file you don't need to then state the the string type your using is from it. There's no harm in it (in fact it's better to avoid using declarations completely for whole namespaces) it's just redundant. Edited by BinaryPhysics
1

Share this post


Link to post
Share on other sites
Just as a side note, you would benefit greatly by learning about classes. Try the tutorials at cplusplus.com: [url="http://www.cplusplus.com/doc/tutorial/"]http://www.cplusplus.com/doc/tutorial/[/url] , I learned a lot about C++ there.

Also, I believe the right term for your problem is "the following code won't compile". I don't think there's such thing as C++ initialization. Edited by DavitosanX
1

Share this post


Link to post
Share on other sites
sorry but thats what my problem so i named it as such but thank you anyway [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] yea i'm still new to c++ obviously so thanks for all the help so fair [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
0

Share this post


Link to post
Share on other sites
[quote name='Big T06' timestamp='1341550094' post='4956205']sorry but thats what my problem so i named it as such[/quote]

This is a compile-time error. It'd be a good habit to get into call errors with their proper name. Initialisation is the issue of a object not having it's data properly set up and is a run-time error. Edited by BinaryPhysics
2

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