Thread: console game

  1. #1
    Slow Learner Prophet-ex's Avatar
    Join Date
    Jan 2005
    Posts
    9

    console game

    Hey everyone. I am currently working on my first game, a simple console text-based battle game. Well actually I just started it today and have already run into serveral obstacles. Here is the code so far
    Code:
    #include <iostream>
    #include <cstring>
    #include <stdlib.h>
    #include <fstream.h>
    
    using namespace std;
     struct character
      { int hp;
        int att;
        int def;
        int acc;
        int eva;
        int randomhit;
        int hitdamage;};
    int main()
    {
      ofstream a_file ( "explaination.txt" ); //opens explanation file
          
      character player;
      character enemy;
      
      player.hp=500;
      player.att=50;
      player.def=45;
      player.acc=25;
      player.eva=12;
      player.randomhit=rand()%18;
      player.hitdamage=rand(45)%55;
      
      enemy.hp=300;
      enemy.att=35;
      enemy.def=42;
      enemy.acc=15;
      enemy.eva=3;
      enemy.randomhit=rand()%10;
      enemy.hitdamage=rand(30)%45;
    
      cout<<"You : "<<player.hp<<"";
      cout<<"Enemy : "<<enemy.hp<<"";
      
      cout<<"Will you....\n";
      cout<<"1) Attack\n2) Defend\n";
      cout<<"\nPlease make your descision\n";
             
        return 0;
    }
    This is just the beggining and I know it's only very simple but once I get this one sorted I'll move on to more complexed games and then graphics, but back to the problem at hand :

    Can someone please tell me why these error messages appear and how to fix them : (please)

    54 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\bits\stl_algobase.h:67, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\memory In file included from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/bits/stl_algobase.h:67, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/memory

    48 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\memory:54, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\string from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/memory:54, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/string

    (There are more to this effect)

    108 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\cstdlib `rand' not declared

    27 C:\Program Files\Dev-Cpp\Templates\chrisbattle.cpp `rand' undeclared (first use this function)

    2 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\backward\backward_warning.h: 32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.

    C:\Program Files\Dev-Cpp\Templates\chrisbattle.cpp In function `int main()':

    Thanks

  2. #2
    10%GameProgrammer compile
    Join Date
    Jan 2005
    Posts
    10
    also look to where it points to as well as the code above.

    1. maybe you dont have the proper syn for using the function rand.

    2.maybe your file
    ofstream a_file;
    a_file.open("explaination.txt" );

    edit: forget all this i the debuged code is below =D
    Last edited by andrewV; 01-04-2005 at 07:54 AM.

  3. #3
    10%GameProgrammer compile
    Join Date
    Jan 2005
    Posts
    10
    here is the corect code:
    [tag]
    Code:
    #include <iostream>
    #include <cstring>
    #include <stdlib.h>
    #include <fstream>
    
    using namespace std;
    
    struct character
    { int hp;
        int att;
        int def;
        int acc;
        int eva;
        int randomhit;
        int hitdamage;
     };
    
    int main()
    {
      ofstream outfile;
      outfile.open( "explaination.txt" );//opens explanation file
          
      character player;
      character enemy;
      
      player.hp=500;
      player.att=50;
      player.def=45;
      player.acc=25;
      player.eva=12;
      player.randomhit=rand()%18;
      player.hitdamage=rand()%55;
      
      enemy.hp=300;
      enemy.att=35;
      enemy.def=42;
      enemy.acc=15;
      enemy.eva=3;
      enemy.randomhit=rand()%10;
      enemy.hitdamage=rand()%45;
    
      cout<<"You : "<<player.hp<<"";
      cout<<"Enemy : "<<enemy.hp<<"";
      
      cout<<"Will you....\n";
      cout<<"1) Attack\n2) Defend\n";
      cout<<"\nPlease make your descision\n";
    [/tag]

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    If you are compiling C++ code then,
    Code:
    #include <stdlib.h>
    //should be
    #include <cstdlib>
    But I'm not sure that will correct your rand() problems

  5. #5
    Slow Learner Prophet-ex's Avatar
    Join Date
    Jan 2005
    Posts
    9
    Just got what u said about look where it points too. I went to the include\c++\3.3.1.etc. folder and looked the files. It came up with a bunch of text that I don't understand at all. Changing the header seemed to get rid of a few problems but most of them still persist
    Last edited by Prophet-ex; 01-04-2005 at 08:12 AM.

  6. #6
    10%GameProgrammer compile
    Join Date
    Jan 2005
    Posts
    10
    what i wrote did give me a score of 0-0 =D

    and it was compiled in the C++

    his big error was
    #include<fstream.h>
    where is should be
    #include<fstream>

    as well for the rand() he tryed to pass it info like this rand(45);
    Last edited by andrewV; 01-04-2005 at 08:09 AM.
    cout<<"hello world"<<endl;

  7. #7
    Slow Learner Prophet-ex's Avatar
    Join Date
    Jan 2005
    Posts
    9
    Could it be that there's something missing in the header file(s) ?
    Man, that would suck.........

  8. #8
    10%GameProgrammer compile
    Join Date
    Jan 2005
    Posts
    10
    i dont know about your header files you had one miss spelled if you copy the code i typed it should work
    cout<<"hello world"<<endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  2. PC or Console gamers, what are you playing?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 119
    Last Post: 04-14-2008, 08:17 AM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. Game console input
    By glUser3f in forum Game Programming
    Replies: 3
    Last Post: 11-07-2003, 04:33 AM
  5. Best game console
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-05-2001, 09:25 PM