Changes between Initial Version and Version 1 of examples_from_lect2


Ignore:
Timestamp:
01/21/16 23:14:27 (8 years ago)
Author:
Evgeny Linsky
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • examples_from_lect2

    v1 v1  
     1{{{
     2#include <stdio.h>
     3
     4class Model{
     5private:
     6        int board[10][10];       
     7        //?
     8public:   
     9        Model() {
     10                for(int i = 0; i < 10; i++) {
     11                        for(int j = 0; j < 10; j++) {
     12                                board[i][j] = -1;
     13                        }
     14                }
     15        }
     16
     17        bool move(int x, int y, bool isZero) {
     18                //?
     19                board[x][y] = isZero ? 0 : 1;
     20        }   
     21       
     22        // Zero, Christ, Draw, Inprogress,
     23        int getState() const {
     24                //?
     25                return 0;
     26        }
     27       
     28        int getCell(int x, int y) const {
     29                //?
     30                return board[x][y];
     31        }
     32       
     33       
     34};
     35
     36class View {
     37private:
     38        Model* myModel;
     39public:
     40        View(Model* m) {
     41                myModel = m;
     42        }
     43       
     44        void show() const {
     45                for(int i = 0; i < 10; i++) {
     46                        for(int j = 0; j < 10; j++) {
     47                                printf("%d", myModel->getCell(i, j));
     48                        }
     49                        printf("\n");
     50                }
     51        }     
     52       
     53        void doGame() const {
     54                int isEnd = 1;
     55                while ( isEnd != 0 ) {
     56                        //input from first player
     57                        //myModel->move(i, j, player);                       
     58                        //player = !player;
     59                        show();
     60                        isEnd = myModel->getState();
     61                }
     62        }
     63
     64};
     65
     66class TestModel {
     67public:
     68        void checkError(bool b, const char* f) {
     69                if(!b) {
     70                        printf("Test failed in %s\n", f);
     71               
     72                }
     73        }
     74       
     75        void getStateTest() {
     76                Model m;
     77                m.move(1, 1, true);
     78                m.move(2, 2, false);
     79               
     80                checkError( m.getState()!= 0, __func__ );
     81       
     82        }
     83};
     84
     85/*
     86// test.cpp
     87int main() {
     88        TestModel tm;
     89        tm.getStateTest();
     90        return 0;
     91}
     92*/
     93
     94int main() {
     95        Model m;
     96        View v(&m);
     97        v.doGame();
     98        return 0;
     99}
     100}}}