diff options
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;
+}
+
|