diff options
| author | Fuwn <[email protected]> | 2024-04-07 23:18:32 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-04-07 23:18:32 -0700 |
| commit | c1b6ffe70bd281c6c230fd63fabcaac2aff47514 (patch) | |
| tree | e8af3b1782a7cd0754590ed618fddc1bdb9b7385 /chapter14/play_connect4.cxx | |
| download | dscode-main.tar.xz dscode-main.zip | |
Diffstat (limited to 'chapter14/play_connect4.cxx')
| -rw-r--r-- | chapter14/play_connect4.cxx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/chapter14/play_connect4.cxx b/chapter14/play_connect4.cxx new file mode 100644 index 0000000..c15bf5c --- /dev/null +++ b/chapter14/play_connect4.cxx @@ -0,0 +1,30 @@ +#include <cctype>
+#include <cstdlib>
+#include <string>
+#include "connect4.h"
+using namespace main_savitch_14;
+
+int main( )
+{
+ connect4 instance;
+ connect4::who winner;
+ char answer;
+ string restline;
+
+ do
+ {
+ winner = instance.play( );
+ switch (winner)
+ {
+ case connect4::HUMAN: cout << "You win" << endl; break;
+ case connect4::COMPUTER: cout << "I win" << endl; break;
+ case connect4::NEUTRAL: cout << "A draw" << endl; break;
+ }
+ cout << "Do you want to play again? [Y/N] ";
+ cin >> answer;
+ getline(cin, restline);
+ } while (toupper(answer) == 'Y');
+
+ return EXIT_SUCCESS;
+}
+
|