Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include "HeadFile.h"
- #include <windows.h>
- #include <string.h>
- using namespace std;
- int Play(char(&spaces)[7][6], int(&color)[7][6], int player, int playerOneWins, int playerTwoWins, int ties)
- {
- HANDLE hConsole;
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- int choice, moves = 0, localColor = 15;
- bool validChoice = false, goodChoice, win = false, tie = true;
- do
- {
- if (player == 1)
- {
- localColor = 12;
- }
- else
- {
- localColor = 14;
- }
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), localColor);
- cout << "\nPlayer #" << player;
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
- cout << "'s turn. " << "Choose a column (1-7):\n";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
- do
- {
- cin >> choice;
- if (choice > 7 || choice < 1)
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
- cout << endl << "Invalid move, choose a column (1-7):";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
- }
- else
- {
- validChoice = true;
- }
- } while (validChoice == false);
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
- goodChoice = CheckColumn(spaces, color, choice, player);
- moves++;
- if (moves >= 7)
- {
- win = CheckForWin(color);
- if (win == true)
- {
- DrawBoard(spaces, color);
- if (player == 1)
- {
- localColor = 12;
- playerOneWins++;
- }
- else
- {
- localColor = 14;
- playerTwoWins++;
- }
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), localColor);
- cout << "Player " << player << " wins!";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
- PlayAgain(playerOneWins, playerTwoWins, ties);
- }
- }
- DrawBoard(spaces, color);
- SwitchPlayers(player);
- } while (moves < 42);
- ties++;
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
- cout << "Tie!";
- PlayAgain(playerOneWins, playerTwoWins, ties);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement