make "pause" in loop

there is a cycle which displays color-continuously. And there's a user who clicks the game start, pause and exit. I can not bound pause during a loop ((somebody tell me?
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  
void processing()
{
    
        do
        {
            switch (current_color)
            {
            case BLUE:
                screen.displayMessage("Blue\n");
                
                current_color = WHITE;
                previos_color = BLUE;
 
            case WHITE:
                screen.displayMessage("WHITE");
                
                if (previos_color == BLUE)      
                {
                    current_color = BLACK;
                }
                else
                {
                    current_color = BLUE;
                    continue;
                }
 
            case BLACK:
                screen.displayMessage("Black light");
                
                current_color = WHITE;
                previos_color = BLACK;
            }
        } while (true);
}
//  user's select
{
    enum key { s = 115, p = 112, e = 101 };
    int ch = 0;
    while (true) {
        while (!_kbhit())
        {
            ch = _getch();
            switch (ch)
            {
            case s:
                if (s) {
                    processing();
                }
                else
                    stop();
 
                break;
            case p:
                screen.displayMessage("PAUSE\n");
                if (p)
                {
                    stop();                   
                }
                else
                    processing();
                break;
            case e:
                screen.displayMessage("Bye-bye\n");
                return;
            default:
                screen.displayMessage("WRON INPUT\n");
                screen.displayMessage("Try again\n");
            }
        }
If you want to be able to pause the game at any time during the program, then you need to start another thread and run it in parallel with your program. The thread should continuously checks for your keyboard input and pause when it receives the command, then stops pausing when it detects the key again

Topic archived. No new replies allowed.