Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //plik cell.h
- #ifndef CELL_H
- #define CELL_H
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Cell
- {
- bool state_current;
- bool state_future;
- void editCell(bool n_state);
- public:
- Cell();
- void show();
- void edit();
- };
- #endif // CELL_H
- //plik cell.cpp
- #include "cell.h"
- Cell::Cell()
- {
- int a=0;
- a=rand()%2;
- if(a==1)
- state_current=true;
- else
- state_current=false;
- state_future=false;
- }
- void Cell::show()
- {
- if(state_current==true)
- cout<<'X';
- else
- cout<<'O';
- }
- void Cell::editCell(bool n_state)
- {
- state_current=n_state;
- }
- void Cell::edit()
- {
- int option;
- cout<<"choose avaible option:\n0.dead\n1.alive"<<endl;
- cin>>option;
- while(option!=1 && option!=0)
- {
- cout<<"choose avaible option"<<endl;
- cin>>option;
- }
- if(option==1)
- editCell(true);
- else
- editCell(false);
- }
- //plik board.h
- #ifndef BOARD_H
- #define BOARD_H
- #include "cell.h"
- class Board :Cell
- {
- int v;
- int c;
- Cell **t;
- public:
- Board(int a=10, int b=10); //konstruktor z wartościami domyślnymi
- void showBoard();
- void getSize();
- void createBoard();
- };
- #endif // BOARD_H
- //plik board.cpp
- #include "board.h"
- Board::Board(int a,int b)
- {
- v=a;
- c=b;
- t=new Cell *[v];
- for(int i=0; i<v; i++)
- t[i]=new Cell [c];
- }
- void Board::createBoard()
- {
- t=new Cell *[v];
- for(int i=0; i<v; i++)
- t[i]=new Cell [c];
- }
- void Board::showBoard()
- {
- for(int i=0; i<v; i++)
- {
- for(int j=0; j<c; j++)
- t[i][j].show();
- cout<<endl;
- }
- }
- void Board::getSize()
- {
- int a,b;
- cout<<"Enter natural numbers"<<endl;
- cin>>a;
- cin>>b;
- while(a<1 && b<1)
- {
- cout<<"Board can't have this size. Enter natural numbers"<<endl;
- cin>>a;
- cin>>b;
- }
- v=a;
- c=b;
- }
- //plik main.cpp
- #include <iostream>
- #include <ctime>
- #include "board.h"
- using namespace std;
- int main()
- {
- int a;
- srand(time(NULL));
- Board board;
- cout<<"Hello in Game of Life"<<endl;
- cout<<"Select available options"<<endl;
- cout<<"1.Start"<<endl;
- cout<<"0.Exit"<<endl;
- cin>>a;
- while(a!=0)
- {
- switch(a)
- {
- case 1:
- {
- cout<<"Default board has got size 10x10"<<endl;
- cout<<"Select available options"<<endl;
- cout<<"1.Go"<<endl;
- cout<<"2.Change size"<<endl;
- cout<<"3.Back"<<endl;
- cin>>a;
- while(a!=3)
- {
- switch (a)
- {
- case 1:
- {
- board.showBoard();
- break;
- }
- case 2:
- {
- board.getSize();
- board.createBoard();
- }
- default:
- cout<<"This option does not exist"<<endl;
- break;
- }
- cout<<"Default board has got size 10x10"<<endl;
- cout<<"Select available options"<<endl;
- cout<<"1.Go"<<endl;
- cout<<"2.Change size"<<endl;
- cout<<"3.Back"<<endl;
- cin>>a;
- }
- break;
- }
- default:
- cout<<"This option does not exist"<<endl;
- break;
- }
- cout<<"1.Start"<<endl;
- cout<<"0.Exit"<<endl;
- cin>>a;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement