void dMap::constructMap(Ninja motions, int nMotions){ this->motions = motions; sNinja::iterator it1; sNinja::iterator it2; for(it1 = motions->begin() ; it1 != motions->end() ; it1++){ for(it2 = motions->begin() ; it2 != motions->end() ; it2++){ /*if(it1 == it2) */ this->compareMotions(it1->second,it2->second); } } }
int main(int argc, const char * argv[]) { Ninja n; Monster m; Enemy *enemy1 = &n; Enemy *enemy2 = &m; enemy1->setAttackPower(20); enemy2->setAttackPower(30); n.attack(); m.attack(); return 0; }
int main() { Ninja n; Monster m; Enemy *enemy1 = &n; Enemy *enemy2 = &m; enemy1->setAttackPower(29); enemy2->setAttackPower(99); n.attack(); m.attack(); }
int main(){ Ninja n; Monster m; //REMEMBER ALL NINJAS ARE ENEMIES SO ARE MONSTERS //SO THE ADDRESS OF NINJA, IS ALSO A ENEMY PTR //ANYTHING AN ENEMY CAN DO A NINJA CAN DO Enemy *enemy1 = &n; Enemy *enemy2 = &m; //NINJA GETS 29 ATTACK POWER enemy1->setAttackPower(29); enemy2->setAttackPower(99); n.attack(); m.attack(); }
int main() { int groupNum; cin >> groupNum; vector<InputGroup> inputVector; int n = 1; while (n <= groupNum) { // int totalLifeUnit; // int dragon_life, ninja_life, iceman_life, lion_life, wolf_life; InputGroup group; cin >> group.totalLifeUnit; cin >> group.dragon_life >> group.ninja_life >> group.iceman_life >> group.lion_life >> group.wolf_life; inputVector.push_back(group); n +=1; } // char name[5] = "test"; // char other[5]; // *other = *name; // cout << other << endl; int i = 0; for (i = 0; i < inputVector.size(); i++) { InputGroup group = inputVector[i]; HeadQuarter red("red"), blue("blue"); Dragon dragon; Lion lion; Iceman iceman; Ninja ninja; Wolf wolf; dragon.SetLife(group.dragon_life); lion.SetLife(group.lion_life); iceman.SetLife(group.iceman_life); ninja.SetLife(group.ninja_life); wolf.SetLife(group.wolf_life); red = group.totalLifeUnit; blue = group.totalLifeUnit; red.AddWarriorPrototype(iceman.Clone()); red.AddWarriorPrototype(lion.Clone()); red.AddWarriorPrototype(wolf.Clone()); red.AddWarriorPrototype(ninja.Clone()); red.AddWarriorPrototype(dragon.Clone()); blue.AddWarriorPrototype(lion.Clone()); blue.AddWarriorPrototype(dragon.Clone()); blue.AddWarriorPrototype(ninja.Clone()); blue.AddWarriorPrototype(iceman.Clone()); blue.AddWarriorPrototype(wolf.Clone()); #if USE_PRINTF printf("Case:%d\n", i+1); #else cout << "Case:" << i+1 << endl; #endif int time = 0; while (red.NotStop() || blue.NotStop()) { red.MakeWarrior(time); blue.MakeWarrior(time); time += 1; } #if USE_PRINTF fflush(stdout); #else cout << flush; #endif } return 0; }
//====================================================================================== //====================================================================================== //====================================================================================== int main() { // GavinsClass GavinsObject("setting initial"); // GavinsObject.setName("I am Gavin"); // cout << GavinsObject.getName() <<endl; // GavinsClass go("Sally mcSalad\n"); // cout << go.getName(); // Burrito bo; #if 0 srand(time(0)); //initial the random function for(int x=1; x<25;x++){ cout << 1+(rand()%6) << endl; // no computer can generate real random number } #endif // 0 #ifdef TS_DefualtArguments cout << volume(); #endif #ifdef TS_UnaryScope int tuna =20; cout << tuna<<endl; cout << ::tuna<<endl; //Global variables #endif #ifdef TS_30_FunctionOverloading int a = 54; float b = 32.45988; printNumber(a); printNumber(b); #endif #ifdef TS_31_Recursion cout << factorialFinder(5)<<endl; #endif #ifdef TS_32_CreateArrayUsingLoops int bucky[9]; cout <<"Element - Value"<<endl; for(int x=0;x<9;x++){ bucky[x]=99; cout << x <<"----------"<<bucky[x]<< endl; } #endif // TS_32_CreateArrayUsingLoops #ifdef TS_42_ArrowMemberSelectionOperator Sally so; Sally *sallyPointer = &so; so.printCrap(); sallyPointer->printCrap(); #endif // TS_42_ArrowMemberSelectionOperator #ifdef TS_44_ConstObject const Sally constObj; constObj.printConst(); #endif // TS_44_ConstObject #ifdef TS_45_MemberInitializers Sally so(3,87); so.print(); #endif // TS_45_MemberInitializers #ifdef TS_46_Composition Birthday birthObject(12,10,1982); people GavinObj("Gavin Wong",birthObject); GavinObj.printInfo(); #endif // TS_46_Composition #ifdef TS_47_Friend StankFist bob; stinkysFriend(bob); #endif // TS_47_Friend #ifdef TS_48_This Hannah ho(23); ho.printCrap(); #endif // TS_48_This #ifdef TS_49_OperatorOverloading OverLoad a(34); OverLoad b(21); OverLoad c; c = a+b; cout << c.OverNum <<endl; #endif // TS_49_OperatorOverloading #ifdef TS_52_Inheritance Son Ethan; Ethan.sayName(); #endif // TS_52_Inheritance #ifdef TS_53_ProtectedMembers Daughter tina; tina.doSomething(); #endif // TS_53_ProtectedMembers #ifdef TS_54_DerivedClassConstructor // Mother mom; Daughter tina; #endif // TS_54_DerivedClassConstructor #ifdef TS_55_Polymorphism Ninja n; Monster m; Enemy *enemy1 = &n; //because ninja is of type enemy,this is valid Enemy *enemy2 = &m; //anything that an enemy can do,monster can do enemy1->setAttackPower(4); //ninja is just a more specific type of enemy enemy2->setAttackPower(26); //every enemy has setAttackPower n.attack(); //can't use enemy1 because its type enemy m.attack(); //Enemy class does not have attack //virtual members make this even easier #endif // TS_55_Polymorphism #ifdef TS_56_VirtualFunctions Ninja n; Monster m; Enemy *enemy1 = &n; Enemy *enemy2 = &m; enemy1->setAttackPower(4); //ninja is just a more specific type of enemy enemy2->setAttackPower(26); //every enemy has setAttackPower enemy1->attack(); enemy2->attack(); #endif // TS_56_VirtualFunctions #ifdef TS_58_Template double x=7.0,y=43.235,z; z =addCrap(x,y); cout << z << endl; int t = 89; double q = 56.78; cout << smaller(t,q) << endl; // 60_ClassTemplate Ethan <int>eo(69,105); cout << eo.bigger() << endl; // 61_Template Specializations Spunky<int> obj1(7); Spunky<double> obj2(3.124); Spunky<char> obj3('a'); #endif // TS_58_Template #ifdef TS_62_Exceptions try{ int momsAge = 30; int sonsAge = 34; if(sonsAge > momsAge){ throw 99; } }catch(int x){ cout <<"son can not be older than mom. ERROR NUMBER: "<< x <<endl; } try{ int num1; cout << "Enter first number: " << endl; cin >> num1; int num2; cout << "Enter second number: " << endl; cin >> num2; if(num2==0){ throw 0; } cout << num1/num2 << endl; }catch(...){ cout << "you cant divided by 0" << endl; } #endif // TS_62_Exceptions #ifdef TS_64_WorkingWithFiles ofstream buckyFile; buckyFile.open("tuna.txt"); //even this file isn't exist buckyFile << "I love tuna and tuna loves me!\n"; buckyFile.close(); ofstream gavinsFile("butterfly.txt");//even this file isn't exist // ofstream gavinsFile("");//even this file isn't exist if(gavinsFile.is_open()){ cout <<"ok, this file is opened"<<endl; gavinsFile << "oi love the beef!\n"; gavinsFile.close(); }else{ cout <<"sorry,you messed up"<<endl; } ofstream theFile("players.txt"); cout << "Enters player's ID, Name, and Money" << endl; cout << "press Ctrl+Z to quit \n" << endl; int idNumber; string name; double money; while(cin>>idNumber>>name>>money){ theFile << idNumber << " " << name << " " << money << endl; } theFile.close(); //Reading custom File structures ifstream readFile("players.txt"); int rdID; string reName; double reMoney; while(readFile >> rdID >> reName >> reMoney){ cout << rdID << ", " << reName << ", " << reMoney << endl; } #endif // TS_64_WorkingWithFiles #ifdef TS_68_CoolProgram int whatTheyWant; whatTheyWant = getWhatTheyWant(); while(whatTheyWant != 4){ displayItems(whatTheyWant); whatTheyWant = getWhatTheyWant(); } #endif // TS_68_CoolProgram #ifdef TS_71_StringClass string s1("hamster "); string s2; string s3; cout << s1.at(3) << endl; for(int t=0;t<s1.length();t++){ cout << s1.at(t) << endl; } s2 = s1; s3.assign(s1); cout<< s1 << s2 << s3 << endl; string x; cout <<"Please enter a string: " << endl; getline(cin,x); cout << x << endl; string bucky; cout <<"Please enter a string: " << endl; cin >> bucky; cout << "the string i entered is " << bucky << endl; #endif // TS_71_StringClass #ifdef TS_72_StringSubstringsSwappingFinding //substring string s1("OMG i think i am preggy!!"); cout << s1.substr(17,7)<<endl; //swapping string one("apples "); string two("beans "); cout << one << two << endl; one.swap(two); cout << one << two << endl; //finding string s3("hi my name is gavin ,and ham is spam oh yes i am!"); cout << s3.find("am") << endl; cout << s3 << endl; s3.erase(20); cout << s3 << endl; s3.replace(14,5,"Jianeng"); cout << s3 << endl; s3.insert(14,"Huang "); cout << s3 << endl; #endif // TS_72_StringSubstringsSwappingFinding return 0; }
void LevelManager::loadLevel(Level* lvl) { printf("STARTING TO LOAD LEVEL \n" ); std::cout << "Entities::start " << cg::Registry::instance()->size() << "\n"; _currentLevel = lvl; _currentClues = 0; static_cast<Scene*>(cg::Registry::instance()->get("Scene"))->reset(); MaterialManager* materialManager = dynamic_cast<MaterialManager*>(cg::Registry::instance()->get("MaterialManager")); TextureManager* textureManager = dynamic_cast<TextureManager*>(cg::Registry::instance()->get("TextureManager")); materialManager->clear(); std::list<Material*>::iterator matit; for(matit = lvl->getMaterials()->begin(); matit != lvl->getMaterials()->end(); matit++) { materialManager->add(*matit); } textureManager->clear(); std::list<Texture*>::iterator texit; textureManager->addMap(lvl->getMapTex()); for(texit = lvl->getTextures()->begin(); texit != lvl->getTextures()->end(); texit++) { textureManager->add(*texit); } printf("LEVEL MANAGER: REMOVING PREVIOUS ENTITIES\n"); //clearing old ones (if there are any) cg::View* v1 = static_cast<cg::View*>(cg::Registry::instance()->get("view1")); std::list<std::string>::iterator entitiesit; for(entitiesit = _currentEntities->begin(); entitiesit != _currentEntities->end(); entitiesit++) { v1->unlinkEntity(*entitiesit); cg::Registry::instance()->remove(*entitiesit); } std::cout << "Entities::after_unlink " << cg::Registry::instance()->size() << "\n"; DebugManager* dm = static_cast<DebugManager*>(cg::Registry::instance()->get("DebugManager")); std::cout << "Debugmanager::Before " << dm->getListsSize() << "\n"; printf("LEVEL MANAGER: REMOVING DEBUG LISTENERS\n"); //removing everything registered for Debug (Ninja is always there) //DebugManager* dm = static_cast<DebugManager*>(cg::Registry::instance()->get("DebugManager")); dm->dispose(); dm->disableDebug(); std::cout << "Debugmanager::After " << dm->getListsSize() << "\n"; CollisionManager* cm = static_cast<CollisionManager*>(cg::Registry::instance()->get("CollisionManager")); std::cout << "Collision::Before " << cm->getListsSize() << "\n"; printf("LEVEL MANAGER: REMOVING COLLISION LISTENERS\n"); //removing everything except Ninja from Collisions //CollisionManager* cm = static_cast<CollisionManager*>(cg::Registry::instance()->get("CollisionManager")); cm->dispose(); std::cout << "Collision::After " << cm->getListsSize() << "\n"; std::cout << "Entities::after_managers " << cg::Registry::instance()->size() << "\n"; _currentEntities->clear(); std::cout << "Entities::after_clean_entities " << cg::Registry::instance()->size() << "\n"; printf("LEVEL MANAGER: STARTING TO LOAD HEIGHT MAP\n"); ImageLoaderHeightMap* ilhm = static_cast<ImageLoaderHeightMap*>(cg::Registry::instance()->get("mappedterrain")); if(ilhm != NULL) ilhm->setHeightMap(LEVEL_PATH + _currentLevel->getHeightMap()); else { ilhm = new ImageLoaderHeightMap("mappedterrain", LEVEL_PATH + _currentLevel->getHeightMap()); cg::Registry::instance()->add(ilhm); } std::cout << "Entities::after_heightmap " << cg::Registry::instance()->size() << "\n"; printf("LEVEL MANAGER: STARTING TO LOAD ITEM MAP\n"); ImageLoaderItemMap* ilim = static_cast<ImageLoaderItemMap*>(cg::Registry::instance()->get("mappeditems")); if(ilim != NULL) ilim->setItemMap(LEVEL_PATH + _currentLevel->getHeightMap(), LEVEL_PATH + _currentLevel->getItemMap()); else { ilim = new ImageLoaderItemMap("mappeditems", LEVEL_PATH + _currentLevel->getHeightMap(), LEVEL_PATH + _currentLevel->getItemMap()); cg::Registry::instance()->add(ilim); } for(entitiesit = _currentEntities->begin(); entitiesit != _currentEntities->end(); entitiesit++) { cg::Registry::instance()->get(*entitiesit)->init(); } //reset ninja position printf("LEVEL MANAGER: RESETING NINJA POSITION\n"); Ninja* ninja = dynamic_cast<Ninja*>(cg::Registry::instance()->get("Ninja")); ninja->reset(); static_cast<Camera*>(cg::Registry::instance()->get("Camera"))->mainCamera(); std::cout << "Entities::after_itemmap " << cg::Registry::instance()->size() << "\n"; std::cout << "Debugmanager::After " << dm->getListsSize() << "\n"; std::cout << "Collision::After " << cm->getListsSize() << "\n"; printf("LEVEL LOADED\n"); }