void printBoard() { if(win==true) { system("CLS"); gameName(); draw(); printWin(); } else { system("CLS"); gameName(); draw(); cout << "Draw" << endl; } }
void multiPlayer() { do { system("CLS"); gameName(); draw(); setMove(getMove()); checkWin(); checkBoard(); }while(gameFinished!=true); printBoard(); system("PAUSE"); resetBoard(); }
void PhotonLib::update(void) { ExitGames::Common::JString gameName(L"Hello World"); switch(mState) { /*case State::INITIALIZED: mLitePeer->connect(L"50.0.206.109:5055"); mState = State::CONNECTING; break; case State::CONNECTED: mLitePeer->opJoin(gameName); mState = State::JOINING; break; case State::JOINED: sendData(); break;*/ case State::CONNECTING: mLitePeer->connect(L"172.16.1.36:5055"); mState = State::WAITING; break; case State::CONNECTED: mLitePeer->opJoin(gameName); //mState = State::SENDING_DATA; break; case State::SENDING_DATA: sendData(); break; case State::RECEIVED_DATA: mLitePeer->opLeave(gameName); mState = State::LEAVING; break; case State::LEFT: mLitePeer->disconnect(); mState = State::DISCONNECTING; break; case State::DISCONNECTED: mState = State::INITIALIZED; break; default: break; } mLitePeer->service(); }
void singlePlayer() { do { system("CLS"); gameName(); draw(); if(player==1) {setRmove(getRmove());} else {setMove(getMove());} checkWin(); checkBoard(); }while(gameFinished!=true); printBoard(); system("PAUSE"); resetBoard(); }
void Board::bandeau() const { for (int i = 0; i < this->_sizeY - 100 + 2; i++) { mvaddch(0, i, '-'); } for (int i = 0; i < 13; i++) { for(int j = 0; j < this->_sizeY - 100; j++) { if (j == 0) mvaddch(i + 1, 0, '|'); } if (i != 0) mvaddch(i, this->_sizeY - 100 + 1, '|'); } for (int i = 0; i < this->_sizeY - 100 + 2 ; i++) { mvaddch(13, i, '-'); } mvprintw(2, 5, "Score | %d ", Game::getScore()); if (this->_player->getHP() > 0) mvprintw(3, 5, "Time | %d ", clock() / 1000000); mvprintw(6, 5, "HP | %d/%d ", this->_player->getHP(), this->_player->getHPM()); gameName(); }
void BoardGame::refresh(QPixmap *cache) { if (gameName() == BoardGame::gameName()) { QPainter painter(cache); painter.setPen(NoPen); painter.setBrush(QBrush(white)); painter.drawRect(cache->rect()); painter.setPen(QPen(COLOR_LINE, 10)); painter.setBrush(QBrush(COLOR_BOARD)); painter.drawEllipse(cache->rect()); QFont f("noah", 24); painter.setFont(f); painter.drawText(cache->rect(), AlignCenter, tr("Board Games!")); return; } /* generalRefresh(cache); } void BoardGame::generalRefresh(QPixmap *cache) {*/ QPainter painter(cache); drawBackground(cache, &painter); switch (boardType()) { case CenterLine: drawBoardLines(cache, &painter); case NoLine: break; case EdgeLine: drawEdgeLines(cache, &painter); } for (int r = 0; r < size().height(); r++) for (int c = 0; c < size().width(); c++) drawPoint(cache, &painter, QPoint(c, r), data.pos[r][c]); if (data.last.x() != -1) drawLast(cache, &painter, data.last, DATA(data.last)); }
//--------------------------------------------------------------// void ofApp::keyPressed(int key){ //-----------------------First Menu---------------------------// //------------------------------------------------------------// /*---employ a big switch case statement here-----*/ switch(unit){ case 0: if ( key == OF_KEY_DOWN && game_search.size() > 0) { currentFile++; currentFile %= game_search.size(); } else if( key == OF_KEY_UP && game_search.size() > 0) { currentFile--; currentFile %= game_search.size(); } else if(key == OF_KEY_RETURN && game_search.size() > 0) { //Takes current file and searches for suffix and passes it to .info update string g = game_search.getName(currentFile); int lastIndex = g.find_last_of("."); string name = g.substr(lastIndex + 1); ofLogVerbose(g.substr(lastIndex + 1)); //Holds results from suffix parse on .info directory vector<string> inf_res = patternUpdate(name); //Holds results of .info and emulator name parse which is path to emulator emu_res = emuUpdate(inf_res); //reads string path to selected file to in games search to a .txt file //--->will need to setup bash script to copy //------------------------------------------------------ game_selection = '"' + game_search.getName(currentFile) + '"'; ofBuffer msg(game_selection.c_str(), game_selection.length()); ofFile gameName(ofToDataPath("game_select.txt"), ofFile::WriteOnly); gameName.create(); ofBufferToFile("game_select.txt", msg); msg.clear(); gameName.close(); ofLogVerbose("written out and closed first time"); unit = 2; } break; case 2: //----------------------------Second Menu-------------------------------// //----------------------------------------------------------------------// if(key == OF_KEY_DOWN && emu_res.size() > 0) { currentFile1++; currentFile1 %= emu_res.size(); } else if(key == OF_KEY_UP && emu_res.size() > 0){ currentFile1--; currentFile1 %= emu_res.size(); } else if(key == OF_KEY_RETURN && emu_res.size() > 0){ emu_selection.push_back(emu_res[currentFile1]); ofFile emuName(ofToDataPath("emu_select.txt"), ofFile::WriteOnly); emuName.create(); ofLogVerbose("file opened"); ofBuffer msg(emu_res[currentFile1]); ofBufferToFile("emu_select.txt", msg); msg.clear(); emuName.close(); ofLogVerbose("Written to out and closed ,second Tiem!"); unit = 3; /* Work on opening file here and putting emu_selection into it */ } break; case 3: if(key == OF_KEY_RETURN && emu_res.size() > 0) { openChildApp(); } }//end of switch }
/*======================================================================*/ void args(int argc, char * argv[]) { char *programName; char *exePoint; #ifdef ARGSDISPLAY int i; MessageBox(NULL, "Hello!", "Windows Arun interpreter", MB_OK); MessageBox(NULL, GetCommandLine(), "", MB_OK); for (i = 0; i < argc; i++) { char buf[199]; sprintf(buf, "arg %d :\"%s\"", i, argv[i]); MessageBox(NULL, buf, "Alan V3 compiler", MB_OK); } #endif #ifdef HAVE_WINGLK argv[0] = GetCommandLine(); #endif if ((programName = strrchr(argv[0], '\\')) == NULL && (programName = strrchr(argv[0], '/')) == NULL && (programName = strrchr(argv[0], ':')) == NULL) programName = strdup(argv[0]); else programName = strdup(&programName[1]); if (strlen(programName) > 4 && (((exePoint = strstr(programName, ".EXE")) != NULL) || (exePoint = strstr(programName, ".exe")) != NULL)) *exePoint = '\0'; /* Now look at the switches and arguments */ switches(argc, argv); #ifdef ARGSDISPLAY { char buf[100]; sprintf(buf, "programName = '%s'\nadventureFileName = '%s'", programName, adventureFileName); MessageBox(NULL, buf, "Alan V3 compiler", MB_OK); } #endif // TODO This is the same as in unixargs.c if (adventureFileName == NULL) { /* No game given, try program name */ if (differentInterpreterName(programName)) { // TODO break out as a function FILE *adventureFile; adventureFileName = duplicate(programName, strlen(programName) +strlen(ACODEEXTENSION)+1); strcat(adventureFileName, ACODEEXTENSION); // TODO break out as utils::fileExists() if ((adventureFile = fopen(adventureFileName, "r")) == NULL) { free(adventureFileName); adventureFileName = NULL; } else fclose(adventureFile); } } adventureName = gameName(adventureFileName); free(programName); }
/* FileOpen: Handles a request to open a file. (Either by menu or generated by the app.) Parameters: HWND sheet: Handle to the property sheet. bool ask: Should AOKTS ask the user which file? int recent: Optionally open from one of the recent file entries. (-1 to disable.) */ void FileOpen(HWND sheet, bool ask, int recent) { OPENFILENAME ofn; struct RecentFile *file = NULL; //the file info will be stored here one way or another char titleBuffer[100]; const char *filename; Game version = scen.game; HWND page = PropSheet_GetCurrentPageHwnd(sheet); //save the scenario if changes have been made (NOT FUNCTIONAL) if (scen.needsave()) { int sel = MessageBox(sheet, askSaveChanges, "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) return; //stop closing } // Hint about whether to open as AOC or SGWB if (setts.recent_first) { scen.game = (Game)setts.recent_first->game; } /* Using a recent file... */ if (recent >= 0) { ofn.Flags = 0; //make sure no random flags set file = setts.recent_first; /* Parse the linked list to find the one we want */ while (recent--) { if (file) file = file->next; else { MessageBox(sheet, "Warning: Recent File open failed.", "Open Warning", MB_ICONWARNING); } } strcpy(setts.ScenPath, file->path); version = (Game)file->game; } /* Prompt the user for a filename. */ else if (ask) { struct RecentFile *r_parse; char dir[_MAX_PATH]; strcpy(dir, setts.BasePath); strcat(dir, "Scenario"); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = sheet; //ofn.hInstance unused ofn.lpstrFilter = extOpen; ofn.lpstrCustomFilter = NULL; //user should not set custom filters ofn.lpstrFile = setts.ScenPath; ofn.nMaxFile = _MAX_PATH; ofn.lpstrFileTitle = NULL; ofn.lpstrInitialDir = dir; ofn.lpstrTitle = NULL; ofn.Flags = OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_NOCHANGEDIR; if (scen.header.header_type == HT_AOE2SCENARIO) { ofn.nFilterIndex = 1; ofn.lpstrDefExt = "aoe2scenario"; } else { switch (scen.game) { case AOK: case AOC: case AOHD: case AOF: case AOHD4: case AOF4: case AOHD6: case AOF6: ofn.nFilterIndex = 1; ofn.lpstrDefExt = "scx"; break; case SWGB: case SWGBCC: ofn.nFilterIndex = 2; ofn.lpstrDefExt = "scx"; break; } } if (!GetOpenFileName(&ofn)) return; switch (ofn.nFilterIndex) { case 1: version = AOC; printf_log("Selected %d, AOE 2.\n", ofn.nFilterIndex); break; case 2: version = SWGB; printf_log("Selected %d, Star Wars.\n", ofn.nFilterIndex); break; } /* Now check if selected file is already on recent list. */ r_parse = setts.recent_first; while (r_parse) { if (!strcmp(r_parse->path, setts.ScenPath)) { file = r_parse; break; } r_parse = r_parse->next; } } /* Open it! */ SendMessage(page, AOKTS_Closing, 0, 0); // set hourglass, might take more than 1ms HCURSOR previous = SetCursor(LoadCursor(NULL, IDC_WAIT)); scen.reset(); try { version = scen.open(setts.ScenPath, setts.TempPath, version); /* Handle recent file stuff */ if (!file) { file = setts.recent_getnext(); strcpy(file->path, setts.ScenPath); strcpy(file->display, PathFindFileName(setts.ScenPath)); file->game = (int)version; } setts.recent_push(file); UpdateRecentMenu(propdata.menu); SetCursor(previous); // for some reason this is always read only. on Wine at least //SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_GRAYED : MF_ENABLED); SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_ENABLED : MF_ENABLED); // set status bar text SetWindowTextW(propdata.statusbar, L"Scenario loaded successfully."); SendMessage(page, AOKTS_Loading, 0, 0); SendMessageW(propdata.mapview, MAP_Recreate, 0, 0); MapView_Reset(propdata.mapview, true); filename = getFilenameFromPath(setts.ScenPath); _snprintf(titleBuffer, sizeof(titleBuffer), "%s - %s", szTitle, filename); SetWindowText(sheet, titleBuffer); } catch (std::exception &ex) { // TODO: better atomic cursor handling? SetCursor(previous); // set status bar text SetWindowText(propdata.statusbar, ex.what()); // report error to user std::string desc = "Failed to open as "; desc.append(gameName(scen.game)); desc.append(" scenario file.\n"); switch (scen.game) { case AOC: desc.append("Try opening as a SWGB scx file instead\nusing File->Open\n"); break; case SWGB: desc.append("Try opening as a Conquerors scx file instead\nusing File->Open\n"); break; } desc.append("\nThe problem: "); desc.append(ex.what()); desc.append("\n\nIf the game is able to open the scenario,\nplease report this error. Thanks."); printf_log("User message: %s\n", desc.c_str()); MessageBox(sheet, desc.c_str(), "Scenario Load Error", MB_ICONWARNING); // unless it's a debug build, clear the bad data #ifndef _DEBUG scen.reset(); SendMessage(page, AOKTS_Closing, 0, 0); #endif /* Updates*/ SendMessage(page, AOKTS_Loading, 0, 0); _snprintf(titleBuffer, sizeof(titleBuffer), "%s", szTitle); SetWindowText(sheet, titleBuffer); } //report errors to logfile fflush(stdout); }
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPTSTR cmdline, int cmdshow) { MSG msg; BOOL ret; HWND sheet, active; HACCEL accelerators; #ifdef MSVC_MEMLEAK_CHECK _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); //check for memory leaks #endif // These two methods are not the same GetModuleFileName(NULL, global::exedir, MAX_PATH); // works PathRemoveFileSpec(global::exedir); //GetCurrentDirectory(_MAX_PATH, global::exedir); // doesn't work //basic initializations aokts = inst; propdata.p = scen.players; //start pointing to first member ret = setts.load(); if (*setts.logname) { char logpath[_MAX_PATH]; //GetCurrentDirectory(_MAX_PATH, logpath); strcpy(logpath, global::exedir); strcat(logpath, "\\"); strcat(logpath, setts.logname); freopen(logpath, "w", stdout); printf_log("Opened log file %s.\n", logpath); } printf_log("TS Path: %s\n", global::exedir); // Hint about whether to open as AOC or SGWB if (setts.recent_first) { scen.game = (Game)setts.recent_first->game; printf_log("Last game was %s.\n", gameName(scen.game)); } //process any compress/decompress requests if ((*cmdline == '/' || *cmdline == '-') && ProcessCmdline(cmdline)) return 0; //read genie data try { switch (scen.game) { case AOK: case AOC: case AOHD: case AOF: esdata.load(datapath_aok); break; case SWGB: case SWGBCC: esdata.load(datapath_swgb); break; default: esdata.load(datapath_aok); } } catch (std::exception& ex) { printf_log("Could not load data: %s\n", ex.what()); MessageBox(NULL, "Could not read Genie Data from data.xml. Terminating...", "Error", MB_ICONERROR); return 0; } //create the property sheet & init misc data InitCommonControls(); sheet = MakeSheet(inst); propdata.tformat = RegisterClipboardFormat("AOKTS Trigger"); propdata.ecformat = RegisterClipboardFormat("AOKTS EC"); propdata.mcformat = RegisterClipboardFormat("AOKTS Mapcopy"); accelerators = LoadAccelerators(inst, (LPCTSTR)IDA_MAIN); //checked for err later //give the sheet its own DialogProc pproc = (DLGPROC)SetWindowLong(sheet, DWL_DLGPROC, (LONG)&MainDlgProc); //check for errors down here, after we create the sheet if (!accelerators) { MessageBox(sheet, "Keyboard Accelerators failed to load. Keyboard shortcuts will not be available.", "Warning", MB_ICONWARNING); } if (!propdata.tformat | !propdata.ecformat) { MessageBox(sheet, "Could not register clipboard format. Clipboard operations will not function.", "Warning", MB_ICONWARNING); } //if (!ret) // MessageBox(sheet, warnNoAOEII, "Warning", MB_ICONWARNING); //open mapview window propdata.mapview = MakeMapView(sheet, cmdshow || SW_MAXIMIZE); //check for, then open the scenario specified in command string if (*cmdline != '\0') { if (*cmdline == '"') { cmdline++; //increment past first doublequote *strrchr(cmdline, '"') = '\0'; //find last " and replace it } strcpy(setts.ScenPath, cmdline); printf_log("cmdline scenpath: %s\n", setts.ScenPath); FileOpen(sheet, false, -1); } //the message loop while (ret = GetMessage(&msg, NULL, 0, 0)) { if (ret < 0) //did GetMessage() fail? { MessageBox(sheet, "Unable to retrieve messages from queue. Click OK to terminate.", "AOKTS Fatal Error", MB_ICONERROR); break; } // Give first dibs to keyboard accelerators and the propsheet. if (TranslateAccelerator(sheet, accelerators, &msg) || PropSheet_IsDialogMessage(sheet, &msg)) continue; // Usually active is the sheet. If it's not, it's a modeless dialog and // it should get a crack, too. if ((active = GetActiveWindow()) != sheet && IsDialogMessage(active, &msg)) continue; // If we get here, it's just a normal message, so Translate and // Dispatch. TranslateMessage(&msg); DispatchMessage(&msg); } //cleanup if (setts.DelTempOnExit) DeleteFile(setts.TempPath); fclose(stdout); return msg.wParam; }
/** * Uploads the save file to CloudyWeb. * * @param Filename Filename of the save game file. * @param PlayerControllerId PlayerControllerId of the player who is saving the game. * * @return Returns true if the file upload was successful. Else, returns false. * */ bool CloudyWebAPIImpl::UploadFile(FString Filename, int32 PlayerControllerId) { bool RequestSuccess = false; CURL *curl; CURLcode res; std::string readBuffer; FString Url = BaseUrl + SaveDataUrl; std::string UrlCString(TCHAR_TO_UTF8(*Url)); // Filepath of .sav file FString Filepath = FPaths::GameDir(); Filepath += "Saved/SaveGames/" + Filename + ".sav"; std::string filePath(TCHAR_TO_UTF8(*Filepath)); // Get game name FString GameName = FApp::GetGameName(); std::string gameName(TCHAR_TO_UTF8(*GameName)); // Get game ID FString GameID = FString::FromInt(GetGameId()); std::string GameIDCString(TCHAR_TO_UTF8(*GameID)); // Get username FString Username = GetUsername(PlayerControllerId); std::string UsernameCString(TCHAR_TO_UTF8(*Username)); // Convert PlayerControllerId FString playerControllerIdFString = FString::FromInt(PlayerControllerId); std::string playerControllerId(TCHAR_TO_UTF8(*playerControllerIdFString)); if (GetGameId() == -1 || Username.Equals("") || PlayerControllerId < 0) { UE_LOG(CloudyWebAPILog, Error, TEXT("The game ID, username, or player controller ID is invalid")); return false; } struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; struct curl_slist *headerlist = NULL; FString AuthHeader = "Authorization: Token " + Token; std::string AuthHeaderCString(TCHAR_TO_UTF8(*AuthHeader)); curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "saved_file", CURLFORM_FILE, filePath.c_str(), CURLFORM_END); /* Fill in the player controller ID field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "user", CURLFORM_COPYCONTENTS, UsernameCString.c_str(), CURLFORM_END); /* Fill in the game name field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "game", CURLFORM_COPYCONTENTS, GameIDCString.c_str(), CURLFORM_END); curl = curl_easy_init(); /* initialize custom header list (stating that Expect: 100-continue is not wanted */ headerlist = curl_slist_append(headerlist, AuthHeaderCString.c_str()); if (curl) { /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, UrlCString.c_str()); /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); /* What form to send */ curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); /* Set up string to write response into */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check if the request was successful */ if (res == CURLE_OK) { RequestSuccess = true; } /* always cleanup */ curl_easy_cleanup(curl); /* then cleanup the formpost chain */ curl_formfree(formpost); /* free slist */ curl_slist_free_all(headerlist); UE_LOG(CloudyWebAPILog, Warning, TEXT("Response data: %s"), UTF8_TO_TCHAR(readBuffer.c_str())); ReadAndStoreSaveFileURL(readBuffer.c_str(), PlayerControllerId); } return RequestSuccess; }
// // Redraw self // void GameInfo::DrawSelf(PaintInfo &pi) { ICWindow::DrawSelf(pi); VarString gameName("$.gameName", this); VarInteger pingSmooth("$.pingSmooth", this); VarInteger pingSmoothDev("$.pingSmoothDev", this); VarInteger pingMax("$.pingMax", this); VarInteger pingMin("$.pingMin", this); VarInteger pingAvg("$.pingAvg", this); VarInteger hops("$.hops", this); VarFloat loss("$.loss", this); // Set the defaults gameName = "-"; pingSmooth = 0; pingSmoothDev = 0; pingMax = 0; pingMin = 0; pingAvg = 0; hops = 0; loss = 0.0f; if (!itemPtr.Alive()) { if (containerPtr.Alive()) { if (IControl *ctrl = containerPtr->Find(itemNameCrc)) { itemPtr = IFace::Promote<GameList::Item>(ctrl); } } } if (itemPtr.Alive()) { gameName = itemPtr->GetSession().name.str; const StyxNet::Std::Data::UserConnection &connection = itemPtr->GetConnection(); pingSmooth = connection.pingSmooth; pingSmoothDev = connection.pingSmoothDev; pingMax = connection.pingMax; pingMin = connection.pingMin; pingAvg = connection.num ? connection.pingSum / connection.num : 0; hops = connection.hopsSmooth; loss = connection.num ? connection.lost * 100.0f / connection.num : 0.0f; MultiPlayer::PingDisplay::Draw ( StyxNet::Std::Data::maxPings, connection.pings, ClipRect ( pi.client.p0.x + pingGraph.p0.x, pi.client.p0.y + pingGraph.p0.y, pi.client.p0.x + pingGraph.p1.x, pi.client.p0.y + pingGraph.p1.y ), pi.alphaScale ); } }