Example #1
0
int main(){
  Critter crit;
  crit.Talk();
  int choice;
  do{
	system("clear");
	cout << "\nCritter Caretaker\n\n";
	cout << "0 - Quit\n";
	cout << "1 - Listen to your critter\n";
	cout << "2 - Feed your crettir\n";
	cout << "3 - Play with your critter\n";
	cout << "Choice: ";
	cin >> choice;
	switch(choice)
	{
	  case 0:
	    cout << "Good-bye.\n";
	    break;
	  case 1:
	    crit.Talk();
	    break;
	  case 2:
	    crit.Eat();
	    break;
	  case 3:
	    crit.Play();
	    break;
	  default:
	    cout << "\nSorry.but " << choice << " isn`t a valid choice.\n";
	}
	usleep(3000000);
    } while (choice !=0);
  return 0;
}
Example #2
0
int main()
{
	Critter crit;
	unsigned choice;
	
	do
	{
		choice = askForInt(MENU, 4,0);
		//std::cout << "Current Mood: " << crit.GetMood() << std::endl;
		switch(choice)
		{
			case 0:
				std::cout << "Good Bye!\n";
				break;
			case 1:
				crit.Talk();
				break;
			case 2:
				crit.Eat();
				break;
			case 3:
				crit.Play();
				break;
			case 4:
				crit.PerformTrick();
				break;
		}
	}while(choice != 0);
	
return 0;
}
Example #3
0
int main () {
    srand(static_cast<unsigned int>(time(0)));

    Critter crit;

    int choice;

    do {
        cout << endl << "Critter Caretaker" << endl;
        cout << "-----------------" << endl << endl;
        cout << "0 - Quit" << endl;
        cout << "1 - Listen to your critter" << endl;
        cout << "2 - Feed your critter" << endl;
        cout << "3 - Play with your critter" << endl;
        cout << "4 - Ask your critter to perform a trick." << endl << endl;

        cout << "Choice: ";
        cin >> choice;

        switch (choice) {
            case 0:
                cout << "Good-bye." << endl;
                break;
            case 1:
                crit.Talk();
                break;
            case 2:
                crit.Eat();
                break;
            case 3:
                crit.Play();
                break;
            case 4:
                crit.PerformTrick();
                break;
            default:
                cout << "Sorry, but " << choice << " isn't a valid choice." << endl;
                break;
        }
    } while (choice != 0);

    return 0;
}
Example #4
0
void Simulation::AddCritter(float x, float y, Critter *parentA, Critter *parentB){
	Critter *c = NULL;
	for(unsigned int n=0; n<critter.size(); n++){
		if(!critter[n].active){
			c = &critter[n];
			break;
		}
	}
	if(c==NULL){
		if(critter.capacity()<=critter.size())return;
		critter.push_back(Critter());
		c = &critter.back();
	}
	if(critCount>params.critMaxInWorld){
		unsigned int t = 0;
		do{ t = params.rnd.Next()%critter.size(); }while((!critter[t].active)||(parentA==&critter[t])||(parentB==&critter[t]));
		RemoveCritter(t);
	}
	c->active = true;
	c->Spawn(x,y,parentA,parentB,&params);
	critCount++;
}
Example #5
0
int main() {
    Critter crit;
    
    crit.Talk();
    
    int choice = -1;
    
    while(choice != 0) {
        printInstructions();
        
        cout << "Choice: ";
        cin >> choice;
        cout << "\n";
        
        switch(choice) {
            case 0:
                cout << "Good bye.\n";
                break;
            case 1:
                crit.Talk();
                break;
            case 2:
                crit.Eat();
                break;
            case 3:
                crit.Play();
                break;
            default:
                cout << "\nSorry, but " << choice << " isn't a valid choice.\n";
                break;
        }
    }
    
    
    return 0;
}
Example #6
0
void Simulation::DrawInfoGUI(SDL_Surface *dst, int posX1, int posY1, int posX2, int posY2){
	sprintf(buffer,
		"Casfire Artificial Life v1.1 - 2012\n"
		"http://casfire.com\n\n"
		"Critters: %u\n"
		"Food: %u\n"
		"Frame: %"PRIu64
		,critCount
		,foodCount
		,frameCount
	);

	if(critSelected){
		infoText.Render(buffer,0x000000FF,13);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,posY2-posY1,false,false);

		Critter *c = &critter[critSelect];
		float xsize = (posX2 - posX1);
		Uint32 fillColor = 0x00AA00FF, badColor = 0xFF0000FF, goodColor = 0x00FF00FF;

		c->Draw(dst,posX1 + xsize*0.8,posY1 + xsize*0.2 - 10,xsize*0.2);

		int px1 = posX1 + 100, px2 = posX2, pxh = (px1+px2)/2;
		xsize = (px2 - px1);

		posY1 += 170;

		infoText.Render("Size:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		boxColor(dst,px1,posY1,px1+(xsize*c->in_size),posY1+15,fillColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;

		infoText.Render("Hunger:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		boxColor(dst,px1,posY1,px1+(xsize*(1.-c->in_energy)),posY1+15,fillColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;

		infoText.Render("Waste:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		boxColor(dst,px1,posY1,px1+(xsize*c->in_waste),posY1+15,fillColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;

		infoText.Render("Age:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		boxColor(dst,px1,posY1,px1+(xsize*c->in_age),posY1+15,fillColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;

		infoText.Render("Membrane:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		boxColor(dst,px1,posY1,px1+(xsize*(0.5*(c->out_expose+1.))),posY1+15,fillColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;

		float val;

		infoText.Render("Mood:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		val = c->out_mood;
		if(val<0.)boxColor(dst,px1+(xsize*0.5*(val+1.)),posY1,pxh,posY1+15,badColor);
		else boxColor(dst,pxh,posY1,pxh+xsize*(val*0.5),posY1+15,goodColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;

		infoText.Render("Spin:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		val = c->out_spin;
		if(val<0.)boxColor(dst,px1+(xsize*0.5*(val+1.)),posY1,pxh,posY1+15,fillColor);
		else boxColor(dst,pxh,posY1,pxh+xsize*(val*0.5),posY1+15,fillColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;

		infoText.Render("Speed:",0x000000FF,11);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,15,false,true);
		val = c->out_move;
		if(val<0.)boxColor(dst,px1+(xsize*0.5*(val+1.)),posY1,pxh,posY1+15,fillColor);
		else boxColor(dst,pxh,posY1,pxh+xsize*(val*0.5),posY1+15,fillColor);
		rectangleColor(dst,px1,posY1,px2,posY1+15,0x000000FF);
		posY1 += 20;
	}else{
		infoText.Render(buffer,0x000000FF,13);
		infoText.Blit(dst,posX1,posY1,posX2-posX1,posY2-posY1,true,true);
	}
}
Example #7
0
int main()
{
  Critter crit;
  cout << crit.GetHunger() << endl;
  return 0;
}
Example #8
0
// take a step in the simulation
// Move all of the critters and handle collisions.
void CritterModel::step() {
    moveCount++;

    std::cout << "\n Beginning simulation move #" << moveCount << std::endl;

    // it's not quite fair to the critters in the lower right section
    // of the map, but it's easy to track the progress, iterate
    // through the map moving each critter
    for(unsigned int x = 0; x < width; x++) {
	for(unsigned int y = 0; y < height; y++) {
	    Critter *currCritter = grid[x][y];

	    // if there's no critter here, move on
	    if(currCritter == NULL ||
	       currCritter->hasGone()) {
		continue;
	    }

	    //update the critter about some state of it's world that
	    //it may care about:
	    currCritter->setAlive(true);
	    currCritter->setX(x);
	    currCritter->setY(y);
	    currCritter->setWidth(width);
	    currCritter->setHeight(height);
	    
	    Critter *neighbor = discoverNeighbor(NORTH, x, y, NULL, NULL);
	    currCritter->setNeighbor(NORTH, neighbor == NULL ? EMPTY_NEIGHBOR : neighbor->getChar());
	    neighbor = discoverNeighbor(SOUTH, x, y, NULL, NULL);
	    currCritter->setNeighbor(SOUTH, neighbor == NULL ? EMPTY_NEIGHBOR : neighbor->getChar());
	    neighbor = discoverNeighbor(EAST, x, y, NULL, NULL);
	    currCritter->setNeighbor(EAST, neighbor == NULL ? EMPTY_NEIGHBOR : neighbor->getChar());
	    neighbor = discoverNeighbor(WEST, x, y, NULL, NULL);
	    currCritter->setNeighbor(WEST, neighbor == NULL ? EMPTY_NEIGHBOR : neighbor->getChar());

	    currCritter->beginTurn();

	    // move the critter!
	    grid[x][y] = NULL;
	    
	    Direction move = currCritter->getMove();
	    unsigned int newX, newY;
	    neighbor = discoverNeighbor(move, x, y, &newX, &newY);
	    if(neighbor == NULL) {
		grid[newX][newY] = currCritter;
		currCritter->setX(newX);
		currCritter->setY(newY);
	    } else if(currCritter->getChar() != neighbor->getChar()) {
		// two critters of different kinds, fight!

		// Note: we use the getChar method of your critters to
		// determine if your critters are "the same".  This
		// models the idea that the critter looks at the other
		// critter to determine whether it should fight.  Also
		// as a bonus, you could try to be sneaky about hiding
		// from your neighbors!

		currCritter->setX(newX);
		currCritter->setY(newY);
		
		if(DEBUG) {
		    std::cout << currCritter->getChar() << " versus " <<
			neighbor->getChar() << ": ";
		}

		Attack attack = currCritter->fight(neighbor->getChar());
		Attack defend = neighbor->fight(currCritter->getChar());

		Critter *winner;
		
		// do rock paper scissors here
		if(attack == defend) {
		    // coin flip for tie
		    winner = rand() % 2 == 0 ? currCritter : neighbor;
		} else {
		    switch(attack) {
		    case ROAR:
			// only a POUNCE defense wins (SCRATCH or FORFEIT will be a win)
			winner = defend == POUNCE ? neighbor : currCritter;
			break;
		    case POUNCE:
			// only a SCRATCH defense wins (ROAR or FORFEIT will be a win)
			winner = defend == SCRATCH ? neighbor : currCritter;
			break;
		    case SCRATCH:
			// only a ROAR defense loses (POUNCE or FORFEIT will be a win)
			winner = defend == ROAR ? neighbor : currCritter;
			break;
		    default: // FORFEIT
			// dead
			winner = neighbor;
			break;
		    }
		}

		Critter *loser = currCritter == winner ? neighbor : currCritter;

		if(DEBUG) {
		    std::cout << winner->getChar() << " wins!" << std::endl;
		}

		winner->win();
		loser->lose();

		loser->setAlive(false);
		delete loser;
		
		grid[newX][newY] = winner;
	    } else { // don't move onto your sibling!
		newX = x;
		newY = y;
		grid[newX][newY] = currCritter;
	    }

	    // make sure that currCritter isn't dead, and if not, mark it and
	    // let it know that its turn is over.
	    if(grid[newX][newY] == currCritter) {
		currCritter->setMark();
		currCritter->endTurn();
	    }
	}
    }

    for(unsigned int x = 0; x < width; x++) {
	for(unsigned int y = 0; y < height; y++) {
	    Critter *currCritter = grid[x][y];
	    
	    // if there's no critter here, move on
	    if(currCritter == NULL) {
		continue;
	    }

	    currCritter->clearMark();
	}
    }
}
void testCopyConstructor(Critter aCopy)
{
	aCopy.Greet();
}
Example #10
0
void GameStatePlay::handleInput() {
	sf::Event event;

	std::map<int, Critter*> critters = current_wave->getContainerOfCritters();

	for(std::map<std::pair<int,int>, Tower*>::iterator it = tower_manager.getTowerMap()->begin() ; it != tower_manager.getTowerMap()->end() ; ++it) {

		Tower* tower = it->second;
		if(tower != NULL) {

			for (int i = 0; i < int(critters.size()); ++i) {
				while(critters[i]->isActive && tower->canAttack(critters[i]) && !this->game->isGamePaused) {
					Critter* target = tower->getTarget();
					tower->attack();
					if(target->getHitPoints() <= 0) target->isActive = false;

					if(target != NULL) {
						std::pair<float, float> tpos = target->getPosition();
						sf::Text ch(std::to_string(target->getHitPoints()), font, 12); 
						if(target->getMovementDirection() == Critter::MovementDirection::LEFT
							|| target->getMovementDirection() == Critter::MovementDirection::RIGHT)
							ch.setPosition(tpos.first, tpos.second - 16);
						else if(target->getMovementDirection() == Critter::MovementDirection::UP
							|| target->getMovementDirection() == Critter::MovementDirection::DOWN)
							ch.setPosition(tpos.first + 10, tpos.second);
						ch.setColor(sf::Color::Red);
						critterHealth[target->getId()] = ch;
						sf::Clock c;
						healthClock[target->getId()] = c;
					}
					if(!critters[i]->getSpecialEffectApplied()) {
						tower->applySpecialEffect(critters[i]);
						critters[i]->setSpecialEffectApplied(true);
					}

				}
			}
		}
	}

	while(!returnToMenu && this->game->game_window.pollEvent(event)) {
		localPosition = sf::Mouse::getPosition(this->game->game_window);
		tileX = localPosition.x/32;
		tileY = localPosition.y/32;

		switch(event.type) {
			/** Close the window */
		case sf::Event::Closed: {
			game->game_window.close();
			break;
								}
		case sf::Event::LostFocus: {
			if (!this->game->isGamePaused)
				this->game->isGamePaused = true;
			break;
								   }
		case sf::Event::GainedFocus: {
			std::cout << "Game Gained Focus" << std::endl;
			if (this->game->isGamePaused)
				this->game->isGamePaused = false;
			break;
									 }
		case sf::Event::MouseButtonPressed: {
			buttonCommandLibrary();
			towerCommandLibrary(tileX, tileY);
			break;
											}
		case sf::Event::MouseMoved: {
			if(tower_manager.getTower(tileX, tileY) != NULL && tower_manager.getTower(tileX, tileY)->spriteContains(localPosition)) {
				towerSpecs.setString(tower_manager.getTower(tileX, tileY)->getTowerSpecs());
				//upgradeTowerSpecs.setString(tower_manager.getTower(tileX, tileY)->getUpgradeTowerSpecs());
			}
			break;
									}
		case sf::Event::KeyPressed: {
			towerCommandLibrary(tileX, tileY);
			blacky->controlCat(event.key.code);	// for controlling blackcat
			if(event.key.code == sf::Keyboard::B)
				(!blacky->isActive) ? blacky->isActive = true : blacky->isActive = false;
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
				(!show_waypoints) ? show_waypoints = true : show_waypoints = false;
			//show_waypoints = !show_waypoints;
			break;
									}
		default: break;
		}
	}
}
Example #11
0
int main(int argc, char** argv[]) {
  /**********************************************
     Creating critters using the CritterFactory
   **********************************************/
  std::cout << "Let's create some critters!" << std::endl;

  // Create a new Cat
  Critter* mr_meow = CritterFactory::createCritter(CritterFactory::CritterType::CAT);
  std::cout << "Critter 1:" << std::endl << *mr_meow;
  
  // Create a new Dog
  Critter* fido = CritterFactory::createCritter(CritterFactory::CritterType::DOG);
  std::cout << "Critter 2:" << std::endl << *fido;
  
  // Create a new Werecat
  Critter* scratches = CritterFactory::createCritter(CritterFactory::CritterType::WERECAT);
  std::cout << "Critter 3:" << std::endl << *scratches;
  
  // Create a new Werewolf
  Critter* jacob = CritterFactory::createCritter(CritterFactory::CritterType::WEREWOLF);
  std::cout << "Critter 4:" << std::endl << *jacob;

  /**************************
     Creating a map
  **************************/
  std::cout << "\nLet's create a map!" << std::endl;

  Map map = Map();

  std::cout << map << std::endl;
  std::cout << "X = Scenery cell" << std::endl
            << "P = Path cell" << std::endl
            << "S = Start cell" << std::endl
            << "E = Exit cell" << std::endl;

  /**************************
     Creating critter waves
   **************************/
  std::cout << "\nLet's create a critter wave!" << std::endl;

  // Create a wave of 9 cats
  CritterWave wave_of_meows(9, CritterFactory::CritterType::CAT);

  for (int i = 1; i <= wave_of_meows.numOfCritters; ++i) {
    wave_of_meows.addCritter(i, CritterFactory::createCritter(wave_of_meows.type));
  }
  
  std::cout <<  "Critters in this wave:\n" << wave_of_meows << std::endl;

  /**************************
    Following a path
  **************************/
  std::cout << "\nLet's follow the path of Critters 1 & 2!" << std::endl
            << "Critters will only move on path cells." << std::endl
            << "Watch Critter 2 follow the lead of Critter 1!\n" << std::endl;
  
  /* Create a player */ 
  Player player;

  /* Start */
  //Spawn first critter in wave at start
  wave_of_meows.spawnAtStartCell(1, 3, 1);

  Critter* critter1 = wave_of_meows.findCritter(1);
  Critter* critter2 = wave_of_meows.findCritter(2);

  std::cout << "Start: " << std::endl 
    << "Critter 1 is on cell " << critter1->getPosition() << std::endl
    << "Critter 2 is not spawned on the map yet." << std::endl;
  
  /* Update 1 */
  //Spawn second critter in wave at start
  wave_of_meows.spawnAtStartCell(2, 3, 1);

  critter1->chooseNextPathCell(map, critter1->row, critter1->col, player);

  std::cout << "Update 1: " << std::endl 
    << "Critter 1 is on cell " << critter1->getPosition() << std::endl
    << "Critter 2 is on cell " << critter2->getPosition() << std::endl;

  /* Update 2 */
  critter1->chooseNextPathCell(map, critter1->row, critter1->col, player);
  critter2->chooseNextPathCell(map, critter2->row, critter2->col, player);

  std::cout << "Update 2: " << std::endl 
    << "Critter 1 is on cell " << critter1->getPosition() << std::endl
    << "Critter 2 is on cell " << critter2->getPosition() << std::endl;

  /* Update 3 */
  critter1->chooseNextPathCell(map, critter1->row, critter1->col, player);
  critter2->chooseNextPathCell(map, critter2->row, critter2->col, player);

  std::cout << "Update 3: " << std::endl 
    << "Critter 1 is on cell " << critter1->getPosition() << std::endl
    << "Critter 2 is on cell " << critter2->getPosition() << std::endl;

  /******************************************************
    Reaching the exit and stealing coins from the player
  *******************************************************/
  std::cout << "\nLooks like Critter 1 has reached the exit!" << std::endl
            << "Player, prepare to lose some coins!" << std::endl;
  
  std::cout << player << std::endl;

  /* Update 4 */
  critter1->chooseNextPathCell(map, critter1->row, critter1->col, player);
  critter2->chooseNextPathCell(map, critter2->row, critter2->col, player);

  std::cout << "Update 4: " << std::endl 
    << "Critter 1 is on cell " << critter1->getPosition() << std::endl
    << "Critter 2 is on cell " << critter2->getPosition() << std::endl;

  std::cout << "Critter 1 says: \"MUHAHAHA, I've stolen " << critter1->getStealStrength() << " coins!" << std::endl;
  std::cout << player << std::endl;
  
  /* Update 5 */
  critter1->chooseNextPathCell(map, critter1->row, critter1->col, player);
  critter2->chooseNextPathCell(map, critter2->row, critter2->col, player);

  std::cout << "Update 4: " << std::endl 
    << "Critter 2 is on cell " << critter2->getPosition() << std::endl;

  std::cout << "Critter 2 says: \"MUHAHAHA, now I've stolen " << critter1->getStealStrength() << " coins!" << std::endl;
  std::cout << player << std::endl;
  
  /******************************************************
    Critter takes damage from towers
  *******************************************************/
  std::cout << "\nLet's get back at those thieving critters!" << std::endl
            << "When Critters move into the range of a tower, they lose health." << std::endl
            << "Critters die if they have no more hit points!" << std::endl;

  std::cout << "\nLet's create a second map with a tower on it!" << std::endl;

  Map map2 = Map();
  map2.placeTower(2, 4);

  std::cout << map2 << std::endl;
  std::cout << "X = Scenery cell" << std::endl
            << "P = Path cell" << std::endl
            << "S = Start cell" << std::endl
            << "E = Exit cell" << std::endl
            << "T = Cell with tower" << std::endl;

  std::cout << "\nOur towers have a strike range of one cell all around them." << std::endl
            << "So, critters walking on the path cells (3,3) and (3,4) will take damage." << std::endl;

  std::cout << "\nLet's create a wave of only one critter to test this!" << std::endl;
 
  // Create a wave of 1 cat (forever alone)
  CritterWave a_lone_meow(1, CritterFactory::CritterType::CAT);
  
  a_lone_meow.addCritter(1, CritterFactory::createCritter(a_lone_meow.type));

  /* Start */  
  //Spawn first critter in wave at start
  a_lone_meow.spawnAtStartCell(1, 3, 1);

  Critter* critter = a_lone_meow.findCritter(1);

  std::cout << "Start: " << std::endl 
    << "Critter is on cell " << critter->getPosition() << std::endl
    << "Critter says: \"I'm safe! Totally not in range. Meow.\"" << std::endl
    << "Critter health: " << critter->getHitPoints() << std::endl;

    /* Update 1 */

  critter->chooseNextPathCell(map, critter->row, critter->col, player);

  std::cout << "Update 1: " << std::endl 
    << "Critter is on cell " << critter->getPosition() << std::endl
    << "Critter says: \"I'm safe! Totally not in range. Meow.\"" << std::endl
    << "Critter health: " << critter->getHitPoints() << std::endl,

  /* Update 2 */

  critter->chooseNextPathCell(map, critter->row, critter->col, player);
  critter->takeDamage(map2.map[1][3].strengthOfAttack);

  std::cout << "Update 2: " << std::endl 
    << "Critter is on cell " << critter->getPosition() << std::endl
    << "Critter says: \"I'm hit! That hurts. HISSST.\"" << std::endl
    << "Critter health: " << critter->getHitPoints() << std::endl;

  /* Update 3 */

  critter->chooseNextPathCell(map, critter->row, critter->col, player);
  critter->takeDamage(map2.map[1][3].strengthOfAttack);

  std::cout << "Update 3: " << std::endl 
    << "Critter is on cell " << critter->getPosition() << std::endl
    << "Critter says: \"I'm hit! That hurts. HISSST.\"" << std::endl
    << "Critter health: " << critter->getHitPoints() << std::endl;

  if (critter->getHitPoints() <= 0) {
    std::cout << "RIP, Critter!" << std::endl;
    // Remove dead Critter from the wave
    a_lone_meow.removeCritter(1);
  }



  return 0;
}