/* * drawpoly * * draw some polygons */ void drawpoly() { float vec[3]; short val; color(YELLOW); /* * Draw a polygon using poly, parray is our array of * points and 4 is the number of points in it. */ poly(4L, parray); color(GREEN); /* * Draw a 5 sided figure by using bgnpolygon, v3d, and endpolygon */ polymode(PYM_LINE); bgnpolygon(); vec[0] = 0.0; vec[1] = 0.0; vec[2] = 0.0; v3f(vec); vec[0] = 3.0; vec[1] = 0.0; vec[2] = 0.0; v3f(vec); vec[0] = 3.0; vec[1] = 4.0; vec[2] = 0.0; v3f(vec); vec[0] = -1.0; vec[1] = 5.0; vec[2] = 0.0; v3f(vec); vec[0] = -2.0; vec[1] = 2.0; vec[2] = 0.0; v3f(vec); endpolygon(); color(MAGENTA); /* * draw a sector representing a 1/4 circle */ arc(1.5, -7.0, 3.0, 0, 900); move2(1.5, -7.0); draw2(1.5, -4.0); move2(1.5, -7.0); draw2(4.5, -7.0); qread(&val); }
static INLINE unsigned uphill (int x, int y, int dir) { unsigned dir1 = dir; unsigned dir0 = (dir1 - 1) % 8; unsigned dir2 = (dir1 + 1) % 8; unsigned d0 = nest_distance_squared (move2 (x, y, dir0)); unsigned d1 = nest_distance_squared (move2 (x, y, dir1)); unsigned d2 = nest_distance_squared (move2 (x, y, dir2)); return pick_lesser (d0, pick_lesser (d0, dir0, d2, dir2), d1, pick_lesser (d1, dir1, d2, dir2)); }
int main() { char s[30],s1[30]; int i,j,n,x,y; while (scanf("%d",&n)!=EOF) { for (i=0; i<n; i++) { a[i].num=1; a[i].block[1]=i; postion[i]=i; } while (scanf("%s",&s)) { if (strcmp(s,"quit")==0) break; scanf("%d%s%d",&x,&s1,&y); if ((postion[x]!=postion[y])&&(x!=y)) { if ((strcmp(s,"move")==0)&&(strcmp(s1,"onto")==0)) { turnback(x); turnback(y); move1(x,y); } if ((strcmp(s,"move")==0)&&(strcmp(s1,"over")==0)) { turnback(x); move1(x,y); } if ((strcmp(s,"pile")==0)&&(strcmp(s1,"onto")==0)) { turnback(y); move2(x,y); } if ((strcmp(s,"pile")==0)&&(strcmp(s1,"over")==0)) { move2(x,y); } } } for (i=0; i<n; i++) { printf("%d:",i); for (j=1; j<=a[i].num; j++) printf(" %d",a[i].block[j]); printf("\n"); } } return 0; }
static void emptyhanded_move (int ant, unsigned x, unsigned y) { heading[ant] = ((15 < scent[ant] ? follow_gradient_unsigned (scent, heading[ant], x, y) : heading[ant]) + (fast_rand () % 3) - 1) % 8; { unsigned neighbor = move2 (x, y, heading[ant]); if (grid[neighbor] == food) { grid[ant] = carrying; gland[ant] = 16000; } else if (grid[neighbor] != empty) { heading[ant] = fast_rand () % 8; return; } grid[neighbor] = grid[ant]; heading[neighbor] = heading[ant]; grid[ant] = empty; } }
bool trigger(TriggerEvent, Room *room, ServerPlayer *player, QVariant &data) const{ PhaseChangeStruct change = data.value<PhaseChangeStruct>(); if (change.to != Player::NotActive) return false; int weapon_id = player->tag.value("DrJiedaoWeapon", -1).toInt(); player->tag["DrJiedaoWeapon"] = -1; if (!player->getWeapon() || weapon_id != player->getWeapon()->getEffectiveId()) return false; ServerPlayer *target = NULL; foreach (ServerPlayer *p, room->getOtherPlayers(player)) if (p->hasFlag("DrJiedaoTarget")) { p->setFlags("-DrJiedaoTarget"); target = p; break; } if (target == NULL) { room->throwCard(player->getWeapon(), NULL); } else { QList<CardsMoveStruct> exchangeMove; CardsMoveStruct move1(player->getWeapon()->getEffectiveId(), target, Player::PlaceEquip, CardMoveReason(CardMoveReason::S_REASON_GOTCARD, player->objectName())); exchangeMove.push_back(move1); if (target->getWeapon() != NULL) { CardsMoveStruct move2(target->getWeapon()->getEffectiveId(), NULL, Player::DiscardPile, CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName())); exchangeMove.push_back(move2); } room->moveCardsAtomic(exchangeMove, true); } return false; }
void EquipCard::use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) const { if (targets.isEmpty()) { CardMoveReason reason(CardMoveReason::S_REASON_USE, source->objectName(), QString(), this->getSkillName(), QString()); room->moveCardTo(this, NULL, Player::DiscardPile, reason, true); } int equipped_id = Card::S_UNKNOWN_CARD_ID; ServerPlayer *target = targets.first(); if (target->getEquip(location())) equipped_id = target->getEquip(location())->getEffectiveId(); QList<CardsMoveStruct> exchangeMove; CardsMoveStruct move1(getEffectiveId(), target, Player::PlaceEquip, CardMoveReason(CardMoveReason::S_REASON_USE, target->objectName())); exchangeMove.push_back(move1); if (equipped_id != Card::S_UNKNOWN_CARD_ID) { CardsMoveStruct move2(equipped_id, NULL, Player::DiscardPile, CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName())); exchangeMove.push_back(move2); } LogMessage log; log.from = target; log.type = "$Install"; log.card_str = QString::number(getEffectiveId()); room->sendLog(log); room->moveCardsAtomic(exchangeMove, true); }
static INLINE void diffuse8_unsigned (unsigned *array, unsigned x, unsigned y, unsigned fraction) { double droplet = array[at (x, y)] / fraction; int i; for (i = 0; i < 8; ++i) array[move2 (x, y, i)] += droplet; array[at (x, y)] -= 8 * droplet; }
void display_non_protect_row() { int temp; #ifdef kdkddkkdkkdkk temp = gtext_buffer_index; if(gtext_buffer_index > 0) { gtext_buffer[gtext_buffer_index] = '\0'; gtext_buffer_index = 0; set_message_viewport(); wrmask(0xff); move2((new_text_col + col_offset)*CHAR_WIDTH + W_LEFT - 9, W_TOP - (new_text_row + row_offset)*CHAR_HEIGHT - 10); color(BACK_COLOR); if(gtext_buffer[1] != '\0') /* clear the row out fully */ { boxr(CHAR_WIDTH*30,CHAR_HEIGHT); } else /* clear this character */ boxr(CHAR_WIDTH,CHAR_HEIGHT); color(FORE_COLOR); move2((new_text_col + col_offset)*CHAR_WIDTH + W_LEFT, W_TOP - (new_text_row + row_offset)*CHAR_HEIGHT); gtext(gtext_buffer); wrmask(io_masks[which_page]); restore_graphics_viewport(); } #endif }
/* * drawgrid * * draw a grid in the middle of the screen */ void drawgrid() { float x; int i; color(GREEN); rect(0.1, 0.4, 0.9, 0.6); x = 0.2; for (i = 0; i < 8; i++) { move2(x, 0.4); draw2(x, 0.6); x += 0.1; } move2(0.1, 0.5); draw2(0.9, 0.5); color(YELLOW); }
/* * rect * * draw a rectangle given two opposite corners * */ void rect(Coord x1, Coord y1, Coord x2, Coord y2) { if (!vdevice.initialised) verror("rect: vogl not initialised"); move2(x1, y1); draw2(x2, y1); draw2(x2, y2); draw2(x1, y2); draw2(x1, y1); }
int main() { int array[6] = {1,3,6,9,13,1}; //BubbleSort(array, 6); QuickSort(array, 0, 5); printf("排序后:"); for (int i = 0; i < 6; ++i) { printf("%d ", array[i]); } printf("\n大小写分开:"); char str[7] = {'a','A','Z','d','B','s','b'}; func1(str, 0, 6); for (int i = 0; i < 7; ++i) { printf("%c ", str[i]); } printf("\n0与非0分开:"); int a[7] = {0,3,0,2,1,0,0}; move1(a, 0, 6); for (int i = 0; i < 7; ++i) { printf("%d ", a[i]); } puts(""); move2(a, 0, 6); for (int i = 0; i < 7; ++i) { printf("%d ", a[i]); } printf("\n荷兰国旗问题:"); int b[10] = {0,1,2,1,1,2,0,2,1,0}; helan(b, 0, 9); for (int i = 0; i < 10; ++i) { printf("%d ", b[i]); } printf("\n找最小的k个数:"); int c[10] = {1,87,4,5,7,5,4,98,5,0}; int k = 4; int out[4] = {0}; findMixk(c, 0, 9, 4, out); for (int i = 0; i < k; ++i) { printf("%d ", out[i]); } return 0; }
void DrJiedaoCard::onEffect(const CardEffectStruct &effect) const{ if (!effect.to->getWeapon()) return; effect.from->tag["DrJiedaoWeapon"] = effect.to->getWeapon()->getEffectiveId(); effect.to->setFlags("DrJiedaoTarget"); QList<CardsMoveStruct> exchangeMove; CardsMoveStruct move1(effect.to->getWeapon()->getEffectiveId(), effect.from, Player::PlaceEquip, CardMoveReason(CardMoveReason::S_REASON_ROB, effect.from->objectName())); exchangeMove.push_back(move1); if (effect.from->getWeapon() != NULL) { CardsMoveStruct move2(effect.from->getWeapon()->getEffectiveId(), NULL, Player::DiscardPile, CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, effect.from->objectName())); exchangeMove.push_back(move2); } effect.to->getRoom()->moveCardsAtomic(exchangeMove, true); }
void SistemWindowView::draw() { int viewWidth = viewMax.getX() - viewMin.getX(); int viewHeight = viewMax.getY() - viewMin.getY(); int windowWidth = windowMax.getX() - windowMin.getX(); int windowHeight = windowMax.getY() - windowMin.getY(); float ratio_x = (float)viewWidth/windowWidth; float ratio_y = (float)viewHeight/windowHeight; point move1(-windowMin.getX(),-windowMin.getY()); point move2(viewMin.getX(),viewMin.getY()); map.clip(windowMin,windowMax) .hasilGeser(move1) .hasilSkala(ratio_x,ratio_y) .hasilGeser(move2).draw(); drawMinimap(); }
void set_message_viewport() { #ifdef ksdslslslsl if(in_which_viewport == MESSAGE_VIEWPORT) return; in_which_viewport = MESSAGE_VIEWPORT; wrmask(0xff); my_size_chars(0); window(W_LEFT + CHAR_X_SHIFT,W_RIGHT + CHAR_X_SHIFT, W_BOTTOM + CHAR_Y_SHIFT,W_TOP + CHAR_Y_SHIFT); viewport(V_LEFT,V_RIGHT,V_BOTTOM,V_TOP); color(BORDER_COLOR); move2(W_LEFT + CHAR_X_SHIFT + W_BORDER_INDENT, W_BOTTOM + CHAR_Y_SHIFT + W_BORDER_INDENT); draw2(W_LEFT + CHAR_X_SHIFT + W_BORDER_INDENT, W_TOP + CHAR_Y_SHIFT - W_BORDER_INDENT); draw2(W_RIGHT + CHAR_X_SHIFT - W_BORDER_INDENT, W_TOP + CHAR_Y_SHIFT - W_BORDER_INDENT); draw2(W_RIGHT + CHAR_X_SHIFT - W_BORDER_INDENT, W_BOTTOM + CHAR_Y_SHIFT + W_BORDER_INDENT); draw2(W_LEFT + CHAR_X_SHIFT + W_BORDER_INDENT, W_BOTTOM + CHAR_Y_SHIFT + W_BORDER_INDENT); window(W_LEFT + CHAR_X_SHIFT + CHAR_WIDTH, W_RIGHT + CHAR_X_SHIFT - CHAR_WIDTH, W_BOTTOM + CHAR_Y_SHIFT + CHAR_HEIGHT, W_TOP + CHAR_Y_SHIFT - CHAR_HEIGHT); viewport(V_LEFT + V_BORDER_INDENT,V_RIGHT - V_BORDER_INDENT, V_BOTTOM + V_BORDER_INDENT,V_TOP - V_BORDER_INDENT); #endif }
TEST_F(MouseControllerUnitTestBase, ShiftOver) {//测试over MouseController mc(root); EXPECT_EQ(nullptr, mc.over()); MouseEvent move(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(80, 80), Point::Make(80, 80), 0); mc.handleEvent(move); EXPECT_EQ(nullptr, mc.over()); MouseEvent move1(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(29, 20), Point::Make(29, 20), 0); mc.handleEvent(move1); EXPECT_EQ(v2, mc.over()); MouseEvent move2(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(45, 45), Point::Make(45, 45), 0); mc.handleEvent(move2); EXPECT_EQ(v31, mc.over()); v31->setMouseable(false); mc.handleEvent(move2); EXPECT_NE(v31, mc.over()); }
static void carrying_move (int ant, unsigned x, unsigned y) { unsigned dir = uphill (x, y, heading[ant]); dir = (dir + fast_rand () % 3 - 1) % 8; heading[ant] = dir; { unsigned neighbor = move2 (x, y, dir); if (grid[neighbor] != empty) heading[ant] = fast_rand () % 8; else if (in_nest (x, y) && fast_rand () % 4 == 0) { grid[neighbor] = food; grid[ant] = emptyhanded; heading[ant] = (dir + 4) % 8; /* turn around */ } else { if (!in_nest (x, y)) { int gl = gland[ant]; if (0 < gl) { scent[ant] += gl; gland[ant] -= 128; } } grid[neighbor] = carrying; heading[neighbor] = dir; grid[ant] = empty; } } }
/* * Shows various combinations of viewing and * projection transformations. */ main() { char device[20]; fprintf(stderr,"Enter device name: "); gets(device); vinit(device); color(BLACK); clear(); /* * we want to draw just within the boundaries of the screen */ viewport(-0.9, 0.9, -0.9, 0.9); ortho2(-5.0, 5.0, -5.0, 5.0); /* set the world size */ color(RED); rect(-5.0, -5.0, 5.0, 5.0); /* draw a boundary frame */ /* * set up a perspective projection with a field of view of * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1, * and the far clipping plane at 1000.0. */ perspective(40.0, 1.0, 0.1, 1000.0); /* * we want the drawing to be done with our eye point at (5.0, 8.0, 5.0) * looking towards (0.0, 0.0, 0.0). The last parameter gives a twist * in degrees around the line of sight, in this case zero. */ lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0); drawtetra(); move2(-4.5, -4.5); textsize(0.6, 0.9); /* set the text size */ drawstr("perspective/lookat"); getkey(); /* * window can also be used to give a perspective projection. Its * arguments are 6 clipping planes, left, right, bottom, top, near, * and far. */ window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0); /* * as window replaces the current transformation matrix we must * specify our viewpoint again. */ lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0); color(BLACK); clear(); color(GREEN); rect(-5.0, -5.0, 5.0, 5.0); drawtetra(); move2(-4.5,-4.5); textsize(0.6, 0.9); /* set the text size */ drawstr("window/lookat"); getkey(); /* * set up our original perspective projection again. */ perspective(40.0, 1.0, 0.1, 1000.0); /* * polarview also specifies our viewpoint, but, unlike lookat, in polar * coordinates. Its arguments are the distance from the world origin, an * azimuthal angle in the x-y plane measured from the y axis, an * incidence angle in the y-z plane measured from the z axis, and a * twist around the line of sight. */ polarview(15.0, 30.0, 30.0, 30.0); color(BLACK); clear(); color(MAGENTA); rect(-5.0, -5.0, 5.0, 5.0); drawtetra(); move2(-4.5,-4.5); textsize(0.6, 0.9); /* set the text size */ drawstr("perspective/polarview"); getkey(); /* * once more with window for comparison */ window(-4.0, 4.0, -4.0, 4.0, -4.0, 4.0); polarview(6.0, 20.0, -30.0, 70.0); color(BLACK); clear(); color(YELLOW); rect(-5.0, -5.0, 5.0, 5.0); drawtetra(); move2(-4.5,-4.5); textsize(0.6, 0.9); /* set the text size */ drawstr("window/polarview"); getkey(); vexit(); }
real calc_check(int check,const char * exp) { real opd_stack[STACK_SIZE]; int opr_stack[STACK_SIZE]; int opd_size = 0,opr_size = 0; int state = 1/*,i*/; extern VAR * find_var (const char *); if (check) { match_exp(exp); l_get_token(); if (token_type!=TT_LINE_END) { merror_msg("illegal expr"); } } pline = exp; while(1) { l_get_token();//puts(token);SHOW_STACK; // exit if (token_type==TT_LINE_END) { break; } else if (token_type==TT_ID) { VAR * v;ARRAY * a; if (state!=1 && !check) { l_put_back(); break; } v = find_var(token); if (v!=NULL) { push_opd(v->value); move2(2); continue; } a = find_array (token); if (a!=NULL) { int index; l_get_token();//skip ( index = (int)calc_check(FALSE,pline); // delete this line,calc_check call skip ( automatically //l_get_token();//skip ) push_opd(get_element(a,index)); move2(2); continue; } merror_msg("Unrecognized identifier '%s'",token); } // constant else if (token_type==TT_INT || token_type==TT_FLOAT) { push_opd((real)atof(token)); move2(2); } // operator else if (IS_OPR(token_type)) { // neg "-" judgement if (token_type==OPR_SUB && state==1) { token_type = OPR_NEG; } // if (opr_size>0 && opr_stack[opr_size-1]!=TT_LBK && priority(token_type) <= priority(opr_stack[opr_size-1])) { real result; result = calc_pop(opd_stack,opr_stack,&opd_size,&opr_size); push_opd(result); } push_opr(token_type); move2(1); } // process '(' and ')' else if (token_type==TT_LBK) { push_opr(token_type); } else if (token_type==TT_RBK) { while(opr_stack[opr_size-1] /* top */ != TT_LBK && opr_size > 0) { real result; result = calc_pop(opd_stack,opr_stack,&opd_size,&opr_size); push_opd(result); } if (opr_stack[opr_size-1] /* top */ == TT_LBK) { opr_size--; // pop '(' } else // funcition call end { break; } } // built-in function call else if (IS_RESWORD(token_type)) { int argc = token_ext,i; real result; FUNCTION func = get_func(token_type); //printf("call <%s>\n",token); // skip '(' l_get_token (); // get all arg and push them in stack for (i=0;i<argc;++i) { result = calc_check(FALSE,pline); push_opd(result); //printf("[%d] |%.4lf|\n",i,result); } // call func result = func(opd_stack + opd_size - argc); // pop args opd_size -= argc; // push result push_opd(result); //printf("call end\n"); } else { if (check) merror_illegal_token(); else { l_put_back(); break; } } } // pop up all while(opr_size > 0) { real result; result = calc_pop(opd_stack,opr_stack,&opd_size,&opr_size); push_opd(result); } if (opd_size != 1) { merror_msg("calc:unknown error!"); } return opd_stack[0]; }
/* * a demonstration of objects */ draw_balls() { if (!inited) { inited = 1; /* * set up our viewing transformation */ perspective(900, 1.0, 0.001, 500.0); lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0); /* * Call a routine to make the sphere object */ makesphere(); hfont("times.rb"); } /* * Now draw the sphere object scaled down. We use the pushmatrix * and the popmatrix to preserve the transformation matrix so * that only this sphere is drawn scaled. */ color(CYAN); pushmatrix(); scale(0.5, 0.5, 0.5); callobj(SPHERE); popmatrix(); /* * now we draw the same sphere translated, with a different * scale and color. */ color(WHITE); pushmatrix(); translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS); scale(0.3, 0.3, 0.3); callobj(SPHERE); popmatrix(); /* * and maybe a few more times.... */ color(RED); pushmatrix(); translate(0.0, RADIUS, 0.7 * RADIUS); scale(0.2, 0.2, 0.2); callobj(SPHERE); popmatrix(); color(GREEN); pushmatrix(); translate(0.0, 1.5 * RADIUS, -RADIUS); scale(0.15, 0.15, 0.15); callobj(SPHERE); popmatrix(); color(YELLOW); pushmatrix(); translate(0.0, -RADIUS, -RADIUS); scale(0.12, 0.12, 0.12); callobj(SPHERE); popmatrix(); color(BLUE); pushmatrix(); translate(0.0, -2.0*RADIUS, -RADIUS); scale(0.3, 0.3, 0.3); callobj(SPHERE); popmatrix(); ortho2(0.0, 1.0, 0.0, 1.0); hcentertext(1); htextsize(0.08, 0.15); move2(0.8, 0.5); htextang(-90.0); hcharstr("I'm very ordinary!"); perspective(900, 1.0, 0.001, 500.0); lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0); }