void draw_line(t_env *env, t_node *start) { if (start->x != env->param->x_max && start->y != env->param->y_max) { check_lines(env, start, start->next); check_lines(env, start, searchinlist(start, env->param)); } else if (start->x == env->param->x_max && start->y != env->param->y_max) check_lines(env, start, searchinlist(start, env->param)); else if (start->x != env->param->x_max && start->y == env->param->y_max) check_lines(env, start, start->next); }
/* moves down the figure and returns true if gameover */ static void move_down (void) { int l, i, rx, ry; if (!canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co)) { /* save figure to board */ for (i = 0; i < 4; i++) { rx = getRelativeX (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cx; ry = getRelativeY (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cy; rockblox_status.board[ry][rx] = rockblox_status.cf; } /* check if formed some lines */ l = check_lines (); if (l) { /* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */ rockblox_status.score += scoring[l - 1] * rockblox_status.level; rockblox_status.lines += l; rockblox_status.level = (int) rockblox_status.lines / 10 + 1; } /* show details */ show_details (); /* generate a new figure */ new_block (); } else move_block (0, 1, rockblox_status.co); }
void drop_loop(void * tp_void_ptr){ thread_params * tp_ptr = (thread_params *) tp_void_ptr; while(* tp_ptr->running > 0){ if(check_move(*tp_ptr->s, *tp_ptr->b, 0, 1, 0)){ tp_ptr->s->y++; }else{ if(add_to_board(*tp_ptr->s, tp_ptr->b) <= 0){ * tp_ptr->running = -1; break; } int clears = check_lines(tp_ptr->b); if(clears > 0){ mvprintw(40 + DEBUG_CNT++, 0, "Cleared lines %d", clears); } * tp_ptr->lines_cleared = * tp_ptr->lines_cleared + clears; new_shape(tp_ptr->s, tp_ptr->bucket); * tp_ptr->hold_cnt = 0; } //need method of changing this value as levels increase usleep(* tp_ptr->drop_speed); //100ms } }
void Field::save_piece() { if(_piece){ unsigned int coordinates[8]; _piece->get_coordinates(coordinates); for(int i = 0; i < 4; i++){ _colors[coordinates[2*i]][coordinates[2*i+1]].set_color(_piece->get_color()); } } check_lines(); }
static int move(int dir) { switch(dir) { case LEFT: col--; break; case RIGHT: col++; break; case DOWN: row++; break; case ROTATE: rot = (rot+1)%4; break; } int rc = check_move(); if(rc == 1) { switch(dir) { case LEFT: col++; break; case RIGHT: col--; break; case DOWN: row--; break; case ROTATE: rot = rot == 0 ? 3 : rot-1; break; } if(dir == DOWN) { cement_block(); trigger_event("BlockHit", NULL); int lines = check_lines(); if(lines) calc_score(lines); new_block(); } } else { trigger_event("MoveSucceeded", (void*)dir); } return rc; }
int check_win(t_gboard *p4, int player) { if (check_lines(p4, player) == 1 || check_columns(p4, player) == 1 || check_left(p4, player, 4) == 1 || check_right(p4, player, 4) == 1) { if (player != p4->ia_id) { ft_putendl("Congratulation human... you win."); ft_putendl(" .... This time !!!"); } return (1); } return (0); }
/*! * @brief 着地後のブロックを固定する * * また、横一列がそろってるかの判定をする。 * @see check_lines() */ static void lock_block(void) { uint i; /* ブロックを壁に加える */ for (i = 0; i < STAGE_HEIGHT; i++) { uint j; for (j = 0; j < STAGE_WIDTH; j++) { stage[i][j] = field[i][j]; } } check_lines(); /* 横一列がそろってるか判定して処理する */ /* 列完成判定後の壁をフィールドへ */ for (i = 0; i < STAGE_HEIGHT; i++) { uint j; for (j = 0; j < STAGE_WIDTH; j++) { field[i][j] = stage[i][j]; } } }
static void check_on_text_changed(GeanyDocument *doc, gint position, gint lines_added) { gint line_number; gint line_count; /* Iterating over all lines which changed as indicated by lines_added. lines_added is 0 * if only a lines has changed, in this case set it to 1. Otherwise, iterating over all * new lines makes spell checking work for pasted text. */ line_count = MAX(1, lines_added); line_number = sci_get_line_from_position(doc->editor->sci, position); /* TODO: storing these information in the global check_line_data struct isn't that good. * The data gets overwritten when a new line is inserted and so there is a chance that thep * previous line is not checked to the end. One solution could be to simple maintain a list * of line numbers which needs to be checked and do this is the timeout handler. */ check_line_data.doc = doc; check_line_data.line_number = line_number; check_line_data.line_count = line_count; /* check only once in a while */ if (! need_delay()) check_lines(NULL); }
char *get_musiclist(char ***plist) { FILE *fp =NULL; char *buf = NULL; ulint list_length = 0; uint lines = 0; int part = 0; system("ls ./music | grep .mp3 >./music/musiclist"); fp = fopen("music/musiclist","rb"); if(fp == NULL) { printf("Cannot open the flie!\n"); return; } buf = read_src_file(&list_length,"music/musiclist"); lines = check_lines(list_length, buf); *plist = (char **)malloc((lines + 1) * sizeof(char **)); //动态分配空间存储每行的首地址 if(*plist == NULL) return NULL; part = src_segment(buf, *plist, "\r\n"); //按行分割 plist[lines] = NULL; #if 1 int i, len; for(i=0;i<part-1;i++) { len = strlen(*(*(plist) + i)); *(*(*(plist) + i) + len -4) = '\0'; //printf("%s\n",plist[i]); } #endif return buf; }
int main(int argc, char *argv[]) { /*checkCaps will keep track of whether -i was chosen*/ int checkCaps = 0; /*printLines will keep track of whether -n was chosen*/ int printLines = 0; if (argc < 2 || argc > 5) { fprintf(stderr, "%s\n", "Usage: gasp [OPTIONS] [STRING] [FILENAME]"); return 1; } for (int i = 0; i < argc; i++) { if (strcmp(argv[i], "-i") == 0) { checkCaps = 1; } if (strcmp(argv[i], "-n") == 0) { printLines = 1; } } char *filename = argv[argc-1]; char *searchString = argv[argc-2]; if (sizeof(searchString) >= MAX_WORD_LENGTH) { fprintf(stderr, "%s\n", "STRING needs to be less than 100 characters"); return 2; } FILE *file = fopen(filename, "r"); if (file != NULL) { check_lines(file, checkCaps, printLines, searchString, filename); return 0; } else { fprintf(stderr, "%s %s\n", argv[argc-1], "not found"); return 2; } return 0; }
// Map::open: Opens a map from an open wadfile // ---------------------------------------- >> bool Map::open(Wad *wad, string mapname) { Lump* lump = NULL; long offset = wad->get_lump_index(mapname); FILE* fp = fopen(wad->path.c_str(), "rb"); long unit_size = 0; //long unit_count = 0; if (offset == -1) { printf("Map %s not found\n", mapname.c_str()); return false; } // Check for BEHAVIOR lump //if (hexen) { long index = offset; bool done = false; while (!done) { index++; if (index == wad->num_lumps) { index--; done = true; } else if (!strncmp(wad->directory[index]->Name().c_str(), "THINGS", 6) || !strncmp(wad->directory[index]->Name().c_str(), "LINEDEFS", 8) || !strncmp(wad->directory[index]->Name().c_str(), "SIDEDEFS", 8) || !strncmp(wad->directory[index]->Name().c_str(), "VERTEXES", 8) || !strncmp(wad->directory[index]->Name().c_str(), "SEGS", 4) || !strncmp(wad->directory[index]->Name().c_str(), "SSECTORS", 8) || !strncmp(wad->directory[index]->Name().c_str(), "NODES", 5) || !strncmp(wad->directory[index]->Name().c_str(), "SECTORS", 7) || !strncmp(wad->directory[index]->Name().c_str(), "REJECT", 6) || !strncmp(wad->directory[index]->Name().c_str(), "SCRIPTS", 7) || !strncmp(wad->directory[index]->Name().c_str(), "BLOCKMAP", 8)) { done = false; } else if (strncmp(wad->directory[index]->Name().c_str(), "BEHAVIOR", 8) == 0) { if (hexen) done = true; else { message_box("This looks like a hexen-format map, please select a different game configuration!", GTK_MESSAGE_INFO); return false; } } else done = true; } if (strncmp(wad->directory[index]->Name().c_str(), "BEHAVIOR", 8) != 0 && hexen) { message_box("Map has no BEHAVIOR lump\n", GTK_MESSAGE_ERROR); return false; } } if (scripts) { delete scripts; scripts = NULL; } if (behavior) { delete behavior; behavior = NULL; } name = mapname; // << ---- Read Vertices ---- >> splash("Loading Vertices"); lump = wad->get_lump("VERTEXES", offset); if (!lump) { printf("Map has no VERTEXES lump\n"); splash_hide(); return false; } // Seek to lump fseek(fp, lump->Offset(), SEEK_SET); // Setup vertices array unit_size = 4; n_verts = lump->Size() / unit_size; verts = (vertex_t **)calloc(n_verts, sizeof(vertex_t *)); // Read vertex data for (DWORD i = 0; i < n_verts; i++) { verts[i] = new vertex_t; fread(&verts[i]->x, 2, 1, fp); fread(&verts[i]->y, 2, 1, fp); } // << ---- Read sides ---- >> splash("Loading Sides"); lump = wad->get_lump("SIDEDEFS", offset); if (!lump) { printf("Map has no SIDEDEFS lump\n"); splash_hide(); return false; } // Seek to lump fseek(fp, lump->Offset(), SEEK_SET); // Setup sides array unit_size = 30; n_sides = lump->Size() / unit_size; sides = (sidedef_t **)calloc(n_sides, sizeof(sidedef_t *)); // Read side data for (DWORD i = 0; i < n_sides; i++) { sides[i] = new sidedef_t; char temp[9] = ""; fread(&sides[i]->x_offset, 2, 1, fp); fread(&sides[i]->y_offset, 2, 1, fp); fread(temp, 1, 8, fp); temp[8] = 0; sides[i]->tex_upper = g_ascii_strup(temp, -1); fread(temp, 1, 8, fp); temp[8] = 0; sides[i]->tex_lower = g_ascii_strup(temp, -1); fread(temp, 1, 8, fp); temp[8] = 0; sides[i]->tex_middle = g_ascii_strup(temp, -1); fread(&sides[i]->sector, 2, 1, fp); } // << ---- Read Lines ---- >> splash("Loading Lines"); int max_vert = 0; lump = wad->get_lump("LINEDEFS", offset); if (!lump) { printf("Map has no LINEDEFS lump\n"); splash_hide(); return false; } // Seek to lump fseek(fp, lump->Offset(), SEEK_SET); if (hexen) { // Setup & read hexen format lines // Setup lines array unit_size = 16; n_lines = lump->Size() / unit_size; lines = (linedef_t **)calloc(n_lines, sizeof(linedef_t *)); // Read line data for (DWORD i = 0; i < n_lines; i++) { BYTE temp = 0; lines[i] = new linedef_t; fread(&lines[i]->vertex1, 2, 1, fp); fread(&lines[i]->vertex2, 2, 1, fp); fread(&lines[i]->flags, 2, 1, fp); fread(&temp, 1, 1, fp); lines[i]->type = temp; fread(lines[i]->args, 1, 5, fp); short s1, s2; fread(&s1, 2, 1, fp); fread(&s2, 2, 1, fp); lines[i]->side1 = (int)s1; lines[i]->side2 = (int)s2; if (n_sides > 32767) { unsigned short us1 = static_cast<unsigned short>(s1); unsigned short us2 = static_cast<unsigned short>(s2); if (s1 != -1) lines[i]->side1 = us1; if (s2 != -1) lines[i]->side2 = us2; } if (lines[i]->vertex1 > max_vert) max_vert = lines[i]->vertex1; if (lines[i]->vertex2 > max_vert) max_vert = lines[i]->vertex2; } } else { // Setup lines array unit_size = 14; n_lines = lump->Size() / unit_size; lines = (linedef_t **)calloc(n_lines, sizeof(linedef_t *)); // Read line data for (DWORD i = 0; i < n_lines; i++) { lines[i] = new linedef_t; fread(&lines[i]->vertex1, 2, 1, fp); fread(&lines[i]->vertex2, 2, 1, fp); fread(&lines[i]->flags, 2, 1, fp); fread(&lines[i]->type, 2, 1, fp); fread(&lines[i]->sector_tag, 2, 1, fp); short s1, s2; fread(&s1, 2, 1, fp); fread(&s2, 2, 1, fp); lines[i]->side1 = (int)s1; lines[i]->side2 = (int)s2; if (n_sides > 32767) { unsigned short us1 = static_cast<unsigned short>(s1); unsigned short us2 = static_cast<unsigned short>(s2); if (s1 != -1) lines[i]->side1 = us1; if (s2 != -1) lines[i]->side2 = us2; } if (lines[i]->vertex1 > max_vert) max_vert = lines[i]->vertex1; if (lines[i]->vertex2 > max_vert) max_vert = lines[i]->vertex2; } } n_verts = max_vert + 1; // << ---- Read sectors ---- >> splash("Loading Sectors"); lump = wad->get_lump("SECTORS", offset); if (!lump) { printf("Map has no SECTORS lump\n"); splash_hide(); return false; } // Seek to lump fseek(fp, lump->Offset(), SEEK_SET); // Setup sides array unit_size = 26; n_sectors = lump->Size() / unit_size; sectors = (sector_t **)calloc(n_sectors, sizeof(sector_t *)); // Read sector data for (DWORD i = 0; i < n_sectors; i++) { sectors[i] = new sector_t; char temp[9] = ""; fread(§ors[i]->f_height, 2, 1, fp); fread(§ors[i]->c_height, 2, 1, fp); fread(temp, 1, 8, fp); temp[8] = 0; sectors[i]->f_tex = g_ascii_strup(temp, -1); fread(temp, 1, 8, fp); temp[8] = 0; sectors[i]->c_tex = g_ascii_strup(temp, -1); fread(§ors[i]->light, 2, 1, fp); fread(§ors[i]->special, 2, 1, fp); fread(§ors[i]->tag, 2, 1, fp); //sectors[i]->hilighted = false; //sectors[i]->selected = false; //sectors[i]->moving = false; } // << ---- Read Things ---- >> splash("Loading Things"); lump = wad->get_lump("THINGS", offset); if (!lump) { printf("Map has no THINGS lump\n"); splash_hide(); return false; } // Seek to lump fseek(fp, lump->Offset(), SEEK_SET); if (hexen) { // Setup & read hexen format things // Setup things array unit_size = 20; n_things = lump->Size() / unit_size; things = (thing_t **)calloc(n_things, sizeof(thing_t *)); // Read thing data for (DWORD i = 0; i < n_things; i++) { things[i] = new thing_t; fread(&things[i]->tid, 2, 1, fp); fread(&things[i]->x, 2, 1, fp); fread(&things[i]->y, 2, 1, fp); fread(&things[i]->z, 2, 1, fp); fread(&things[i]->angle, 2, 1, fp); fread(&things[i]->type, 2, 1, fp); fread(&things[i]->flags, 2, 1, fp); fread(&things[i]->special, 1, 1, fp); fread(things[i]->args, 1, 5, fp); } } else { // Setup things array unit_size = 10; n_things = lump->Size() / unit_size; things = (thing_t **)calloc(n_things, sizeof(thing_t *)); // Read thing data for (DWORD i = 0; i < n_things; i++) { things[i] = new thing_t; fread(&things[i]->x, 2, 1, fp); fread(&things[i]->y, 2, 1, fp); fread(&things[i]->angle, 2, 1, fp); fread(&things[i]->type, 2, 1, fp); fread(&things[i]->flags, 2, 1, fp); } } // << ---- Read Scripts/Behavior ---- >> if (hexen) { lump = wad->get_lump("SCRIPTS", offset); if (lump) { fseek(fp, lump->Offset(), SEEK_SET); scripts = new Lump(0, lump->Size(), "SCRIPTS"); fread(scripts->Data(), lump->Size(), 1, fp); } else scripts = new Lump(0, 0, "SCRIPTS"); lump = wad->get_lump("BEHAVIOR", offset); if (lump) { fseek(fp, lump->Offset(), SEEK_SET); behavior = new Lump(0, lump->Size(), "BEHAVIOR"); fread(behavior->Data(), lump->Size(), 1, fp); } else behavior = new Lump(0, 0, "BEHAVIOR"); } splash("Removing Unused Vertices"); remove_free_verts(); splash("Checking Lines"); if (check_lines()) popup_console(); splash("Checking Sides"); if (check_sides()) popup_console(); // Set thing colours/radii/angle splash("Init Thing Data"); for (int a = 0; a < n_things; a++) things[a]->ttype = get_thing_type(things[a]->type); init_map(); opened = true; splash_hide(); return true; }
int start_game(){ char board[ BOARD_HEIGHT ][ BOARD_WIDTH ]; char mtx_brick[4][4]; int score = 0; int level = 0; int lines = 0; int tmp_lines = 0; char x, y; char brick; char next_brick; int vel = 10; timespec req; req.tv_sec = 0; req.tv_nsec = vel * PULSE; srand( time( 0 ) ); memset( board, 0, BOARD_HEIGHT * BOARD_WIDTH ); next_brick = rand() % 7 + 1; init_screen(); WINDOW* wboard = create_wboard(); WINDOW* wpreview = create_wpreview(); WINDOW* wscore = create_wscore(); show_title(); show_score( wscore, score, level, lines ); wait_start( wboard ); bool play = true; while( play ){ brick = next_brick; next_brick = rand() % 7 + 1; show_preview( wpreview, next_brick ); show_score( wscore, score, level, lines ); show_board( wboard, board ); x = ( ( BOARD_WIDTH / 3 ) % 2 == 0 ) ? BOARD_WIDTH / 3 : BOARD_WIDTH / 3 + 1; y = - 3; get_brick( brick, mtx_brick ); bool move = true; int delay = 0; while( move ){ switch( getch() ){ case KEY_UP: move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break; case 'z': move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break; case 'x': move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_L ); break; case KEY_DOWN: move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN ); break; case KEY_LEFT: move_brick( wboard, board, mtx_brick, brick, &y, &x, LEFT ); break; case KEY_RIGHT: move_brick( wboard, board, mtx_brick, brick, &y, &x, RIGHT ); break; case ' ': move_brick( wboard, board, mtx_brick, brick, &y, &x, BOTTOM ); break; case 27: play = move = false; break; case 'q': play = move = false; break; default: break; } // switch( getch() ) if( ++delay == DELAY_DOWN ){ move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN ); } if( delay == DELAY_BOTTOM ){ delay = 0; if( check_brick(mtx_brick, board, y + 1, x ) ){ move = false; if( y < 0 ) play = false; } } nanosleep( &req, 0 ); } // while( move ) set_board( board, mtx_brick, brick, y, x ); tmp_lines += check_lines( board, &score, &lines ); if( tmp_lines >= CH_LEV ){ req.tv_nsec = vel * PULSE; score += 1; level++; if( vel > 1 ) vel--; tmp_lines = tmp_lines % CH_LEV; } } // while( quit ) delwin( wboard ); delwin( wpreview ); delwin( wscore ); restore_screen(); return 0; }
/* Glues the tetrimino to the playfield. Also, it sets some stuff and does basic game checks. */ void glue() { u32 posx = in_play->posx; u32 posy = in_play->posy; u8 type = in_play->type; u8 rotation = in_play->rotation; if(!cfg.ARS) //SRS { if(type != I_TYPE) for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j) { if(posx + i >= 0 && posy+j <= DIM_Y && posx + i < DIM_X) level_grid[posx+i][posy+j] |= rotations[type][rotation][j][i]; } else for(int i = 0; i < 5; ++i) for(int j = 0; j < 5; ++j) { if(posx + i >= 0 && posy+j <= DIM_Y && posx + i < DIM_X) level_grid[posx+i][posy+j] |= rotation_I[rotation][j][i]; } } else //ARS { if(type != I_TYPE) for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j) { if(posx + i >= 0 && posy+j <= DIM_Y && posx + i < DIM_X) level_grid[posx+i][posy+j] |= ARS_rotations[type][rotation][j][i]; } else for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) { if(posx + i >= 0 && posy+j <= DIM_Y && posx + i < DIM_X) level_grid[posx+i][posy+j] |= ARS_rotation_I[rotation][j][i]; } } ticks_before_glue = 0; last_deployed = in_play; u32 lines = check_lines(); total_lines += lines; u32 score_to_add = 0; back_to_back_flag_old = back_to_back_flag; switch(lines) //todo - maybe add graphical effects for T-spins { case 0: //no lines? try to deploy a new one if(!cfg.ARS && in_play->type == T_TYPE && last_T_rotation && T_corners_occupied() >= 3) { score_to_add = level * last_T_kick ? 100 : 400; indicator = TSPIN; back_to_back_flag = 0; } deploy_next(false); return; break; case 1: if(!cfg.ARS && in_play->type == T_TYPE && last_T_rotation && T_corners_occupied() >= 3) { score_to_add = level * last_T_kick ? 200 : 800; back_to_back_flag = 1; indicator = TSPINSINGLE; } else { score_to_add = level * 100; back_to_back_flag = 0; } break; case 2: if(!cfg.ARS && in_play->type == T_TYPE && last_T_rotation && T_corners_occupied() >= 3) { score_to_add = level * 1200; back_to_back_flag = 1; indicator = TSPINDOUBLE; } else { score_to_add = level * 300; back_to_back_flag = 0; } break; case 3: if(!cfg.ARS && in_play->type == T_TYPE && last_T_rotation && T_corners_occupied() >= 3) { score_to_add = level * 1600; back_to_back_flag = 1; indicator = TSPINTRIPLE; } else { score_to_add = level * 500; back_to_back_flag = 0; } break; case 4: score_to_add = level * 800; back_to_back_flag = 1; indicator = TETRIS; break; } if(back_to_back_flag_old && back_to_back_flag) { score_to_add *= 3; score_to_add >>= 1; }