Share your repls and programming experiences

← Back to all posts
A STORY ( A Game of Mystery) Beta 0.0.1
nt998302 (8)

I just coded this mystery game as my first ever C++ Game! You guys can check it out and notify me if there are any bugs or if you have any suggestions.

Commentshotnewtop
Highwayman (617)

If anything I posted was confusing or unhelpful, please ping me with as many questions as you like.

Highwayman (617)

Why do you encapsulate null in eXpo, only to use a global using statement on the eXpo namespace? What is the advantages of the namespace? I feel it is simply code bloat there. I suggest just declaring null as a regular global variable.

Also, since you already say using namespace std; just before main on line 31, you do not need to write the using statements on lines 16 to 20. I would however suggest getting rid of line 31 instead of getting rid of lines 16 to 20 because it is generally better to leave as much name mangling as possible, seeing as it reduces confusion for the compiler (and you, maybe) as to what is what, like if you made a function with the same name as a function in one of your headers (easy to do, seeing as you have, like, 12 headers) it will know whether to call your function or the headers function.

nt998302 (8)

@Highwayman First of all, thank you so much just for checking out my game! For the namespace, it pretty much is just code bloat. I was checking out some new syntax, so I'll take that part out. Also for the namespace std things, I didn't want to risk causing code errors, so I'll change that too.

Highwayman (617)
On lines 19, 38, 42, 48, 54, 60, 62, 64, 70, 76, 92, 98, 101, 104, 107, 120, 131, 136, 141, 145, 153, 155, 158, 160, 163, 165, 168, 170, 173, 175, 178, 181, 183, and 186 you use usleep() when you have sleep_for() as well? I suggest using either just sleep_for() or just usleep(). It is probably preferable that you use sleep_for(), actually, since usleep() is coming from a header that is only accessible on Unix systems. So then it could work on a windows os too.
I noticed that you are including both <cstdlib> and <stdlib.h>. This is not needed, because they are the same header. The only difference is that <cstdlib> is specifically made made for c++ (the c in front of the name instead of the h after signifies that the header is a c header.)
I noticed that you have included both <chrono> and <time.h>. I strongly that you either just use <time.h> or just use <chrono>, seeing as they are just time libraries. If you use <time.h>, I suggest you instead include <ctime>, because it is the exactly the same header, only it shows that it is a c header more clearly because if the c before the name, like with <cstdlib> and <stdlib.h> as I explained above.
I noticed you used "/0" in your declaration of null. Did you mean "\0"?
nt998302 (8)

@Highwayman I'm not really sure how to use the sleep_for() function. Does it refer to milliseconds or seconds? Also, for null, I searched it up and found that /0 is correct. I have fixed the #include <> statements too. Thank you so much for all your help!

Highwayman (617)

@nt998302 here, I’ll show you how to use sleep_for() and also I’m going to give you a really good resource for any stl stuff for c++11 and under (and I think maybe a little bit of c++14 stuff, not much though).

First, sleep_for() can use milliseconds, seconds, microseconds nanoseconds... basically any type of duration of time. To use the sleep_for function it looks something like this:

std::this_thread::sleep_for(std::chrono::durationType(amount_of_duration_type);

you can either make your own duration type, or you can use one of the many durations that are made for you.
Here is a list of durations you can use:

std::chrono::hours
std::chrono::minutes
std::chrono::seconds
std::chrono::milliseconds
std::chrono::microseconds
std::chrono::nanoseconds

all this information on sleep_for() can be found here (along with an example implementation) here: http://www.cplusplus.com/reference/thread/this_thread/sleep_for/?kw=sleep_for

And the really helpful reference is found here: http://www.cplusplus.com/reference/ (that is where the first reference is from, as you can see.)

nt998302 (8)

@Highwayman Thank you so much for all of your feedback! You're the best!

Highwayman (617)

@nt998302 thank you, I wouldn’t say so though - that site actually has a bunch of forums filled with a lot of bad asses, you should check them out the next time you have a c++ question, they are very good.