Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Gra kółko.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdlib.h>
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- char czysc()
- {
- system("cls");
- return 0;
- }
- bool tryb_gry(char player)
- {
- char wybor;
- cout << "Przeciwnik " << player << endl << "1 - gracz" << endl << "2 - bot" << endl;
- cin >> wybor;
- if (wybor == '1') return true;
- if (wybor == '2') return false;
- }
- void rysuj_plansze(char t[9])
- {
- cout << endl << " " << t[0] << " | " << t[1] << " | " << t[2] << " [0, 1, 2]" << endl;
- cout << " " << t[3] << " | " << t[4] << " | " << t[5] << " [3, 4, 5]" << endl;
- cout << " " << t[6] << " | " << t[7] << " | " << t[8] << " [6, 7, 8]" << endl;
- cout << "-----------------------------------" << endl;
- }
- bool wygrana(char t[], char znak, int c)
- {
- int i=0, numergracza;
- if (t[i] == znak && t[i + 1] == znak && t[i + 2] == znak)
- {
- if (c % 2 == 0)
- {
- numergracza = 0;
- }
- else
- {
- numergracza = 1;
- }
- cout << "Wygral gracz " << numergracza << endl;
- return true;
- }
- else
- {
- return false;
- }
- }
- /*bool remis(char t[])
- {
- }*/
- void ruch(char t[], int a)
- {
- int k, n;
- char znak;
- if (a % 2 == 0)
- {
- n = 0;
- znak = 'O';
- }
- else
- {
- n = 1;
- znak = 'X';
- }
- cout << "Gracz " << n << endl << "Twoj ruch : ";
- cin >> k;
- if ((k >= 0) && (k <= 8) && (t[k] == '-'))
- {
- t[k] = znak;
- }
- }
- int main()
- {
- /*bool player1;
- bool player2;
- player1 = tryb_gry('1');
- player2 = tryb_gry('2');*/
- char plansza_glowna[9] = { '-', '-', '-', '-', '-', '-', '-', '-', '-' };
- int i;
- char g = 'X';
- czysc();
- for (i = 0; wygrana != false; ++i) {
- rysuj_plansze(plansza_glowna);
- ruch(plansza_glowna, i);
- wygrana(plansza_glowna, g, i);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement