void test_display_played_board() { Board* board = draw_board(); char expected[] = "X O X O X O O X O "; show_board(board); destroy_board(board); assert(strstr(writer_log, expected)); }
/* DRAWING BOARD */ void draw_board_and_runners() { draw_board(); for (int i = 0; i < NUMBER_OF_RUNERS; i++) { if (runners[i] -> tree_root != NULL) draw_runner(runners[i]); } }
static void draw_stuff(t_game *game) { draw_board(game); draw_blocks(game); draw_ball(game); draw_score(game->score, 1.8f, -1.6f); draw_score(game->life, 0.2f, -1.6f); }
GLvoid draw_static_board(GLvoid) { // printf("drawing static board\n"); glTranslatef(0.0f, 0.0f, -21.0f); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); // glScalef(0.1f, 0.1f, 0.1f); // glRotatef(90.0f, 1.0f, 0.0f, 0.0f); draw_board(origin, 0); }
/*F*********************************************************** * display(void) * * PURPOSE : Our glutDisplayFunc, it draws the borders of the board * and it draws the values inside of the board to the screen * * RETURN : void * * NOTES : *F*/ void display(void) { draw_board(); draw_numbers(); glutPostRedisplay(); return; }
void portal_travel() { int start_y; int start_x; int y; int x; // int target_x; // int target_y; start_y = player->y / FLOOR_H; start_x = player->x / CELL_TO_TILES; player->y--; draw_board(); lpause(); player->y--; draw_board(); lpause(); for (y = 0; y < MAX_FLOORS; y++) { for (x = 0; x < CELLS_W; x++) { if (get_cell(y, x) == CELL_PORTAL && x != start_x && y != start_y) { player->x = x * CELL_TO_TILES + 4; player->y = y * FLOOR_H + FLOOR_Y - 3; view_y = y * FLOOR_H; recenter(false); } } } draw_board(); lpause(); player->y++; draw_board(); lpause(); player->y++; draw_board(); return; }
void player_release_layers(PLAYER *player) { char *source, *target; int mask; int capacity = BoardDepth * BoardWidth; int source_count, released_count; const static int release_bonus[4] = { 100, 300, 600, 1000}; source_count = BoardHeight; released_count = 0; source = target = player->board; mask = player->released_details; while(--source_count >= 0) { if (mask & 1) released_count++; else { if (target != source) memmove(target, source, capacity); target += capacity; } mask >>= 1, source += capacity; } source_count = released_count; while(--source_count >= 0) { memset(target, '\0', capacity); target += capacity; } player->tile_code = 0; memset(player->tile_pos, '\0', sizeof(short)*Dimension); memset(player->tile_size, '\0', sizeof(short)*Dimension); player->layers += released_count; player->released_details = released_count; if (released_count) { if(player->type == 0) player->status |= PLST_DELAY; draw_board(PT_FOREGROUND, player, 0); player->status &= ~PLST_DELAY; } /* player->score += released_count * 100; */ player->score += release_bonus[released_count-1]; update_score(PT_FOREGROUND, player->score, player->layers); }
void draw_game(Game* game, GdkPixmap* pixmap) { draw_board(game->board, pixmap); int i = 0; for(i = 0; i < 32 ; i ++) { if(game->man[i] != NULL) draw_chessman(game->man[i], pixmap); } }
void test_handles_draw() { Board* board = draw_board(); Player* p1 = create_player('X', &fake_move); Player* p2 = create_player('O', &fake_move); start_game(board, p1, p2); destroy_board(board); destroy_player(p1); destroy_player(p2); assert(strstr(writer_log, "Draw")); }
void OPENGL_Nib::updateDraw(const Snake & s, const Fruit & f, const std::pair<int, int>& map) { glClear(GL_COLOR_BUFFER_BIT); draw_board(map); drawFruit(f); drawSnake(s); glFlush(); SDL_GL_SwapBuffers(); }
int main() { draw_board(); while(1) { play1(); play2(); } return 0; }
int main(int argc, char *argv[]) { int success = 0; int iterations = 0; sranddev(); init_board(' '); draw_board(); while (!success) { iterations++; success = place_five(); } printf("\n\niterations = %d\n", iterations); draw_board(); return 0; }
GLvoid draw_scene(GLvoid) { // printf("drawing scene\n"); glTranslatef(0.0f, 0.0f, -20.0f); // glRotatef(rot_x+30, 1.0f, 0.0f, 0.0f); glRotatef(rot_x+90, 1.0f, 0.0f, 0.0f); glRotatef(rot_y, 0.0f, 1.0f, 0.0f); glRotatef(rot_z, 0.0f, 0.0f, 1.0f); glScalef(zoom, zoom, zoom); glRotatef(rot, 0.0f, 1.0f, 0.0f); // draw_table(); // glCallList(DRAW_LIST_TABLE); draw_board(origin, DRAW_BOARD_FULL); draw_board(origin, 0); }
void Goban2D::draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(-1.0, -1.0, 0.0); //draw_border(); draw_board(); draw_text(); }
int main(int argc, char** argv){ int i; int j; int* score = (int*) malloc(sizeof(int)); if (SDL_Init(SDL_INIT_EVERYTHING) == -1){ printf("SDL_Init: %s\n", SDL_GetError()); return 1; } // Unicode support for hiscore table SDL_EnableUNICODE(1); if(TTF_Init()==-1) { printf("TTF_Init: %s\n", TTF_GetError()); return 1; } SDL_Surface* screen = SDL_SetVideoMode(608, 640, 32, SDL_SWSURFACE); SDL_WM_SetCaption("martet", "martet"); SDL_Surface* board = create_surface(320, 640); SDL_Surface* border = load_image("../data/tetborder.png"); draw_surface(321, 0, border, screen, NULL); draw_text(390, 35, screen, "Next tetromino:", 255, 255, 255); draw_text(330, 200, screen, "Score: ", 255, 255, 255); // create menu struct Menu* menu = menu_create(); menu_addelement(menu, "Start Game"); menu_addelement(menu, "Quit"); menu->active_element = &menu->elements[0]; menu->active_element->active = 1; bool running = true; while (running){ if (menu_martet(screen, board, menu, score) == KEYEVENT_EXIT) break; // fill the board with blocks on game over for (i = 0; i < BOARD_HEIGHT; i++) { char* line = get_board_line(i); for (j = 0; j < BOARD_WIDTH; j++) { line[j] = rand() % 7 + '0'; } draw_board(board); draw_surface(0, 0, board, screen, NULL); SDL_Flip(screen); SDL_Delay(50); } manage_hiscores(screen, board, score); board_delete(); } menu_destroy(menu); SDL_FreeSurface(border); SDL_FreeSurface(board); free(score); SDL_Quit(); return 0; }
/** * TBD * * @param widget TBD * @param event TBD * @return TBD */ gint main_wnd_expose( GtkWidget * widget, GdkEventExpose * event ) { static int first = TRUE; if ( first ) { expose_init( ); first = FALSE; } compute_size_elements_board( ); draw_board( widget->window ); return FALSE; } // main_wnd_expose
/* Clear the board and history for a new game */ void new_game(unsigned int size) { tree_view_clear(1); clear_history(0); set_board_size(size); board = NULL; go_to_move(0); board->moves_left = start_q; board->turn = PIECE_BLACK; draw_board(); stop_ai(); setup_move(); }
int board_accept_new_tile(PLAYER *player, short tile_code, const short tile_pos[], const short tile_size[]) { char *board; if (player->status & PLST_FINISHED) return 0; player->status &= ~PLST_DROPPED; player->status |= PLST_NEWTILE; player->released_details = 0; player->bonus = (player->options & PLOP_SHOWNEXT) ? 15 : 20; board = player->board; if (!check_tile_insert(board, tile_pos, tile_size)) { player->status |= PLST_FINISHED; draw_board(PT_FOREGROUND, player, 0); return 0; } memcpy(player->tile_pos, tile_pos, sizeof(short)*Dimension); memcpy(player->tile_size, tile_size, sizeof(short)*Dimension); player->tile_code = tile_code; tile_insert(board, tile_pos, tile_size, tile_code); player->status |= PLST_CHANGED; if (player->options & PLOP_SHOWNEXT) show_next(PT_FOREGROUND, player); update_bonus(PT_FOREGROUND, player->bonus); draw_board(PT_FOREGROUND, player, 0); return 1; }
void test_gets_valid_move() { Board* board = draw_board(); unset_move(board, 1); Player* p1 = create_player('X', &incrementing_move); Player* p2 = create_player('O', &fake_move); start_game(board, p1, p2); destroy_board(board); destroy_player(p1); destroy_player(p2); current_move = 0; assert(strstr(writer_log, "Player 1's turn")); assert(strstr(writer_log, "Invalid move")); assert(strstr(writer_log, "X wins!")); }
void test_handles_win() { Board* board = draw_board(); unset_move(board, 0); Player* p1 = create_player('O', &fake_move); Player* p2 = create_player('X', &fake_move); start_game(board, p1, p2); destroy_board(board); destroy_player(p1); destroy_player(p2); assert(strstr(writer_log, "1 O X O X O O X O")); assert(strstr(writer_log, "Player 1's turn")); assert(strstr(writer_log, "O O X O X O O X O")); assert(strstr(writer_log, "O wins!")); }
void test_switches_turns() { Board* board = draw_board(); unset_move(board, 0); unset_move(board, 1); Player* p1 = create_player('X', &incrementing_move); Player* p2 = create_player('O', &incrementing_move); start_game(board, p1, p2); destroy_board(board); destroy_player(p1); destroy_player(p2); current_move = 0; assert(strstr(writer_log, "Player 1's turn")); assert(strstr(writer_log, "Player 2's turn")); assert(strstr(writer_log, "Draw")); }
void show_bord_player() { draw_board(); for (int j=0;j<=4 ;j++) { for (int k=0 ;k<=4;k++) { if (location[j][k]==1) draw_tiger(j,k); else if(location[j][k]==2) draw_goat(j,k); } } blit(buffer,screen,0,0,0,0,640,480); }
static void tourney_dialog_stop(GtkWidget *button) { int total = tourney_wins[PIECE_BLACK] + tourney_wins[PIECE_WHITE] + tourney_wins[PIECE_NONE]; gtk_widget_hide(tourney_halt); gtk_widget_show(tourney_exec); tournament = 0; if (tourney_wins[PIECE_BLACK] > tourney_wins[PIECE_WHITE]) window_status(va("Black won tournament (%d%% of games won)", tourney_wins[PIECE_BLACK] * 100 / total)); else if (tourney_wins[PIECE_WHITE] > tourney_wins[PIECE_BLACK]) window_status(va("White won tournament (%d%% of games won)", tourney_wins[PIECE_WHITE] * 100 / total)); else window_status("Tournament was a draw"); draw_board(); }
void start_game() { // p==1 then X p==0 then O check_draw(); move_to(getPossibleWinningPos()); draw_board(); if (isWinning(comp)) { gotoxy(30, 20); SetConsoleTextAttribute(h, FOREGROUND_BLUE); printf("Computer wins\n"); SetConsoleTextAttribute(h, 7); //7 - WHITE _getch(); menu(); } else player_turn(); }
void init_board(void) { int i, j; startx = 50, starty = 50, endx=xres() - 50, endy = yres() - 50, scope = 0; maxn = (xres() - 500) / D, maxm = (yres() - 150) / D; if (maxn >= MAXWIDTH) maxn = MAXWIDTH - 1; if (maxm >= MAXHEIGHT) maxm = MAXHEIGHT - 1; //init board to zero for (i = 0; i<= maxn; i++) for (j = 0; j<= maxm; j++) board[j][i] = 0; printf("\033[?25l"); //隐藏光标 system("clear"); background_pic("background.bmp"); draw_board(); printlet((maxn + 2) * D + 50, 2 * D + 100, "NEXT"); print_scope(0); }
JS_EXPORT_API void dominantcolor_draw1(JSValueRef canvas, const char* path, double size, JSData* data) { if (_mask && _board) { cairo_t* cr = fetch_cairo_from_html_canvas(data->ctx, canvas); GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(path, size, size, NULL); if (pixbuf) { double r, g, b; calc_dominant_color_by_path(path, &r, &g, &b, clamp1); cairo_save(cr); cairo_scale(cr, _board_scale, _board_scale); draw_board(cr, _board, _mask, r, g, b); cairo_restore(cr); gdk_cairo_set_source_pixbuf(cr, pixbuf, 4, 4); cairo_paint(cr); g_object_unref(pixbuf); } canvas_custom_draw_did(cr, NULL); } }
/* Loop through 9 turns or until somebody wins. */ void play_game(void) { int turn; for (turn = 1; turn <= 9; turn++) { /* Check if turn is even or odd to determine which player should move. */ if (turn % 2 == 1) { if (computer == 'X') computer_move(); else player_move(); } else { if (computer == 'O') computer_move(); else player_move(); } draw_board(); if (symbol_won(computer)) { printf("\nI WIN!!!\n\n"); return; } else if (symbol_won(user)) { printf("\nCongratulations, you win!\n\n"); return; } } printf("\nThe game is a draw.\n\n"); return; }
/* This is the entry-point for the game! */ void c_start(void) { /* TODO: You will need to initialize various subsystems here. This * would include the interrupt handling mechanism, and the various * systems that use interrupts. Once this is done, you can call * enable_interrupts() to start interrupt handling, and go on to * do whatever else you decide to do! */ seed_rand_with_time(); init_interrupts(); init_keyboard(); init_timer(); enable_interrupts(); int board[BOARD_SIZE][BOARD_SIZE] = { }; animation_descriptor descriptor = { }; initialize(board); int high_score = current_score(board); init_video(high_score); draw_board(board); /* Loop forever, so that we don't fall back into the bootloader code. */ while (1) { if (!isemptyqueue()) { key k = dequeue(); if (k == enter_key) { for (int *b = *board; b < *board + BOARD_SIZE * BOARD_SIZE; b++) *b = 0; initialize(board); init_video(high_score); draw_board(board); continue; } else { shift_direction direction = key_to_direction(k); // Setup animation copy_board(board, descriptor.board); descriptor.direction = direction; // Only add a box if the pieces actually move if (shift(board, direction, descriptor.offsets)) { add_random_box(board); int score = current_score(board); if (score > high_score) high_score = score; init_video(high_score); } } int num_frames = frame_count(descriptor.direction); int incr = get_axis(descriptor.direction) == horizontal_axis ? 12 : 2; int frame = 0; while (frame <= num_frames) { draw_board_frame(descriptor, frame); sleep(30); if (frame == num_frames) break; else frame = min(frame + incr, num_frames); } draw_board(board); if (!move_available(board)) { draw_failure_message(); } } } }
void board_action(int player_no, ACTION action) { PLAYER *player = players[player_no]; player->status &= ~PLST_NEWTILE; switch(action) { case ACT_BACKRIGHT: if (!board_shift_wd(player, 1, -1) && !board_shift_wd(player, 1, 0)) board_shift_wd(player, 0, -1); break; case ACT_BACK: board_shift_wd (player, 0, -1); break; case ACT_BACKLEFT: if (!board_shift_wd (player, -1, -1) && !board_shift_wd(player, -1, 0)) board_shift_wd(player, 0, -1); break; case ACT_LEFT: board_shift_wd (player, -1, 0); break; case ACT_RIGHT: board_shift_wd(player, 1, 0); break; case ACT_FRONTLEFT: if (!board_shift_wd (player, -1, 1) && !board_shift_wd(player, -1, 0)) board_shift_wd(player, 0, 1); break; case ACT_FRONT: board_shift_wd (player, 0, 1); break; case ACT_FRONTRIGHT: if(!board_shift_wd (player, 1, 1) && !board_shift_wd(player, 1, 0)) board_shift_wd(player, 0, 1); break; case ACT_DOWN: board_shift_h (player); break; case ACT_TURNFWD: board_turn (player, 1); break; case ACT_TURNBACK: board_turn (player, -1); break; case ACT_ROTATEFWD: board_rotate (player, 1); break; case ACT_ROTATEBACK: board_rotate (player, -1); break; case ACT_DROP: case ACT_BACKTAB: board_drop (player); break; case ACT_QUIT: player->status |= PLST_FINISHED; player->status |= PLST_QUITTED; break; case ACT_SHOWNEXT: player->options ^= PLOP_SHOWNEXT; show_next(PT_FOREGROUND, player); break; case ACT_REDRAW: player->status |= PLST_DELAY; LastSaveLayer = -1; draw_board(PT_FOREGROUND, player, 0); player->status &= ~PLST_DELAY; if (player->type == 0) { long score = player->score; if (score < 50) score = 0; else score-= 50; draw_score_line(PT_FOREGROUND, SL_SCORE, score); player->score = score; } break; case ACT_LEVEL: if (player_no==0) player->status |= PLST_SKIPLEVEL; break; /* case ACT_TAB: boss_routine(); break; case ACT_PAUSE: pause_game(); break; */ default: ; } }
void open_door(int dir) { int c_x; int y; recenter(true); y = player->y; c_x = player->x + dir * 5; stile(y, c_x - 5, TL_DOOR_OPEN_L); stile(y, c_x + 5, TL_DOOR_OPEN_R); // Remove handle stile(y - 1, c_x - dir, TL_VOID); stile(y - 0, c_x, TL_DOOR_SIDE); stile(y - 1, c_x, TL_DOOR_SIDE); stile(y - 2, c_x, TL_DOOR_SIDE); stile(y - 3, c_x, TL_DOOR_SIDE); stile(y - 0, c_x + dir, TL_DOOR); stile(y - 1, c_x + dir, (dir > 0 ? TL_DOOR_HF : TL_DOOR_HF)); stile(y - 2, c_x + dir, TL_DOOR); stile(y - 3, c_x + dir, TL_DOOR); draw_board(); mpause(); stile(y - 1, c_x, TL_DOOR_SIDE); stile(y - 0, c_x + dir, TL_DOOR_SIDE); stile(y - 1, c_x + dir, TL_DOOR_SIDE); stile(y - 2, c_x + dir, TL_DOOR_SIDE); stile(y - 3, c_x + dir, TL_DOOR_SIDE); stile(y - 0, c_x + dir * 2, TL_DOOR); stile(y - 1, c_x + dir * 2, (dir > 0 ? TL_DOOR_HF : TL_DOOR_HF)); stile(y - 2, c_x + dir * 2, TL_DOOR); stile(y - 3, c_x + dir * 2, TL_DOOR); draw_board(); mpause(); stile(y - 1, c_x + dir, TL_DOOR_SIDE); stile(y - 0, c_x + dir * 2, TL_DOOR_SIDE); stile(y - 1, c_x + dir * 2, TL_DOOR_SIDE); stile(y - 2, c_x + dir * 2, TL_DOOR_SIDE); stile(y - 3, c_x + dir * 2, TL_DOOR_SIDE); stile(y - 0, c_x + dir * 3, TL_DOOR_SIDE); stile(y - 1, c_x + dir * 3, TL_DOOR_HF); stile(y - 2, c_x + dir * 3, TL_DOOR_SIDE); stile(y - 3, c_x + dir * 3, TL_DOOR_SIDE); // Remove door stop so enemies can pass through open doors // The other side has already been overwritten by the open door itself stile(y, c_x - dir * 2, TL_VOID); draw_board(); return; }