int main(void) { unsigned Seed; Seed = (unsigned)time(NULL); /*RNG for computer opponents selections*/ srand(Seed); int RunCount = 0; /*Counts numbers of rounds, ends when board filled (at 9)*/ int Win = 0; /*Win condition yay or nay*/ int PlayerSelection = 0; /*Exit condition for progam if 2, ask after game*/ int PlayerWeapon, Row, Column, Counter1, Counter2; /*Player weapon choice. 1 for X, 2 for O*/ int Board[BOARDSIZE][BOARDSIZE] = { 0 }; /*Play board (Also Array)*/ while (PlayerSelection != 2) /*Run until player selects 2 to exit after a round*/ { PlayerWeapon = XOSelection(); /*Set players weapon to X or O depending on selection from XOSelection()*/ while (RunCount <= 4 || Win==1) /*Run until board is filled or a winner is found*/ { DisplayBoard(Board); /*Display the current state of the board*/ Row = RowSelection(); /*Run function for player row selection*/ Column = ColumnSelection(); /*Run function for player column selection*/ if (Board[Row][Column] == 1 || Board[Row][Column] == 2) /*Checks if slot is taken ether by player or PC*/ { printf("\nERROR: Slot taken, Select a new slot\n"); Column = ColumnSelection(); Row = RowSelection(); } if (Board[Row][Column] == 0 ) { Board[Row][Column] = 1; /*Set players slot choice to 1*/ } int PCRow = (rand() % 3); /*Set PC row choice to something between 1 and 3*/ int PCColumn = (rand() % 3); /*Set PC column choice to something between 1 and 3*/ if (Board[PCRow][PCColumn] == 1 || Board[PCRow][PCColumn] == 2) /*Checks if selected slot is already taken, runs RNG again to find free slot*/ { printf("\n\n**PC has selected a filled slot, will run again**\n\n"); /*DEBUG, REMOVE BEFORE 1.0*/ int PCRow = (rand() % 3); /*Set PC row choice to something between 1 and 3*/ int PCColumn = (rand() % 3); /*Set PC column choice to something between 1 and 3*/ printf("Row %d", PCRow); /*DEBUG, REMOVE BEFORE 1.0*/ printf("Column %d", PCColumn); /*DEBUG, REMOVE BEFORE 1.0*/ } if (Board[PCRow][PCColumn] == 0) { Board[PCRow][PCColumn]=2; /*Set PC slot choice to 2*/ } RunCount++; /*Increase count one step closer to max (9)*/ } printf("\n\nGame has ended\n\n"); DisplayBoard(Board); printf("\n\nPress 1 to play again\nPress 2 to exit\n"); scanf_s("%d", &PlayerSelection); } return 0; /*That's all folks*/ }
void FOOTPRINT_EDIT_FRAME::updateView() { auto dp = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() ); dp->UseColorScheme( &Settings().Colors() ); dp->DisplayBoard( GetBoard() ); m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); updateTitle(); }
/* Procedure de gestion de l'affichage du menu * @param SDL_Surface* window * Surface de la fenetre * @param E_GameMode gameMode * Mode de jeu du programme en cours * @param S_AIFunctions* aiFunctions * Structure de stockage des fonctions des bibliotheques */ void DisplayMenu(SDL_Surface* window, E_GameMode gameMode, S_AIFunctions* aiFunctions) { SDL_Surface *menu_bg = IMG_Load(DESIGN_PATH "menu.png"); TTF_Font *font = TTF_OpenFont(DESIGN_PATH "font.ttf", 25); SDL_Rect position; position.x = 0; position.y = 0; E_MenuSelected selected = NONE; S_GameConfig gameConfig; // Initialisation de la configuration du match gameConfig.player1Color = BLACK; gameConfig.option = 0; gameConfig.points = 5; gameConfig.mode = gameMode; gameConfig.aiFunctions = aiFunctions; InitPlayersName(&gameConfig); // Affichage SDL_BlitSurface(menu_bg, NULL, window, &position); DisplayText(window, font, gameMode, selected); DisplayOverlays(window, font, selected, gameConfig); int finish = 0; SDL_Event event; while(!finish) { // Affichage if (event.type == SDL_MOUSEBUTTONUP || event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_KEYUP) { SDL_BlitSurface(menu_bg, NULL, window, &position); DisplayText(window, font, gameMode, selected); DisplayOverlays(window, font, selected, gameConfig); } SDL_Flip(window); // Gestion des evenements E_MenuSelected button = EventsMenu(&event, &gameConfig, &selected); if (button == START) finish = DisplayBoard(window, gameConfig); else if (button == QUIT) finish = 1; SDL_Delay(5); } TTF_CloseFont(font); SDL_FreeSurface(menu_bg); }
int turn( char board[ROWS][COLS], char mark, int cumulative_tries ) { int row; int col; int status; // Display current board // Query message before entering rows and cols clear_screen(); printf("%c's turn! Go go go, %c!\n\n", mark, mark); DisplayBoard(board); printf("\n"); row = enter_row(); col = enter_col(); printf("\n"); status = 0; status = PlayerMove(row, col, board, mark); printf("\n"); if ( status == 0 ) { if ( cumulative_tries == 3 ) { // Print something about not having forfeited turn return 1; } clear_screen(); return turn( board, mark, cumulative_tries + 1 ); } // Push back if invalid position was entered // display the board clear_screen(); DisplayBoard(board); // display victory message return DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); }
//----------------------------------------------------------------- // Name: FrameAdvance() // Desc: Called to signal that we are now rendering the next frame. //----------------------------------------------------------------- void CTetris::FrameAdvance( ) { static float fTotalFallTime = 0.f; m_FrameTimer.Tick((float)FPS); m_FallTimer.Tick(); fTotalFallTime += m_FallTimer.GetTimeElapsed(); ClearOldBlockFromBoard( );//clears the block from the board if( fTotalFallTime >= m_fCurrFallDelay ) { //######################### NOTE: My idea ###################################################### //#1. Timer runs out # //#2. check to see if block can move down # //# a. if so move block down 1 row. done. # //# b. if not check for row completion # //# i. if nothing completed, done. # //# ii. if completed, clear those rows # //# iii. and everything above that row drops one row down. # //# 1. if more then one row is completed. Handle in order that you find compelted # //# meaning, ever row above the completion row moves down one row. and by the time# //# it reaches a non-complete row it's Y coordinate stores the amount n times that# //# it has to move down # //# c. start timer. # //# d. pick new block # //# e. start over. # //############################################################################################## if( !MoveTetrad( ) ) //meaning it can't move down { RenderBlockintoBoard(); //Render the block into the board before you pick a new one CheckRowCompletion(); switch ( WinLose() ) { case WIN : DisplayWin(*this); break; case LOSE : DisplayLose(*this); m_bExit = true; break; } PickTetrad( ); //Picks new block and sets up possition m_fCurrFallDelay = m_fFallDelay[m_nLevel]; } fTotalFallTime = 0.f; } while(m_bPause) { ProcessInput(); Sleep(10);} Scoreing(); ProcessInput( ); //Gets user input and orientates block RenderBlockintoBoard(); //Puts block on the board DisplayBoard(*this); }
int main() { // declare variables char board[ROWS][COLS]; // initialize board InitializeBoard(board); // populate the board with moves PlayerMove( 1, 1, board, MARKONE ); PlayerMove( 1, 2, board, MARKONE ); PlayerMove( 4, 3, board, MARKONE ); PlayerMove( 1, 1, board, MARKTWO ); PlayerMove( 6, 2, board, MARKTWO ); PlayerMove( 4, 12, board, MARKTWO ); // display the board DisplayBoard(board); // exit program return 0; }
int main(int argc, const char *argv[]) { char initialArray[ROWS][COLS] = { {'a', 'b'}, {'c', 'd'} }; char* pointerArray[ROWS][COLS]; for (int row = 0; row < ROWS; row++) { for (int col = 0; col < COLS; col++) { pointerArray[row][col] = &initialArray[row][col]; } } DisplayBoard( pointerArray ); // int min; // ROWS < COLS ? (min = ROWS) : (min = COLS); // char* diagonalArray1[ROWS + COLS - 1][min]; // char* diagonalArray2[ROWS + COLS - 1][min]; // // diagonalArray1[0][0] = &initialArray[0][0]; // printf( "%c\n", *diagonalArray1[0][0] ); // printf( "%c\n", *diagonalArray1[0][1] ); // DisplayBoard( *diagonalArray1 ); return 0; }
int main() { // declare variables char board[ROWS][COLS]; // Produce a NoWin condition // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(1, 2, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a horizontal victory // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(1, 2, board, MARKONE); PlayerMove(1, 3, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a vertical victory // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKTWO); PlayerMove(2, 1, board, MARKTWO); PlayerMove(3, 1, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a diagonal-down victory // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(2, 2, board, MARKONE); PlayerMove(3, 3, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a diagonal-up victory // initialize board InitializeBoard(board); // populate board PlayerMove(3, 1, board, MARKTWO); PlayerMove(2, 2, board, MARKTWO); PlayerMove(1, 3, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a multiple player victory // initialize board InitializeBoard(board); // populate board PlayerMove(4, 1, board, MARKONE); PlayerMove(4, 2, board, MARKONE); PlayerMove(4, 3, board, MARKONE); PlayerMove(3, 1, board, MARKTWO); PlayerMove(2, 2, board, MARKTWO); PlayerMove(1, 3, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a tie // initialize board // InitializeBoard(board); // populate board // for (int k = 0; k < COLS; ) { /* code */ // k % 2 == 0 ? k+=1 : k += 3; // } // display the board // DisplayBoard(board); // display victory message // DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // exit program return 0; }
void main() { clrscr(); int pos; char choice; int legal; cout<<"Do You Want Me to Start?\nChoice(y/n):"; //Who plays the first move? cin>>choice; DisplayBoard(a); switch(choice) { case 'y': { while(move<5) //First one to move would make a maximum of 5 moves { pos=MiniMax(a); a[pos]=2; DisplayBoard(a); if(CheckWin(a)) { DisplayBoard(a); cout<<"\n\nYou lost!"; delay(5000); break; } else if(CheckDraw(a)) { DisplayBoard(a); cout<<"\n\nIts Draw!"; delay(5000); break; } enterAgain1: cout<<"\n\nEnter position(0-8):"; cin>>pos; legal=CheckLegal(a,pos); if(legal==0) { cout<<"\nInvalid Move!"; goto enterAgain1; } a[pos]=1; DisplayBoard(a); if(CheckLose(a)) { DisplayBoard(a); cout<<"\n\nYou won!"; delay(5000); break; } else if(CheckDraw(a)) { DisplayBoard(a); cout<<"\n\nIts Draw!"; delay(5000); break; } move++; } break; } case 'n': { while(move<5) { DisplayBoard(a); enterAgain2: cout<<"\n\nEnter position(0-8):"; cin>>pos; legal=CheckLegal(a,pos); if(legal==0) { cout<<"\nInvalid Move!"; goto enterAgain2; } a[pos]=1; DisplayBoard(a); if(CheckLose(a)) { DisplayBoard(a); cout<<"\n\nYou won!"; delay(5000); break; } else if(CheckDraw(a)) { DisplayBoard(a); cout<<"\n\nIts Draw!"; delay(5000); break; } pos=MiniMax(a); a[pos]=2; cout<<"\n\t"<<pos; DisplayBoard(a); if(CheckWin(a)) { DisplayBoard(a); cout<<"\n\nYou lost!"; delay(5000); break; } else if(CheckDraw(a)) { DisplayBoard(a); cout<<"\n\nIts Draw!"; delay(5000); break; } move++; } break; } default: { break; } } }
void main() { int i=0, j=0, winner=2; char isContinue = '0' ; while(1) { count = 0; for(i=0;i<9;i++){ z[i]= 0 ; a[i]= 0 ; } printf("\n\n\tWelcome to the game of Tic-Tac-Toe\n"); printf("\tPlease enter numbers only from 1 to 9\n\n"); printf("\n\tThe Blocks are numbered as below, for reference"); printf("\n\t\t | | \n\t\t 1 | 2 | 3 \n\t\t___|___|___ \n\t\t 4 | 5 | 6 \n\t\t___|___|___ \n\t\t 7 | 8 | 9 \n\t\t | | \n\n"); while(count<9) { if((count%2) == 0) { printf(" Player 1 make your move:\t"); make_entry(); winner = check_for_win(); } if((count%2)==1) { printf(" Player 2 make your move:\t"); make_entry(); winner = check_for_win(); } count++; if(winner == 1) // if winner is Player1 { printf("\n Player 1 wins!!! Congratulations\n"); /* for(j=0;j<9;j++) printf("%d\t", z[j]); */ break; } if(winner == -1) // if winner is Player2 { printf("\n Player 2 wins!!! Congratulations\n"); /* for(j=0;j<9;j++) printf("%d\t", z[j]); */ break; } if(winner == 3) // Draw :( { printf("\n Match Drawn\n"); /* for(j=0;j<9;j++) printf("%d\t", z[j]); */ break; } DisplayBoard(); } printf("Do you wish to continue[y/n]\n" ); scanf("%c",&isContinue); if(isContinue == 'n'){ printf("Exiting the game\nThanks for playing see you soon!!!!\n"); break; } } }
int main(int argc, char** argv) { if(argc < 3) { return(-1); } seg_key = atoi(argv[1]); sem_key = atoi(argv[2]); sop = (struct sembuf*) malloc(sizeof(struct sembuf)); sop[0].sem_flg = 0; seg_id = shmget(seg_key,sizeof(struct game_info), 0777); if(seg_id < 0) { sem_id = semget(sem_key,2, IPC_CREAT | 0600); semctl(sem_id,0,SETVAL,1); semctl(sem_id,1,SETVAL,0); seg_id = shmget(seg_key,sizeof(struct game_info), IPC_CREAT | 0777); game = shmat(seg_id,NULL,0); if(game == (struct game_info*)-1) { printf("HOST ERROR\n\n"); } buffor = game; GameStart(buffor); while(buffor->end != true) { printf("\nPlease wait\n"); sop[0].sem_num = 0; sop[0].sem_op = 0; semop(sem_id,sop,1); DisplayBoard(buffor); if(buffor->end == true) { break; } do { printf("\nMake a turn\n"); printf("X: "); scanf("%d",&x); printf("\nY: "); scanf("%d",&y); }while(!Turn(x,y,buffor)); DisplayBoard(buffor); isEnd(buffor); buffor->player=1; sop[0].sem_num = 0; sop[0].sem_op = 1; semop(sem_id,sop,1); sop[0].sem_num = 1; sop[0].sem_op = -1; semop(sem_id,sop,1); } if(buffor->end) { printf("The game has ended\n"); } sop[0].sem_num = 1; sop[0].sem_op = -1; semop(sem_id,sop,1); } else { sem_id = semget(sem_key,2, IPC_CREAT | 0600); game = shmat(seg_id,NULL,0); if(game == (struct game_info*)-1) { printf("GUEST ERROR\n\n"); } buffor = game; //GameStart(buffor); while(buffor->end != true) { printf("\nPlease wait\n"); DisplayBoard(buffor); if(buffor->end == true) { break; } do { printf("\nMake a turn\n"); printf("X: "); scanf("%d",&x); printf("\nY: "); scanf("%d",&y); }while(!Turn(x,y,buffor)); DisplayBoard(buffor); isEnd(buffor); buffor->player=0; if(buffor->end == false) printf("\nPlease wait\n"); sop[0].sem_num = 0; sop[0].sem_op = -1; semop(sem_id,sop,1); sop[0].sem_num = 1; sop[0].sem_op = 1; semop(sem_id,sop,1); sop[0].sem_num = 1; sop[0].sem_op = 0; semop(sem_id,sop,1); } if(buffor->end) { printf("The game has ended\n"); } sop[0].sem_num = 1; sop[0].sem_op = -1; semop(sem_id,sop,1); shmdt(game); shmdt(buffor); semctl(sem_id, 0, IPC_RMID); semctl(sem_id, 1, IPC_RMID); } /* game = malloc(sizeof(struct game_info)); GameStart(game); DisplayBoard(game); Turn(1,1,game); DisplayBoard(game); */ }