Tuesday, June 3, 2014

#8 game.h Include Igra

#ifndef C_GAME_H
#define C_GAME_H
#include <graphics.h>
#include "c_shape.h"
#include "c_turtle.h"
#include "c_square.h"
class c_game{

private:

public:

c_game();
~ c_game();
void play(int _maxX,int _maxY);
void move (char direction, int step,int _maxX,int _maxY, int backColor, c_shape* shape);
};

c_game::c_game(){
    // constructor
}
c_game::~c_game(){
    //destructor
}
void c_game::play(int _maxX,int _maxY){

     c_shape *shape=new c_square(_maxX/2,_maxY/2,20,GREEN);
     char c=' ';
while(c!='q'){
  if(kbhit( )){
      c=getch();
      this->move((int) c,10,_maxX,_maxY,BLACK,shape);          
  }
}  
}
void c_game::move(char direction, int step,int _maxX,int _maxY, int backColor, c_shape* shape){
  switch(direction){
    case KEY_LEFT:
       if (shape->getX()-shape->getRadius()-step>0) {
        shape->moveMe(shape->getX()-step,shape->getY(),backColor);            
       }
    break;
    case KEY_RIGHT:
       if (shape->getX()+shape->getRadius()+step<maxX) {
        shape->moveMe(shape->getX()+step,shape->getY(),backColor);  
       }
    break;
    case KEY_UP:
       if (shape->getY()-shape->getRadius()-step>0) {
       shape->moveMe(shape->getX(),shape->getY()-step,backColor);
       }
    break;
    case KEY_DOWN:
       if (shape->getY()+shape->getRadius()+step<maxY) {
        shape->moveMe(shape->getX(),shape->getY()+step,backColor);
       }
    break;                                  
 }  

}

#endif

No comments:

Post a Comment