• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ rand_range函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rand_range函数的典型用法代码示例。如果您正苦于以下问题:C++ rand_range函数的具体用法?C++ rand_range怎么用?C++ rand_range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rand_range函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: rand_range

npc::npc(dungeon_t *d, const monster_description &m)
{
  pair_t p;
  uint32_t room;

  symbol = m.symbol;
  color = m.color;
  room = rand_range(1, d->num_rooms - 1);
  do {
    p[dim_y] = rand_range(d->rooms[room].position[dim_y],
                          (d->rooms[room].position[dim_y] +
                           d->rooms[room].size[dim_y] - 1));
    p[dim_x] = rand_range(d->rooms[room].position[dim_x],
                          (d->rooms[room].position[dim_x] +
                           d->rooms[room].size[dim_x] - 1));
  } while (d->charmap[p[dim_y]][p[dim_x]]);
  pc_last_known_position[dim_y] = p[dim_y];
  pc_last_known_position[dim_x] = p[dim_x];
  position[dim_y] = p[dim_y];
  position[dim_x] = p[dim_x];
  d->charmap[p[dim_y]][p[dim_x]] = this;
  speed = m.speed.roll();
  hp = m.hitpoints.roll();
  damage = &m.damage;
  bounty = (hp + damage->roll()) / 10; //Bounty
  level = m.level;
  next_turn = d->the_pc->next_turn;
  alive = 1;
  sequence_number = ++d->character_sequence_number;
  characteristics = m.abilities;
  have_seen_pc = 0;
  name = m.name.c_str();
  description = (const char *) m.description.c_str();
}
开发者ID:NotGoodAtCoding,项目名称:CS327,代码行数:34,代码来源:npc.cpp


示例2: tm_rect_generate_overlapping

void tm_rect_generate_overlapping( tm_rect_t* r, tm_rect_t* overlap_r, tm_vect_t* sz, vect_t* map_sz )
{
	tm_vect_t* unit = tm_vect_create(1, 1);
	tm_rect_t aux_r;

	tm_vect_substract( &overlap_r->v1, sz, &aux_r.v1 );
	tm_vect_add( &aux_r.v1, unit, &aux_r.v1 );
	if( (int) aux_r.v1.x < 0 )
		aux_r.v1.x = 0;
	if( (int) aux_r.v1.y < 0 )
		aux_r.v1.y = 0;

	tm_vect_substract( &overlap_r->v2, unit, &aux_r.v2 );
	tm_vect_add( &aux_r.v2, sz, &aux_r.v2 );
	if( (int) aux_r.v2.x > map_sz->x )
		aux_r.v2.x = map_sz->x;
	if( (int) aux_r.v2.y > map_sz->y )
		aux_r.v2.y = map_sz->y;

	assert( rect_is_valid(&aux_r) );

	tm_vect_init( &r->v1, rand_range((int)aux_r.v1.x, (int)aux_r.v2.x), rand_range((int)aux_r.v1.y, (int)aux_r.v2.y) );
	tm_vect_add( &r->v1, sz, &r->v2 );

	tm_vect_destroy( unit );
}
开发者ID:mikedw,项目名称:synquake_tsx,代码行数:26,代码来源:tm_geometry.c


示例3: mon_create_drop_count

/**
 * Return the number of things dropped by a monster.
 *
 * \param race is the monster race.
 * \param maximize should be set to false for a random number, true to find
 * out the maximum count.
 */
int mon_create_drop_count(const struct monster_race *race, bool maximize)
{
	int number = 0;
	static const int drop_4_max = 6;
	static const int drop_3_max = 4;
	static const int drop_2_max = 3;

	if (maximize) {
		if (rf_has(race->flags, RF_DROP_20)) number++;
		if (rf_has(race->flags, RF_DROP_40)) number++;
		if (rf_has(race->flags, RF_DROP_60)) number++;
		if (rf_has(race->flags, RF_DROP_4)) number += drop_4_max;
		if (rf_has(race->flags, RF_DROP_3)) number += drop_3_max;
		if (rf_has(race->flags, RF_DROP_2)) number += drop_2_max;
		if (rf_has(race->flags, RF_DROP_1)) number++;
	} else {
		if (rf_has(race->flags, RF_DROP_20) && randint0(100) < 20) number++;
		if (rf_has(race->flags, RF_DROP_40) && randint0(100) < 40) number++;
		if (rf_has(race->flags, RF_DROP_60) && randint0(100) < 60) number++;
		if (rf_has(race->flags, RF_DROP_4)) number += rand_range(2, drop_4_max);
		if (rf_has(race->flags, RF_DROP_3)) number += rand_range(2, drop_3_max);
		if (rf_has(race->flags, RF_DROP_2)) number += rand_range(1, drop_2_max);
		if (rf_has(race->flags, RF_DROP_1)) number++;
	}

	return number;
}
开发者ID:datatypevoid,项目名称:angband,代码行数:34,代码来源:mon-make.c


