本文整理汇总了C++中randInt函数的典型用法代码示例。如果您正苦于以下问题:C++ randInt函数的具体用法?C++ randInt怎么用?C++ randInt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randInt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: randFloat
void TestCanvas::testQuadBezier(GiCanvas* canvas, int n)
{
float x1 = randFloat(100.f, 400.f);
float y1 = randFloat(100.f, 400.f);
for (int i = 0; i < n; i++) {
canvas->beginPath();
float x2 = x1 + randFloat(-100.f, 100.f);
float y2 = y1 + randFloat(-100.f, 100.f);
float x3 = x2 + randFloat(-100.f, 100.f);
float y3 = y2 + randFloat(-100.f, 100.f);
canvas->moveTo(x1, y1);
canvas->lineTo((x1 + x2) / 2, (y1 + y2) / 2);
for (int j = randInt(5, 20); j > 0; j--) {
canvas->quadTo(x2, y2, (x3 + x2) / 2, (y3 + y2) / 2);
x1 = x2; x2 = x3;
y1 = y2; y2 = y3;
x3 = x2 + randFloat(-100.f, 100.f);
y3 = y2 + randFloat(-100.f, 100.f);
}
canvas->lineTo(x2, y2);
if (s_randStyle) {
canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), randFloat(0, 6), randInt(0, 4), 0);
}
canvas->drawPath(true, false);
}
}
示例2: KSprite
/*! \class KRock
\brief Class KRock is the base class for three sizes of rock.
The rock base class generates and holds some random values
used when computing the next image to display. This makes
the rocks look like they are tumbling.
The static count of rocks created is incremented.
\internal
*/
KRock::KRock() : KSprite()
{
skip_ = randInt(2);
cskip_ = skip_;
step_ = randInt(2) ? -1 : 1;
++rocksCreated_;
allRocksDestroyed_ = false;
}
示例3: randFloat
void TestCanvas::testEllipse(GiCanvas* canvas)
{
for (int i = 0; i < 100; i++) {
canvas->drawEllipse(randFloat(10.f, 600.f), randFloat(10.f, 600.f),
randFloat(10.f, 400.f), randFloat(10.f, 400.f),
randInt(0, 1) == 1, randInt(0, 1) == 1);
}
}
示例4: Snakewomen
Snakewomen:: Snakewomen (int r, int c, char name, string full_name, Pit* p) : Monster(r,c,name, full_name,p)
{
set_Hit_points(randInt(4)+3);//Hp is between 3-6
set_stregth_points(2); //strength is between 2
set_desterity(6);// set desterity between 3;
set_armor_points(2);//set armor to 2;
set_damage_point(randInt(return_strength_points() + 2));
set_weapon_wielding("magicfangsofsleep");
}
示例5: randInt
void TestCanvas::testLine(GiCanvas* canvas, int n)
{
for (int i = 0; i < n; i++) {
if (s_randStyle) {
canvas->setPen(randInt(10, 0xFF) << 24 | randInt(0, 0xFFFFFF), -1.f, -1, 0);
}
canvas->drawLine(randFloat(10.f, 600.f), randFloat(10.f, 600.f),
randFloat(10.f, 400.f), randFloat(10.f, 400.f));
}
}
示例6: KFragment
/*!
A private function that explodes the ship into a number of
ship \l {KFragment} {fragments}.
*/
void KShip::explode()
{
KFragment* f;
for (int i=0; i<8; i++) {
f = new KFragment();
f->setPos((x()+5) - (randDouble()*10), (y()+5) - (randDouble()*10));
f->setImage(randInt(FRAG_IMAGE_COUNT));
f->setVelocity(1 - (randDouble()*2), 1 - (randDouble()*2));
f->setMaximumAge(60 + randInt(60));
f->show();
}
}
示例7: updateFalling
void updateFalling(void)
{
for(int j=0; j<numberOfFalling; j++)
{
if(moving[j].use==true)
{
swirlingDirection=randInt(MAXSWIRL);
if(randomEvent(2)==true)
swirlingDirection=-swirlingDirection;
moving[j].stepX=moving[j].stepX+swirlingDirection;
if(moving[j].stepX>maxXStep)
moving[j].stepX=maxXStep;
if(moving[j].stepX<-maxXStep)
moving[j].stepX=-maxXStep;
moving[j].y=moving[j].y+moving[j].stepY;
moving[j].x=moving[j].x+moving[j].stepX+windSpeed+(gustOffSet*gustDirection);
if(checkOnWindow(&moving[j])==false)
{
if(moving[j].y>displayHeight+moving[j].object->h[0])
{
moving[j].use=false;
moving[j].y=0-moving[j].object->h[0];
updateBottomSnow(&moving[j]);
}
}
else
{
moving[j].use=false;
moving[j].y=0-moving[j].object->h[0];
}
if(moving[j].x>displayWidth+moving[j].object->w[0])
moving[j].x=0-moving[j].object->w[0];
if(moving[j].x<0-moving[j].object->w[0])
moving[j].x=displayWidth;
}
else
{
if(randomEvent(fallingSpread)==true)
{
moving[j].use=true;
moving[j].stepY=randInt(fallSpeed-minFallSpeed+1)+minFallSpeed;
moving[j].x=(rand() % displayWidth);
moving[j].imageNum=randInt(moving[j].object->anims);
moving[j].countDown=fallingAnimSpeed;
moving[j].direction=randomEvent(2);
}
}
}
}
示例8: switch
void Player::attack(Actor* monster){
//check if the function input is acually a monster through dynamic cast
Monster* temp = dynamic_cast<Monster*>(monster);
string monsterName;
char c = temp->getType();
//check the monsters type and based on that, assign monsterName a specific name
switch (c) {
case 'S':
monsterName = " a Snakewoman";
break;
case 'B':
monsterName = " a Boogeyman";
break;
case 'D':
monsterName = " a Dragon";
break;
case 'G':
monsterName = " a Goblin";
break;
default:
break;
}
//check if the players attackerPoints are greater than the monsters defenderPoints
if (randInt(dexterity() + equiped->dex_bonus) >= randInt(monster->dexterity() + monster->armor())) {
//subtract the inflicted damage from the monster
monster->setHealth(monster->health() - randInt(strength() + equiped->str_bonus));
//if the user is using MagicFangs and probablilty is greater than 1/3 then put the monster to sleep
if (equiped->m_name == "Magic fangs of sleep") {
if(trueWithProbability(.3)){
monster->setSleep(2+randInt(5));
//add an action to action vector
dungeon()->action_vector.push_back("Player" + equiped->action() + monsterName+" and puts him to sleep.");
}
else
//add an action saying that the player hit but did not put to sleep
dungeon()->action_vector.push_back("Player" + equiped->action() +monsterName + " and hits.");
}
else
//add an action saying that the player hit
dungeon()->action_vector.push_back("Player" + equiped->action() +monsterName + " and hits.");
}
else
//add an action saying that the player missed
dungeon()->action_vector.push_back("Player" + equiped->action() + monsterName+ " and misses.");
}
示例9: randInt
void ParticlePool::spark(Position &pos)
{
int numParticles = randInt(3,6);
for(int ii=0; ii<numParticles; ii++)
{
Position particlePos(pos);
particlePos.impulse( randFloat(-50, 50), randFloat(-50, 50) );
float whiteness = randInt(0, 255);
Particle p = Particle(whiteness, whiteness, 255, randInt(170, 255), 0.15, particlePos, 300);
add(p);
}
}
示例10: getLocation
void Spider::doSomething()
{
if(restNow)
{
restNow=false; //rest every other tick
return;
}
int x, y;
getLocation(x, y); //get its current location
if(m_distance==0) //if its distance is 0, flip its vertical direction and select a new distance
{
if(!movingDown) //if moving up
{
movingDown=true;
m_distance=randInt(1, y-1);
}
else //if moving down
{
movingDown=false;
m_distance=randInt(1, GARDEN_HEIGHT-y-1);
}
}
int newx, newy; //calculate the new diagonal location
if(movingDown)
newy=y-1;
else
newy=y+1;
if(movingRight)
newx=x+1;
else
newx=x-1;
m_distance--; //decrement its vertical direction
if(getWorld()->mushroomThere(newx, newy))
getWorld()->removeMushroom(newx, newy); //if there is a mushroom, remove it
if(newx<0 || newx>=GARDEN_WIDTH || newy<0 || newy>=GARDEN_HEIGHT) //if it moves out of bounds, set it to dead
setDead();
else
moveTo(newx, newy); //move the spider
getWorld()->killPlayer(newx, newy); //if it lands on player, kill it
restNow=true; //if it didn't rest this tick, next tick it will rest
}
示例11: randAllele
// do the Allele selection
int randAllele(int numMom, int numDad, float selection) {
if ((numMom == 0) && (numDad == 0)) {
return 0;
}
else if ((numMom == 1) && (numDad == 0)) {
return randInt(2);
}
else if ((numMom == 2) && (numDad == 0)) {
return 1;
}
else if ((numMom == 0) && (numDad == 1)) {
return randInt(2);
}
else if ((numMom == 1) && (numDad == 1)) {
float val = randRange(0,(3+selection));
if (val < 1.0) {
return 0;
}
else if (val < 3.0) {
return 1;
}
else {
return 2;
}
}
else if ((numMom == 2) && (numDad == 1)) {
float val = randRange(0,(1+selection));
if (val < 1.0) {
return 1;
}
else {
return 2;
}
}
else if ((numMom == 0) && (numDad == 2)) {
return 1;
}
else if ((numMom == 1) && (numDad == 2)) {
float val = randRange(0,(1+selection));
if (val < 1.0) {
return 1;
}
else {
return 2;
}
}
else if ((numMom == 2) && (numDad == 2)) {
return 2;
}
}
示例12: randInt
void CadMdiChild::on_addCircles_clicked() {
auto builder = std::make_shared<lc::operation::Builder>(document());
auto layer = _storageManager->layerByName("0");
for (int i = 0; i < 1000; i++) {
double x1 = randInt(-4000, 4000);
double y1 = randInt(-4000, 4000);
double r = randInt(0, 150);
builder->append(std::make_shared<lc::Circle>(lc::geo::Coordinate(x1, y1), r, layer));
}
builder->execute();
}
示例13: randInt
void GameObjects::initializeSpot()
{
int r = 1 + randInt(LEVEL_ROWS - 1);
int c = 1 + randInt(LEVEL_COLS - 1);
if (m_dungeon->noWalls(r, c) && (m_dungeon->noWalls(r, c - 1) || m_dungeon->noWalls(r, c + 1))
&& (m_dungeon->noWalls(r - 1, c) || m_dungeon->noWalls(r + 1, c)))
{
m_row = r;
m_col = c;
}
else
initializeSpot();
return;
}
示例14: qsrand
/** Sets a random position to the player */
void Player::randompos()
{
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
QThread::msleep(10);
int p = randInt(2,WIDTH-2);
int p2 = randInt(2,HEIGHT-2);
pX = p;
pY = p2;
}
示例15: generateFile
void generateFile(char *path, long size, int minKeyValue, int maxKeyValue, int minValLen, int maxValLen) {
srand(time(NULL));
FILE *file = fopen(path, "w");
long i;
int next;
fprintf(file, "%ld\n", size);
for (i = 0; i < size; i++) {
next = randInt(minKeyValue, maxKeyValue);
int len = randInt(minValLen, maxValLen);
char *value = randStr(len);
fprintf(file, "%d %s\n", next, value);
free(value);
}
fclose(file);
}