void player::startGame(WINDOW*& interfaceWindow, bool userOrNot) { int interfacePrintX = 77; int interfacePrintY = 5; bool goodInput = false; if(userOrNot == true) { mvwprintw(interfaceWindow, interfacePrintY + 1, interfacePrintX, " "); mvwprintw(interfaceWindow, interfacePrintY, interfacePrintX, "Would you like to go to (C)ollege or start your (L)ife?"); wrefresh(interfaceWindow); while(goodInput != true) { char startDecision = getch(); startDecision = toupper(startDecision); if(startDecision == 'C' || startDecision == 'L') { goodInput = true; if(startDecision == 'C') { setLocation(location -> getNext()); addMoney(-100000); } if(startDecision == 'L') { setLocation(location -> getSplit()); } } else { goodInput = false; } } } else if(userOrNot == false) { int randChoice = rand() % 2; if(randChoice == 0) { setLocation(location -> getNext()); addMoney(-100000); } else if(randChoice == 1) { setLocation(location -> getSplit()); } } mvwprintw(interfaceWindow, interfacePrintY, interfacePrintX, " "); wrefresh(interfaceWindow); }
int main(void){ double balance = 0, wager = 0; int choice = 0; printGameRules(); balance = getBankBalance(); //Display game menu and allow user to continually choose options until they quit while(choice != 4){ displayGameMenu(); choice = getChoice(); switch (choice){ case 1: printf("Current bank balance: $%.2lf\n", balance); break; case 2: balance = addMoney(balance); printf("You now have $%.2lf in the bank\n", balance); break; case 3: balance = playRound(balance); break; case 4: break; default: printf("\nMenu choice is invalid, Please choose a number between 1 and 4\n"); //Validates menu choice break; } } return 0; }
bool Mechanoid::buy(float money) { if (money < 0 || !hasMoney(money)) return false; addMoney(-money); return true; }
int main() { int nSelection = -1; printf("\n"); printf("欢迎进入计费管理系统\n"); do{ outputMenu();//输出系统菜单 scanf("%d",&nSelection);//输入菜单项编号 switch(nSelection){ case 1:{ add();// printf("添加卡\n"); break; } case 2:{ query();//printf("查询卡\n"); break; } case 3:{ logon();// printf("上机\n"); break; } case 4:{ settle();//printf("下机\n"); break; } case 5:{ addMoney();//printf("充值\n"); break; } case 6:{ refundMoney();//printf("退费\n"); break; } case 7:{ printf("查询统计\n"); break; } case 8:{ annul();//printf("注销卡\n"); break; } case 0:{ exitApp(); break; } default:printf("输入菜单序号错误!请选择(0~8)\n");break; } }while(nSelection != 0); system("pause"); return 0; }
// returns true if the player gets another go. bool stinkingRich::InputSystem::doMove() { bool retVal = false; auto playerEntity = stinkingRich::StinkingRich::currentPlayer.lock(); auto positionComponent = ashley::ComponentMapper<stinkingRich::Position>::getMapper().get( playerEntity); auto playerComponent = ashley::ComponentMapper<stinkingRich::Player>::getMapper().get( playerEntity); int dieOne = stinkingRich::StinkingRich::getRand(1, 6); int dieTwo = stinkingRich::StinkingRich::getRand(1, 6); die1 = dieOne; die2 = dieTwo; int totalMove = dieOne + dieTwo; if (keyStates[SDL_SCANCODE_1]) { totalMove = 1; } else if (keyStates[SDL_SCANCODE_5]) { totalMove = 5; } std::cout << "Rolled " << dieOne << " and " << dieTwo << ", moving " << totalMove << " spaces.\n"; if (dieOne == dieTwo) { playerComponent->rolledDouble(); int doubles = playerComponent->getDoublesRolled(); std::cout << "Double rolled, total of " << doubles << ".\n"; if (playerComponent->isJailed()) { playerComponent->freeFromJail(); } else { retVal = true; if (doubles == 3) { jailPlayer(); return false; } else { getsAnotherGo = true; } } } else { getsAnotherGo = false; } if (!playerComponent->isJailed()) { auto boardLocationMapper = ashley::ComponentMapper<stinkingRich::BoardLocation>::getMapper(); for (int i = 0; i < totalMove; i++) { auto newLocation = positionComponent->position.lock(); auto newLoc = newLocation->nextLocation.lock(); auto newBoardLoc = boardLocationMapper.get(newLoc); newLocation = nullptr; newLoc = nullptr; positionComponent->position = std::shared_ptr<BoardLocation>(newBoardLoc); stinkingRich::LocationType &type = newBoardLoc->details.type; if (type == stinkingRich::LocationType::GO) { std::cout << "GO: Money changed by " << newBoardLoc->details.value.toString() << ".\n"; playerComponent->addMoney(newBoardLoc->details.value); } if (i == (totalMove - 1)) { playerComponent->handleMoveResult(positionComponent); } newLoc = nullptr; } } std::cout.flush(); if (playerComponent->isJailed()) { retVal = false; } return retVal; }
void Mechanoid::sell(float money) { addMoney(money); }