Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include "HeadFile.h"
  4. #include <windows.h>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. int Play(char(&spaces)[7][6], int(&color)[7][6], int player, int playerOneWins, int playerTwoWins, int ties)
  10. {
  11. HANDLE hConsole;
  12. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  13.  
  14. int choice, moves = 0, localColor = 15;
  15. bool validChoice = false, goodChoice, win = false, tie = true;
  16. do
  17. {
  18. if (player == 1)
  19. {
  20. localColor = 12;
  21. }
  22. else
  23. {
  24. localColor = 14;
  25. }
  26. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), localColor);
  27. cout << "\nPlayer #" << player;
  28. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  29. cout << "'s turn. " << "Choose a column (1-7):\n";
  30. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  31. do
  32. {
  33. cin >> choice;
  34. if (choice > 7 || choice < 1)
  35. {
  36. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
  37. cout << endl << "Invalid move, choose a column (1-7):";
  38. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  39. }
  40. else
  41. {
  42. validChoice = true;
  43. }
  44. } while (validChoice == false);
  45. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  46. goodChoice = CheckColumn(spaces, color, choice, player);
  47. moves++;
  48. if (moves >= 7)
  49. {
  50. win = CheckForWin(color);
  51. if (win == true)
  52. {
  53. DrawBoard(spaces, color);
  54. if (player == 1)
  55. {
  56. localColor = 12;
  57. playerOneWins++;
  58. }
  59. else
  60. {
  61. localColor = 14;
  62. playerTwoWins++;
  63. }
  64. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), localColor);
  65. cout << "Player " << player << " wins!";
  66. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  67. PlayAgain(playerOneWins, playerTwoWins, ties);
  68. }
  69. }
  70. DrawBoard(spaces, color);
  71. SwitchPlayers(player);
  72.  
  73. } while (moves < 42);
  74. ties++;
  75. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  76. cout << "Tie!";
  77. PlayAgain(playerOneWins, playerTwoWins, ties);
  78. return(0);
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement