-
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.http://cboard.cprogramming.com/game-programming/41431-post-your-games-here.html )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.
-
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.
-
-
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
-
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
-
i think you have to
Code:
#include <windows.h>
and i believe it is
c++ is case sensitive
-
Ah thank you i try that out i just figure before i came and check here and found out i needed <windows.h>.
-
Hey it works, thanks guys for your help!
-
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~
-
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
-
No works fine without a flush, but needs windows header include.