bool mergeLeft(struct tile **board, int size, int pos_rel, int multi) { bool plus = false; int current_row, current_col; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (j != size - 1 && board[i][j].value != 0) { //move from left to right if (board[i][j].value == board[i][j + 1].value) { board[i][j].value = 2 * board[i][j].value; plus = true; current_row = i; current_col = j; win(board[i][j].value); board[i][j + 1].value = 0; //calculate points for 2 people if (pos_rel == SHIFT_RIGHT) { score += board[current_row][current_col].value; } else { score_p2 += board[current_row][current_col].value; } printScore(score, score_p2, multi); } } } } cleanBoard(board, size, pos_rel); return plus; }
bool mergeDown(struct tile **board, int size, int pos_rel, int multi) { bool plus = false; int current_row, current_col; for (int col = 0; col < size; col++) { for (int row = size - 1; row >= 0; row--) { if (row != 0 && board[row][col].value != 0) { if (board[row][col].value == board[row - 1][col].value) { board[row][col].value = 2 * board[row][col].value; plus = true; current_row = row; current_col = col; win(board[row][col].value); board[row - 1][col].value = 0; if (pos_rel == SHIFT_RIGHT) { score += board[current_row][current_col].value; } else { score_p2 += board[current_row][current_col].value; } printScore(score, score_p2, multi); } } } } cleanBoard(board, size, pos_rel); return plus; }
bool mergeRight(struct tile **board, int size, int pos_rel, int multi) { bool plus = false; int current_col; int current_row; for (int i = 0; i < size; i++) { for (int j = size - 1; j >= 0; j--) { //if the tile is not the first column keep going from right to left if (j != 0 && board[i][j].value != 0) { if (board[i][j].value == board[i][j - 1].value) { board[i][j].value = 2 * board[i][j].value; plus = true; board[i][j - 1].value = 0; current_row = i; current_col = j; //check if the added value == goal win(board[i][j].value); //update score if (pos_rel == SHIFT_RIGHT) { score += board[current_row][current_col].value; } else { score_p2 += board[current_row][current_col].value; } printScore(score, score_p2, multi); } } } } //clean the board cleanBoard(board, size, pos_rel); return plus; }
void printScreen(int snake[TAILLE_SNAKE][2], int len_snake, int pommes[20][2], int len_pommes, unsigned long int time, int score){ EffacerEcran(CouleurParNom("black")); printTerrain(snake, len_snake, pommes, len_pommes); ChoisirCouleurDessin(CouleurParNom("white")); printScore(score); printTime(time); CopierZone(1,0,0,0,60*TAILLE_CASE+2*BORD,40*TAILLE_CASE+BORD+40,0,0); }
int printImg(BITMAP * nave, BITMAP * buffer,BITMAP * alien,BITMAP * gun,SAMPLE * sound,SAMPLE * music,BITMAP * bg, int x,int y){ int valid = controllAlien(buffer,alien,bg); if(valid == 1){ return 1; } controllNave(buffer,nave,sound,x,y); controllGun(buffer,gun,music); printScore(buffer); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W,SCREEN_H); clear(buffer); return 0; }
void gameOver() { // gameOver start = false; glColor3ub(255,255,255); if(win == true) { char mess10[] = "You won!"; printText(strlen(mess10), mess10, width/2 - 10, length - 25 - 25); } else { char mess10[] = "You lost!"; printText(strlen(mess10), mess10, width/2 - 10, length - 25 - 25); } printScore(); }
void GameState::renderItems() { SDL_RenderClear(ren_); SDL_RenderCopy(ren_, background_, NULL, NULL); SDL_Rect sect = catChar_->getSection(); SDL_Texture* text = catChar_->getTexture(); SDL_Rect dest = catChar_->getDestination(); SDL_RenderCopy(ren_, text, §, &dest); for (unsigned int i = 0; i < enemyList_.size(); i++) { SDL_RenderCopy(ren_, enemyList_[i]->getTexture(), &enemyList_[i]->getSection(), &enemyList_[i]->getDestination()); } for (unsigned int i = 0; i < shotList_.size(); i++) { SDL_RenderCopy(ren_, shotList_[i]->getTexture(), &shotList_[i]->getSection(), &shotList_[i]->getDestination()); } printScore(); SDL_RenderPresent(ren_); }
//function definitions // Takes 2 fasta files and scoring matrix. Prints optimal alignment score and local alignment. int localAlignment(FILE *fasta1, FILE *fasta2, int score[3]) { int numSeqs1; int numSeqs2; sequence_t *seq1 = readSequence(fasta1, &numSeqs1); sequence_t *seq2 = readSequence(fasta2, &numSeqs2); int dp_rows = seq1->sequence_length+1; //length of sequence + null character + 1. Need extra space for base case. int dp_cols = seq2->sequence_length+1; direction **bt = allocateMemDirection(dp_rows, dp_cols); //backtrace table int **distance = allocateMemInt(dp_rows, dp_cols); //table of scores fillMatrixLocal(dp_rows, dp_cols, distance, bt, seq1->sequence, seq2->sequence, score); //printMatrix(dp_rows, dp_cols, distance, bt); //print DP table for debugging //print out the highest score in the table. int highest_score_coordinates[2] = {0, 0}; int maxScore = max_score_in_dp(dp_rows, dp_cols, distance, highest_score_coordinates); printScore(maxScore, -2); //void backtrace(int srow, int scol, sequence_t *seq1, sequence_t *seq2, int dp_cols, direction bt[][dp_cols]) backtraceAlignment(highest_score_coordinates[0], highest_score_coordinates[1], seq1, seq2, bt, -2); return 0; }
void gameStart(int mode) { bool success;//是否下落成功;若失败,则说明沉底 int i, j, k, t = 0; int cmd = 0; int timeLeft[TOTAL_PLAYER+1] = {0, 1000, 1000}; Block tpBlk[TOTAL_PLAYER+1]; gameInit();//初始化游戏 while(1) { for(i = 1; i <= TOTAL_PLAYER; i++) { t++;//计时器增加 setorigin(0, 0); //设置原点 recoverBk(0, g_player[i].preview.y + 4 * BLOCK_SIZE, 160, 30); recoverBk(0, 480 - 30, 160, 30); //重绘预览区 printScore(t);//显示得分 drawStageLine();//绘制边界线 FlushBatchDraw();//执行绘图 if(g_player[i].dropped == true) { saveState(i, g_player[i].nowBlk);//保存方块的存在状态 if(mode == CLEAR && g_player[1+(i==1)].score >= 100)gameOver(i); if(reachTop(i)) { gameOver(i); continue; }//判断游戏结束 k = fullColumn(i); if(k > 0) { g_player[i].score += k * k; if(mode == NORMAL && g_player[i].score % 10 == 0)newColumn(1 + (i == 1)); }//计分与消行 tpBlk[i] = g_player[i].preBlk; //备份预览方块 g_player[i].nowBlk = preToNow(g_player[i].preBlk);//previewBlock变为player[1].nowBlk g_player[i].preBlk = createBlk(); //产生新的预览方块 refreshBlk(i, tpBlk[i], g_player[i].preBlk, PREVIEW); //绘制新的previewBlock g_player[i].dropped = false; } getCmd(&cmd);//获得命令 timeLeft[i] -= 10; for (j = 1; j <= TOTAL_PLAYER; j++) { tpBlk[j] = g_player[j].nowBlk; success = DispatchCommand(j, cmd); if(success)refreshBlk(j, tpBlk[j], g_player[j].nowBlk); else continue; }//在一个玩家的循环中要同时处理两个玩家 if(timeLeft[i] <= 0) { if(mode == NORMAL)timeLeft[i] = INIT_DELAY - (int)(2.5 * g_player[1+(i==1)].score); else timeLeft[i] = (int)(INIT_DELAY - (t / 1000.0)); //速度规则 if(timeLeft[i] < MIN_DELAY)timeLeft[i] = 3 * MIN_DELAY; tpBlk[i] = g_player[i].nowBlk; if(i == 1) success = DispatchCommand(1, CMD_DOWN); else success = DispatchCommand(2, CMD_DOWN2); if(success)refreshBlk(i, tpBlk[i], g_player[i].nowBlk); } } } getch(); closegraph(); }
///Modo de jogo em que só há uma vida, e termina apenas quando o jogador morre void survivalMode() { system("mode con:cols=90 lines=30"); //tamanho da tela de jogo LEVEL_SCENE hell = {RED, {176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,177, 176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,177, 176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,177,177, 176,176,176,176,176,176,176,176,178,178,176,176,176,176,176,176,178,177,177,177, 176,176,178,177,177,176,176,178,178,178,178,176,176,176,176,178,178,177,177,177, 176,176,178,177,177,177,176,178,178,178,178,176,176,176,176,178,178,178,177,177, 178,178,178,177,177,177,176,178,178,178,178,176,176,176,178,178,178,178,178,178, 178,178,177,177,177,177,176,178,178,178,178,178,176,178,178,178,178,177,178,178, 177,178,177,177,177,177,177,177,178,178,177,177,177,177,177,177,177,177,177,178, 177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177 } }; //cenário do modo de jogo FILE *arq; int score; //pontuação int level; //como só há um level nesse jogo, esta variavél serve apenas para o peso da pontuação int speed; //velocidade do jogo int rows, columns; //Linhas e colunas do mapa int rocksNum; // Número de pedras int ratNum; //Indica qual o rato a ser gerado, há no máximo 4 ratos na tela int ratsEaten; int ratsColor; //Cor do rato a ser gerado int i; // Usado nos loops for int cont; //Usado para contabilizar o número de movimentos da snake char auxDirection; // BOOL isDead; //Flag de morte da snake char map[ROWSMAX][COLUMNSMAX]; int hasPassed[ROWSMAX*COLUMNSMAX]; SNAKE snake; POSN initialCoord; //Coordenada onde a snake começa o nível POSN rocks[ROWSMAX*COLUMNSMAX]; POSN rats[4]; ratNum = 0; ratsColor = 2; ratsEaten = 0; cont = 0; isDead = 0; level = 1; score = 0; speed = 200; //speed inicial for(i=0; i<rocksNum; i++) hasPassed[i]=0; readMap(42, &rows, &columns, map, &rocksNum, rocks, &initialCoord); restartLevel(&snake, columns, rows, rats, speed, &speed, initialCoord, &isDead); print_lvlART(hell, columns + 5, 0); fadeIN(rows, columns, GREY, 1); printMap(rows, columns, map, hell.color); printRocks(rows, columns, rocksNum, rocks, map); printSnake(&snake); getch(); //pausa o jogo while(!isDead) { for(i=0; i<rocksNum; i++) { if(hasPassed[i]!=0) hasPassed[i]+=1; } print_lvlART(hell, columns + 5, 0); printScore(score); eraseTrail(snake); updateSnakeCoord(&snake); printSnake(&snake); checkColision(&snake, &isDead, rows, columns, map, rocks, rocksNum, hasPassed, &score); if(score < 0) { score = 0; //Não há score negativo! } cont++; //contador de movimentos if(cont % 10 == 0) { makeRats(rows, columns, rats, ratNum, &snake, map, &ratsColor); //gera e printa um rato ratNum++; if(ratNum == 4) //Há 4 ratos, de 0 a 3, logo rato 4 == rato 0 { ratNum = 0; } } eatRat(&snake, rats, &ratsEaten, &score, level); //checa se um rato foi comido Sleep(speed); //controla a velocidade do jogo if(speed > 100) //máxima velocidade do jogo speed -= 1; auxDirection = changeDirection(snake.direction); //lê nova direção to teclado if(auxDirection == 'P') { getch(); //Pausa o jogo } else if(auxDirection == 'C') { cheatCode(&isDead, &isDead, &speed); //Lê cheat code } else if(auxDirection == 'Q' || auxDirection == ESC) //Se o jogador aperta para sair, perde suas vidas para encerrar { isDead = 1; } else snake.direction = auxDirection; //só troca a direção se a nova direção não for uma tecla de pause ou saída } fadeOUT(rows, columns, GREY, 1); //Efeito de fade out na tela printGameOver(); arq = fopen("highscore_survival.bin", "rb+"); //Abre arquivo de highscore, informando caso de erro if(arq == NULL) printf("error"); uptadeHighScore(score, arq); //coloca o score no rank system("cls"); }
int main() { char toReroll[DICE]; int sectionSelection; int categorySelection; int counter= 1; int upperUsed1 = 0; int upperUsed2 = 0; int upperUsed3 = 0; int upperUsed4 = 0; int upperUsed5 = 0; int upperUsed6 = 0; int lowerUsed1 = 0; int lowerUsed2 = 0; int lowerUsed3 = 0; int lowerUsed4 = 0; int lowerUsed5 = 0; int lowerUsed6 = 0; int lowerUsed7 = 0; srand(time(NULL)); int i; while (counter < 13) { //Must go 13 times to fill all categories printf("\: %i\n", counter); int rolls=1; //Variable to hold how many re-rolls a user gets for(i = 0; i < DICE; i++) { dice[i] = generateDice(); //Generates dice } printf("Your Roll: "); for(i = 0; i < DICE; i++){ printf("%i ", dice[i]); //Prints dice } printf("\n"); while(rolls < 3 ) { //Loop to re-roll dice if necessary printf("Which dice to reroll?\n"); scanf("%s", &toReroll); if(toReroll[0] == '0') { //Do not reroll any more dice if user enters '0' break; } else { for(i = 0; i < DICE; i++) { //printf("%c\n", toReroll[i]); if(toReroll[i] == NULL) { break; } int num = toReroll[i] - '0'; //Converts from char to int num -= 1; dice[num] = generateDice(); } int x; for(x = 0; x < DICE; x++){ printf("%i ", dice[x]); //Prints dice } printf("\n"); } rolls++; } printf("Place dice into:\n"); printf("1) Upper Section\n"); printf("2) Lower Section\n"); printf("Selection? "); scanf("%i", §ionSelection); printf("\n"); if(sectionSelection == 1) { //Place into Upper Section while(1) { printf("Place dice into:\n"); printf("1) Ones\n"); printf("2) Twos\n"); printf("3) Threes\n"); printf("4) Fours\n"); printf("5) Fives\n"); printf("6) Sixes\n"); scanf("%i", &categorySelection); printf("\n"); if(categorySelection == 1) { if(upperUsed1) { printf("Already used. Please pick again\n\n"); continue; } upper.ones = computeScore(categorySelection); score+= upper.ones; upperUsed1 = 1; break; } else if (categorySelection == 2) { if(upperUsed2) { printf("Already used. Please pick again\n\n"); continue; } upper.twos = computeScore(categorySelection); score+= upper.twos; upperUsed2 = 1; break; } else if (categorySelection == 3) { if(upperUsed3) { printf("Already used. Please pick again\n\n"); continue; } upper.threes = computeScore(categorySelection); score+= upper.threes; upperUsed3 = 1; break; } else if (categorySelection == 4) { if(upperUsed4) { printf("Already used. Please pick again\n\n"); continue; } upper.fours = computeScore(categorySelection); score+= upper.fours; upperUsed4 = 1; break; } else if (categorySelection == 5) { if(upperUsed5) { printf("Already used. Please pick again\n\n"); continue; } upper.fives = computeScore(categorySelection); score+= upper.fives; upperUsed5 = 1; break; } else if (categorySelection == 6) { if(upperUsed6) { printf("Already used. Please pick again\n\n"); continue; } upper.sixes = computeScore(categorySelection); score+= upper.sixes; upperUsed6 = 1; break; } } printScore(); printf("\n\n"); } else { //Place into Lower Section while(1) { char takeZero; printf("Place dice into:\n"); printf("1) Three of a Kind\n"); printf("2) Four of a Kind\n"); printf("3) Full House\n"); printf("4) Small Straight\n"); printf("5) Large Straight\n"); printf("6) Yahtzee\n"); printf("7) Chance\n"); scanf("%i", &categorySelection); printf("\n"); if(categorySelection == 1) { if(lowerUsed1) { printf("Already used. Please pick again\n\n"); continue; } if(!isThreeOfAKind()){ printf("You do not have three of a kind. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.threeOfAKind = 0; } else{ continue; } } else{ int sum = 0; for(i = 0; i < DICE; i++) { sum += dice[i]; } lower.threeOfAKind = sum; score+= lower.threeOfAKind; lowerUsed1 = 1; } } else if (categorySelection == 2) { if(lowerUsed2) { printf("Already used. Please pick again\n\n"); continue; } if(!isFourOfAKind()){ printf("You do not have four of a kind. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.fourOfAKind = 0; } else { continue; } } else{ int sum = 0; for(i = 0; i < DICE; i++) { sum += dice[i]; } lower.fourOfAKind = sum; score+= lower.fourOfAKind; lowerUsed2 = 1; } } else if (categorySelection == 3) { if(lowerUsed3) { printf("Already used. Please pick again\n\n"); continue; } if(!isFullHouse()) { printf("You do not have a full house. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.fullHouse = 0; } else { continue; } } else { lower.fullHouse = FULL_HOUSE; score += FULL_HOUSE; lowerUsed3 = 1; } } else if (categorySelection == 4) { if(lowerUsed4) { printf("Already used. Please pick again\n\n"); continue; } if(!isSmallStraight()) { printf("You do not have small straight. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.smallStraight = 0; } else { continue; } } else { lower.smallStraight = SMALL_STRAIGHT; score += SMALL_STRAIGHT; lowerUsed4 = 1; } } else if (categorySelection == 5) { if(lowerUsed5) { printf("Already used. Please pick again\n\n"); continue; } if(!isLargeStraight()) { printf("You do not have large straight. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.largeStraight = 0; } else { continue; } } else { lower.largeStraight = LARGE_STRAIGHT; score += LARGE_STRAIGHT; lowerUsed5 = 1; } } else if (categorySelection == 6) { if(lowerUsed6) { printf("Already used. Please pick again\n\n"); continue; } if(!isYahtzee()){ printf("You do not have yahtzee. Would you like to take a 0 for this category? [y/n]\n\n"); scanf("%c", &takeZero); if(takeZero == 'y') { lower.threeOfAKind = 0; } else { continue; } } else { lower.yahtzee = YAHTZEE; score += YAHTZEE; lowerUsed6 = 1; } } else if(categorySelection == 7) { if(lowerUsed7) { printf("Already used. Please pick again\n\n"); continue; } int i; int tempScore = 0; for (i = 0; i < DICE; i++) { tempScore += dice[i]; } lower.chance = tempScore; score += tempScore; lowerUsed7 = 1; } printScore(); printf("\n"); break; } //End while } //End else counter++; } //End while if( (upper.ones + upper.twos + upper.threes + upper.fours + upper.fives + upper.sixes) > 63) { printf("35 Bonus points because your upper section totalled more than 63\n"); score+= 35; } addInZeros(); printf("Final Score\n"); printf("------------------------------------------\n"); printScore(); printf("------------------------------------------\n"); return 0; }
void moveDot(char screen[HEIGHT][WIDTH], Direction dotDirection, Dot * d, Racket ** list) { if (screen[d->height][d->width] == RACKET_BRUSH) { screen[d->height][d->width] = RACKET_BRUSH; return; } screen[d->height][d->width] = SPACE; bool hitWall = false; switch (dotDirection) { case UP: d->height -= d->deltaHeight; break; case DOWN: d->height += d->deltaHeight; break; case RIGHT: d->width += d->deltaWidth; break; case LEFT: d->width -= d->deltaWidth; break; case UPLEFT: moveDot(screen, UP, d, list); moveDot(screen, LEFT, d, list); break; case UPRIGHT: moveDot(screen, UP, d, list); moveDot(screen, RIGHT, d, list); break; case DOWNLEFT: moveDot(screen, DOWN, d, list); moveDot(screen, LEFT, d, list); break; case DOWNRIGHT: moveDot(screen, DOWN, d, list); moveDot(screen, RIGHT, d, list); break; } /* Bounding Box */ if (d->height <= 0) { d->height = 1; hitWall = true; } if (d->height >= HEIGHT - 1) { d->height = HEIGHT - 2; hitWall = true; } if(d->width < 0) { gameScore(list[1]); printScore(list[0]->score, list[1]->score); initializeDot(screen, d, UPLEFT); }else if (d->width >= WIDTH) { gameScore(list[0]); printScore(list[0]->score, list[1]->score); initializeDot(screen, d, UPRIGHT); } if (hitWall) { dotHitWall(screen, d); } screen[d->height][d->width] = DOT; }
int Gaming(){ int i, j, k, flag; stopcheck = 0; bla = whi = 2; printScore(); while(CheckWin()){ if(leftPress() != 1){ getMousePosition(&mx,&my); if(mousex != mx||mousey != my){ putimage(mousex,mousey,imagep,XOR_PUT); mousex = mx; mousey = my; putimage(mousex,mousey,imagep,XOR_PUT); } } else if(mouseLeftFlag == 1) /*得到点击的位置*/ { mouseLeftFlag = 0; getMousePosition(&mx,&my); for(i = 1; i < 9; i++){ for(j = 1; j < 9; j++){ if((mx > STARTX + SIDELENGTH * j && mx < STARTX + SIDELENGTH * (j+1)) && (my > STARTY + SIDELENGTH * i && my < STARTY + SIDELENGTH * (i+1))){ break; } } if((mx > STARTX + SIDELENGTH * j && mx < STARTX + SIDELENGTH * (j+1)) && (my > STARTY + SIDELENGTH * i && my < STARTY + SIDELENGTH * (i+1))){ break; } } if(color[i][j] == EMPTY){ color[i][j] = colornow; inow = i; jnow = j; if(change(i,j) == 1){ if(BLA == colornow){ ChessBlaSound(); colornow = WHI; } else{ ChessWhiSound(); colornow = BLA; } } else{ WarningSound(); color[i][j] = EMPTY; } } cleardevice(); drawTable(); flag = bla = whi = count = 0; for(i = 1; i < 9; i++){ for(j = 1; j < 9; j++){ if(color[i][j] == BLA){ bla++; count++; }else if(color[i][j] == WHI){ whi++; count++; }else if(color[i][j] == EMPTY){ color[i][j] = colornow; if(determine(i,j) == 1) flag = 1; color[i][j] = EMPTY; } drawChessman(i,j,color[i][j]); } } if(color[inow][jnow] != EMPTY) drawChessnow(); if(flag == 0){ if(BLA == colornow) colornow = WHI; else colornow = BLA; for(i = 1; i < 9; i++){ for(j = 1; j < 9; j++){ if(color[i][j] == EMPTY){ color[i][j] = colornow; if(determine(i,j) == 1) flag = 1; color[i][j] = EMPTY; } } } if(flag == 0) stopcheck = 1; } printScore(); } } return 1; }
void keyboardchar(int key) { static int controlvoice = 0; switch (key) { case '0': nextpattern = 0; break; // select level 0 case '1': nextpattern = 1; break; // select level 1 case '2': nextpattern = 2; break; // select level 2 case '3': nextpattern = 3; break; // select level 3 case '4': nextpattern = 4; break; // select level 4 case '5': nextpattern = 5; break; // select level 5 case '6': nextpattern = 6; break; // select level 6 (cadences) case 'a': nextsubpattern = 0; break; // select subgroup a case 'b': nextsubpattern = 1; break; // select subgroup b case 'c': nextsubpattern = 2; break; // select subgroup c case 'd': nextsubpattern = 3; break; // select subgroup d case '/': printScore(rpscore); break; // for debugging case '[': // slow down the tempo tempo *= 0.99; cout << "Tempo = " << tempo << endl; break; case ']': // speed up the tempo tempo *= 1.01; cout << "Tempo = " << tempo << endl; break; case '-': // lower the key number for the given voice voicetokey[controlvoice]--; voicetokey[controlvoice] = midilimit(voicetokey[controlvoice]); cout << "Voice: " << controlvoice << "\tkey: " << voicetokey[controlvoice] << endl; break; case '+': // raise the key number for the given voice case '=': // same as '+' without the shift key voicetokey[controlvoice]++; voicetokey[controlvoice] = midilimit(voicetokey[controlvoice]); cout << "Voice: " << controlvoice << "\tkey: " << voicetokey[controlvoice] << endl; break; case ' ': // restart the pattern cycle nextpatterntime = t_time; break; case 'q': controlvoice = 0; break; // control timber of voice 0 with -/= case 'w': controlvoice = 1; break; // control timber of voice 1 with -/= case 'e': controlvoice = 2; break; // control timber of voice 2 with -/= case 'r': controlvoice = 3; break; // control timber of voice 3 with -/= case 't': controlvoice = 4; break; // control timber of voice 4 with -/= case 'y': // turn voice 0 on/off activevoice[0] = !activevoice[0]; cout << "Voice 0 = " << activevoice[0] << endl; break; case 'u': // turn voice 1 on/off activevoice[1] = !activevoice[1]; cout << "Voice 1 = " << activevoice[1] << endl; break; case 'i': // turn voice 2 on/off activevoice[2] = !activevoice[2]; cout << "Voice 2 = " << activevoice[2] << endl; break; case 'o': // turn voice 3 on/off activevoice[3] = !activevoice[3]; cout << "Voice 3 = " << activevoice[3] << endl; break; case 'p': // turn voice 4 on/off activevoice[4] = !activevoice[4]; cout << "Voice 4 = " << activevoice[4] << endl; break; } }
int main(int argc, char *argv[]) { char **playersNameList; int totalPlayersNumber; int turn, i; char buffer[BUFF_SIZE]; FILE *configFile; /* legge gli argomenti */ char **name1, **name2; if (argc < 4) { fprintf(stderr, "ERROR: Wrong number of arguments. \n USAGE: %s\n", USAGE); exit(EXIT_FAILURE); } playersNameList = argv + 3; totalPlayersNumber = argc - 3; /* controlla se ci sono due giocatori con lo stesso nome */ for (name1 = playersNameList; *name1; name1++) for (name2 = name1 + 1; *name2; name2++) if (strcmp(*name1, *name2) == 0) { fprintf(stderr, "ERROR: found two player with the" "same name \"%s\"\n", *name1); exit(EXIT_FAILURE); } initIoInterface(argv[2]); /* crea e inizializza le strutture dati per i giocatori */ initPlayersManager(totalPlayersNumber); for (; *playersNameList; playersNameList++) addPlayer(*playersNameList); initBoard(); /* * legge il file di configurazione secondo il formato: * numero_casella:descrizione della prova\n * e aggiunge le descrizioni al tabellone */ if ((configFile = fopen(argv[1], "r")) == NULL) { printErr("ERROR: error while opening configuration file\n"); exit(EXIT_FAILURE); } while (fgets(buffer, BUFF_SIZE, configFile)) { char *description; int boxNumber; /* legge il numero di casella */ if ((boxNumber = atoi(buffer)) <= 0) { printErr("ERROR:invalid box num(\"%s\") in" " configuration file\n", buffer); exit(EXIT_FAILURE); } /* aggiunge una nuova casella con la relativa descrizione */ if ((description = strchr(buffer, ':')) == NULL) { printErr("ERROR: missing ':' in configuration file\n"); exit(EXIT_FAILURE); } addBox(boxNumber, description + 1); } if (getTotalBoxesNumber() == 0) { printErr("ERROR: invalid configuration file\n"); exit(EXIT_FAILURE); } fclose(configFile); printBoard(); showGame(); /* avvia la simulazione del gioco */ srand(time(NULL)); for (turn = 0; !allPlayersDone(); turn++) { if (!nextStep()) return EXIT_SUCCESS; printMessage("\n**************************************\n"); printMessage("turno %d", turn + 1); printMessage("\n**************************************\n"); showGame(); /* * per ogni giocatore G che non ha terminato il gioco: * 1. se G e' fermo per un turno cambia il suo stato in * modo che al turno successivo venga rimesso in gioco * 2. altrimenti viene lanciato il dado, mosso il giocatore * e visualizzata la sua prova */ while (nextPlayer()) { int state = getPlayerState(); if (state == ACTIVE || state == TEST_PASSED || state == TO_BE_ACTIVATED) { if (state != ACTIVE) setPlayerState(ACTIVE, 0); movePlayer((rand() % 6) + 1); if (getPlayerBox() > getTotalBoxesNumber()) setPlayerState(DONE, turn); else printMessage("player %s: \"%s\"\n", getPlayerName(), getDescription(getPlayerBox())); } else if (state == OUT_OF_TURN) setPlayerState(TO_BE_ACTIVATED, 0); } showGame(); /* * Legge e registra l'esito di tutte le prove sostenute nel * turno corrente dai giocatori */ for (i = getActivePlayersNumber(); i > 0; i--) { int playerNumber; bool result; do { result = askPlayerResult(&playerNumber); if (playerNumber > totalPlayersNumber) printErr("WARNING: player number %d out of " "bounds [1; %d]\n", playerNumber, totalPlayersNumber); else { setCurrentPlayer(playerNumber); if (getPlayerState() != ACTIVE) printErr("WARNING: player number %d not " "valid because player:" "\n\t-won" "\n\t-is out of turn" "\n\t-already passed the test\n", playerNumber); } } while (playerNumber > totalPlayersNumber || getPlayerState() != ACTIVE); if (result) setPlayerState(TEST_PASSED, 0); else setPlayerState(OUT_OF_TURN, 0); } } printScore(); closeIoInterface(); return EXIT_SUCCESS; }
int startGame(Pipe* lead, Pipe* trail, int scrWidth, int scrHeight) { int loop = 1; int score = 0; double birdX = 150, birdY = 275, birdR = 12, birdV = 0, t = .05; int flap = 0; //#1 - to see game over screen make this while (loop < 5) and uncomment #2 while (loop) { //if bird touches the drawpipe loop = 2 gfx_clear(); //draw background drawBackground(scrWidth, scrHeight); //check for loss if ((lead->leadingX-3 <= birdX+16 && lead->trailingX+3 >= birdX-16) && (lead->topHeight >= birdY-16 || lead->bottomHeight <= birdY-16+24)) break; if (birdY-16+24 >= scrHeight) break; flap = drawBird(birdX, birdY, birdR, flap); updateBird(&birdY, &birdV, &t, birdY, birdV, t); if(gfx_event_waiting()){ char c = gfx_wait(); if(c == ' ') birdV = -40; } //draw leading pipe drawPipe(lead, scrWidth, scrHeight); updatePipe(lead); //increase the score upon passing through a pair of pipes if(lead->trailingX == birdX){ score++; } if (lead->trailingX < scrWidth/2) { drawPipe(trail, scrWidth, scrHeight); updatePipe(trail); } if (lead->trailingX <= 0) { //swap the leader Pipe *temp = lead; lead = trail; trail = temp; initializePipe(trail, scrWidth, scrHeight); } //print the score on the top of the screen printScore(score, scrWidth); gfx_flush(); usleep(10000); t+=.001; //loop++ #2 -- to see end screen uncomment this and above } return score; }
void printShip(Ship *ship) { printf("\nShip:\n\tLife: %d", ship->life); printPosition(ship->position); printVelocity(ship->velocity); printScore(ship); }
/** * @brief Starts the game, connecting libraries and UI */ int cruceGameLogic() { setlocale(LC_ALL, ""); initscr(); cbreak(); if (has_colors() == FALSE) { endwin(); printf("Your terminal does not support colors!"); return 0; } start_color(); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(7, COLOR_WHITE, COLOR_BLACK); refresh(); welcomeMessage(); int limitScore = getScoreLimit(); int noOfPlayers = getNoOfPlayers(); struct Game *game = game_createGame(limitScore); for (int i = 0; i < noOfPlayers; i++) { int err; while ((err = game_addPlayer(newPlayer(i + 1), game)) == DUPLICATE_NAME) printw("The player's name have to be unique\n"); if (err != 0) printw("ERROR: game_addPlayer() %d\n", err); } formTeams(game); for (int i = 0; !game_winningTeam(game); i++) { game_arrangePlayersRound(game, i % MAX_GAME_PLAYERS); struct Deck *deck = deck_createDeck(); deck_deckShuffle(deck); round_distributeDeck(deck, game->round); clear(); refresh(); for (int i = 0; i < game->numberPlayers; i++) { getBid(game, i); clear(); refresh(); } displayBids(game, game->numberPlayers); refresh(); sleep(2); clear(); refresh(); struct Player *bidWinner = round_getBidWinner(game->round); int first = round_findPlayerIndexRound(bidWinner, game->round); for (int i = 0; team_hasCards(game->players[0]); i++) { round_arrangePlayersHand(game->round, first); for (int j = 0; j < game->numberPlayers; j++) { WINDOW *scoreTableWindow = newwin(11, 49, 0, 30); #ifdef BORDERS box(scoreTableWindow, 0, 0); #endif printScore(game, game->round, scoreTableWindow); wrefresh(scoreTableWindow); delwin(scoreTableWindow); displayCardsAndPickCard(game, j); clear(); refresh(); } struct Player *handWinner = round_handWinner(game->round->hands[i], game->round); first = round_findPlayerIndexRound(handWinner, game->round); if (deck_cardsNumber(deck) > 0) round_distributeCard(deck, game->round); } int oldScore[MAX_GAME_PLAYERS]; for(int i = 0; i < MAX_GAME_TEAMS; i++) { if(game->teams[i] != NULL) { oldScore[i] = game->teams[i]->score; } } game_updateScore(game, bidWinner); printRoundTerminationMessage(game, oldScore); getch(); deck_deleteDeck(&deck); round_deleteRound(&game->round); } clear(); refresh(); gameEndingMessage(game_winningTeam(game)); for (int i = 0; i < MAX_GAME_PLAYERS; i++) if (game->players[i]) team_deletePlayer(&game->players[i]); for (int i = 0; i < MAX_GAME_TEAMS; i++) if (game->teams[i]) team_deleteTeam(&game->teams[i]); game_deleteGame(&game); getch(); endwin(); return EXIT_SUCCESS; }
void playFreedomGame(){ char board[ROW][COL] = { {'W', 'B', 'W', 'W', 'B', 'B', 'W', 'W', 'W', 'B'}, {'B', 'B', 'B', 'B', 'W', 'W', 'B', 'B', 'B', 'B'}, {'W', 'W', 'B', 'W', 'W', 'B', 'W', 'W', 'W', 'W'}, {'W', 'W', 'B', 'W', 'W', 'B', 'B', 'W', 'B', 'B'}, {'B', 'B', 'W', 'B', 'B', 'W', 'W', 'B', 'B', 'W'}, {'W', 'W', 'B', 'W', 'W', 'W', 'B', 'B', 'W', 'B'}, {'B', 'B', 'W', 'B', 'B', 'W', 'B', 'W', 'W', 'W'}, {'W', 'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B', 'B'}, {'B', 'W', 'B', 'B', 'W', 'W', 'B', 'B', 'B', 'W'}, {'B', 'W', 'B', 'W', 'B', 'B', 'W', 'W', 'B', 'W'} }; // char board[ROW][COL] = // { // {'B', 'B', 'B', 'B', 'B'}, // {'W', 'W', 'B', 'W', 'B'}, // {'W', 'B', 'W', 'B', 'B'}, // {'B', 'W', 'B', 'W', 'B'}, // {'W', 'B', 'W', 'W', 'W'} // }; // char board[ROW][COL] = {' '}; // fillArr(board, ' '); printBoard(board); int row = 0, col = 0, i = 0; while(howManyEmptyLeft(board) != 0){ printf("Player 1:\n"); getLocationForPlayers(board, &row, &col); board[row][col] = 'W'; getMove(board, row, col); getPlayerTwo(board, &row, &col); while(howManyEmptyLeft(board) != 0){ getPlayerOne(board, &row, &col); if(!isThereMove(board, row, col)){ break; } getPlayerTwo(board, &row, &col); if(!isThereMove(board, row, col)){ break; } printf("%d\n", howManyEmptyLeft(board)); i++; } } printScore(board, 'W'); printScore(board, 'B'); }
void addScore(SnakeHead * snake, int score=1) { snake->score += score; printScore(snake); }
void printScreen(int snake[300][2], int len_snake, int pommes[20][2], int len_pommes, int time, int score){ EffacerEcran(CouleurParNom("black")); printTerrain(snake, len_snake, pommes, len_pommes); printScore(score); printTime(time); }