示例4: main

int main(int argc, char** argv) {
  lightDirection.normalize();

  srand((unsigned) time(NULL));

  // 球体をランダムに配置
  for(int i = 0; i < sphere_n; i++) {
    double r = rand_range(50,200);
    Vector3d center(rand_range(-500,500), r, rand_range(-1000,0));
    //Vector3d color = HSVtoRGB( (360.0/sphere_n)*i, 255, 255);
    Vector3d color = HSVtoRGB( rand_range(0,360), 255, 255);
    sphere[i] = Sphere(center, r, color);
  }

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(600,600);
  glutInitWindowPosition(180,10);
  glutCreateWindow(argv[0]);
  glClearColor(1.0, 1.0, 1.0, 1.0);
  glShadeModel(GL_FLAT);

  glutDisplayFunc(display);
  glutReshapeFunc(resizeWindow);
  glutKeyboardFunc(keyboard);
  glutMainLoop();

  return 0;
}
开发者ID:gam0022,项目名称:computer-graphics,代码行数:29,代码来源:q9_5.cpp


示例5: make_map

static void
make_map(void) {
    int w = WIDTH;
    int h = HEIGHT;
    float deviance;

    //Reset the whole heightmap to the minimum height
    for (int e = 0; e < HEIGHT; ++e)
        for (int i = 0; i < WIDTH; ++i)
            heightmap[i][e] = MINHEIGHT;

    //Add our starting corner points
    heightmap[0][0] = rand_range(-RANGE_CHANGE, RANGE_CHANGE);
    heightmap[0][HEIGHT] = rand_range(-RANGE_CHANGE, RANGE_CHANGE);

    deviance = 1.0;
    while (1) {
        draw_all_squares(w, h, deviance);
        draw_all_diamonds(w, h, deviance);

        w /= 2;
        h /= 2;

        if (w < 2 && h < 2)
            break;

        if (w < 2)
            w = 2;
        if (h < 2)
            h = 2;
        deviance *= REDUCTION;
    }
}
开发者ID:0xAether,项目名称:Fractal-Terrain-Test,代码行数:33,代码来源:frac.c


示例6: pred_mutate

/**
 * Genome mutation function
 *
 * Recalculates phenotype if necessary
 *
 * @param  genes
 * @return
 */
void pred_mutate(pred_genome_t genome)
{
    int max_changed_genes = _metadata->mutation_rate * _metadata->genotype_length;
    int genes_to_change = rand_range(0, max_changed_genes);

    for (int i = 0; i < genes_to_change; i++) {
        // choose mutated gene
        int gene = rand_range(0, _metadata->genotype_length - 1);
        pred_gene_t old_value = genome->_genes[gene];

        // generate new value
        pred_gene_t value = rand_urange(0, _metadata->max_gene_value);
        if (_metadata->genome_type == permuted) {
            // either unused or same value is valid, so make corrections
            while(genome->_used_values[value] && old_value != value) {
                value = (value + 1) % (_metadata->max_gene_value + 1);
            };
        }

        // rewrite gene
        genome->_genes[gene] = value;
        genome->_used_values[value] = true;
    }

    pred_calculate_phenotype(genome);
}
开发者ID:xurban46,项目名称:bc,代码行数:34,代码来源:predictors.c


示例7: io_teleport_pc

uint32_t io_teleport_pc(dungeon_t *d)
{
  /* Just for fun. */
  pair_t dest;

  do {
    dest[dim_x] = rand_range(1, DUNGEON_X - 2);
    dest[dim_y] = rand_range(1, DUNGEON_Y - 2);
  } while (charpair(dest));

  d->charmap[character_get_y(d->pc)][character_get_x(d->pc)] = NULL;
  d->charmap[dest[dim_y]][dest[dim_x]] = d->pc;

  character_set_y(d->pc, dest[dim_y]);
  character_set_x(d->pc, dest[dim_x]);

  if (mappair(dest) < ter_floor) {
    mappair(dest) = ter_floor;
  }

  pc_observe_terrain(d->pc, d);

  dijkstra(d);
  dijkstra_tunnel(d);

  return 0;
}
开发者ID:NotGoodAtCoding,项目名称:CS327,代码行数:27,代码来源:io.cpp


