Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. // Gra kółko.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include <cstdlib>
  8.  
  9.  
  10. using namespace std;
  11.  
  12. char czysc()
  13. {
  14. system("cls");
  15. return 0;
  16. }
  17.  
  18. bool tryb_gry(char player)
  19. {
  20. char wybor;
  21. cout << "Przeciwnik " << player << endl << "1 - gracz" << endl << "2 - bot" << endl;
  22. cin >> wybor;
  23. if (wybor == '1') return true;
  24. if (wybor == '2') return false;
  25. }
  26.  
  27. void rysuj_plansze(char t[9])
  28. {
  29. cout << endl << " " << t[0] << " | " << t[1] << " | " << t[2] << " [0, 1, 2]" << endl;
  30. cout << " " << t[3] << " | " << t[4] << " | " << t[5] << " [3, 4, 5]" << endl;
  31. cout << " " << t[6] << " | " << t[7] << " | " << t[8] << " [6, 7, 8]" << endl;
  32. cout << "-----------------------------------" << endl;
  33. }
  34.  
  35.  
  36. bool wygrana(char t[], char znak, int c)
  37. {
  38. int i=0, numergracza;
  39. if (t[i] == znak && t[i + 1] == znak && t[i + 2] == znak)
  40. {
  41. if (c % 2 == 0)
  42. {
  43. numergracza = 0;
  44. }
  45. else
  46. {
  47. numergracza = 1;
  48. }
  49. cout << "Wygral gracz " << numergracza << endl;
  50. return true;
  51. }
  52. else
  53. {
  54. return false;
  55. }
  56. }
  57.  
  58.  
  59.  
  60. /*bool remis(char t[])
  61. {
  62.  
  63. }*/
  64.  
  65. void ruch(char t[], int a)
  66. {
  67. int k, n;
  68. char znak;
  69. if (a % 2 == 0)
  70. {
  71. n = 0;
  72. znak = 'O';
  73. }
  74. else
  75. {
  76. n = 1;
  77. znak = 'X';
  78. }
  79. cout << "Gracz " << n << endl << "Twoj ruch : ";
  80. cin >> k;
  81. if ((k >= 0) && (k <= 8) && (t[k] == '-'))
  82. {
  83. t[k] = znak;
  84. }
  85. }
  86.  
  87.  
  88. int main()
  89. {
  90. /*bool player1;
  91. bool player2;
  92.  
  93. player1 = tryb_gry('1');
  94. player2 = tryb_gry('2');*/
  95.  
  96. char plansza_glowna[9] = { '-', '-', '-', '-', '-', '-', '-', '-', '-' };
  97.  
  98. int i;
  99. char g = 'X';
  100. czysc();
  101.  
  102. for (i = 0; wygrana != false; ++i) {
  103. rysuj_plansze(plansza_glowna);
  104. ruch(plansza_glowna, i);
  105. wygrana(plansza_glowna, g, i);
  106. }
  107.  
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement