@@ -45,6 +45,13 @@ void Game::ProcessInput()
45
45
{
46
46
mGrid ->ProcessInput (GetMouseX (), GetMouseY ());
47
47
}
48
+ else if (mGameState == WIN || mGameState == GAME_OVER)
49
+ {
50
+ if (IsKeyReleased (KEY_SPACE))
51
+ {
52
+ mGrid ->Reset ();
53
+ }
54
+ }
48
55
}
49
56
50
57
void Game::UpdateGame ()
@@ -69,32 +76,53 @@ void Game::GenerateOutput()
69
76
GuiSetStyle (DEFAULT, TEXT_SIZE, 40 );
70
77
GuiSetStyle (DEFAULT, TEXT_SPACING, 10 );
71
78
GuiSetStyle (BUTTON, BASE_COLOR_NORMAL, 0x000000FF );
72
- if (GuiButton ({ (mScreenWidth / 2 .f ) - (buttonWidth / 2 .f ),
73
- (mScreenHeight / 2 .f ) - (buttonHeight / 2 .f ) - padding,
74
- buttonWidth,
75
- buttonHeight },
79
+ if (GuiButton ({(mScreenWidth / 2 .f ) - (buttonWidth / 2 .f ),
80
+ (mScreenHeight / 2 .f ) - (buttonHeight / 2 .f ) - padding,
81
+ buttonWidth,
82
+ buttonHeight},
76
83
" START" ))
77
84
{
78
85
printf (" START GAME!\n " );
79
86
mGameState = PLAYING;
80
87
}
81
- if (GuiButton ({ (mScreenWidth / 2 .f ) - (buttonWidth / 2 .f ),
82
- (mScreenHeight / 2 .f ) - (buttonHeight / 2 .f ) + buttonHeight,
83
- buttonWidth,
84
- buttonHeight },
88
+ if (GuiButton ({(mScreenWidth / 2 .f ) - (buttonWidth / 2 .f ),
89
+ (mScreenHeight / 2 .f ) - (buttonHeight / 2 .f ) + buttonHeight,
90
+ buttonWidth,
91
+ buttonHeight},
85
92
" EXIT" ))
86
93
{
87
94
printf (" EXIT GAME!\n " );
88
95
mIsRunning = false ;
89
96
}
90
97
}
91
98
break ;
92
- case PLAYING:
99
+ default :
100
+ {
101
+ // This is our default PLAYING rendering output
102
+ // This way we can render our GAME_OVER rectangular box correctly
93
103
ClearBackground (LIGHTGRAY);
94
- for (auto drawCom : mDraws )
104
+ for (auto drawCom: mDraws )
95
105
{
96
106
drawCom->Draw ();
97
107
}
108
+ if (mGameState == GAME_OVER)
109
+ {
110
+ int fontSize = 50 ;
111
+ int width = 1200 , height = 500 ;
112
+ DrawRectangle ((mScreenWidth / 2 ) - (width / 2 ), (mScreenHeight / 2 ) - (height / 2 ), width, height, {0 , 0 , 0 , 220 });
113
+ DrawText (" YOU CLICKED A MINE CELL! GAME OVER!" , (mScreenWidth / 2 ) - 500 , (mScreenHeight / 2 ) - 40 , fontSize, RED);
114
+ DrawText (" PRESS SPACE BAR TO TRY AGAIN!" , (mScreenWidth / 2 ) - 500 , (mScreenHeight / 2 ) + 20 , fontSize, RED);
115
+ }
116
+ else if (mGameState == WIN)
117
+ {
118
+ int width = 1200 , height = 500 ;
119
+ int fontSize = 50 ;
120
+ DrawRectangle ((mScreenWidth / 2 ) - (width / 2 ), (mScreenHeight / 2 ) - (height / 2 ), width, height, {0 , 0 , 0 , 220 });
121
+ DrawText (" CONGRATULATIONS, YOU HAVE WON!" , (mScreenWidth / 2 ) - 500 , (mScreenHeight / 2 ) - 40 , fontSize, GREEN);
122
+ DrawText (" PRESS SPACE BAR TO PLAY AGAIN!" , (mScreenWidth / 2 ) - 500 , (mScreenHeight / 2 ) + 20 , fontSize, GREEN);
123
+ }
124
+ }
125
+ break ;
98
126
}
99
127
EndDrawing ();
100
128
}
0 commit comments