示例8: prepare_sprite

// converts a dead person in black particles
void Person::burn()
{
  GamePlay *gameplay = GAMEPLAY;
  BITMAP *sprite = prepare_sprite();
  int x, y, u, v;

  gameplay->get_level()->to_screen(m_pos, x, y);

  x = x-TILE_W/2;
  y = y-TILE_H+1;

  for (v=0; v<sprite->h; ++v)
    for (u=0; u<sprite->w; ++u) {
      int color, ou;

      if (m_right)
	color = getpixel(sprite, ou=u, v);
      else
	color = getpixel(sprite, ou=sprite->w-1-u, v);

      if (color != bitmap_mask_color(sprite))
	gameplay->add_particle
	  (new PixelParticle(vector2d((m_pos.x*TILE_W - TILE_W/2 + ou) / TILE_W,
				      (m_pos.y*TILE_H - TILE_H+1 + v) / TILE_H),
			     vector2d(0, rand_range(-2.0, -0.1)),
			     vector2d(rand_range(0.5, 4.0), 0),
			     rand_range(BPS/4, BPS*3/4),
			     makecol(0, 0, 0),
			     makecol(0, 0, 0)));

    }
}
开发者ID:dacap,项目名称:defenderofnothing,代码行数:33,代码来源:person.cpp


示例9: while

    void Snake::setAppleLocation() {
        if (!needFood)
            return;
        int x;
        int y;

        while(true){

            x = rand_range(10, wW - 10);
            if (x % 10 != 0)
                x -= (x % 10);

            y = rand_range(windowOffset, wH - 10);
            if (y % 10 != 0)
                y -= (y % 10);

            bool allowed = true;
            for (std::list<Location>::const_iterator it = locations.begin(), end = locations.end(); it != end; ++it) {
                if ((*it).x == x && (*it).y == y){
                    allowed = false;
                    break;
                }
            }
            if (allowed)
                break;
        }


        foodLocation.x = x;
        foodLocation.y = y;
        needFood = false;

    }
开发者ID:taganaka,项目名称:snake,代码行数:33,代码来源:snake.cpp


示例10: generate_world

void generate_world(World* world, Tile_Info* info, isize ti_count, uint64 seed, Memory_Arena* arena)
{
	Random r_s;
	Random* r = &r_s;
	init_random(r, seed);


	for(isize i = 0; i < world->areas_height; ++i) {
		for(isize j = 0; j < world->areas_width; ++j) {
			isize index = i * world->areas_width + j;
			World_Area* area = world->areas + index;
			init_world_area(area, arena);
			area->map.info = info;
			area->map.info_count = ti_count;
			generate_tilemap(&area->map, next_random_uint64(r));
			for(isize i = 0; i < World_Area_Tilemap_Width; ++i) {
				Entity* e = world_area_get_next_entity(area);
				Sim_Body* b = sim_find_body(&area->sim, e->body_id);
				e->sprite.texture = Get_Texture_Coordinates(0, 96, 32, 64);
				b->shape.hw = 16;
				b->shape.hh = 12;
				b->inv_mass = 1.0f;
				e->sprite.size = v2(32, 64);
				e->sprite.center = v2(0, 20);
				entity_add_event_on_activate(e, test_on_activate);
				do {
					b->shape.center = v2(
						rand_range(r, 0, area->map.w * 32),
						rand_range(r, 0, area->map.h * 32));
				}
				while (info[tilemap_get_at(&area->map, b->shape.center)].solid);
			}

			generate_statics_for_tilemap(&area->sim, &area->map);

			isize north_link = modulus(i - 1, world->areas_height) * world->areas_width + j;
			isize south_link = modulus(i + 1, world->areas_height) * world->areas_width + j;
			isize west_link = i * world->areas_width + modulus(j - 1, world->areas_width);
			isize east_link = i * world->areas_width + modulus(j + 1, world->areas_width);
			area->north = Area_Link {
				v2i(World_Area_Tilemap_Width / 2,  World_Area_Tilemap_Height - 1), 
				world->areas + north_link
			};
			area->south = Area_Link {
				v2i(World_Area_Tilemap_Width / 2, 1),
				world->areas + south_link
			};
			area->west = Area_Link {
				v2i(World_Area_Tilemap_Width - 1, World_Area_Tilemap_Height / 2),
				world->areas + west_link
			};
			area->east = Area_Link {
				v2i(1, World_Area_Tilemap_Height / 2),
				world->areas + east_link
			};
		}
	}

}
开发者ID:CHMyFork,项目名称:rituals-game,代码行数:59,代码来源:rituals_world.cpp


