Facebook
From Crimson Coyote, 7 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 264
  1. #include <iostream>
  2.  
  3. class Kik{
  4.         public:
  5.                 mutable char *plansza;
  6.                 mutable int ilosc_wypisan;
  7.                 mutable int bledne_wywolania;
  8.                 static int errors;
  9.                 static int count;
  10.                
  11.                 Kik(){
  12.                         (*this).plansza = new char[9];
  13.                         (*this).ilosc_wypisan = 0;
  14.                         (*this).bledne_wywolania = 0;
  15.                         count++;
  16.                        
  17.                         for(int i = 0; i < 9; i++){
  18.                                 (*this).plansza[i] = '.';
  19.                         }
  20.                 }
  21.                
  22.                 Kik(const Kik &A){
  23.                         (*this).plansza = new char[9];
  24.                         (*this).ilosc_wypisan = 0;
  25.                         (*this).bledne_wywolania = 0;
  26.                         count++;
  27.                        
  28.                         for(int i = 0; i < 9; i++){
  29.                                 (*this).plansza[i] = A.plansza[i];
  30.                         }
  31.                 }
  32.                
  33.                 Kik(char A[3][3]){
  34.                         (*this).plansza = new char[9];
  35.                         (*this).ilosc_wypisan = 0;
  36.                         (*this).bledne_wywolania = 0;
  37.                         count++;
  38.                        
  39.                         for(int i = 0; i < 3; i++){
  40.                                 for(int j = 0; j < 3; j++){
  41.                                         (*this).plansza[i * 3 + j] = A[i][j];
  42.                                 }
  43.                         }
  44.                 }
  45.                
  46.                 ~Kik(){
  47.                         errors -= (*this).bledne_wywolania;
  48.                         count--;
  49.                 }
  50.                
  51.                 Kik operator=(Kik A){
  52.                         if(this == &A) return *this;
  53.                        
  54.                         (*this).plansza = new char[9];
  55.                         (*this).ilosc_wypisan = 0;
  56.                         (*this).bledne_wywolania = 0;
  57.  
  58.                         for(int i = 0; i < 9; i++){
  59.                                 (*this).plansza[i] = A.plansza[i];
  60.                         }
  61.                         return *this;
  62.                 }
  63.                
  64.                 void playAt(int i, int j, char k) const {
  65.                         if(i >= 0 && i <= 2 && j >= 0 && j <= 2){
  66.                                 if(plansza[i * 3 + j] == '.' && (k == 'X' || k == 'O')){
  67.                                         (*this).plansza[i * 3 + j] = k;
  68.                                 }
  69.                                 else{
  70.                                         (*this).bledne_wywolania++;
  71.                                         errors++;
  72.                                 }
  73.                         }
  74.                         else{
  75.                                 (*this).bledne_wywolania++;
  76.                                 errors++;
  77.                         }
  78.                 }
  79.                
  80.                 int printNumber() const {
  81.                         return (*this).ilosc_wypisan;
  82.                 }
  83.                
  84.                 static int errorNumber(){
  85.                         return errors;
  86.                 }
  87.                
  88.                 static int objectNumber(){
  89.                         return count;
  90.                 }
  91.                 friend std::ostream& operator<<(std::ostream &stream, const Kik &A){
  92.                         A.ilosc_wypisan++;
  93.                         for(int i = 0; i < 3; i ++){
  94.                                 for(int j = 0; j < 3; j++){
  95.                                         stream << A.plansza[i * 3 + j] << " ";
  96.                                 }
  97.                                 stream << std::endl;
  98.                         }
  99.                         return stream;
  100.                 }
  101. };
  102.  
  103. int Kik::errors = 0;
  104. int Kik::count = 0;
  105.