void update(void){
			f.update();
			razer_convert_keycode_to_pos(keys_history[0],&pos);
			if (last_pos.x!=pos.x || last_pos.y!=pos.y){
				last_pos.x=pos.x; last_pos.y=pos.y;
				//cout <<"key pos = "<<(pos).x<<","<<(pos).y<<endl;
			}
			direction_t d=LEFT;
			if(pos.x == 16 && pos.y == 4)
				d=UP;
			else if(pos.x == 16 && pos.y == 5)
				d=DOWN;
			else if(pos.x == 15 && pos.y == 5)
				d=LEFT;
			else if(pos.x == 17 && pos.y == 5)
				d=RIGHT;
			s.move(d);
			g.update();
			s.update();
			razer_update_keys(chroma,chroma->keys);
			usleep(400000);
			Cord sc = s.getFront();
			Cord fc = g.getPosition();
			if(sc.x==fc.x && sc.y==fc.y){
				Food tmp = Food();
				s.grow();
				s.grow();
				g = tmp;
			}
			razer_update(chroma);
			razer_frame_limiter(chroma,13);
		}
int main() {
    Food apple;
    Food pie;

    pie.beCooked(true);

    Food sugar = apple + pie;

    operator<<(cout, apple);
    cout << apple;

    cout << "-------\n";

    Food carrots = pie;
    carrots = pie;

    cout << carrots;

    cout << "-------\n";

    Car mustang;
    Food celery = mustang;

    cout << Food(mustang);
    cout << (Food)mustang;
    cout << static_cast<Food>(mustang);

    return 0;
}
示例#3
0
void onTimer( int v ) {
	 
	glutTimerFunc( TIMER_PERIOD, onTimer, 0 ) ;
	// Write your codes here.

    
	
	 // to refresh the window it calls display() function

	if ( gameState != RUN ) return ;

	if ( lastKey == UP ) snake.setSpeed(Vec(0,1)) ;
	if ( lastKey == DOWN ) snake.setSpeed(Vec(0,-1)) ;
	if ( lastKey == LEFT ) snake.setSpeed(Vec(-1,0)) ;
	if ( lastKey == RIGHT ) snake.setSpeed(Vec(1,0)) ;

	snake.Update() ;

	if( snake.getPos().equal( food.getPos())) {
		score++;
		food.reset();
		snake.grow();
	}

	/*if ( snake.hitWall()) {
		gameState = GAMEOVER ;
	}*/

	if ( snake.bites() ) {
		gameState = GAMEOVER ;
	}

	glutPostRedisplay() ; // display()

}
示例#4
0
Dish* Ingridients::readDish(const QJsonObject& json) {
    PRINT_DEBUG("Reading new dish");

    QJsonArray itemsList = json["items"].toArray();
    Food* newFood = readFood(itemsList[0].toObject()["food"].toObject());
    Dish* newDish = new Dish(json["name"].toString().toStdString(), newFood,
                             itemsList[0].toObject()["amount"].toInt());

    avaliableItems.push_back(newFood);
    newFood->addItemList(&avaliableItems);

    for ( int index = 1; index < itemsList.size(); index++ ) {
        newFood = readFood(itemsList[index].toObject()["food"].toObject());
        newDish->addFood(newFood, itemsList[index].toObject()["amount"].toInt());
        std::list<Item*>::iterator it;

        for ( it = avaliableItems.begin(); ; it++ ) {
            if ( !(*it)->getName().compare(newFood->getName()) ) {
                delete newFood;

                break;
            } else if ( it == avaliableItems.end() ) {
                avaliableItems.push_back(newFood);
                newFood->addItemList(&avaliableItems);
            }
        }
    }

    return newDish;
}
示例#5
0
文件: simple.cpp 项目: cornelius/kode
Food Food::parseElement( const QDomElement &element, bool *ok )
{
  if ( element.tagName() != "food" ) {
    qCritical() << "Expected 'food', got '" <<element.tagName() << "'.";
    if ( ok ) *ok = false;
    return Food();
  }

  Food result = Food();

  QDomNode n;
  for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    QDomElement e = n.toElement();
    if ( e.tagName() == "name" ) {
      result.setName( e.text() );
    }
    else if ( e.tagName() == "taste" ) {
      result.setTaste( e.text() );
    }
  }


  if ( ok ) *ok = true;
  return result;
}
示例#6
0
bool		Core::posFood(const Food &food)
{
  if ((food.getPosX() == _pos[0].getPosX()) && (food.getPosY() == _pos[0].getPosY()))
    setFood(true);
  else
    setFood(false);
  return (true);
}
示例#7
0
void SamsMode::insFood(int nr)
{
	Food *f = new Food;
	f->energyLevel = *food_maxenergy;
//	f->resize();
	f->createBody( m_dynamicsWorld, btVector3( (critterspacing/2)+(critterspacing*nr), 3.0f, 8.0f ) );
	food_units.push_back( f );
}
示例#8
0
void Animal::updateStomachContents() {
    std::vector<Food *>::iterator it = stomach.begin();
    while (it != stomach.end()) {
        Food *food = (*it);
        if (food->getAmount() <= 0.0) {
            it = stomach.erase(it);
        } else {
            it++;
        }
    }
}
示例#9
0
bool Store::addFood(Food food) {
  if (food.getId() != getNextId()) {
    throw "Food has invalid id #";
    return false;
  }
  bst->insert(food);
  hashBrownTable.insertItem(food.getId(), bst->get(food));
  numFoods++;
  maxId++;
  return true;
}
void AdminWindow::populateFoodList()
{
    listFood = new QListWidget();


    QWidget *widget = new QWidget();
    QVBoxLayout *layout = new QVBoxLayout();

    QSqlQuery query;
    query.prepare("SELECT * FROM Foods");
    bool r = query.exec();
    if(r == true)
    {
        while(query.next())
        {
          //  qDebug()<<"Food Selected: "<<query.record().value("name").toString();
            //======================
            QListWidgetItem* item = new QListWidgetItem();
            item->setSizeHint(QSize(0,60));



            FoodRow *catagory = new FoodRow();
            Food *food = new Food();
            food->setName(query.record().value("Name").toString());
            food->setCatagroy(query.record().value("Catagory").toString());
            food->setPrice(query.record().value("Price").toFloat());



            catagory->SetFood(food);
            layout->addWidget(catagory);


            connect(catagory, SIGNAL(signal_foodRemoved(QString)), this, SLOT(onFoodRemoved(QString)));
            connect(catagory, SIGNAL(signal_foodEdited(Food*)), this, SLOT(onFoodEdited(Food*)));


        }



        widget->setLayout(layout);
        ui->scrollArea_FoodAdd->setWidget(widget);



    }
}
示例#11
0
void		Core::displayBegin(const IGui *gui, const Food &food) const
{
  int		i;

  i = 0;
  if (gui)
    {
      while (i <= SIZE_SNAKE)
	{
	  gui->displayBody(_pos[i].getPosX(), _pos[i].getPosY());
	  i++;
	}
      gui->displayFood(food.getPosX(), food.getPosY());
    }
}
示例#12
0
void Ingridients::writeFood(QJsonObject& json, Food& food) const {
    PRINT_DEBUG("Writing food" << food.getName());

    json["name"] = QString::fromStdString(food.getName());
    json["mass"] = static_cast<qint64>(food.getMass());
    json["price"] = static_cast<qint64>(food.getPrice());
    json["measureType"] = static_cast<int>(food.getUnitType());
    json["fats"] = static_cast<qint64>(food.getFats());
    json["proteins"] = static_cast<qint64>(food.getProteins());
    json["carbohydrates"] = static_cast<qint64>(food.getCarbohydrates());
    json["calories"] = static_cast<qint64>(food.getCalories());
}
void InGameLayer::moveAllFood()
{
	Food* getFood = nullptr;
	float vx = mPanda->getVx();
	for (int i = foodList.size() - 1; i >= 0 ; i--)
	{
		getFood = foodList.at(i);
		getFood->move(vx);
		if (getFood->getPositionX() <= -getFood->getContentSize().width)
		{
			mFoodPool.takeIn(getFood);
			elementLayer->removeChild(getFood);
			foodList.eraseObject(getFood);
		}
	}
}
示例#14
0
文件: snake.cpp 项目: ale93111/snake
	void playon(Board & terminal)
	{
		while((command = getch()) != 'q' && !gameover)
		{
			clear();
			
			//mvprintw(y,x,"☺");
			Ekans.move(command);
			
			Ekans.display();
			
			gameover = Ekans.check_coord(terminal);
				
			pidgey.check(Ekans, terminal);

			refresh();
		}
	
		if(gameover) 
		{
			clear();
			//center end screen
			mvprintw(ystart-2,xstart-6, "GAMEOVER");
			mvprintw(ystart  ,xstart-6, "Score: %d ", Ekans.score);
			refresh();
			sleep(2);
		}
	}