示例11: paintLight

void paintLight(lightSource *theLight, short x, short y, boolean isMinersLight) {
	short i, j, k;
	short colorComponents[3], randComponent, lightMultiplier, thisComponent;
	short fadeToPercent;
	float radius;
	char grid[DCOLS][DROWS];
	boolean dispelShadows;
	
#ifdef BROGUE_ASSERTS
	assert(rogue.RNG == RNG_SUBSTANTIVE);
#endif
	
	radius = randClump(theLight->lightRadius);
	radius /= 100;
	
	randComponent = rand_range(0, theLight->lightColor->rand);
	colorComponents[0] = randComponent + theLight->lightColor->red + rand_range(0, theLight->lightColor->redRand);
	colorComponents[1] = randComponent + theLight->lightColor->green + rand_range(0, theLight->lightColor->greenRand);
	colorComponents[2] = randComponent + theLight->lightColor->blue + rand_range(0, theLight->lightColor->blueRand);
	
	// the miner's light does not dispel IS_IN_SHADOW,
	// so the player can be in shadow despite casting his own light.
	dispelShadows = !isMinersLight && colorComponents[0] + colorComponents[1] + colorComponents[2] > 0;
	
	fadeToPercent = theLight->radialFadeToPercent;
	
	// zero out only the relevant rectangle of the grid
	for (i = max(0, x - radius); i < DCOLS && i < x + radius; i++) {
		for (j = max(0, y - radius); j < DROWS && j < y + radius; j++) {
			grid[i][j] = 0;
		}
	}
	
	getFOVMask(grid, x, y, radius, T_OBSTRUCTS_VISION, (theLight->passThroughCreatures ? 0 : (HAS_MONSTER | HAS_PLAYER)),
			   (!isMinersLight));
	
	for (i = max(0, x - radius); i < DCOLS && i < x + radius; i++) {
		for (j = max(0, y - radius); j < DROWS && j < y + radius; j++) {
			if (grid[i][j]) {
				lightMultiplier = 100 - (100 - fadeToPercent) * (sqrt((i-x) * (i-x) + (j-y) * (j-y)) / (radius));
				for (k=0; k<3; k++) {
						thisComponent = colorComponents[k] * lightMultiplier / 100;
						tmap[i][j].light[k] += thisComponent;
				}
				if (dispelShadows) {
					pmap[i][j].flags &= ~IS_IN_SHADOW;
				}
			}
		}
	}
	
	tmap[x][y].light[0] += colorComponents[0];
	tmap[x][y].light[1] += colorComponents[1];
	tmap[x][y].light[2] += colorComponents[2];
	
	if (dispelShadows) {
		pmap[x][y].flags &= ~IS_IN_SHADOW;
	}
}
开发者ID:alunbestor,项目名称:Brogue,代码行数:59,代码来源:Light.c


示例12: lerp

void PE_Torpedo_Explosion::emit_single_particle(Particle& p)
{
  p.cur_pos = lerp(RAND_0_1,m_p1,m_p2) + vec2(RAND_0_1 * 0.002f, RAND_0_1 * 0.002f);
	p.cur_speed = normalized(vec2(RAND_1_1,RAND_1_1))*rand_range(0.01,0.1);
	p.cur_size = 0.0;
  float col = rand_range(0.0,0.1);
	p.cur_color = vec4(col,col,col,1);
}
开发者ID:basman,项目名称:Sea-Defender,代码行数:8,代码来源:pe_torpedo_expl.cpp


示例13: main

