本文整理汇总了C++中Monsters::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Monsters::size方法的具体用法?C++ Monsters::size怎么用?C++ Monsters::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monsters
的用法示例。
在下文中一共展示了Monsters::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: monsters_round
static int monsters_round()
{
int ret = 0;
int yoffset = 0;
int xoffset = 0;
for (unsigned i=0; i<monsters.size(); i++) {
ret++;
Object *m = &monsters[i];
mvwaddch(win_disp->win, m->y, m->x, ' ');
yoffset = me.y - m->y;
xoffset = me.x - m->x;
if (abs(yoffset) > abs(xoffset)) {
if (yoffset > 0) {
m->y++;
} else {
m->y--;
}
} else {
if (xoffset > 0) {
m->x++;
} else {
m->x--;
}
}
if (m->y == me.y && m->x == me.x) {
me.life--;
}
mvwaddch(win_disp->win, m->y, m->x, m->face);
wrefresh(win_disp->win);
usleep(1000*200);
}
return ret;
}
示例2: fire_fly
static int fire_fly()
{
int hit = 0;
int ret = 0;
for (unsigned i=0; i<fires.size(); i++) {
ret++;
hit = 0;
Object *f = &fires[i];
mvwaddch(win_disp->win, f->y, f->x, ' '); // erase old face
f->x += f->xstep;
f->y += f->ystep;
if (f->x < 0 || f->x >= win_disp->locate.w
|| f->y < 0 || f->y >= win_disp->locate.h) {
fires.erase(fires.begin() + i);
break;
}
// hit test
for (unsigned j=0; j<monsters.size(); j++) {
Object *m = &monsters[j];
if (f->x == m->x && f->y == m->y) {
m->life--;
if (m->life <= 0) {
hit = 1;
monsters.erase(monsters.begin() + j);
me.score += m->score;
break;
}
}
}
if (hit) {
continue;
}
mvwaddch(win_disp->win, f->y, f->x, f->face);
draw_me();
wrefresh(win_disp->win);
usleep(1000*100);
}
return ret;
}
示例3: draw
static void draw()
{
unsigned i = 0;
if (NULL == win_disp) {
return;
}
wclear(win_disp->win);
char msg[16] = {0};
sprintf(msg, "L%d R%d Score:%d", level, round, me.score);
mvwaddstr(win_disp->win, 0, 1, msg);
mvwaddch(win_disp->win, me.y, me.x, me.face);
for (i=0; i<monsters.size(); i++) {
Object *m = &monsters[i];
mvwaddch(win_disp->win, m->y, m->x, m->face);
}
for (i=0; i<fires.size(); i++) {
Object *f = &fires[i];
mvwaddch(win_disp->win, f->y, f->x, f->face);
}
wrefresh(win_disp->win);
}
示例4: do_round
static int do_round(char *key)
{
unsigned i = 0;
int ret = 0;
int len = strlen(key);
for (i=0; i<monsters.size(); i++) {
ret++;
Object *m = &monsters[i];
m->score += len*10;
}
for (i=0; i<len; i++) {
char cmd = key[i];
switch(cmd) {
case 'w':
if (me.y > 1) {
me.y--;
}
break;
case 'a':
if (me.x > 1) {
me.x--;
}
break;
case 's':
if (me.y < win_disp->locate.h) {
me.y++;
}
break;
case 'd':
if (me.x < win_disp->locate.w) {
me.x++;
}
break;
case 'h':
new_fire(-1, 0);
break;
case 'j':
new_fire(0, 1);
break;
case 'k':
new_fire(0, -1);
break;
case 'l':
new_fire(1, 0);
break;
default:
break;
}
ret = monsters_round();
draw();
fire_fly();
if (me.life <= 0) {
gameover();
return -1;
}
if (ret <= 0) {
while (fire_fly() > 0);
break;
}
usleep(1000*500);
}
return ret;
}