示例#15
0
void Snake::Move(Food& food, int dif)
{
	TestBorderCollision();
	if (gameover)
	{
		return;
	}

	for (int i = 0; i < s_parts.size(); i++)
	{
		standard_field.EraseAtMap(s_parts[i].GetX(), s_parts[i].GetY());
		switch (s_parts[i].GetDirection())
		{
		case UP:
			s_parts[i].SetY(s_parts[i].GetY() - 1);
			break;
		case RIGHT:
			s_parts[i].SetX(s_parts[i].GetX() + 1);
			break;
		case DOWN:
			s_parts[i].SetY(s_parts[i].GetY() + 1);
			break;
		case LEFT:
			s_parts[i].SetX(s_parts[i].GetX() - 1);
			break;
		}

		standard_field.AddToMap(s_parts[i].GetX(), s_parts[i].GetY(), SNAKE_PART);
	}

	if (s_parts[0].GetX() == food.GetX() && s_parts[0].GetY() == food.GetY())
	{
		EatFood(food, dif);
		food.Generate();										    
	}

	for (int i = s_parts.size() - 1; i > 0; i--)
	{
		if (s_parts[i].GetDirection() != s_parts[i - 1].GetDirection())
		{
			s_parts[i].SetDirection(s_parts[i - 1].GetDirection());
		}
	}

	TestSelfCollision();
}
示例#16
0
bool Store::anyRecipeReferences(int id) {
  vector<Food> *v = getInSortedOrder();
  for (int i = 0; i < v->size(); i++) {
    Food food = v->operator[](i);
    if (food.isRecipe()) {
      vector<int> ingredients = food.getIngredients();
      for (int j = 0; j < ingredients.size(); j++) {
        if (ingredients[j] == id) {
          delete v;
          return true;
        }
      }
    }
  }
  delete v;
  return false;
}
示例#17
0
void Evolution::init()
{
    mFoodAmount = 500;
    mMaxBio = 520;
    mFoodSpawnTime = 0.0f;
    mFoodSpawnCycleLength = 0.0f;

    //int j = 0;
    for (int i=0; i<mMaxBio-mFoodAmount; ++i)
    {
        Stat stat;
        stat.pos = GetRandPos();
        //stat.canSee = false;
        //stat.eggEater = false;
        stat.carnivore = false;
        stat.lifeTimeLength = 180.0f;
        stat.eggTimeLength = 60.0f;
        stat.eggCycleLength = 30.0f;//30.0f
        stat.foodCycleLength = 45.0f;
        stat.speed = 20.0f;//20.0f
        stat.sightDistance = 0.0f;//0.0f
        //stat.species = j;
        stat.fearDistance = 17.0f;//17.0f
        stat.pursuitLength = 5.0f;
        //stat.foodBeforeEgg = 2;
        //stat.eyeParts = 0;
        //stat.eggEatParts = 0;
        //stat.carnivore = true;
        stat.carnivoreParts = 0;//0.0f
        //stat.family.pParent = NULL;
        stat.nameber = GetRandFloat()*1000.0f;

        Lifeform lifeform;
        lifeform.spawn(stat);
        lifeformList.push_back(lifeform);
        //++j;
        //if (j > 4) j = 0;
    }

    for (int i=0; i<mFoodAmount; ++i)
    {
        Food food;
        food.spawn(GetRandPos());
        foodList.push_back(food);
    }
}
void Philosopher::operator()(Food& food, Philosopher& phil)
{
  while (food.hasFood()) {
    if (phil.hungry()) {
      if (phil.m_isOdd)
        food.acquireForksOdd(phil.m_id);
      else
        food.acquireForks(phil.m_id);
      food.eat(phil.m_id);
      phil.m_amountToEat--;
      food.releaseForks(phil.m_id);
      phil.m_eaten++;

      think();
    }
  }
}
示例#19
0
void Simulation::AddFood(float x, float y, float energy, float waste, float dir){
	Food *f = NULL;
	for(unsigned int n=0; n<food.size(); n++){
		if(!food[n].active){
			f = &food[n];
			break;
		}
	}
	if(f==NULL){
		if(food.capacity()<=food.size())return;
		food.resize(food.size()+1);
		f = &food.back();
	}
	f->Spawn(x,y,energy,waste,dir,&params);
	f->active = true;
	foodCount++;
}
示例#20
0
vector<Food> *Store::getMatching(vector<string> keywords) {
  vector<Food> *foods = getInSortedOrder();
  vector<Food> *ret = new vector<Food>();
  for (int i = 0; i < foods->size(); i++) {
    Food food = foods->operator[](i);
    bool matching = false;
    for (int j = 0; j < keywords.size(); j++) {
      if (lower(food.getName()).find(keywords[j]) != -1) {
        matching = true;
      }
    }
    if (matching) {
      ret->push_back(food);
    }
  }
  delete foods;
  return ret;
}
示例#21
0
void Ingridients::loadFood(const QJsonArray& jsonArray) {
    PRINT_DEBUG("Loading food");

    for ( int i = 0; i < jsonArray.size(); i++ ) {
        Food* newFood = readFood(jsonArray[i].toObject());
        std::list<Item*>::iterator it;

        for ( it = avaliableItems.begin(); ; it++ ) {
            if ( !(*it)->getName().compare(newFood->getName()) ) {
                delete newFood;

                break;
            } else if ( it == avaliableItems.end() ) {
                avaliableItems.push_back(newFood);
                newFood->addItemList(&avaliableItems);
            }
        }
    }
}
示例#22
0
void Players::checkNom(Food &noms) {
	for (int ii = 0; ii < n_players; ii++) {
		if (noms.isEaten(Agario[ii].getPosition(), Agario[ii].getRadius())) {
			Agario[ii].grow();
		}
		if (int num = isEaten(Agario[ii].getPosition(), Agario[ii].getRadius())) {
			Agario[ii].grow(num);
		}
	}
}
示例#23
0
void World::snakeFoodCollision()
{
    if(!snakeHead->collision(*food))
        return;

    snakeHead->addTail();
    /// check if the snake is already present at the new position of the food
    // collision detected; set a new random position for the food
    auto size = window.getSize();
    food->setRandomPosition(size.x, size.y);
}
示例#24
0
文件: ofApp.cpp 项目: Eqip3u/EACA
void ofApp::CheckWinOrLoose ()
{
    
    if(ofDist(snake.x, snake.y, food.x, food.y) < snake.width) {
        snake.countEatFood++;
        food.reLocation();
    }
    
    if(snake.x < 0 || snake.x > ofGetWidth() || snake.y > ofGetHeight() || snake.y < 0) {
        SetState(S_LOOSE);
    }
}
示例#25
0
void		Core::loopBegin(const IGui *gui, Food food, t_key key)
{
  int		score;

  score = 0;
  if (gui)
    {
      displayBegin(gui, food);
      while ((key != ESCAPE_KEY) &&
	     (collisionWithWall(_pos[0].getPosX(), _pos[0].getPosY())) &&
	     (collisionWithSnake(_pos[0].getPosX(), _pos[0].getPosY())) &&
	     (posFood(food)))
	{
	  if (getFood())
	    {
	      food.putFood(_pos, _width, _height);
	      gui->displayFood(food.getPosX(), food.getPosY());
	      score += 100;
	    }
	  if (!getFood())
	    {
	      gui->displayAfterFood(_pos[_pos.size() - 1].getPosX(), _pos[_pos.size() - 1].getPosY());
	      _pos.pop_back();
	    }
	  key = gui->manageKey();
	  if (key == ESCAPE_KEY)
	    std::cout << "You're a poor loser, you leave the game !" << std::endl;
	  if (key == SPEEDP_KEY || key == SPEEDL_KEY)
	    setSpeed(key);
	  else
	    setDirectionSnake(key);
	  moveDirection();
	  gui->displayBody(_pos[0].getPosX(), _pos[0].getPosY());
	  gui->displayScore(score);
	  if (_speed <= 0)
	    _speed += -(_speed);
	  usleep(_speed);
	}
    }
}
示例#26
0
void Snake::EatFood(Food& food, int dif)
{
	switch (s_parts.back().GetDirection())
	{
	case LEFT:
		s_parts.push_back(Part(s_parts.back().GetX() + 1, s_parts.back().GetY(), LEFT));
		break;
	case RIGHT:
		s_parts.push_back(Part(s_parts.back().GetX() - 1, s_parts.back().GetY(), RIGHT));
		break;
	case UP:
		s_parts.push_back(Part(s_parts.back().GetX(), s_parts.back().GetY() + 1, UP));
		break;
	case DOWN:
		s_parts.push_back(Part(s_parts.back().GetX(), s_parts.back().GetY() - 1, DOWN));
		break;
	}

	switch (dif)
	{
	case 0:
		score += 150;
		break;
	case 1:
		score += 10;
		break;
	case 2:
		score += 20;
		break;
	case 3:
		score += 30;
		break;
	case 4:
		score += 70;
		break;
	}

	standard_field.AddToMap(food.GetX(), food.GetY(), SNAKE_PART);
}
示例#27
0
//--------------------------------------------------------------
void testApp::setup(){
    ofEnableAlphaBlending();
    
    ofBackground(0);
    
    bg.loadImage("bg3.png"); //artwork tim reynolds
    bg.resize(ofGetWindowWidth(), ofGetWindowHeight());
    
    ofSetVerticalSync(true);
    timer = ofGetElapsedTimef();

    
    for (int i=0; i<30; i++) {
        Food bitesOfFood;
        bitesOfFood.setup();
        bites.push_back(bitesOfFood);
    }
    
    for(int i = 0; i< 10; i++) {
        Prey prey;
        prey.setup();
        preys.push_back(prey);
    }
    
    for(int i = 0; i< 3; i++) {
        Predator predator;
        predator.setup();
        predators.push_back(predator);
    }
    
    myVectorField.setup(ofGetWindowWidth(), ofGetWindowHeight(), 20);
    
    for(int i = 0; i < 50000; i++){
        Particle tmp;
        particleList.push_back( tmp );
        particleList[i].setParams(ofRandomWidth(), ofRandomHeight(), ofRandom(-1,1), ofRandom(-1,1));
    }
}
示例#28
0
//--------------------------------------------------------------
void testApp::setup(){
    
    
    for (int i=0; i<30; i++) {
        
        Food bitesOfFood;
        bitesOfFood.setup();
        
        bites.push_back(bitesOfFood);
        
    }
    
    
    for(int i = 0; i< 5; i++) {
        
        Prey prey;
        prey.setup();
        
        preys.push_back(prey);
        
    }
    
}
示例#29
0
void display()
{
	glClearColor( 1, 1 , 1 , 0 );
	glClear( GL_COLOR_BUFFER_BIT );

	drawBG() ;
	if ( gameState == RUN ) {
	snake.Draw() ;
	food.Draw();
	} else if ( gameState == GAMEOVER ) {
		glColor3f(0,0,1) ;
		vprint2(-80, -180, 0.2, "GAME OVER" ) ;
	}
 
	glutSwapBuffers();
}
示例#30
0
Food * Food::create(CCPoint p)
{
	Food * ret = new Food();
	ret->setSprite(CCSprite::create("img/food.png"));
	ret->getSprite()->setPosition(Map::tiledPositionToCoordGL(p));

	ret->getSprite()->retain();
	

	if(ret && ret->getSprite() && ret->init())
		return ret;

	return NULL;
}