int game(char **grid, char **gridenemy) { char str[3]; int *coord; if ((coord = malloc(sizeof(*coord) * 2)) == NULL) return (1); while (check_loose(grid, gridenemy) != 1) { my_printf("\nmy navy:"); my_display(grid); my_printf("\nenemy navy:"); my_display(gridenemy); my_printf("\nattack : "); check_input_coord(str, coord); send_coord(coord); hitornot(gridenemy, coord); if (check_win(grid, gridenemy) == 1) return (1); my_printf("\nwaiting for enemy's attack...\n"); receive_coord(coord); check_result(grid, coord); } free(coord); return (0); }
int display(int argc, char argv[ARGS_MAX][ARG_MAX + 1]) { my_display(); return STATUS_OK; }
/* TODO for EC: have more fun in here */ void my_mouse(int b, int s, int x, int y) { switch (b) { /* b indicates the button */ case GLUT_LEFT_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Left button pressed at %d %d\n", x, y); my_x = x; my_y = y; my_display(); } else if (s == GLUT_UP) { /* button released */ printf("Left button released\n"); } break; case GLUT_RIGHT_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Right button pressed\n"); } else if (s == GLUT_UP) { /* button released */ printf("Right button released\n"); } break; case GLUT_MIDDLE_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Middle button pressed at %d %d\n", x, y); } else if (s == GLUT_UP) { /* button released */ printf("Middle button released\n"); } break; } }
/************************************************* Function: int check_putin(LINK *head) Description: 检测用户输入的指令,并执行该功能函数 Calls: my_add(head); my_display(head); my_delete(head); my_search(head); menu(head); Called By: menu(LINK *head) Input: LINK *head 链表头指针 Return: NO *************************************************/ int check_putin(LINK *head) { char check[MAX]; setbuf(stdin,NULL); //清空输入缓冲 printf("\t\t\033[47;31mplease input conmand:\033[0m "); gets(check); //读入输入的命令 if(my_strcmp(check,"ADD") == 0) //若输入的为ADD 则调用my_add增加一个联系人 { my_add(head); } else if(my_strcmp(check,"DISPLAY") == 0) //若输入为DISPLAY 调用my_display函数 { my_display(head); } else if(my_strcmp(check,"DELETE") == 0) //若输入为DELETE 调用my_delete函数 { my_delete(head); } else if(my_strcmp(check,"SEARCH") == 0) //若输入为SEARCH 调用my_search函数 { my_search(head); } else if(my_strcmp(check,"QUIT") == 0) //若输入为QUIT 程序退出 { write_to_file(head); //退出前保存数据进文件 system("clear"); printf("\n"); printf("\t\t\tTHANKS FOR USEING!\n"); getchar(); exit(1); } /*若错误输入 则继续调用menu函数 提示错误并重新输入*/ else { printf("\t\t\033[47;31m输入错误,请重新输入!\033[0m"); // getchar(); scanf("%*[^\n]"); system("clear"); menu(head); } return SUCCESS; }
void my_idle(void) { loops = 0; while(GetTickCount() > next_game_tick && loops < MAX_FRAME_SKIP){ // Update Game Stuff m->update_movement(); m->update(); // Update Timing Stuff next_game_tick += SKIP_TICKS; loops++; } // Display Screen my_display(); return; }
int colle(int x, int y) { int i; int j; j = 0; while (j < x && x > 0) { i = 0; while (i < y) { my_display(x, y, j, i); i++; } my_putchar('\n'); j++; } return (0); }
void colle(int x, int y) { int i; int j; i = 0; j = 0; while (j < y) { i = 0; while (i < x) { my_display(x, y, i, j); i++; } my_putchar('\n'); j++; } }
/* TODO for EC: do something fun in here */ void my_TimeOut(int id) { /* id is the id of the timer; you can schedule as many timer events as you want in the callback setup section of glut_setup */ /*...you could use this timer event to advance the state of animation incrementally */ /* if animating you shd replace the 20 secs with something smaller, like 20 msec */ /* but anyway, right now it only displays a benign message */ //printf("Tick! It's been 20 seconds: benign timer at your service!\n"); /*As time goes on, things fall. */ for(i = 0; i <= num_shapes; i++) { if(shapes[i].type == 0) { if(shapes[i].y > 0) { shapes[i].y--; shapes[i].x += shapes[i].force_x; shapes[i].y += shapes[i].force_y; } } else { if(shapes[i].circle_vertices[num_vertices * 3 / 4][1] > 1.0 / window_h) { for(j = 0; j < num_vertices; j++) { shapes[i].circle_vertices[j][1] -= 1.0 / window_h; shapes[i].circle_vertices[j][0] += shapes[i].force_x / window_w; shapes[i].circle_vertices[j][1] += shapes[i].force_y / window_h; } } } } glutTimerFunc(20, my_TimeOut, 0);/* schedule next timer event, 20 msecs from now */ my_display(); }
/* TODO for EC: have more fun in here */ void my_mouse(int b, int s, int x, int y) { switch (b) { /* b indicates the button */ case GLUT_LEFT_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Left button pressed at %d %d\n", x, y); my_x = x; my_y = window_h - y; rect_or_circle *= -1; shapes[curr] = new Shape(rect_or_circle, my_x, my_y); curr += 1; curr = curr % 25; my_display(); } else if (s == GLUT_UP) { /* button released */ printf("Left button released\n"); } break; case GLUT_RIGHT_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Right button pressed\n"); } else if (s == GLUT_UP) { /* button released */ printf("Right button released\n"); } break; case GLUT_MIDDLE_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Middle button pressed at %d %d\n", x, y); } else if (s == GLUT_UP) { /* button released */ printf("Middle button released\n"); } break; } }
/* called if mouse event (i.e., mouse click) */ void my_mouse(int b, int s, int x, int y) { switch (b) { /* b indicates the button */ case GLUT_LEFT_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Left button pressed at %d %d\n", x, y); //Filling the struct for the new shape if(num_shapes < 25) { num_shapes++; } shapes[shapes_head].type = next_shape; //next_shape = (next_shape + 1) % 2; //cycles it between 0 and 1 if(next_shape == 0) next_shape = 1; else next_shape = 0; shapes[shapes_head].color[2] = 1; //default to blue if(shapes[shapes_head].type == 1) shapes[shapes_head].color[0] = 1; //if its a circle, switch to red shapes[shapes_head].radius = window_w / 13; //its a good proportion shapes[shapes_head].x = x; //set the position of the shape shapes[shapes_head].y = window_h - y; //sets up the vertices of the circle, if it is time for a circle rather than a rectangle if(shapes[shapes_head].type == 1) { for(i = 0; i < num_vertices; i++) { shapes[shapes_head].circle_vertices[i][0] = (shapes[shapes_head].x + cos((float)(i)/num_vertices * 2 * M_PI) * shapes[shapes_head].radius) / window_w; //printf("%f ", circle_vertices[i][0]); shapes[shapes_head].circle_vertices[i][1] = (shapes[shapes_head].y + sin((float)(i)/num_vertices * 2 * M_PI) * shapes[shapes_head].radius) / window_h; //printf("%f\n", circle_vertices[i][1]); } } //advance the head of the circular array shapes_head++; if(shapes_head > 24) { shapes_head = 0; } my_display(); } else if (s == GLUT_UP) { /* button released */ printf("Left button released\n"); } break; case GLUT_RIGHT_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Right button pressed\n"); } else if (s == GLUT_UP) { /* button released */ printf("Right button released\n"); } break; case GLUT_MIDDLE_BUTTON: if (s == GLUT_DOWN) { /* button pressed */ printf("Middle button pressed at %d %d\n", x, y); } else if (s == GLUT_UP) { /* button released */ printf("Middle button released\n"); } break; } }