int main()
{
  char keyboard_input[100];
  XColor black_col,white_col,red_col,green_col,blue_col,yellow_col,magenta_col,cyan_col;
  Colormap colormap;
  char black_bits[] = "#000000";
  char white_bits[] = "#FFFFFF";    // Mix red, green and blue to get white
  char red_bits[] = "#FF0000";
  char green_bits[] = "#00FF00";
  char blue_bits[] = "#0000FF";
  char yellow_bits[] = "#FFFF00";   // Mix red and green to get yellow
  char magenta_bits[] = "#FF00FF";  // A sort of purple color
  char cyan_bits[] = "#00FFFF";     // A blue-green color

  //Display *dpy = XOpenDisplay(NIL); 
  dpy = XOpenDisplay(NIL); assert(dpy);   // Open the display
  // Define the colors we want to use
  colormap = DefaultColormap(dpy, 0);
  XParseColor(dpy, colormap, black_bits, &black_col); XAllocColor(dpy, colormap, &black_col);
  XParseColor(dpy, colormap, white_bits, &white_col); XAllocColor(dpy, colormap, &white_col);
  XParseColor(dpy, colormap, red_bits, &red_col); XAllocColor(dpy, colormap, &red_col);
  XParseColor(dpy, colormap, green_bits, &green_col);XAllocColor(dpy, colormap, &green_col);
  XParseColor(dpy, colormap, blue_bits, &blue_col);XAllocColor(dpy, colormap, &blue_col);
  XParseColor(dpy, colormap, yellow_bits, &yellow_col);XAllocColor(dpy, colormap, &yellow_col);
  XParseColor(dpy, colormap, magenta_bits, &magenta_col);XAllocColor(dpy, colormap, &magenta_col);
  XParseColor(dpy, colormap, cyan_bits, &cyan_col);XAllocColor(dpy, colormap, &cyan_col);
  // Create the window  The numbers are the x and y locations on the screen, the width and height, 
  // border width (which is usually zero)
  w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, window_width, window_height,
  0, black_col.pixel, black_col.pixel);
  XSelectInput(dpy, w, StructureNotifyMask);        // We want to get MapNotify events
  XMapWindow(dpy, w);         // "Map" the window (that is, make it appear on the screen)
  for(;;){XEvent e; XNextEvent(dpy,&e); if(e.type == MapNotify) break;} //Wait for the MapNotify event
  // which means that the window has appeared on the screen.
  gc = XCreateGC(dpy, w, 0, NIL);        // Create a "Graphics Context"
  get_pen(white_col);
  //  We are finally ready to do some drawing!  Whew!  

  // ................  Students: you put your beautiful code HERE: .......................
  srand(time(NULL)); //  Get ready to make random numbers.  The time "seeds" the generator.
  int i;
  double x=0,  y=0;
  home();      // Send the turtle to the middle of the window.  That's its "home"
  get_pen(green_col);  pen_down();
  for (i=0; i<36; i++) {
    x = x + rand_range(-30.0, 30.0);  //Generates random number between these two numbers.
    y = y + rand_range(-30.0, 30.0)+5.0;
    gotoxy(x, y);   // Move the turtle to the new location.  It will draw a line if the pen is down.
    XFlush(dpy); // Tell the graphics server that it should really show us the results now.
    printf("1 x=%g y=%g heading=%g\n",turtle_x,turtle_y,turtle_heading); //Optional: use for debugging
    usleep(100000); XFlush(dpy); // Optional: use this to see the lines being drawn, one-by-one
  }
  XFlush(dpy); // Tell the graphics server that it should really show us the results now.
  sleep(1);  // Wait for 1 second
  printf("Press enter when done.\n");
  fgets (keyboard_input,100,stdin); 
  return(0);
}
开发者ID:Vikas-Kaushik,项目名称:algorithms,代码行数:58,代码来源:copied_example3.cpp


示例14: relocate_targets

void relocate_targets(){
	
    for (int i=0; i<max_targets; i++) {
        targets[i].x=rand_range(100,getDisplayWidth()-100);
        targets[i].y=rand_range(100,getDisplayHeight()-100);
    }

    reassign_flares();	
}
开发者ID:armageddon421,项目名称:gles2framework,代码行数:9,代码来源:test.c


示例15: normal_value

XiEta normal_value(double mu, double sigma){
// Returns two normaly distributed, independent values with mu=0 and sigma=1
// based on the Box-Muller Method
  double u = rand_range(0,1);
  double v = rand_range(0,1);

  XiEta x = {mu + sigma*sqrt(-2*log(u))*cos(2*PI*v), mu + sigma*sqrt(-2*log(u))*sin(2*PI*v)};
  return x;
}
开发者ID:Marcello-Sega,项目名称:bachelorthesis,代码行数:9,代码来源:neighbor_list_force.c


