Skip to content

Commit

Permalink
feat: fluse terminal & confirm input
Browse files Browse the repository at this point in the history
  • Loading branch information
jschang19 committed Dec 16, 2023
1 parent cacde17 commit d5a7686
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <thread>
#include <chrono>
#include "ChatGPT/include/Error.h"
#include "ChatGPT/include/Game.h"
// this is the main function
Expand Down Expand Up @@ -33,19 +36,27 @@ int main(int args,char** argv){

try {
for (int i=0; i<STORY_NUM; i++){
std::cout << "\033[2J\033[H";

int story_id = story_ids[i];
OpenAI::Message prompt = game.generateStoryPrompt(i);
game.addPrompt(chatGpt, story_id);
auto chatCompletion = game.sendToChatGPT(chatGpt);
game.parseGPTResponse(chatCompletion, story_id);
std::cout << "\033[2J\033[H";
game.printOptions(story_id);
std::cout<<std::endl;

std::string userInput;
std::cout<<"輸入你的選擇:";
std::cout<<"你的選擇是( 輸入英文小寫代號 ):";
std::getline(std::cin,userInput);

std::cout<<std::endl;
game.print("你選擇了 "+userInput, "w");
game.setUserChoice(story_id, userInput);
game.current_count += 1;
std::cout<<std::endl;

std::this_thread::sleep_for(std::chrono::seconds(1));
}
}catch(OpenAI::Error& e){
//JSON error returned by the server
Expand Down

0 comments on commit d5a7686

Please sign in to comment.