void Play(tGame * game) { int legal; tScan scan; tCommand command; command.undo.can_undo = FALSE; command.undo.undo_error = FALSE; command.undo.lastboard.rows = game->visualboard.rows; command.undo.lastboard.columns = game->visualboard.columns; CreateBoard(&command.undo.lastboard);; do { PrintAll(game, &command); do { if ((legal = InputCommand(&scan))) { if((legal = LegalCommand(&scan, &command))) if (command.command_ref < 5) /*All commands but quit or undo*/ legal = LegalParams(game, &command, &scan); } if (!legal) printf("%s%s%s\n", KERR, COMMAND_ERR, KDEF); } while (!legal); ExecCommand(game, &command); CheckGameState(game); } while(game->gamestate == GAMESTATE_DEFAULT); PrintResult(game); freeBoard(game->hiddenboard.board, game->hiddenboard.rows); freeBoard(game->visualboard.board, game->hiddenboard.rows); return; }
//---------- GameCore ---------- int Mines::GameCore() { // int game_end = 0; // string InPut = ""; // unsigned int xpos = 0, ypos = 0; getch InPut; int key = 0; if (!initiated) Init(STD_HEIGHT, STD_WIDTH, 0); while (MinesMenu()) { Create(); SetGameState(CONTINUE); while (game_state == CONTINUE) { Draw(); key = InPut.GetKey(); if (key == UP_KEY) { focus.MoveUp(); } else if (key == DOWN_KEY) { focus.MoveDown(); } else if (key == RIGHT_KEY) { focus.MoveRight(); } else if (key == LEFT_KEY) { focus.MoveLeft(); } else if (key == OPEN_FIELD) { if (first_time) { focus.GetField()->SetState(PROTECTED); SetMines(); focus.GetField()->SetState(COVERED); first_time = false; } UnCover(focus.GetField()); } else if (key == MARK_FIELD) { MarkBomb(focus.GetField()); } else if (key == QUIT_KEY) { SetGameState(MANUAL_END); } else { // E.Error("There's no such option"); #ifdef DEBUG D.Debug("There's no such option"); #endif //DEBUG } CheckGameState(); } if (game_state == FAIL) { RevealMines(); } Draw(); if (game_state == FAIL) { losses++; cout << "You've lost\n"; Enter(); } else if (game_state == WIN) { wins++; cout << "You've won!\n"; Enter(); } else if (game_state == MANUAL_END); else { cout << "Why the f*** has the game ended??\n"; Enter(); } } #ifdef __UNIX__ system("clear"); #endif //__UNIX__ #ifdef __WINDOWS__ system("cls"); #endif //__WINDOWS__ return 0; }