bool RockPaperScissors::placePiece(int playerNumber, const Piece& p, int fromRow, int fromColumn, int toRow, int toColumn, int lineNumber, const string& line, Status& currentStatus) { Cell& fromCell = board[fromRow][fromColumn]; if (currentStatus.getIsPositioningPhase() == true) { //empty valid cell if (fromCell.getPlayerOwning() == NO_PLAYER) { //player has pieces left if (getNumberOfPiecesLeftToPlace(playerNumber, p) > 0) { decreasePieceFromStock(playerNumber, p);//reduce 1 piece left for player increasePieceOnBoard(playerNumber, p);//increase 1 piece on board for player fromCell.setCell(p, playerNumber); return true; } //illegal - out of pieces else { cout << "Player " << playerNumber << " had no more " << p << " pieces at line " << lineNumber + 1 << ":" << endl \ << line << endl; currentStatus.setStatus(playerNumber, PossibleStatus::input_File_Error, fromRow, line); return false; } } //illegal - same place piece else if (fromCell.getPlayerOwning() == playerNumber) { cout << "Player " << playerNumber << " tried to place a " << p << " in line " << lineNumber + 1 << ":" << endl \ << line << endl \ << "where he already placed there a " << fromCell.getCellPiece() << " before." << endl; currentStatus.setStatus(playerNumber, PossibleStatus::input_File_Error, lineNumber + 1, line); return false; } //legal place - fight else { decreasePieceFromStock(playerNumber, p);//reduce 1 piece from stock increasePieceOnBoard(playerNumber, p);//increase 1 piece on board fight(fromRow, fromColumn, p, playerNumber); return true; } } else {//moving phase Cell& toCell = board[toRow][toColumn]; const Piece& newP = fromCell.getCellPiece(); //empty destination cell if (toCell.getPlayerOwning() == NO_PLAYER) { toCell.setCell(newP, playerNumber); //move piece to destination fromCell.setCell(Piece()); //remove piece from source cell } //legal place - fight else { fight(toRow, toColumn, newP, playerNumber); setPieceAt(fromRow, fromColumn, NO_PLAYER);//remove piece from original cell } } return true; }
void fight(FragTrap *p1, ScavTrap *p2) { bool live1 = true; bool live2 = true; SuperTrap *p3 = new SuperTrap("Ninja"); while ((live1 && live2)) { std::cout << p1->getName() << " (" << p1->getHitpoint() <<") - " << p2->getName() << " (" << p2->getHitpoint() << ")" << std::endl; attack(*p1, *p2); if (p2->getHitpoint() == 0) live2 = false; if (live2) attack(*p2, *p1); if (p1->getHitpoint() == 0) live1 = false; } if (live1) { std::cout << "The winnner of the fight (" << p1->getName() << " - " << p2->getName() << " ) is : " << p1->getName() << std::endl; delete p2; if (fight((NinjaTrap*)p3, p1) == 1) { delete p1; std::cout << "but " << p3->getName() << " is kill by the system." << std::endl; delete p3; } else { delete p3; std::cout << "but " << p1->getName() << " is kill by the system." << std::endl; delete p1; } } else { std::cout << "The winnner of the fight (" << p1->getName() << " - " << p2->getName() << " ) is : " << p2->getName() << std::endl; delete p1; if (fight((NinjaTrap*)p3, p2) == 1) { delete p2; std::cout << "but " << p3->getName() << " is kill by the system." << std::endl; delete p3; } else { delete p3; std::cout << "but " << p2->getName() << " is kill by the system." << std::endl; delete p2; } } }
void CDiceView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default int roughX, roughY, excessX, excessY, nodeX, nodeY; int selectedNode; if(buttonRect.PtInRect(point)) { btnClicked = true; CWnd::InvalidateRect(buttonRect); return; } roughX = point.x/cellx; roughY = point.y/celly; excessX = point.x%cellx; excessY = point.y%celly; if( (excessX>radius && excessX<cellx-radius) ||(excessY>radius && excessY<celly-radius) ) return; if(excessX<radius) nodeX = roughX; else nodeX = roughX+1; if(excessY<radius) nodeY = roughY; else nodeY= roughY+1; selectedNode = (nodeY-1)*6 + nodeX-1; // CRect rect(nodeX*cellx-radius-5,nodeY*celly-radius-5,nodeX*cellx+radius+5,nodeY*celly+radius+5); if(chosenNode<0) { if(nodes[selectedNode].country != 0) return; chosenNode = selectedNode; nodes[chosenNode].isChosen = true; CWnd::InvalidateRect(nodes[chosenNode].nodeRect); } else if(chosenNode == selectedNode) { nodes[chosenNode].isChosen = false; CWnd::InvalidateRect(nodes[chosenNode].nodeRect); chosenNode = -1; } else { if(isFightable(chosenNode, selectedNode)) { nodes[selectedNode].isChosen = true; CWnd::InvalidateRect(nodes[selectedNode].nodeRect); fight(chosenNode, selectedNode); } } CView::OnLButtonDown(nFlags, point); }
void executeCommand(enum Commands command, User *bot, ...) { va_list a_list; va_start(a_list, bot); char *sender, *cmdStr; char **parameters; switch (command) { case PONG: pong(bot); break; case PRIVMSG: sender = va_arg(a_list, char *); cmdStr = va_arg(a_list, char *); parameters = va_arg(a_list, char **); if (strcmp("speak", cmdStr) == 0 && strcmp("Anthony`", sender) == 0) privmsg(bot, sender, parameters[0]); else if (strcmp("rolldice", cmdStr) == 0) rolldice(bot, sender, atoi(parameters[0])); else if (strcmp("die", cmdStr) == 0 && strcmp("Anthony`", sender) == 0) killBot(bot); else if (strcmp("coolmeter", cmdStr) == 0) coolmeter(bot, sender, parameters[0]); else if (strcmp("fight", cmdStr) == 0) fight(bot, sender, parameters[0], parameters[1]); else if (strcmp("getlatestpost", cmdStr) == 0) getLatestRlPost(bot, sender); break; } va_end(a_list); }
int main() { srand(0); //seed generator with 0 for debugging dungeon *game = generate_dungeon(10, 20); tutorial(game); for(;;) { set_stage(game); get_desc(game); switch(input("", I_CHAR)) { case 'q': goto END_GAME; case 'n': move(game, D_NORTH); break; case 's': move(game, D_SOUTH); break; case 'e': move(game, D_EAST); break; case 'w': move(game, D_WEST); break; case 'i': action(game, A_INVENTORY); break; case 'd': action(game, A_DROP); break; case 'l': action(game, A_LOOT); break; case 'p': action(game, A_PUTON); break; case 'a': action(game, A_ARM); break; case 'c': action(game, A_CONSUME); break; case 'f': fight(game); break; case 'h': help(); break; case 'r': reflect(&(game->player)); break; case 'z': dump_dungeon(game); break; default: printf("Invalid Command!\n"); } } END_GAME: return 0; }
bool Battle::initiate() { option = 1; onWaitLeft = 0; onDmgLeft = 0; cout << "You have encountered a Level " << monster.getLevel() << " monster!\r\n"; cout << "\nMonster Stats: Strength = " << monster.getStrength() << " Speed = " << monster.getSpeed() << " Armor = " << monster.getArmor() << "\r\n\n"; cout << "What do you want to do?\r\n"; cout << "1) Fight\r\n2) Cast a Spell\r\n3) Inventory\r\n4) Flee\r\n>>"; cin >> option; if (option == FIGHT || option == SPELL || option == INVENTORY) { fight(); } else { cout << "\r\nYou fled the battle!\r\n\n"; } timeCount = 0; return (hero->getHealth() > 0 && monster.getHealth() <= 0); }
void playGame(){ struct pokemon *team; struct pokemon *enemy; getEnemySaying(); char *name; name = getEnemyName(); enemy = getEnemyPokemon(); printf("%s sends out %s [%s.]\n\n", name, enemy[0].name, enemy[0].element); fflush(stdout); team = buildPlayerTeam(); printf("Who will you choose?\n"); printf("[1] %s [%s].\n[2] %s [%s].\n[3] %s [%s].\n", team[0].name, team[0].element, team[1].name, team[1].element, team[2].name, team[2].element); fflush(stdout); int choice = 0; scanf(" %d", &choice); struct pokemon player; switch(choice){ case 1 : player = team[0]; break; case 2 : player = team[1]; break; case 3 : player = team[2]; break; default : /* Optional */ printf("Failed\n"); exit(1); } fight(enemy[0], player); }
int hit_monster(int y, int x, struct object *weapon, struct thing *thrower) { struct linked_list *mon; coord target; target.y = y; target.x = x; if (thrower == &player) return(fight(&target, weapon, THROWN)); if (ce(target, hero)) { if (good_monster(*thrower)) { if (on(*thrower, ISFAMILIAR)) msg("Please get out of the way, Master! I nearly hit you."); else msg("Get out of the way %s!", whoami); return(FALSE); } return(attack(thrower, weapon, THROWN)); } if ((mon = find_mons(y, x)) != NULL) return(mon_mon_attack(thrower, mon, weapon, THROWN)); else return(FALSE); }
int fun(int S){ if(0 != state[S]) return state[S]; int tem = 1; state[S] = -1; for(int i = 0 ; i < n;i++){ if(0 != (tem & S)){ tem <<= 1; continue; } int nS = S|tem ; int nSxue = fun(nS); tem <<= 1 ; if(-1 == nSxue) continue; fight(nS,i,S); } int exp = 0; tem = 1; for(int i = 0 ; i < n ;i ++){ if(0 == (tem&S)) exp += enemy[i][3]; tem <<= 1; } Exp[S] = exp; return state[S]; }
int follow() { if (followfight == Time){ puts("The Dark Lord leaps away and runs down secret tunnels and corridoors."); puts("You chase him through the darkness and splash in pools of water."); puts("You have cornered him. His laser sword extends as he steps forward."); position = FINAL; fight(DARK,75); setbit(location[position].objects,TALISMAN); setbit(location[position].objects,AMULET); return(0); } else if (followgod == Time){ puts("The goddess leads you down a steamy tunnel and into a high, wide chamber."); puts("She sits down on a throne."); position = 268; setbit(location[position].objects,NORMGOD); notes[CANTSEE] = 1; return(0); } else puts("There is no one to follow."); return(-1); }
void Snake::action() { int r = next_rand(4); if (r == 0) go_random(); else if (r == 1) fight(random_actor()); }
int hit_monster(int y, int x, struct object *obj) { static coord mp; mp.y = y; mp.x = x; return fight(&mp, winat(y, x), obj, TRUE); }
/* * hit_monster: * Does the missile hit the monster? */ int hit_monster(int y, int x, const THING *obj) { coord mp; mp.y = y; mp.x = x; return fight(&mp, obj, TRUE); }
int zzz() { int oldtime; register int n; oldtime = Time; if ((snooze - Time) < (0.75 * CYCLE)) { Time += 0.75 * CYCLE - (snooze - Time); printf("<zzz>"); for (n = 0; n < Time - oldtime; n++) printf("."); printf("\n"); snooze += 3 * (Time - oldtime); if (notes[LAUNCHED]) { fuel -= (Time - oldtime); if (location[position].down) { position = location[position].down; crash(); } else notes[LAUNCHED] = 0; } if (OUTSIDE && rnd(100) < 50) { puts("You are awakened abruptly by the sound of someone nearby."); switch(rnd(4)) { case 0: if (ucard(inven)) { n = rnd(NUMOFOBJECTS); while(!testbit(inven,n)) n = rnd(NUMOFOBJECTS); clearbit(inven,n); if (n != AMULET && n != MEDALION && n != TALISMAN) setbit(location[position].objects,n); carrying -= objwt[n]; encumber -= objcumber[n]; } puts("A fiendish little Elf is stealing your treasures!"); fight(ELF,10); break; case 1: setbit(location[position].objects,DEADWOOD); break; case 2: setbit(location[position].objects,HALBERD); break; default: break; } } } else return(0); return(1); }
//判断碰撞类型 CollisionType Hero::checkCollision(Point heroPosition) { //cocos2d-x坐标转换为Tilemap坐标 targetTileCoord = sGlobal->gameMap->tileCoordForPosition(heroPosition); //如果勇士坐标超过地图边界,返回kWall类型,阻止其移动 if (heroPosition.x < 0 || targetTileCoord.x > sGlobal->gameMap->getMapSize().width - 1 || targetTileCoord.y < 0 || targetTileCoord.y > sGlobal->gameMap->getMapSize().height - 1) return kWall; //获取墙壁层对应坐标的图块ID int targetTileGID = sGlobal->gameMap->getWallLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有墙 if (targetTileGID) { return kWall; } //获取怪物层对应坐标的图块ID targetTileGID = sGlobal->gameMap->getEnemyLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有怪物 if (targetTileGID) { //开始战斗 fight(); return kEnemy; } //获取物品层对应坐标的图块ID targetTileGID = sGlobal->gameMap->getItemLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有物品 if (targetTileGID) { //拾取物品 pickUpItem(); return kItem; } //获取门层对应坐标的图块ID targetTileGID = sGlobal->gameMap->getDoorLayer()->tileGIDAt(targetTileCoord); //如果图块ID不为0,表示有门 if (targetTileGID) { //打开门 openDoor(targetTileGID); return kDoor; } //从npc字典中查询 int index = targetTileCoord.x + targetTileCoord.y * sGlobal->gameMap->getMapSize().width; NPC *npc = sGlobal->gameMap->npcDict.at(index); if (npc != NULL) { actWithNPC(); return kNPC; } //从Teleport字典中查询 Teleport *teleport = sGlobal->gameMap->teleportDict.at(index); if (teleport != NULL) { doTeleport(teleport); return kTeleport; } //可以通行 return kNone; }
int main() { srand(time(NULL)); std::cout << "SUPERTRAP" << std::endl; SuperTrap *p1 = new SuperTrap("player1"); std::cout << "SCAVTRAP" << std::endl; ScavTrap *p2 = new ScavTrap("player2"); fight((FragTrap*)p1, p2); return 0; }
bool NPC::action(Environment& env){ float r = ((float) rand() / (RAND_MAX)); if (r < go_prob){ //GO std::vector<std::string> directions = env.directions(); if (directions.size() > 0){ int random_index = rand() % directions.size(); std::string direction = directions[random_index]; go(env, direction); } } r = ((float) rand() / (RAND_MAX)); if (r < fight_prob){ //FIGHT Character* player = env.get_player(); if (player != NULL){ fight(*player, env); } } r = ((float) rand() / (RAND_MAX)); if (r < pickup_prob){ //PICK UP if (env.get_object_names().size() > 0){ std::vector<std::string> object_names = env.get_object_names(); int random_index = rand() % object_names.size(); std::string name = object_names[random_index]; Object* object = env.get_object(name); env.pick_up(*object); pick_up(*object); } } r = ((float) rand() / (RAND_MAX)); if (r < drop_prob){ //DROP std::vector<Object *> inventory = (*container).get_objects(); if (inventory.size() > 0){ int random_index = rand() % inventory.size(); Object& object = *inventory[random_index]; env.drop(object); drop(object); } } return true; }
static void movePlayer(int x, int y) { char_t *p = getPlayer(); if(p->stats.health <= 0){ return; } if(moveCharMap(&map, p, p->x + x, p->y + y) == MOVE_RETURN_ENEMY){ tile_t *t = getTile(&map, p->x + x, p->y + y); fight(t->c); }else{ popupText(""); } endTurn(); }
void Animal::endFight() { _target->release(); _target = NULL; _stopMoveAction(); _state = AnimalState::Stop; auto enemyList = WorldManager::getInstance()->getEnemyAnimalList(); for (auto enemy : enemyList) { if (enemy->isTarget(this)) { fight(enemy); return; } } startWalk(); }
vector<Population> Game::play(bool render) { TimeTracker& tt = *TimeTracker::getInstance(); size_t dur = tt.measure([&]() { tt.execute("game", "prepare", [&]() { prepare(); }); tt.execute("game", "place", [&]() { place(); }); tt.execute("game", "fight", [&]() { fight(render); }); tt.execute("game", "mate", [&]() { mate(); }); tt.execute("game", "score", [&]() { score(); }); tt.execute("game", "print", [&]() { print(); }); tt.execute("game", "cleanup", [&]() { cleanup(); }); }); std::cerr << "game/s: " << 1000000.0f/dur << std::endl; if(!GameState::getInstance()->isRunning()) { scenario_->restoreTeams(teams_); return teams_; } else { scenario_->restoreTeams(newTeams_); return newTeams_; } }
bool Ant::move(Ground& ground) { --time; //first fight std::list<Ant*> ants_near = ground.findAntsNextTo(x, y, id); if (!ants_near.empty()) { return fight(ants_near.front()); } if (move_function == nullptr) //ant just go out nest { move_function = &Ant::freeMove; } else if (food == can_carry_food) //and is going to nest, no matter what happen { move_function = &Ant::goToNest; } else if (food != can_carry_food && ground.isFood(x, y)) //on food field { move_function = &Ant::getFood; } else if (time < 0) //out of stamina ;] { move_function = &Ant::goToNest; make_path = false; } else if (ground.isSmell(x, y, id)) //smell { move_function = &Ant::followSmell; } (this->*move_function)(ground); last_x = x; last_y = y; if (x == nest_x && y == nest_y) //going into nest { move_function = nullptr; time_in_nest = nest_time_distribution(*gen); return false; } return true; }
/* * Does the missile hit the monster */ int hit_monster(int y, int x, struct object *obj, struct thing *tp) { static coord mp ; mp.y = y ; mp.x = x ; if (tp == &player) { /* Make sure there is a monster where it landed */ if (!isalpha(mvwinch(mw, y, x))) { return(FALSE) ; } return(fight(&mp, obj, TRUE)) ; } else { if (!ce(mp, hero)) { return(FALSE) ; } return(attack(tp, obj, TRUE)) ; } }
void GameLogic::ProcessEvents() { fight(); move(); mine(); enemyTurn(); foreach (GameUnit *unit, gameUnits) { unit->nextFrame(); } foreach (UICooldownButton *button, cooldownButtons) { button->updateCooldownElapsedIfNeeded(); } emit GameUpdated(); }
/** * search for prey on any neighboring field and eat it, if there is one * when the animal eats the prey, it will move forward to the neighboring field * and returns it new position * * otherwise, this method will return 0 */ struct Field* check_for_food(struct Field *field) { for (int i = 0; i < NUMBER_OF_DIRECTIONS; i++) // alle umliegenden Felder prüfen { struct Field *neighboring_field = get_neighboring_field_in_direction(field->x, field->y, i); if(field->population_type == PREDATOR) { if (neighboring_field->population_type == PREY) // Predator eats prey { // fight! if(fight(field, neighboring_field)) { field->energy = MAX_ENERGY; field->last_step++; move_field_to(field, neighboring_field); } else { reset_field(field); return 0; } } } else if(field->population_type == PREY) { if (neighboring_field->contains_plant) // Prey eats Plants { field->last_step++; field->energy = MAX_ENERGY; field->contains_plant = 0; move_field_to(field, neighboring_field); return neighboring_field; } } } return 0; }
/*! \brief Melee attack * * Do an enemy melee attack. Enemies only defend if they are in critical * status. This could use a little more smarts, so that more-intelligent * enemies would know to hit spellcasters or injured heroes first, and so * that berserk-type enemies don't defend. The hero selection is done in * a different function, but it all starts here. * * \param whom Target */ static void enemy_attack (int whom) { int a, b, c; if (fighter[whom].hp < (fighter[whom].mhp / 5) && fighter[whom].sts[S_CHARM] == 0) { if (rand () % 4 == 0) { fighter[whom].defend = 1; cact[whom] = 0; return; } } if (fighter[whom].sts[S_CHARM] == 0) b = auto_select_hero (whom, NO_STS_CHECK); else { if (fighter[whom].ctmem == 0) b = auto_select_hero (whom, NO_STS_CHECK); else b = auto_select_enemy (whom, NO_STS_CHECK); } if (b == -1) { fighter[whom].defend = 1; cact[whom] = 0; return; } if (b < PSIZE && numchrs > 1) { c = 0; for (a = 0; a < numchrs; a++) if (pidx[a] == TEMMIN && fighter[a].aux == 1) c = a + 1; if (c != 0) { if (pidx[b] != TEMMIN) { b = c - 1; fighter[c - 1].aux = 2; } } } fight (whom, b, 0); cact[whom] = 0; }
void CDiceView::actInTurn(int country) { set<int> finishedNodes; MSG msg; while(1) { for(set<int>::iterator iter = players[country].nodes.begin(); iter != players[country].nodes.end(); iter++) { int AIchosenNode = *iter; if(finishedNodes.find(AIchosenNode) != finishedNodes.end()) continue; for(set<int>::iterator pNeighbor = path[*iter].begin(); pNeighbor != path[*iter].end(); pNeighbor++) { int selectedNode = *pNeighbor; if(isFightable(AIchosenNode, selectedNode) && nodes[AIchosenNode].diceNum >= nodes[selectedNode].diceNum) { nodes[AIchosenNode].isChosen = true; nodes[selectedNode].isChosen = true; CWnd::InvalidateRect(nodes[AIchosenNode].nodeRect); CWnd::InvalidateRect(nodes[selectedNode].nodeRect); // CWnd::Invalidate(); // GetMessage(&msg,NULL,0,0); // TranslateMessage(&msg); // DispatchMessage(&msg); // ::Sleep(10); fight(AIchosenNode, selectedNode); } } finishedNodes.insert(AIchosenNode); } if(finishedNodes.size() == players[country].nodes.size()) break; } players[country].maxConnection = countMaxConnection(country); addDice(country); }
void Troll::action() { //Fight other actors in room. Don't fight yourself. for(const auto & a : curr_location->actors_in_room) { if(a->name().compare(name()) != 0) { fight(a); return; } } //Go to random adjacent room size_t neighbors_size = curr_location->neighbors.size(); srand(time(NULL)); int index = rand() % neighbors_size; int i = 0; for(auto const &ent1 : curr_location->neighbors) { if(i == index) { go(ent1.first); return; } i++; } }
bool move_player(struct player *player, bool keys[4], enum tile map[50][30], struct enemy enemies[100]) { int new_x=player->x; int new_y=player->y; if(player->last_move>1) { if(keys[KEY_UP] && player->y>0 && map[player->x][player->y-1]==FLOOR) new_y--; else if(keys[KEY_RIGHT] && player->x<49 && map[player->x+1][player->y]==FLOOR) new_x++; else if(keys[KEY_DOWN] && player->y<29 && map[player->x][player->y+1]==FLOOR) new_y++; else if(keys[KEY_LEFT] && player->x>0 && map[player->x-1][player->y]==FLOOR) new_x--; if(is_enemy(new_x, new_y, enemies)==100) { player->x=new_x; player->y=new_y; } else { fight(player, enemies, is_enemy(new_x, new_y, enemies)); } if(keys[KEY_UP] || keys[KEY_DOWN] || keys[KEY_RIGHT] || keys[KEY_LEFT]) { player->last_move=0; return true; } } else { player->last_move++; } return false; }
void news(void) { int n; int hurt; if (ourtime > 30 && position < 32) { puts("An explosion of shuddering magnitude splinters bulkheads and"); puts("ruptures the battlestar's hull. You are sucked out into the"); puts("frozen void of space and killed."); die(0); } if (ourtime > 20 && position < 32) puts("Explosions rock the battlestar."); if (ourtime > snooze) { puts("You drop from exhaustion..."); zzz(); } if (ourtime > snooze - 5) puts("You're getting tired."); if (ourtime > (rythmn + CYCLE)) { if (location == nightfile) { convert(TODAY); if (OUTSIDE && ourtime - rythmn - CYCLE < 10) { puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn."); puts("You awake from a misty dream-world into stark reality."); puts("It is day."); } } else { convert(TONIGHT); ClearBit(location[POOLS].objects, BATHGOD); if (OUTSIDE && ourtime - rythmn - CYCLE < 10) { puts("The dying sun sinks into the ocean, leaving a blood-stained sunset."); puts("The sky slowly fades from orange to violet to black. A few stars"); puts("flicker on, and it is night."); puts("The world seems completely different at night."); } } rythmn = ourtime - ourtime % CYCLE; } if (!wiz && !tempwiz) if ((TestBit(inven, TALISMAN) || TestBit(wear, TALISMAN)) && (TestBit(inven, MEDALION) || TestBit(wear, MEDALION)) && (TestBit(inven, AMULET) || TestBit(wear, AMULET))) { tempwiz = 1; puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard."); } if (TestBit(location[position].objects, ELF)) { printf("%s\n", objdes[ELF]); fight(ELF, rnd(30)); } if (TestBit(location[position].objects, DARK)) { printf("%s\n", objdes[DARK]); fight(DARK, 100); } if (TestBit(location[position].objects, WOODSMAN)) { printf("%s\n", objdes[WOODSMAN]); fight(WOODSMAN, 50); } switch (position) { case 267: case 257: /* entering a cave */ case 274: case 246: notes[CANTSEE] = 1; break; case 160: case 216: /* leaving a cave */ case 230: case 231: case 232: notes[CANTSEE] = 0; break; } if (TestBit(location[position].objects, GIRL)) meetgirl = 1; if (meetgirl && CYCLE * 1.5 - ourtime < 10) { SetBit(location[GARDEN].objects, GIRLTALK); SetBit(location[GARDEN].objects, LAMPON); SetBit(location[GARDEN].objects, ROPE); } if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) { ClearBit(location[DOCK].objects, GIRL); ClearBit(location[DOCK].objects, MAN); } if (meetgirl && ourtime - CYCLE * 1.5 > 10) { ClearBit(location[GARDEN].objects, GIRLTALK); ClearBit(location[GARDEN].objects, LAMPON); ClearBit(location[GARDEN].objects, ROPE); meetgirl = 0; } if (TestBit(location[position].objects, CYLON)) { puts("Oh my God, you're being shot at by an alien spacecraft!"); printf("The targeting computer says we have %d seconds to attack!\n", ourclock); fflush(stdout); sleep(1); if (!visual()) { hurt = rnd(NUMOFINJURIES); injuries[hurt] = 1; puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll."); puts("The viper shudders under a terrible explosion."); printf("I'm afraid you have suffered %s.\n", ouch[hurt]); } else ClearBit(location[position].objects, CYLON); } if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) { puts("I'm afraid you have suffered fatal injuries."); die(0); } for (n = 0; n < NUMOFINJURIES; n++) if (injuries[n] == 1) { injuries[n] = 2; if (WEIGHT > 5) WEIGHT -= 5; else WEIGHT = 0; } if (injuries[ARM] == 2) { if (CUMBER > 5) CUMBER -= 5; else CUMBER = 0; injuries[ARM]++; } if (injuries[RIBS] == 2) { if (CUMBER > 2) CUMBER -= 2; else CUMBER = 0; injuries[RIBS]++; } if (injuries[SPINE] == 2) { WEIGHT = 0; injuries[SPINE]++; } if (carrying > WEIGHT || encumber > CUMBER) notes[CANTMOVE] = 1; else notes[CANTMOVE] = 0; }
//The primary conroller for the game. Using the progress value passed in, //the function knows what the current stat of the game is. Currently, there //is nothing after progress value = 3, and the game isn't saved after the fight //ends, but this can be changed/expanded void playGame(Hero* heroes, char* playerName, Boss* boss, int progress, int choice) { //Added flavor if(progress > 0) { printf("\nWelcome back %s.\n\n", playerName); } //holds what the last thing done was. int initialprogress = progress; Hero* chosenHeroes; Shop* s; //another check for how the data is laid out. This is so we can immediately print out //heroes if we have already selected heroes. if(progress > 1) { chosenHeroes = heroes; } switch(progress) { //initial player identification case 0: playerName = getPlayerName(); choice = chooseSaveFile(); saveFileData(choice, choiceToFile(choice-1), NULL, playerName, 1); //hero selection case 1: chosenHeroes = pickHeroes(heroes); saveFileData(choice, choiceToFile(choice-1), chosenHeroes, playerName, 2); free(heroes); //equip heroes with items case 2: //shop s = loadShop(); goShopping(chosenHeroes, s); saveFileData(choice, choiceToFile(choice-1), chosenHeroes, playerName, 3); //fight the boss (a boss? Maybe find some way to get more than one boss in there?) case 3: boss = loadBoss(); int result = fight(boss, chosenHeroes); result == 0 ? printf("You won! Congrats!\n") : printf("Oh no, you lost! Reload to try again.\n"); //If you're in here, it's probably to delete this line first printf("\n\n**********CONGRATS! YOU MADE IT TO THE END OF 2050!*************\n\n"); freeHeroesAndItems(chosenHeroes); freeBossTree(boss->root); free(boss); break; default: //What? printf("Something fatal happened with the progress value. Check gamestate.txt.\n"); break; } //I don't actually remember why I did this, but it works. //I think because if it's a save file, it's freed elsewhere? if(initialprogress == 0) { free(playerName); } return; }