Example #1
0
void Bullet::checkCollision()
{
    QList<QGraphicsItem *> l=scene()->items();
    foreach(QGraphicsItem *item, l) {
        if ( (item->type()==man_type) && item->collidesWithItem(this, Qt::IntersectsItemBoundingRect) ) {
            Man* deadman = (Man*)item;
            if (deadman->frame() != 5) return;
            deadman->done();
            emit score(10);
            setShotCount(shotcount+1);
            nobullets--;
            deleteLater();
            return;
        }
        else if ( (item->type()==helicopter_type) && item->collidesWithItem(this, Qt::IntersectsItemBoundingRect) ) {
            Helicopter* deadchopper = (Helicopter*) item;
            deadchopper->done();
            emit score(50);
            setShotCount(shotcount+1);
            nobullets--;
            deleteLater();
            return;
        }
    }
    //check shot is not out of bounds
    if ( (y() < 0) || (x() < 0) ||
        (y() > scene()->height()) ||
        ( x() > scene()->width()))  {
        nobullets--;
        deleteLater();
        return;
    }
}
Example #2
0
// Function to read configurations from file.
void inputConfigurations(void)
{
   float readValue;
   int i;
   Man newMan;

   inFile.open("animateManDataIn.txt");
   
   while (!inFile.eof())
   {
      newMan = Man();
      for (i=0; i < 9; i++)
	  {
         inFile >> readValue;
		
         newMan.setPartAngle(readValue);
         newMan.incrementSelectedPart();
	  }
      inFile >> readValue;
	
      newMan.setUpMove(readValue);
      inFile >> readValue;
      newMan.setForwardMove(readValue);
      manVector.push_back(Man(newMan));
   }
   manVector.pop_back(); // Remove configuration at the back because the routine
                         // read eol after the last configuration and before eof and
                         // creates a fake configuration.
}                        
Example #3
0
bool Pawn::canMove(int x, int y, int move_x, int move_y)
{
	if(isPromoted()) {
		return move_x == 0 || move_y == 0 || abs(move_x)==abs(move_y);
	}
	int dir = getSide()==0?-1:1;
	if(move_x == 0) {
		if(board_->get(x,y+dir) != NULL) {
			return false;
		}
		if(move_y == dir) {
			return true;
		}
		if(!isMoved() && move_y==dir*2) {
			return board_->get(x,y+move_y)==NULL;
		}
		return false;
	}
	if(move_y != dir) {
		return false;
	}
	if(abs(move_x) != 1) {
		return false;
	}
	Man *target = board_->get(x+move_x,y+move_y);
	return target?target->getSide()!=getSide():false;
}
Example #4
0
Pensioner Pensioner::deserialize(std::istream& save) {
	
	Man pensioner = Man::deserialize(save);
	
	std::string pension_s;
	getline(save, pension_s);
	
	int pension;
	std::istringstream temp(pension_s);
	temp >> pension; 
	
	std::string grandchildren_s;
	getline(save, grandchildren_s);
	
	int grandchildren;
	std::istringstream temp1(grandchildren_s);
	temp1 >> grandchildren; 
	
	if(!save)
		throw Exception("Couldn't deserialize Pensioner object.");
		
	Pensioner deserialized = Pensioner(pensioner.get_pesel(), pensioner.get_name(), pensioner.get_age(), pensioner.get_status(), pensioner.get_hometown(), pension, grandchildren);
	return deserialized;
	
}
Example #5
0
int main(int argc, const char * argv[])
{
    Man *m = new Man(20);
    printf("age %d\n",m->getAge());
    delete m;
    return 0;
}
Example #6
0
int main() {
    Man *m = new Man();
    m -> sayHello();

    printf("man age is %d\n", m->getAge());

    return 0;
}
Example #7
0
int main()
{
    Man *m = new Man(21);
    m->sayHello();
    m->People::sayHello();

    return 0;
}
Example #8
0
int main()
{
   Man Hritik;
   Hritik.SetValues();
cout << "Weight = "<<Hritik.weight << endl;
cout << "Height = "<<Hritik.height << endl;
cout << "Name = "<<Hritik.Name << endl;
  Hritik.PrintValues();
//cout << "earning= "<<Hritik.Earning<< endl;
   return 0;
}
Example #9
0
int main()
{
  Car ford =  Car(1000);
  Mechanic fordGuro;
  Man goshoForda;

  std::cout << fordGuro.carRepairPrice(ford) << std::endl;
  fordGuro.repairCar(ford);
  goshoForda.crashCar(ford);

  return 0;
}
Example #10
0
int main(int argc, const char * argv[]) {
    
    Man *m = new Man(20);
    
    
    printf("age:%d\n",m->getAge());
    
    
    
    std::cout << "Hello, World!\n";
    return 0;
}
Example #11
0
int main(int argc, const char * argv[]) {

    Man *man = new Man(21);
    man->sayHello();
    man->People::sayHello();
    
    beiluo::People * p = new Man(21);
    p->sayHello();
    p->People::sayHello();
    ((Man*)p)->sayHello();
    
    return 0;
}
Example #12
0
int main()
{
	Man henry;
	Hombre enrique;

	henry.speak();
	henry.speak("It's a beautiful evening.");

	enrique.speak("Hola!");
	enrique.Man::speak("Es una tarde hermosa.");

	return 0;
}
Example #13
0
int main(int argc, const char * argv[]) {
    Man *m = new Man();
    delete m;
    
    m = new Man(20);
    printf("Man->age = %d\n",m->getAge());
    m->setAge(30);
    printf("Man->age = %d\n",m->getAge());
    
    
    delete m;
    
    return 0;
}
Example #14
0
void Board::updatePromotion()
{
	for(int x = 0; x < GRID_X; ++x) {
		for(int y = 0; y < GRID_Y; ++y) {
			Man *man = board_[x][y];
			if(man && man->getTypeId() == TYPE_PAWN) {
				if((man->getSide()==0&&y==0) || (man->getSide()==1&&y==GRID_Y-1)) {
					static_cast<Pawn*>(man)->setPromoted(true);
					cout << "promoted" << endl;
				}
			}
		}
	}
}
Example #15
0
void Board::merge(BoardDiff& diff)
{
	last_moved_ = NULL;
	for(map<Man*,Diff>::iterator it = diff.begin(); it != diff.end(); ++it) {
		Diff& diff = (*it).second;
		if(diff.to.x != -1) {
			Man *man = (*it).first;
			is_last_move_valid_ = man->canMove(diff.from.x, diff.from.y, diff.to.x-diff.from.x, diff.to.y-diff.from.y);
		}
	}
	for(map<Man*,Diff>::iterator it = diff.begin(); it != diff.end(); ++it) {
		Diff& diff = (*it).second;
		if(diff.from.x != -1) {
			set(diff.from.x, diff.from.y, NULL);
		}
	}
	for(map<Man*,Diff>::iterator it = diff.begin(); it != diff.end(); ++it) {
		Diff& diff = (*it).second;
		if(diff.to.x != -1) {
			Man *man = (*it).first;
			set(diff.to.x, diff.to.y, man);
			if(man && man->getTypeId() == TYPE_PAWN) {
				if((man->getSide()==0&&diff.to.y==0) || (man->getSide()==1&&diff.to.y==GRID_Y-1)) {
					static_cast<Pawn*>(man)->setPromoted(true);
					cout << "promoted" << endl;
				}
			}
			man->setMoved(true);
			last_moved_ = man;
			cout << "(" << diff.from.x << "," << diff.from.y << ")->(" << diff.to.x << "," << diff.to.y << ")" << endl;
		}
	}
}
Example #16
0
int main()
{
    Man *m = new Man(1, "Man:WuWenhao");
    //执行当前类的函数
    //若派生类与基类有相同的函数,则运行派生类的函数,否则运行基类的函数
    m->sayHello();
    //执行父级函数
    m->People::sayHello();

    People *p1 = new Man();
    p1->sayHello();

    m->Eat();
    p1->Eat();
    p1->Sleep();


    int age = m->getAge();
    int sex = m->getSex();
    char *name = m->getName();

    delete m;
    delete p1;
    return 0;
}
Example #17
0
void Bullet::checkCollision()
{
    QCanvasItem* item;
    QCanvasItemList l=collisions(FALSE);
      for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
          item = *it;
          if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) {
               Man* deadman = (Man*)item;
               if (deadman->frame() != 5) return;
               deadman->done();
	       emit score(10);
               setShotCount(shotcount+1);
               setAnimated(false);
               nobullets--;
               delete this;
               return;
          }
          else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) {
               Helicopter* deadchopper = (Helicopter*) item;
               deadchopper->done();
	       emit score(50);
               setAnimated(false);
               nobullets--;
               delete this;
               return;
         }
      }
      //check shot is not out of bounds
     if ( (y() < 0) || (x() < 0) ||
          (y() > canvas()->height()) ||
          ( x() > canvas()->width()))  {
          setAnimated(false);
          nobullets--;
          delete this;
          return;
     }
}
Example #18
0
void Pawn::updatePossibleMoves()
{
	possible_move_.clear();
	int x = move_history_.back().first;
	int y = move_history_.back().second;
	if(isPromoted()) {
		checkLine(x,y, -1,-1);
		checkLine(x,y, -1, 0);
		checkLine(x,y, -1, 1);
		checkLine(x,y,  0,-1);
		checkLine(x,y,  0, 1);
		checkLine(x,y,  1,-1);
		checkLine(x,y,  1, 0);
		checkLine(x,y,  1, 1);
	}
	else {
		Man *target = NULL;
		int next_x, next_y;
		switch(player_) {
			case 0:
				next_x = x;
				next_y = y-1;
				break;
			case 1:
				next_x = x;
				next_y = y+1;
				break;
		}
		if(board_->isInBounds(next_x, next_y) && !board_->get(next_x, next_y)) {
			possible_move_.push_back(pair<int,int>(next_x,next_y));
			if(!isMoved()) {
				switch(player_) {
					case 0:
						next_x = x;
						next_y = y-2;
						break;
					case 1:
						next_x = x;
						next_y = y+2;
						break;
				}
				if(board_->isInBounds(next_x, next_y) && !board_->get(next_x, next_y)) {
					possible_move_.push_back(pair<int,int>(next_x,next_y));
				}
			}
		}
		switch(player_) {
			case 0:
				next_x = x+1;
				next_y = y-1;
				break;
			case 1:
				next_x = x-1;
				next_y = y+1;
				break;
		}
		if(board_->isInBounds(next_x, next_y)) {
			Man *target = board_->get(next_x, next_y);
			if(target) {
				if(target->getSide() != getSide()) {
					possible_move_.push_back(pair<int,int>(next_x,next_y));
				}
			}
			else {
				switch(player_) {
					case 0:
						target = board_->get(next_x, next_y+1);
						break;
					case 1:
						target = board_->get(next_x, next_y-1);
						break;
				}
				/**
				Pawn *pawn = dynamic_cast<Pawn*>(board_->getLastMoved());
				if(pawn && pawn->isJump() && pawn == target) {
					possible_move_.push_back(pair<int,int>(next_x,next_y));
				}
				/**/
			}
		}
		switch(player_) {
			case 0:
				next_x = x-1;
				next_y = y-1;
				break;
			case 1:
				next_x = x+1;
				next_y = y+1;
				break;
		}
		if(board_->isInBounds(next_x, next_y)) {
			Man *target = board_->get(next_x, next_y);
			if(target) {
				if(target->getSide() != getSide()) {
					possible_move_.push_back(pair<int,int>(next_x,next_y));
				}
			}
			else {
				switch(player_) {
					case 0:
						target = board_->get(next_x, next_y+1);
						break;
					case 1:
						target = board_->get(next_x, next_y-1);
						break;
				}
				/**
				Pawn *pawn = dynamic_cast<Pawn*>(board_->getLastMoved());
				if(pawn && pawn->isJump() && pawn == target) {
					possible_move_.push_back(pair<int,int>(next_x,next_y));
				}
				/**/
			}
		}
	}
}
Example #19
0
int main(int argc, const char * argv[]) {
    Man *m = new Man(20);
    m->sayHello();
    return 0;
}