Facebook
From Melodic Matamata, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 286
  1. #include <iostream>
  2.  
  3. class Kik{
  4.       public:
  5.               mutable char *plansza;
  6.               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.  
  92.               static void zwieksz(Kik &A){
  93.                       A.ilosc_wypisan++;
  94.               }
  95.  
  96.               friend std::ostream& operator<<(std::ostream &stream, Kik &A){
  97.                       Kik::zwieksz(A);
  98.                       for(int i = 0; i < 3; i ++){
  99.                               for(int j = 0; j < 3; j++){
  100.                                       stream << A.plansza[i * 3 + j] << " ";
  101.                               }
  102.                               stream << std::endl;
  103.                       }
  104.                       return stream;
  105.               }
  106. };
  107.  
  108. int Kik::errors = 0;
  109. int Kik::count = 0;