int main() { gamestart(); gamecircle(); endgame(); return 0; }
short parse_input_string (char *str, struct board *board) { short cnt = 0, move; char *p; p = str; board->cpu = 3; switch (*p) { case 'a': board->white_lev = 1; board->black_lev = 1; break; case 'b': board->white_lev = 2; board->black_lev = 2; break; case 'c': board->white_lev = 3; board->black_lev = 3; break; default: return -1; } p++; while (p[cnt] != '0') { move = (short) (p[cnt] - '1'); if (move < 0 || move > 6) return -1; if (board->stack[move] < BOARDY) makemove (board, move); else return -2; if (cnt >= 42 || endgame (board) != 0) return -2; cnt++; } return 1; }
/* * playgame: * play a game */ void playgame(void) { bool *bp; getword(); Errors = 0; bp = Guessed; while (bp < &Guessed[26]) *bp++ = FALSE; while (Errors < MAXERRS && index(Known, '-') != NULL) { prword(); prdata(); prman(); getguess(); } endgame(); }
/* * playgame: * play a game */ void playgame(void) { int i; if (syms) sym_getword(); else getword(); Errors = 0; for (i = 0; i < 26 + 10; i++) Guessed[i] = FALSE; while (Errors < MAXERRS && strchr(Known, '-') != NULL) { prword(); prdata(); prman(); getguess(); } endgame(); }
int main (void) { int board[SIZE + 2][SIZE + 2], ray, score, done; char hints[SIZE * 4]; char token; srand (time (NULL)); intro (); do { setup (board, hints); token = 'a'; score = 0; done = 0; do { drawbox (board, hints, 1); printf ("Ray # ? "); scanf ("%d", &ray); if (ray && ray < 4 * SIZE) score += shoot (ray, hints, &token, board); if (!ray) done = endgame (board, hints, &score); } while (!done); } while (playmore ()); puts ("Goodbye!"); exit (0); }
int main(int argc, char **argv) { char *s; int i; int flags; prand = getpid(); while(1) { switch(getopt(argc, argv, "+w:At:n:N:Ce:d")) { case 'w': who = strdup(optarg); break; case 'A': authq = 1; break; case 't': qtype = atoi(optarg); for (i=DNSQTYPEMIN;i<=DNSQTYPEMAX;i++) { s = dnsqtypename(i); if (s && !strcmp(optarg, s)) { qtype = i; break; } } if (!qtype) puke("Bad -t option"); break; case 'n': newns(optarg, 0); break; case 'N': newns(optarg, 1); break; case 'C': syncsev = CRITBIT; break; case 'e': newexp(optarg); break; case 'd': debug = 1; break; case EOF: goto doneopts; default: usage(); } } doneopts: if (!who) usage(); dnsfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (dnsfd == -1) barf("socket"); /* see UNPv2 p58 */ if ((flags = fcntl(dnsfd, F_GETFL, 0)) == -1) barf("fcntl F_GETFL"); flags |= O_NONBLOCK; if (fcntl(dnsfd, F_SETFL, flags) == -1) barf("fcntl F_SETFL"); sloop(); endgame(); }
void snakemove() { snake *nexthead; cantcrosswall(); nexthead = (snake*)malloc(sizeof(snake)); if (status == U) { SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); nexthead->x = head->x; nexthead->y = head->y - 1; if (nexthead->x == food->x&&nexthead->y == food->y) { nexthead->next = head; head = nexthead; q = head; Pos(q->x, q->y); printf("■"); score = score + add; createfood(); } else { nexthead->next = head; head = nexthead; q = head; while (q->next->next != NULL) { Pos(q->x, q->y); printf("■"); q = q->next; } Pos(q->next->x, q->next->y); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); printf("■"); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); free(q->next); q->next = NULL; } } if (status== D) { SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); nexthead->x = head->x; nexthead->y = head->y + 1; if (nexthead->x == food->x&&nexthead->y == food->y) { nexthead->next = head; head = nexthead; q = head; while (q != head) { Pos(q->x, q->y); //SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE ); printf("■"); q = q->next; } score = score + add; createfood(); } else { nexthead->next = head; head = nexthead; q = head; while (q->next->next != NULL) { Pos(q->x, q->y); printf("■"); q = q->next; } Pos(q->next->x, q->next->y); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); printf("■"); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); free(q->next); q->next = NULL; } } if (status == L) { SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE ); nexthead->x = head->x-2; nexthead->y = head->y; if (nexthead->x == food->x&&nexthead->y == food->y) { nexthead->next = head; head = nexthead; q = head; while (q != head) { Pos(q->x, q->y); printf("■"); q = q->next; } score = score + add; createfood(); } else { nexthead->next = head; head = nexthead; q = head; while (q->next->next != NULL) { Pos(q->x, q->y); printf("■"); q = q->next; } Pos(q->next->x, q->next->y); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); printf("■"); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); free(q->next); q->next = NULL; } } if (status == R) { SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); nexthead->x = head->x+2; nexthead->y = head->y; if (nexthead->x == food->x&&nexthead->y == food->y) { nexthead->next = head; head = nexthead; q = head; while (q != head) { Pos(q->x, q->y); printf("■"); q = q->next; } score = score + add; createfood(); } else { nexthead->next = head; head = nexthead; q = head; while (q->next->next != NULL) { Pos(q->x, q->y); printf("■"); q = q->next; } Pos(q->next->x, q->next->y); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); printf("■"); SetConsoleTextAttribute(Handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); free(q->next); q->next = NULL; } } if (biteself() == 1) { endgamestatus = 1; endgame(); } }
void drawacard(int x) { int z = 1 + rand() % 13; int a = 0; int guard = 0; int y = 1 +rand() % 4; char csuit = 'd'; while (playershand[x].cvalue[a] != 0) a = a + 1; while ((cards_used[z] > (decks * 4)) && (guard < 50)) { z = 1 + rand () % 13; guard = guard + 1; } if (guard > 49) { endgame(); } cards_used[z] = cards_used[z] + 1; guard = 0; /*NAMES AND VALUES ARE ASSIGNED TO THE CARDS*/ if ((z > 1) && (z < 10)) { playershand[x].cvalue[a] = z; playershand[x].cname[a] = ((char) '0' + z); } else if (z == 10) { playershand[x].cvalue[a] = z; playershand[x].cname[a] = 'T'; } else if (z == 11) { playershand[x].cvalue[a] = 10; playershand[x].cname[a] = 'J'; } else if (z == 12) { playershand[x].cvalue[a] = 10; playershand[x].cname[a] = 'Q'; } else if (z == 13) { playershand[x].cvalue[a] = 10; playershand[x].cname[a] = 'K'; } else if (z == 1) { playershand[x].cvalue[a] = 1; playershand[x].cname[a] = 'A'; } /*Assignments of the Suits Randomly*/ if (y == 1) csuit = 'c'; if (y == 2) csuit = 'd'; if (y == 3) csuit = 'h'; if (y == 4) csuit ='s'; acecheck(x); /*LINKING THE PICTURE IS REMAINGING*/ char pic[20]; snprintf(pic, sizeof(pic), "card/%c.bmp", csuit); playershand[a].card_pic[x]=load_bmp(pic, NULL); tallythevalueofcards(a); }
void game(int mx,int my) { cleardevice(); int x,y,cl=0,i,j,ctr=0,points=0,lives=3,dt=100; int *ycoord,*bomby; int delaytime[20]; int randomcolor; int *xcoord,*bombx,numctr=0,playtime=0; int nob=0,bombctr=0,temp,selbomb; callmouse(); setlimits(23,mx-23,23,my-23); delay(100); // ASSIGN THE SPEED for(i=0;i<10;i++){delaytime[i]=i+10;} // ALOCATE MEMORY FOR COORDINATES if((ycoord=(int *)malloc(10))==NULL||(xcoord=(int *)malloc(10))==NULL||(bomby=(int *)malloc(10))==NULL||(bombx=(int *)malloc(10))==NULL) { cout<<"\nMEMORY ALLOCATION ERROR!"; getch(); exit(0); } randomize(); outline(mx,my); //THE GAME BEGINS int start=clock(),end; for(i=0;i<lives;i++) { setcolor(WHITE); circle((mx-200)+(i*20),my-10,6); setfillstyle(SOLID_FILL,RED); floodfill((mx-200)+(i*20),my-10,WHITE); } for(;;) { // ASSIGN COORDINATES TO BOMBS selbomb=random(10); if( (selbomb%7)==0 && nob<=3) { *(bombx+bombctr)=50; *(bomby+bombctr)=random(my-100)+50; bombctr++; nob++; } // ASSIGN COORDINATES TO BUBLES if(numctr<3) { *(xcoord+ctr)=48; *(ycoord+ctr)=random(my-100)+48; numctr++; ctr++; } // DROP THE BOMBS for(i=0;i<nob;i++) { setcolor(WHITE); circle(*(bombx+i),*(bomby+i),22); } // CREATE BUBLES for(i=0;i<numctr;i++) { randomcolor=random(5)+1; setcolor(randomcolor); circle(*(xcoord+i),*(ycoord+i),20); } // MOUSE altermouse(x,y,cl); delay(dt); // CHECK WHAT HAPPENED WITH BUBLES temp=numctr; for(i=0;i<temp;i++) { // CHECK IF BUBLES WERE HIT if(x < *(xcoord+i)+20 && x > *(xcoord+i)-20 && y< *(ycoord+i)+20 && y>*(ycoord+i)-20) { points+=10; numctr--; ctr=i; cleardevice(); outline(mx,my); for(j=0;j<lives;j++) { setcolor(WHITE); circle((mx-200)+(j*20),my-10,6); setfillstyle(SOLID_FILL,RED); floodfill((mx-200)+(j*20),my-10,WHITE); } } // DE-CREATE THE BUBLES setcolor(BLACK); circle(*(xcoord+i),*(ycoord+i),20); // LET THE BUBLES MOVE *(xcoord+i)+=delaytime[i]; // CHECK FOR PLAYER'S DEATH if(xcoord[i]>=mx-48) { numctr--; lives--; if(lives==0){goto again;} for(j=0;j<lives+1;j++) { setcolor(BLUE); circle((mx-200)+(i*20),my-10,6); setfillstyle(SOLID_FILL,BLUE); floodfill((mx-200)+(j*20),my-10,BLUE); } for(j=0;j<lives;j++) { setcolor(WHITE); circle((mx-200)+(j*20),my-10,6); setfillstyle(SOLID_FILL,RED); floodfill((mx-200)+(j*20),my-10,WHITE); } ctr=i; } } // CHECK WHAT HAPPENED WITH THE BOMB temp=nob; for(i=0;i<temp;i++) { // CHECK FOR PLAYERS DEATH AND THE END OF GAME if(x < *(bombx+i)+22 && x > *(bombx+i)-22 && y< *(bomby+i)+22 && y>*(bomby+i)-22) { goto again; } // DE-CREATE THE BOMBS setcolor(BLACK); circle(*(bombx+i),*(bomby+i),22); // LET THE BOMBS MOVE *(bombx+i)+=delaytime[i]; // CHECK FOR THE BOMBS DEATH if(*(bombx+i)>=mx-45) { bombctr=i; nob--; *(bombx+bombctr)=48; *(bomby+bombctr)=random(my-100)+50; nob++; } } end=clock(); playtime=ceill((end-start)/CLK_TCK); if(playtime>10) { dt-=10; start=clock(); } } // THIS IS THE END : again: cleardevice(); outline(mx,my); endgame(points,mx,my); readscore(points); hidemouse(); delete ycoord,xcoord; menu(mx,my); }
void CoreGame::runCode(void *params) { int x = 0; double time = 0.f; t_movement mouv; sf::Event event; std::string port; port = this->intToString(); this->_idSocketRoom = this->_socketInGame->connectToSocket(_sconnect.ip, port); this->_window->createWindow(); this->_backgroundFirstPart->setPosition((float)x, 0.0); this->_backgroundSecondePart->setPosition((float(x + SIZEIMAGE)), 0); #ifdef _WIN32 FILETIME ttmp{ 0, 0 }; MTime *mtime = new MTime(ttmp); ULARGE_INTEGER tbegin; #else MTime *mtime = new MTime; struct timeval start; #endif while (this->_window->getWindow()->isOpen()) { #ifdef _WIN32 mtime->updateClock(&tbegin); if ((time = mtime->getTime(tbegin)) < 0.02) { int res = (int)std::floor((0.02 - time) * 1000); Sleep(res); } #else if ((time = mtime->getTime()) < 0.02) { int res = (int)std::floor((0.02 - time) * 1000); usleep(res); } #endif this->_window->getWindow()->clear(); this->_backgroundFirstPart->setPosition((float)x, 0.0); this->_backgroundSecondePart->setPosition((float(x + SIZEIMAGE)), 0.0); x--; if (x < -SIZEIMAGE) x = 0; this->_backgroundTop->setPosition(0.0, 0.0); this->_backgroundBottom->setPosition(0.0, 695.0); this->_window->getWindow()->draw(*this->_backgroundFirstPart); this->_window->getWindow()->draw(*this->_backgroundSecondePart); this->_window->getWindow()->draw(*this->_backgroundTop); this->_window->getWindow()->draw(*this->_backgroundBottom); if (endgame() == true) return ; updateDeath(); drawPlayer(this->_classShared->_mapPlayer); drawMonster(this->_classShared->_mapMonster); drawAmmo(this->_classShared->_mapAmmo); drawBoss(this->_classShared->_mapBoss); drawAnExplosion(); while (this->_window->getWindow()->pollEvent(event)){ if (event.type == sf::Event::Closed) this->_window->getWindow()->close(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) this->moveRight(mouv); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) this->moveLeft(mouv); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) this->moveUp(mouv); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) this->moveDown(mouv); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) this->shoot(mouv); this->_window->getWindow()->display(); } }
int main( int ac, char **av ) { char c; partie_t *partie; int largeur; int hauteur; int score; static int pos; if ( ac ) { if ( av[1] ) { if ( ft_check_location( av[1] ) ) { if (ft_check_extension( av[1] )) ft_sokoban( av[1] ); else ft_putendl("invalid extension"); } else ft_putendl("invalid location"); } else if ( av[1] == NULL ) { largeur = 10; hauteur = 10; score = 1; alloc_memoire_partie( partie ); partie->score = score; alloc_memoire_plateau( partie->p ); alloc_memoire_plateau( partie->tampon ); partie->p->largeur = largeur; partie->p->hauteur = hauteur; alloc_memoire_tableau( partie->p ); partie->tampon->largeur = partie->p->largeur; partie->tampon->hauteur = partie->p->hauteur; alloc_memoire_tableau( partie->tampon ); plateau( partie->p ); tableau_tampon( partie->p, partie->tampon ); afficher_tableau( partie->p ); while( partie->p->tab[A] != 'C' ) { printf("Rentrez i pour aller en haut , k pour aller en bas ,"); printf(" j pour aller a gauche , l pour aller a droite , "); printf("r pour revenir au coup precedent\n"); scanf(" %c",&c); printf("\n\n"); deplacement( c, partie->p, partie->tampon ); tableau_tampon( partie->p, partie->tampon ); system( "clear" ); printf( "COUP N'%d\n\n\n\n",partie->score ); afficher_tableau( partie->p ); partie->score++; } printf( "Vous avez reussi\n" ); endgame( partie ); } } return ( 0 ); }
EXT_MOD_GAME void start_game(int difficulty) { Tela *tela; Peca *peca, *prox_peca; int end=0, in; WINDOW* main; srand(time(NULL)); tela = nova_tela(); prox_peca = nova_peca(tela, -TELA_LARGURA/2, TELA_ALTURA/8-1); while(!end) { clock_t ini; peca = prox_peca; prox_peca = nova_peca(tela, -TELA_LARGURA/2, TELA_ALTURA/8-1); peca_move_x(peca, TELA_LARGURA); if(peca_touching(peca, tela, 's')) { deleta_peca(peca); break; } ini = clock(); while(!end) { clock_t now; mostra_tela(tela); mostra_peca(peca); mostra_peca(prox_peca); refresh(); in = pega_input(1); switch(in) { case 'S': case 's': if(!peca_touching(peca, tela, 's')) peca_move_y(peca, 1); break; case 'A': case 'a': if(!peca_touching(peca, tela, 'a')) peca_move_x(peca, -1); break; case 'D': case 'd': if (!peca_touching(peca, tela, 'd')) peca_move_x(peca, 1); break; case ENTER: prende_peca(peca, tela); break; case 'q': case 'Q': end = 1; break; case ESC: set_color(COR_TELA); mvaddstr(tela->y + TELA_ALTURA/2 -1, tela->x + TELA_LARGURA/2 + 2, "PAUSED"); do {in = getch();} while(in != ESC && in!='q' && in!='Q'); if(in == 'q' || in == 'Q') { end = 1; deleta_peca(peca); } break; } clear(); if(end) break; now = clock(); if(now - ini > 5) { peca_move_y(peca, 1); ini = clock(); } if(peca_touching(peca, tela, 's')) { prende_peca(peca, tela); deleta_peca(peca); break; } } if(endgame(tela)) { end = 1; deleta_tela(tela); } } }