void FishCollection::addFishAtHwId(unsigned int fishHwId) { bool found = isFishConfigured(fishHwId); if (!found) { Fish* fish = new Fish(fishHwId, this); if (0 == m_fish) { m_fish = fish; } else { Fish* next = m_fish; while (next->next() != 0) { next = next->next(); } next->setNext(fish); } if (0 != m_adapter) { // Notify: Fish with the particular HW ID created! m_adapter->notifyFishEvent(fishHwId, FishNotificationAdapter::EvtFishAdded); } } else { if (0 != m_adapter) { // ERROR: Fish with the particular HW ID already exists, no new fish created! m_adapter->notifyFishError(fishHwId, FishNotificationAdapter::ErrFishAlreadyExists); } } }
int main(int argc, char ** argv) { Fish f; f.numBones(); f.spooky(); return 0; }
Fish* Fish::create(FishType type) { Fish* fish = new Fish(); fish->init(type); fish->autorelease(); return fish; }
bool Fish::TrackFish(Fish fish) { if(!fish.IsDanglingFish()) return false; if(IsTheFish(fish)) { UpdateBoundingRect(fish.GetBoundingRect()); return true; } }
Fish* Fish::create() { Fish *sprite = new Fish(); if (sprite && sprite->initWithFile("turtle_1.png")){ sprite->setup(); sprite->autorelease(); return sprite; } CC_SAFE_DELETE(sprite); return nullptr; }
int main() { Fish* fish = Fish_new(); // 创建鱼对象 Dog* dog = Dog_new(); // 创建狗对象 Car* car = Car_new(); // 创建车子对象 Animal* animals[2] = { 0 }; // 初始化动物容器(这里是Animal指针数组) IMoveable* moveObjs[3] = { 0 }; // 初始化可移动物体容器(这里是IMoveable指针数组) int i = 0; // i和j是循环变量 int j = 0; // 初始化鱼对象的昵称为:小鲤鱼,年龄为:1岁 fish->init(fish, "Small carp", 1); // 将fish指针转型为Animal类型指针,并赋值给animals数组的第一个成员 animals[0] = SUPER_PTR(fish, Animal); // 初始化狗对象的昵称为:牧羊犬,年龄为:2岁 dog->init(dog, "sheepdog", 2); // 将dog指针转型为Animal类型指针,并赋值给animals数组的第二个成员 animals[1] = SUPER_PTR(dog, Animal); // 将fish指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第一个成员 moveObjs[0] = SUPER_PTR(fish, IMoveable); // 将dog指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第二个成员 moveObjs[1] = SUPER_PTR(dog, IMoveable); // 将car指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第三个成员 moveObjs[2] = SUPER_PTR(car, IMoveable); // 循环打印动物容器内的动物信息 for(i=0; i<2; i++) { Animal* animal = animals[i]; animal->eat(animal); animal->breathe(animal); animal->sayHello(animal); } // 循环打印可移动物体容器内的可移动物体移动方式的信息 for(j=0; j<3; j++) { IMoveable* moveObj = moveObjs[j]; moveObj->move(moveObj); } lw_oopc_delete(fish); lw_oopc_delete(dog); lw_oopc_delete(car); return 0; }
HarvestSpriteProduceStrategy::AddFish(float delta) { timeSinceLastAddFish += delta; if(timeSinceLastAddFish > ADD_FISH_TIME_INTERVAL) { timeSinceLastAddFish = 0.0f; if(rand() % 5 == 0) { Fish *fish = SpriteFactory::GetInstance()->CreateFish(component->model); fish->SetComponent(component); component->fishes->Add(fish); } } }
int main(){ cout << sizeof(Animal) << endl; cout << sizeof(Cat) << endl; Cat cat; cat.show(); cat.catfun(); Fish fish; fish.name="test"; fish.age=10; fish.type="a"; fish.show(); fish.fishfun(); }
int main() { Fish myFish; Bear myBear; Dinosaur myDino; cout << "Fish eats bear? " << myFish.eats(myBear) << endl; cout << "Fish eats dino? " << myFish.eats(myDino) << endl; cout << "Dino eats bear? " << myDino.eats(myBear) << endl; cout << "Bear eats fish? " << myBear.eats(myFish) << endl; return 0; }
void Aquarium::init(void) { if(_doLog) cout << "init" << endl; for(int i=0; i<_start_n_whitefish; i++) { Fish *fish = new Whitefish(); fish->set_baby(false); if(!addFish(fish)) delete fish; } for(int i=0; i<_start_n_predator; i++) { Fish *fish = new Predator(i+_start_n_whitefish); if(!addFish(fish)) delete fish; } }
Fish *Fish::createWithFishType(int fishType, GameLayer *gameLayer, CCSpriteBatchNode *pBatchNode) { Fish *fish = new Fish(); if(fish && fish->initWithFishType(fishType, gameLayer, pBatchNode)) { fish->autorelease(); return fish; } else { delete fish; return NULL; } }
void Scene::display() { // Clear screen, initialise culling glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Select model view matrix glMatrixMode(GL_MODELVIEW); // Draw solid bodies glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLoadIdentity(); Fish* f = Fish::getFirst(); Vector* v = f->getPosition(); GLfloat lightPos[] = { static_cast<GLfloat>(v->x), static_cast<GLfloat>(v->y - 10), static_cast<GLfloat>(v->z), 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, lightPos); // args 1-3: viewer coordinates, // args 4-5: point looked at, // args 7-9: "up" vector gluLookAt( camPos[activeCam]->x, camPos[activeCam]->y, camPos[activeCam]->z, 0.0, 20.0, 0.0, 0.0, 1.0, 0.0); // Draw scene graph fishList->work(); if (!calculateFishCount) { sharkList->work(); } graph->work(); if (drawNames) { Text::drawAll(); } else { fpsDisplay->draw(); for (list<Text*>::iterator it = helpDisplay.begin(); it != helpDisplay.end(); it++) { (*it)->draw(); } } glFlush(); glutSwapBuffers(); if (calculateFishCount) { glutPostRedisplay(); } frames++; }
Fish* Fish::create(FishType type/* = k_Fish_Type_SmallFish */) { Fish* fish = new Fish; if (fish && fish->init(type)) { fish->autorelease(); return fish; } else { CC_SAFE_DELETE(fish); return NULL; } }
void FishLayer::addFish(float dt){ CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //随机增加Fish int countToAdd = CCRANDOM_0_1() * 20 + 1; int countHasAdded = 0; CCObject* iterator; CCARRAY_FOREACH(_fishes, iterator){ Fish* fish = (Fish*)iterator; if (fish->getParent() == NULL){ this->addChild(fish); this->resetFish(fish); countHasAdded++; if (countHasAdded == countToAdd){ break; } } }
void timeExpired() { if (!m_fishCollection->queue()->isEmpty() && !m_fishCollection->isBusy()) { Fish* fish = m_fishCollection->queue()->dequeue(); if (0 != fish) { fish->activateMotion(); } else { if (0 != m_fishCollection->adapter()) { m_fishCollection->adapter()->notifyFishError(0, FishNotificationAdapter::ErrFishQueueCorrupt); } } } }
bool AI::findPath(const int beginX,const int beginY,const int endX,const int endY, Fish & f) { int currentX = beginX; int currentY = beginY; for(int i = 0; i < 4; i++) //4 choices { switch(i) { case 0: //NORTH currentY--; break; case 1: //EAST currentX++; break; case 2: //SOUTH currentY++; break; case 3: //WEST currentX--; break; } if(isValidLoc(currentX,currentY)) { if(currentX == endX && currentY == endY) //success! { f.move(currentX,currentY); return true; } else { f.move(currentX,currentY); findPath(currentX,currentY,endX,endY,f); } } else return false; } return false; }
int main(int argc, char*argv[]) { myFish.compute_fish(argv[1]); // Driver function argv[1] should contain the input file name given at the command line. return(EXIT_SUCCESS); }
void FishLayer::addFish() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); int countToAdd = CCRANDOM_0_1() * 10 + 1; int countHasAdded = 0; CCObject* iterator; CCARRAY_FOREACH(_fishes, iterator){ Fish* fish = (Fish*)iterator; if(fish->isRunning() == false){ this->addChild(fish); //todo 后期应重设Fish产生时的随机坐标 int randomX = CCRANDOM_0_1() * winSize.width; int randomY = CCRANDOM_0_1() * winSize.height; fish->setPosition(CCPointMake(randomX, randomY)); countHasAdded++; if(countToAdd == countHasAdded){ break; } } }
void FishLayer::addFish(float dt) { Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); int countToAdd = CCRANDOM_0_1() * 10 + 1; int countHasAdded = 0; CCObject* iterator; CCARRAY_FOREACH(_fishes, iterator){ Fish* fish = (Fish*)iterator; if (fish->isRunning() == false){ this->addChild(fish); //todo 后期应重设Fish产生时的随机坐标 int randomX = CCRANDOM_0_1() * visibleSize.width; int randomY = CCRANDOM_0_1() * visibleSize.height; fish->setPosition(Vec2(origin.x+randomX, origin.y+randomY)); countHasAdded++; if (countToAdd == countHasAdded){ break; } } }
void World::update() { for(int i=0; i < fishes.size(); ++i) { //各fishがどこの領域に属するかを更新 Fish* fish = fishes.at(i); vec2d pos = fish->get_pos(); int pre_idx = fish->get_pidx(); int idx = pos.x / (int)(width / PARTITION_X) + (int)(pos.y / (int)(height / PARTITION_Y))*PARTITION_X; if(pre_idx != idx) { partitons.at(pre_idx).erase(partitons.at(pre_idx).find(fish->get_id())); partitons.at(idx).insert(std::make_pair(fish->get_id(), fish)); fish->set_pidx(idx); } fishes.at(i)->update(this); } for(int i=0; i < sharks.size(); ++i) { int idx = sharks.at(i)->get_pos().x / (int)(width / PARTITION_X) + (int)(sharks.at(i)->get_pos().y / (int)(height / PARTITION_Y))*PARTITION_X; sharks.at(i)->set_pidx(idx); sharks.at(i)->update(this); } }
static void down_cast_test() { class Animal { public: void running() { printf("running()\n"); } }; class Fish : public Animal { public: Fish() { age = 1000; } void swimming() { printf("swim()\n"); } int age; }; Animal animal; Fish* fish = (Fish*)(&animal); printf("&animal = %p\n", &animal); printf("fish = %p\n", fish); fish->running(); fish->swimming(); printf("fish->age = %d\n", fish->age); // 结果不确定 }
int main() { // Read mesh from file Mesh mesh("../mesh.xml.gz"); // Read velocity field from file Functionals::CoefficientSpace_p Vp(mesh); Function p(Vp, "../pressure.xml.gz"); // Functionals for lift and drag Functionals::Form_lift L(mesh, p); Functionals::Form_drag D(mesh, p); // Assemble functionals over sub domain Fish fish; fish.mark_facets(mesh, 1); const double lift = assemble(L); const double drag = assemble(D); info("Lift: %f", lift); info("Drag: %f", drag); }
void GameLayer::updateFish(float dt) { vector< int >::iterator it = m_currentFish.begin(); while(it != m_currentFish.end()) { Fish * fish = (Fish *)this->getFishes()->getObjectAtIndex(*it); if(fish->getDeleted()){ fish->setDeleted(false); fish->setVisible(false); it = m_currentFish.erase(it); } else ++it; } _timeStampAddFish += dt * 20; if(_timeStampAddFish > _nextTimeStampAddFish){ int _time = _timeStampAddFish / DELTA_ADDFISH; // Check current avaible Fish Generation Time this->setCrtTime(_time); this->addFish(); _nextTimeStampAddFish = _timeStampAddFish + DELTA_ADDFISH; if(this->getCrtTime() > 180){ int randomScript = (int)(CCRANDOM_0_1() * 100) % MAX_SCRIPT_SIZE; this->setCrtScript(randomScript + 1); this->setCrtTime(0); _nextTimeStampAddFish = _timeStampAddFish = 0; } } }
World::World(): width(640), height(640) { partitons.resize(PARTITION_X*PARTITION_Y); for(int i = 0; i < 400; ++i) { //位置はランダム、初期速度はゼロ Fish* fish = new Fish(vec2d(100+(double)rand()/RAND_MAX*400, 100+(double)rand()/RAND_MAX*400), vec2d()); fishes.push_back(fish); //どこの領域にいるかを計算・更新 int idx = fish->get_pos().x / (int)(width / PARTITION_X) + (int)(fish->get_pos().y / (int)(height / PARTITION_Y))*PARTITION_X; partitons.at(idx).insert(std::make_pair(fish->get_id(), fish)); fish->set_pidx(idx); } //三匹sharkを追加 sharks.push_back(new Shark(vec2d(100,100), vec2d(0,0))); sharks.push_back(new Shark(vec2d(250,250), vec2d(0,0))); sharks.push_back(new Shark(vec2d(450,450), vec2d(0,0))); }
void FishCollection::delFishAtHwId(unsigned int fishHwId) { Fish* fish = findFishByHwId(fishHwId); if (0 != fish) { if (fish == m_fish) { fish = m_fish->next(); delete m_fish; m_fish = fish; } else { Fish* next = m_fish; while (next->next() != fish) { next = next->next(); } next->setNext(fish->next()); delete fish; fish = 0; } if (0 != m_adapter) { // Notify: Fish with the particular HW ID deleted! m_adapter->notifyFishEvent(fishHwId, FishNotificationAdapter::EvtFishDeleted); } } else { if (0 != m_adapter) { // ERROR: Fish with the particular HW ID not found, nothing to delete! m_adapter->notifyFishError(fishHwId, FishNotificationAdapter::ErrFishNotFound); } } }
Fish* FishCollection::findFishByHwId(unsigned int fishHwId) { Fish* matchingFish = 0; if (0 != m_fish) { if (m_fish->getFishHwId() == fishHwId) { matchingFish = m_fish; } else { Fish* next = m_fish; while ((next->next() != 0) && (next->next()->getFishHwId() != fishHwId)) { next = next->next(); } if (next->next() != 0) { matchingFish = next->next(); } } } return matchingFish; }
int main(int argc, char* argv[]){ srand(time(NULL)); std::vector<Fish> fishies; std::vector<std::vector<std::vector<colorChar>>> background; std::vector<std::vector<std::vector<colorChar>>> foreground; int frameSpeed = 250000; if(argc == 1){ help(); return 0; } for(int i = 1; i < argc; i++){ if(std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h"){ help(); return 0; } else if(std::string(argv[i]) == "--list" || std::string(argv[i]) == "-l"){ std::cout << "fish\n\n"; system(("ls " + homedir + "/.freefish/fish").c_str()); std::cout << "\ntanks\n\n"; system(("ls " + homedir + "/.freefish/background").c_str()); std::cout <<"\nthis function does not check for errors, missing flips, or missing foreground\n"; return 0; } else if(std::string(argv[i]) == "--speed" || std::string(argv[i]) == "-s"){ i++; if(i < argc){ try{ frameSpeed = std::stoi(std::string(argv[i])); } catch(std::invalid_argument e){ std::cout << "speed not a valid integer\n"; return 0; } } else{ help(); return 0; } } else if(std::string(argv[i]) == "--tank" || std::string(argv[i]) == "-t" ){ i++; if(i < argc){ std::string input(argv[i]); background = readFile(homedir + "/.freefish/background/" + input); foreground = readFile(homedir + "/.freefish/foreground/" + input); if(!checkFile(background, "background", input) || !checkFile(foreground, "foreground", input)){ return 0; } if(background[0].size() != foreground[0].size() || background[0][0].size() != foreground[0][0].size()){ std::cout << "tank " << input << " mismatching background and foreground sizes\n"; return 0; } } else{ help(); return 0; } } else if(std::string(argv[i]) == "--fish" || std::string(argv[i]) == "-f"){ Fish fish; i++; while(argc > i && argv[i][0] != '-'){ std::string input(argv[i]); if(!fish.load(homedir + "/.freefish/fish/" + input, homedir + "/.freefish/flip/" + input, input)){ return 0; } fishies.push_back(fish); i++; } i--; } else{ help(); return 0; } } if(background.size() == 0){ help(); return 0; } for(int i = 0; i < fishies.size(); i++){ if (!fishies[i].init(background[0].size(), background[0][0].size())){ return 0; } } bool fishThere = false; int backgroundFrame = 0; int foregroundFrame = 0; system("clear"); while(true){ for(int y = 0; y < background[backgroundFrame].size(); y++){ //std::cout << y; for(int x = 0; x < background[backgroundFrame][y].size(); x++){ if(foreground[foregroundFrame][y][x].character != ' '){ std::cout << foreground[foregroundFrame][y][x]; } else{ fishThere = false; for(int f = 0; f < fishies.size(); f++){ Fish fish = fishies[f]; if(!fish.flip && x >= fish.x && x < fish.x + fish.width && y >= fish.y && y < fish.y + fish.height && fish.fishChars[fish.frame][y - fish.y][x - fish.x].character != ' '){ fishThere = true; std::cout << fish.fishChars[fish.frame][y-fish.y][x-fish.x]; break; } if(fish.flip && x >= fish.x && x < fish.x + fish.width && y >= fish.y && y < fish.y + fish.height && fish.flipChars[fish.frame][y - fish.y][x - fish.x].character != ' '){ fishThere = true; std::cout << fish.flipChars[fish.frame][y-fish.y][x-fish.x]; break; } } if(!fishThere){ std::cout << background[backgroundFrame][y][x]; } } } std::cout << '\n'; } usleep(frameSpeed); std::cout << "\033[1;1H"; std::cout.flush(); for(int i = 0; i < fishies.size(); i++){ fishies[i].updatePosition(background[0].size(), background[0][0].size()); } foregroundFrame++; backgroundFrame++; for(int i = 0; i < fishies.size(); i++){ fishies[i].frame++; } if(foregroundFrame >= foreground.size()){ foregroundFrame = 0; } if(backgroundFrame >= background.size()){ backgroundFrame = 0; } for(int i = 0; i < fishies.size(); i++){ if (fishies[i].frame >= fishies[i].fishChars.size()) fishies[i].frame = 0; } } return 0; }
void Net::Update(float deltaTicks, Fish &fish) { switch(state) { case START: frame = 0; show = true; released = false; state = RUNNING; break; case RUNNING: if(CheckCollision(fish.GetCollisionBox(), collisionBox)) { state = RELEASED; } if(collisionBox.y + 64 <= 0) { state = CAPTURED; } break; case CAPTURED: //do wriggle animation if(!timer.GetStarted()) { timer.Start(); } state = END; break; case RELEASED: if(!timer.GetStarted()) { timer.Start(); } if(frame == 5) { state = END; released = true; timer.Stop(); } if(timer.GetTicks() >= 100) { frame += 1; timer.Stop(); } break; case END: if(!timer.GetStarted()) { timer.Start(); } show = false; released = false; //this needs to be changed to proper level scaling posX = (rand() % 2000 - 64); posY = (rand() % 1000 + 64); if(timer.GetTicks() >= 3000) { state = START; timer.Stop(); } break; } //BasicSprite::Update(deltaTicks); collisionBox.x = posX; collisionBox.y = posY; collisionBox.h = height; collisionBox.w = width; }
bool Fish::IsTheFish(Fish fish) const { if(norm(GetExpectedMarkPoint() - fish.GetMarkPoint()) < 30) return true; return false; }
//This function is called each time it is your turn. //Return true to end your turn, return false to ask the server for updated information. bool AI::run() { Fish* coolFish = getFish(0, 0, fishes); if(coolFish != NULL) { coolFish->carryingWeight(); } for(int i = 0;i < tiles.size();i++) { if(tiles[i].owner() == playerID() && getFish(tiles[i].x(), tiles[i].y(), fishes) == NULL) { for(int p = 0;p<species.size(); p++) { if(species[p].season() == currentSeason()) { if(players[playerID()].spawnFood() >= species[p].cost() && tiles[i].hasEgg() == false) { species[p].spawn(tiles[i].x(), tiles[i].y()); } } } } } for(int i = 0;i < fishes.size();i++) { if(fishes[i].owner() == playerID()) { int x = fishes[i].x(); int y = fishes[i].y(); if(fishes[i].x() >= 1) { if(getTile(x - 1, y, mapHeight(), tiles).trashAmount() > 0 && fishes[i].carryingWeight() + 1 <= fishes[i].carryCap()) { fishes[i].pickUp(x - 1, y, 1); } } if(fishes[i].carryingWeight() > 0) { if(fishes[i].x() < mapWidth()/2 - boundLength() - 1) { if(fishes[i].y() != 0) { if(getTile(x,y - 1,mapHeight(),tiles).owner() == 2 && getFish(x,y + 1,fishes) == NULL) { fishes[i].drop(x, y - 1, fishes[i].carryingWeight()); } } else { if(getTile(x,y + 1,mapHeight(),tiles).owner() == 2 && getFish(x,y + 1,fishes) == NULL) { fishes[i].drop(x, y + 1, fishes[i].carryingWeight()); } } } } if(fishes[i].x() >= 1) { if(getTile(x - 1,y,mapHeight(),tiles).owner() != enemyAI_ID && getTile(x - 1,y,mapHeight(),tiles).trashAmount() == 0) { if(getFish(x - 1, y, fishes) == NULL && getTile(x - 1, y, mapHeight(), tiles).hasEgg() == false) { fishes[i].move(x - 1,y); } } } } } return true; }