Question on making game.

This is a discussion on Question on making game. within the C++ Programming forums, part of the General Programming Boards category; Hi,Im new to C++ programming langauge.Im wanting to make a text base game.Im wanting the text to look like it ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    8

    Question on making game.

    Hi,Im new to C++ programming langauge.Im wanting to make a text base game.Im wanting the text to look like it being type out,(EX.Post your games here... )Look for The Adventure of You file on there, if im not explain it fully.I tryed looking at the code but its in C and I really dont know C.

  2. #2
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    The only real C thing in that code is the 'printf' function.. which is 'cout' in C++ and 'getche()' there is 'cin' in C++.. the rest is pretty general to C or C++. Theres of course things like system("PAUSE") and str functions used in it that might be better to use C++ functions for, but its not required. I'm not sure what the question is but yah if you follow the tutorial on the main site and study it.. you shouldnt have huge difficulties starting a text based game like that one. If you cant port it, you could look at the parts of it to see how the concept.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    Thanks!

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    Code:
    #include <cstdlib>
    #include <iostream>
    
    
    
    int main(int argc, char *argv[])
    
    {
    char senta[]="Hi Im praticing my coding\n";
    
    int size;
    int x;
    size=strlen(senta);
                for(x=0;x<size;x++)
                {   
                    sleep(40);
                    printf("%c",senta[x]);
                }    
    
    }
    Im haveing probly with The function Sleep.Everytime I try and complie this code I get "sleep' undeclared (first use this function)".Im useing Dev C++ 4.9.9.2

  5. #5
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    I've never used sleep(), but I'm assuming it's part of cstdlib.

    What you'd need to do is put
    Code:
    using namespace std;
    below the preprocessors. If it's not in the cstdlib, I have no idea what the problem is. :P

  6. #6
    Banned
    Join Date
    Jun 2005
    Posts
    594
    i think you have to
    Code:
     #include <windows.h>
    and i believe it is

    Code:
    Sleep();
    c++ is case sensitive

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    Ah thank you i try that out i just figure before i came and check here and found out i needed <windows.h>.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    Hey it works, thanks guys for your help!

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    3
    here a little function to clear everything..

    Code:
    #include <iostream>
    
    using namespace std;
    
    void typing(string text,int time) {
         for (int x = 0; x <= text.length(); x++) {
                  cout<<text[x];
                  Sleep(time);
             }
    }
    here a exemple :

    Code:
    typing("hello, my name is..uh...what it was, again??", 50 );
    cya~
    Last edited by wejav; 06-19-2005 at 10:52 AM.

  10. #10
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    You may want to edit that function there:

    Code:
    #include <iostream>
    
    using namespace std;
    
    void typing(string text,int time) {
         for (int x = 0; x <= text.length(); x++) {
                  cout<<text[x] << flush ;
                  Sleep(time);
             }
    }
    I'm pretty positive the flush goes there, otherwise the sleep function is added together in the end
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  11. #11
    *this
    Join Date
    Mar 2005
    Posts
    498
    No works fine without a flush, but needs windows header include.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  2. 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
  3. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  4. craps game & dice game..
    By cgurl05 in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 06:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21