Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. // 3 op een rij.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include <iostream>
  7. #include <string>
  8. #include <conio.h>
  9. using namespace std;
  10.  
  11. char aanduiding[10]{'0','1','2','3','4','5','6','7','8','9'};
  12. int kijkwin();
  13. void bord();
  14.  
  15. int keuze;
  16. string X = "X";
  17. string O = "O";
  18. string dilemma;
  19.  
  20.  
  21. int main()
  22. {
  23. cout << "Jelmers 3 op een rij\n" << endl;
  24. cout << "Speler 1, kies je vorm\n1.X\n2.O" << endl;
  25.  
  26. int speler = 1, i, keuze;
  27.  
  28. speler = (speler % 2) ? 1 : 2;
  29.  
  30.  
  31.  
  32. char gemarkeerd;
  33. system("cls");
  34.  
  35. do {
  36. bord();
  37.  
  38. cout << "Speler " << speler << ", voer een nummer in"<< endl;
  39. cin >> keuze;
  40.  
  41. gemarkeerd = (speler == 1) ? 'X' : 'O';
  42.  
  43. if (keuze == 1 && aanduiding[1] == '1') {
  44. aanduiding[1] = gemarkeerd;
  45. }
  46. else if (keuze == 2 && aanduiding[2] == '2') {
  47. aanduiding[2] = gemarkeerd;
  48. }
  49. else if (keuze == 3 && aanduiding[3] == '3') {
  50. aanduiding[3] = gemarkeerd;
  51. }
  52. else if (keuze == 4 && aanduiding[4] == '4') {
  53. aanduiding[4] = gemarkeerd;
  54. }
  55. else if (keuze == 5 && aanduiding[5] == '5') {
  56. aanduiding[5] = gemarkeerd;
  57. }
  58. else if (keuze == 6 && aanduiding[6] == '6') {
  59. aanduiding[6] = gemarkeerd;
  60. }
  61. else if (keuze == 7 && aanduiding[7] == '7') {
  62. aanduiding[7] = gemarkeerd;
  63. }
  64. else if (keuze == 8 && aanduiding[8] == '8') {
  65. aanduiding[8] = gemarkeerd;
  66. }
  67. else if (keuze == 9 && aanduiding[9] == '9') {
  68. aanduiding[9] = gemarkeerd;
  69. }
  70. else {
  71. cout << "Deze bitch move is niet toegestaan door de comissie" << endl;
  72.  
  73. speler--;
  74. cin.ignore();
  75. cin.get();
  76. }
  77.  
  78. i = kijkwin();
  79. if (speler == 2) {
  80. speler--;
  81. }
  82. else if (speler == 1) {
  83. speler++;
  84. }
  85. } while (i = -1);
  86. bord();
  87. if (i == 1) {
  88. cout << "==>\aSpeler" << --speler << "wint" << endl;
  89. }
  90. else {
  91. cout << "Gelijkspel" << endl;
  92. cin.ignore();
  93. cin.get();
  94. return 0; cout << "\n\n\tDrie op een rij\n\n";
  95.  
  96. cout << "Speler 1 (X) - Speler 2 (O)" << endl << endl;
  97. cout << endl;
  98.  
  99. cout << " | | " << endl;
  100. cout << " " << aanduiding[1] << " | " << aanduiding[2] << " | " << aanduiding[3] << endl;
  101.  
  102. cout << "_____|_____|_____" << endl;
  103. cout << " | | " << endl;
  104.  
  105. cout << " " << aanduiding[4] << " | " << aanduiding[5] << " | " << aanduiding[6] << endl;
  106.  
  107. cout << "_____|_____|_____" << endl;
  108. cout << " | | " << endl;
  109.  
  110. cout << " " << aanduiding[7] << " | " << aanduiding[8] << " | " << aanduiding[9] << endl;
  111.  
  112. cout << " | | " << endl << endl;
  113. }
  114.  
  115. }
  116.  
  117.  
  118. int kijkwin() {
  119. if (aanduiding[1] == aanduiding[2] && aanduiding[2] == aanduiding[3]) {
  120. return 1;
  121. }
  122. else if (aanduiding[4] == aanduiding[5] && aanduiding[5] == aanduiding[6]) {
  123.  
  124. return 1;
  125. }
  126. else if (aanduiding[7] == aanduiding[8] && aanduiding[8] == aanduiding[9]) {
  127.  
  128. return 1;
  129. }
  130. else if (aanduiding[1] == aanduiding[4] && aanduiding[4] == aanduiding[7]) {
  131.  
  132. return 1;
  133. }
  134. else if (aanduiding[2] == aanduiding[5] && aanduiding[5] == aanduiding[8]) {
  135.  
  136. return 1;
  137. }
  138. else if (aanduiding[3] == aanduiding[6] && aanduiding[6] == aanduiding[9]) {
  139.  
  140. return 1;
  141. }
  142. else if (aanduiding[1] == aanduiding[5] && aanduiding[5] == aanduiding[9]) {
  143.  
  144. return 1;
  145. }
  146. else if (aanduiding[3] == aanduiding[5] && aanduiding[5] == aanduiding[7]) {
  147.  
  148. return 1;
  149. }
  150. else if (aanduiding[1] != '1' && aanduiding[2] != '2' && aanduiding[3] != '3'
  151. && aanduiding[4] != '4' && aanduiding[5] != '5' && aanduiding[6] != '6'
  152. && aanduiding[7] != '7' && aanduiding[8] != '8' && aanduiding[9] != '9'){
  153.  
  154. return 0;
  155. }
  156. else {
  157. return -1;
  158. }
  159. }
  160.  
  161.  
  162.  
  163. void bord() {
  164. system("cls");
  165. cout << "\n\n\tDrie op een rij\n\n";
  166.  
  167. cout << "Speler 1 (X) - Speler 2 (O)" << endl << endl;
  168. cout << endl;
  169.  
  170. cout << " | | " << endl;
  171. cout << " " << aanduiding[1] << " | " << aanduiding[2] << " | " << aanduiding[3] << endl;
  172.  
  173. cout << "_____|_____|_____" << endl;
  174. cout << " | | " << endl;
  175.  
  176. cout << " " << aanduiding[4] << " | " << aanduiding[5] << " | " << aanduiding[6] << endl;
  177.  
  178. cout << "_____|_____|_____" << endl;
  179. cout << " | | " << endl;
  180.  
  181. cout << " " << aanduiding[7] << " | " << aanduiding[8] << " | " << aanduiding[9] << endl;
  182.  
  183. cout << " | | " << endl << endl;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement