Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class kkgame{
- private:
- char _t[3][3];
- public:
- kkgame(){
- for(int i=0; i<=2; i++){
- for(int j=0; j<=2; j++){
- _t[i][j] = '-';
- }
- }
- this->render();
- }
- void render(){
- cout << endl << this->_t[0][0] << this->_t[0][1] << this->_t[0][2] << endl;
- cout << this->_t[1][0] << this->_t[1][1] << this->_t[1][2] << endl;
- cout << this->_t[2][0] << this->_t[2][1] << this->_t[2][2] << endl;
- }
- bool set(int x, int y, char znak){
- if(x > 2 || x < 0 || y > 2 || y < 0 || (znak != 'X' && znak != 'O')){
- cout << "Blad" << endl;
- this->render();
- return false;
- }
- if(this->_t[x][y] == 'X' || this->_t[x][y] == 'O'){
- cout << "Juz istnieje" << endl;
- this->render();
- return false;
- }
- this->_t[x][y] = znak;
- this->render();
- return true;
- }
- bool check(char znak){
- if(this->_t[0][0] == znak && this->_t[0][1] == znak && this->_t[0][2] == znak){
- return true;
- }
- if(this->_t[1][0] == znak && this->_t[1][1] == znak && this->_t[1][2] == znak){
- return true;
- }
- if(this->_t[2][0] == znak && this->_t[2][1] == znak && this->_t[2][2] == znak){
- return true;
- }
- if(this->_t[0][0] == znak && this->_t[1][0] == znak && this->_t[2][0] == znak){
- return true;
- }
- if(this->_t[1][0] == znak && this->_t[1][1] == znak && this->_t[1][2] == znak){
- return true;
- }
- if(this->_t[2][0] == znak && this->_t[2][1] == znak && this->_t[2][2] == znak){
- return true;
- }
- if(this->_t[0][0] == znak && this->_t[1][1] == znak && this->_t[2][2] == znak){
- return true;
- }
- if(this->_t[2][0] == znak && this->_t[1][1] == znak && this->_t[0][2] == znak){
- return true;
- }
- return false;
- }
- };
- int main(void){
- kkgame g1;
- int i = 0;
- while(1){
- int x, y, a;
- a = 0;
- cout << i << endl;
- cout << "wiersz? ";
- cin >> x;
- cout << "kolumna? ";
- cin >> y;
- if(i%2 == 0){
- if(g1.set(x, y, 'X')){
- i+=1;
- }
- }else{
- if(g1.set(x, y, 'O')){
- i+=1;
- }
- }
- if(g1.check('X')){
- cout << "wygrywa X" << endl;
- return 0;
- }else if(g1.check('O')){
- cout << "wygrywa O" << endl;
- return 0;
- }
- if(i >= 9){
- cout << "nie wygral nikt" << endl;
- return 255;
- }
- }
- return 0;
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement