Code review on text RPG

My remarks at the top of the code explain where I'm at and what my main problem is. Sleep was not part of my original design but for the game to be more playable (less boring) I would like to implement it. I can't see a way round this without a major redesign to implement it and would welcome suggestions on how I could do this. (My thoughts to do this was to plus 4 to both the timer and counter variable's).
Apologies for all my code in main, I was trying to get it all working before making it a function (to stop all my variables being global variables) but I haven't quite sussed pass by reference to do that yet (but I will). Temp flag I know I need to loose and use bool instead (at least I think I can)? Not sure what else is wrong but I'm sure there probably is somethink?
This part of the game would run in the background and be called when needed from my movement routine.
If we could keep the flames to a minimum please, I know my coding is probably messy and annoying but, I'm out here and I'm trying.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Timer part of a console RPG (in the making)!
//every 2 moves (2 for testing, 12 for game) the clock time is displayed (incrementing hourly).
//Dawn, daylight, dusk & darkness display (tempFlag to stop multiple displaying of event)
//Sleep function (sleep for 4 hours) not done yet! (anticipated problem is that if sleep
//function invoked while counter on 12 timer will not reset to 1 for 12 hour clock, same with
//counter on 24! Can't change "if (counter == 13) {timer = 1;}" to (counter > 13) because
//timer will then continually equall 1 as counter increments.
//This code compiles and works.

#include <iostream>
using namespace std;

int main()
{
int moves = 0;
int MovesReset = 2;
int timer = 12;
char move;
int counter = 12;
int tempFlag =0;

cout << "Press any key to move or 'q' to quit (2 moves will display time)" << endl;

while (1){
        cin >> move;
        moves++;

        if (counter == 13) {timer = 1;}     //will not work with sleep
        if (counter == 25) {counter = 1; timer = 1;}
        
        if (counter == 7&& tempFlag ==1) {cout << "1 Hour to dawn!" << endl; tempFlag =0;}
        else if (counter == 7&& tempFlag ==0) {tempFlag =1;}
        if (counter == 8&& tempFlag ==1) {cout << "Daylight" << endl; tempFlag =0;}
        else if (counter == 8&& tempFlag ==0) {tempFlag =1;}
        if (counter == 19 && tempFlag ==1) {cout << "It's Dusk!" << endl; tempFlag =0;}
        else if (counter == 19 && tempFlag ==0) {tempFlag =1;}
        if (counter == 20 && tempFlag ==1) {cout << "Darkness falls" << endl; tempFlag =0;}
        else if (counter == 20 && tempFlag ==0) {tempFlag =1;}
    
        if (moves == MovesReset && counter <= 12)
        { cout << timer << ":AM" << endl; moves=0; counter++; timer++;}
        
        else if (moves == MovesReset && counter > 12 && counter <= 24)
        { cout << timer << ":PM" << endl; moves=0; counter++; timer++;}
        
        if (move == 'q'){return 0;}

        }
system ("Pause");
return 0;
}

Thanks in advance, Leppie
First and the most important thing you have to do is read http://www.cplusplus.com/forum/articles/28558/

Back to your code.. Well, there are 40 lines of it. Not much to review.. A couple of notes:
You write the same thing many times. lines 31-38 could be
31
32
33
34
35
36
37
if(tempFlag){
   if(counter == 7)  cout << "...";
   else if(counter == 8)  cout << "...";
   else if(counter == 19)  cout << "...";
   else if(counter == 20)  cout << "...";
   tempFlag = 0;
}else tempFlag = 1;

You shouldn't write many things in one line.
if(...){ ...; ...; ... ;} is a lot harder to read then
1
2
3
4
5
if(...){
   ...;
   ...;
   ...;
}

Also, read http://www.cplusplus.com/forum/articles/11153/

Off topic, why did you start making your rpg from day/night cycle? I assume it will have an important role in it, but still, something like movement seeks like a more core feature..

Anyway, good luck with the project..
Thanks hamsterman for all your advice (and the articles), point taken on both of them! I've actually got the movement class sorted and working with this as a background function to be called (Vamps in daylight stuff), Lol. Still would like to learn C++ though, so I'll be sticking with it. I was just using the game as a way to implement the stuff I have learned and to stretch my knowledge of programming further. In over my head again but how else do you learn.
Leppie
Still would like to learn C++ though, so I'll be sticking with it


SFML, etc are C++. They're just libraries to make your life easier.

You'd be doing yourself a disservice not to use them.
Well don't I look silly now! Thanks Disch, no seriously I mean it thanks. Guess I'll have to have a look at SFML now then.
Leppie
Topic archived. No new replies allowed.