示例16: vec2

void PE_SmokeTrail::emit_single_particle(Particle& p)
{
    p.cur_pos = m_pos + vec2(RAND_0_1 * 0.005f,RAND_0_1 * 0.005f);
    p.cur_size = 0.01 + RAND_0_1 * 0.01;
//  float col = rand_range(0.0,0.4);
    float col = rand_range(0.1,0.4);
    p.cur_color = vec4(col,col,col,0.0);
    p.cur_speed = vec2(-0.03,0.0) + normalized(vec2(rand_range(-1.0,1.0),rand_range(-1.0,1.0))) * 0.01;
}
开发者ID:snoutmate,项目名称:Sea-Defender,代码行数:9,代码来源:pe_smoketrail.cpp


示例17: place_pc

void place_pc(dungeon_t *d)
{
  d->pc.position[dim_y] = rand_range(d->rooms->position[dim_y],
                                     (d->rooms->position[dim_y] +
                                      d->rooms->size[dim_y] - 1));
  d->pc.position[dim_x] = rand_range(d->rooms->position[dim_x],
                                     (d->rooms->position[dim_x] +
                                      d->rooms->size[dim_x] - 1));
}
开发者ID:influential,项目名称:dungeon,代码行数:9,代码来源:pc.c


示例18: hyp_neuron_init

void hyp_neuron_init(neuron_t *n)
{
	for (size_t i = 0; i < n->input_count; i++)
	{
		n->weights->values[i] =
		  rand_range(-INITIAL_WEIGHT_RANGE, INITIAL_WEIGHT_RANGE);
	}
	n->bias = rand_range(-INITIAL_WEIGHT_RANGE, INITIAL_WEIGHT_RANGE);
}
开发者ID:dekarrin,项目名称:hypatia-ai,代码行数:9,代码来源:neuron.c


示例19: tm_rect_generate_position

void tm_rect_generate_position( tm_rect_t* r, vect_t* sz, rect_t* map_r )
{
	assert( map_r->v2.x - map_r->v1.x >= sz->x );
	assert( map_r->v2.y - map_r->v1.y >= sz->y );
	r->v1.x = rand_range( map_r->v1.x, (map_r->v2.x - sz->x) );
	r->v1.y = rand_range( map_r->v1.y, (map_r->v2.y - sz->y) );
	r->v2.x = r->v1.x + sz->x;
	r->v2.y = r->v1.y + sz->y;
}
开发者ID:mikedw,项目名称:synquake_tsx,代码行数:9,代码来源:tm_geometry.c


示例20: new_player_spot

/*
 * Returns random co-ordinates for player/monster/object
 */
bool new_player_spot(void)
{
    int    y = 0, x = 0;
    int max_attempts = 10000;

    cave_type *c_ptr;
    feature_type *f_ptr;

    /* Place the player */
    while (max_attempts--)
    {
        /* Pick a legal spot */
        y = rand_range(1, cur_hgt - 2);
        x = rand_range(1, cur_wid - 2);

        c_ptr = &cave[y][x];

        /* Must be a "naked" floor grid */
        if (c_ptr->m_idx) continue;
        if (dun_level)
        {
            f_ptr = &f_info[c_ptr->feat];

            if (max_attempts > 5000) /* Rule 1 */
            {
                if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
            }
            else /* Rule 2 */
            {
                if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
                if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
            }

            /* Refuse to start on anti-teleport grids in dungeon */
            if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
        }
        if (!player_can_enter(c_ptr->feat, 0)) continue;
        if (!in_bounds(y, x)) continue;

        /* Refuse to start on anti-teleport grids */
        if (c_ptr->info & (CAVE_ICKY)) continue;

        /* Done */
        break;
    }

    if (max_attempts < 1) /* Should be -1, actually if we failed... */
        return FALSE;

    /* Save the new player grid */
    py = y;
    px = x;

    return TRUE;
}
开发者ID:MichaelDiBernardo,项目名称:poschengband,代码行数:58,代码来源:grid.c



注:本文中的rand_range函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rand_s函数代码示例发布时间:2022-05-30
下一篇:
C++ rand_r函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap