// main function int main() { CountRanking(); while(1){ selection=StartMenu(selection); switch(selection){ case '1': // 게임 시작 GamePlay(); return 0; case '2': // Ranking 확인 ViewRanking(); break; case '3': // 도움말 HelpScreen(); break; case '4': // 게임 종료 ExitGame(); system("PAUSE"); return 0; break; } // switch } // while return 0; }
int main(int argc, char **argv) { int cfgresult; int c; /* set locale for cwdate & time formatting in chrono.c */ setlocale(LC_TIME, ""); /* get uname information */ if (uname(&unamebuf) == -1) { perror("uname"); return (EXIT_FAILURE); } /* setup error handlers */ signal(SIGINT, exit_program); /* Ctrl-C */ signal(SIGTERM, exit_program); /* "regular" kill */ signal(SIGHUP, exit_program); /* kill -HUP */ signal(SIGPIPE, exit_program); /* write to closed socket */ signal(SIGKILL, exit_program); /* kill -9 [cannot be trapped; but ...] */ /* No error output from getopt */ opterr = 0; /* get options from command line */ while ((c = getopt(argc, argv, "s:p:e:c:fhv")) > 0) { char *end; switch (c) { /* c is for config file */ case 'c': configfile = optarg; break; /* s is for server */ case 's': server = optarg; break; /* p is for port */ case 'p': port = strtol(optarg, &end, 0); if ((*optarg == '\0') || (*end != '\0') || (port <= 0) || (port >= 0xFFFF)) { fprintf(stderr, "Illegal port value %s\n", optarg); exit(EXIT_FAILURE); } break; case 'e': islow = strtol(optarg, &end, 0); if ((*optarg == '\0') || (*end != '\0') || (islow < 0)) { fprintf(stderr, "Illegal delay value %s\n", optarg); exit(EXIT_FAILURE); } break; case 'f': foreground = TRUE; break; case 'h': HelpScreen(EXIT_SUCCESS); break; case 'v': fprintf(stderr, "LCDproc %s\n", version); exit(EXIT_SUCCESS); break; /* otherwise... Get help! */ case '?': /* unknown option or missing argument */ /* FALLTHROUGH */ default: HelpScreen(EXIT_FAILURE); break; } } /* Read config file */ cfgresult = process_configfile(configfile); if (cfgresult < 0) { fprintf(stderr, "Error reading config file\n"); exit(EXIT_FAILURE); } /* Set default reporting options */ if (report_dest == UNSET_INT) report_dest = DEFAULT_REPORTDEST; if (report_level == UNSET_INT) report_level = DEFAULT_REPORTLEVEL; /* Set reporting settings */ set_reporting("lcdproc", report_level, report_dest); /* parse non-option arguments: modes to add/delete */ if (argc > max(optind, 1)) { int i; /* * if no config file was read, ignore hard coded default * modes */ if (cfgresult == 0) clear_modes(); /* turn additional options on or off (using ! as prefix) */ for (i = max(optind, 1); i < argc; i++) { int state = (*argv[i] == '!') ? 0 : 1; char *name = (state) ? argv[i] : argv[i] + 1; int shortname = (strlen(name) == 1) ? name[0] : '\0'; int found = set_mode(shortname, name, state); if (!found) { fprintf(stderr, "Invalid Screen: %s\n", name); return (EXIT_FAILURE); } } } if (server == NULL) server = DEFAULT_SERVER; /* Connect to the server... */ sock = sock_connect(server, port); if (sock < 0) { fprintf(stderr, "Error connecting to LCD server %s on port %d.\n" "Check to see that the server is running and operating normally.\n", server, port); return (EXIT_FAILURE); } sock_send_string(sock, "hello\n"); usleep(500000); /* wait for the server to say hi. */ /* We grab the real values below, from the "connect" line. */ lcd_wid = 20; lcd_hgt = 4; lcd_cellwid = 5; lcd_cellhgt = 8; if (foreground != TRUE) { if (daemon(1, 0) != 0) { fprintf(stderr, "Error: daemonize failed\n"); return (EXIT_FAILURE); } if (pidfile != NULL) { FILE *pidf = fopen(pidfile, "w"); if (pidf) { fprintf(pidf, "%d\n", (int)getpid()); fclose(pidf); pidfile_written = TRUE; } else { fprintf(stderr, "Error creating pidfile %s: %s\n", pidfile, strerror(errno)); return (EXIT_FAILURE); } } } /* Init the status gatherers... */ mode_init(); /* And spew stuff! */ main_loop(); exit_program(EXIT_SUCCESS); /* NOTREACHED */ return EXIT_SUCCESS; }
static HandleInputResult HandleInput( int c, int m, int *xc, int *yc, int *xcOld, int *ycOld, Mission *scrap) { HandleInputResult result = { false, false, false, false }; Mission *mission = CampaignGetCurrentMission(&gCampaign); UIObject *o = NULL; brush.Pos = GetMouseTile(&gEventHandlers); // Find whether the mouse has hovered over a tooltip bool hadTooltip = sTooltipObj != NULL; if (!UITryGetObject(sObjs, gEventHandlers.mouse.currentPos, &sTooltipObj) || !sTooltipObj->Tooltip) { sTooltipObj = NULL; } // Need to redraw if we either had a tooltip (draw to remove) or there's a // tooltip to draw if (hadTooltip || sTooltipObj) { result.Redraw = true; } // Make sure a redraw is done immediately if the resolution changes // Otherwise the resolution change is ignored and we try to redraw // later, when the draw buffer has not yet been recreated if (gEventHandlers.HasResolutionChanged) { result.Redraw = true; } // Also need to redraw if the brush is active to update the highlight if (brush.IsActive) { result.Redraw = true; } if (m && (m == SDL_BUTTON_LEFT || m == SDL_BUTTON_RIGHT || m == SDL_BUTTON_WHEELUP || m == SDL_BUTTON_WHEELDOWN)) { result.Redraw = true; if (UITryGetObject(sObjs, gEventHandlers.mouse.currentPos, &o)) { if (!o->DoNotHighlight) { if (sLastHighlightedObj) { UIObjectUnhighlight(sLastHighlightedObj); } sLastHighlightedObj = o; UIObjectHighlight(o); } CArrayTerminate(&sDrawObjs); *xcOld = *xc; *ycOld = *yc; // Only change selection on left/right click if (m == SDL_BUTTON_LEFT || m == SDL_BUTTON_RIGHT) { if (!(o->Flags & UI_LEAVE_YC)) { *yc = o->Id; AdjustYC(yc); } if (!(o->Flags & UI_LEAVE_XC)) { *xc = o->Id2; AdjustXC(*yc, xc); } } if (!(o->Flags & UI_SELECT_ONLY) && (!(o->Flags & UI_SELECT_ONLY_FIRST) || (*xc == *xcOld && *yc == *ycOld))) { if (m == SDL_BUTTON_LEFT || m == SDL_BUTTON_WHEELUP) { c = SDLK_PAGEUP; } else if (m == SDL_BUTTON_RIGHT || m == SDL_BUTTON_WHEELDOWN) { c = SDLK_PAGEDOWN; } } } else { if (!(brush.IsActive && mission)) { UIObjectUnhighlight(sObjs); CArrayTerminate(&sDrawObjs); sLastHighlightedObj = NULL; } } } if (!o && (MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_LEFT) || MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_RIGHT))) { result.Redraw = true; if (brush.IsActive && mission->Type == MAPTYPE_STATIC) { // Draw a tile if (IsBrushPosValid(brush.Pos, mission)) { int isMain = MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_LEFT); EditorResult r = EditorBrushStartPainting(&brush, mission, isMain); if (r == EDITOR_RESULT_CHANGED || r == EDITOR_RESULT_CHANGED_AND_RELOAD) { fileChanged = 1; Autosave(); result.RemakeBg = true; sHasUnbakedChanges = true; } if (r == EDITOR_RESULT_CHANGED_AND_RELOAD) { Setup(0); } } } } else { if (mission) { // Clamp brush position brush.Pos = Vec2iClamp( brush.Pos, Vec2iZero(), Vec2iMinus(mission->Size, Vec2iUnit())); EditorResult r = EditorBrushStopPainting(&brush, mission); if (r == EDITOR_RESULT_CHANGED || r == EDITOR_RESULT_CHANGED_AND_RELOAD) { fileChanged = 1; Autosave(); result.Redraw = true; result.RemakeBg = true; sHasUnbakedChanges = true; } if (r == EDITOR_RESULT_CHANGED_AND_RELOAD) { Setup(0); } } } // Pan the camera based on keyboard cursor keys if (mission) { if (KeyIsDown(&gEventHandlers.keyboard, SDLK_LEFT)) { camera.x -= CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } else if (KeyIsDown(&gEventHandlers.keyboard, SDLK_RIGHT)) { camera.x += CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } if (KeyIsDown(&gEventHandlers.keyboard, SDLK_UP)) { camera.y -= CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } else if (KeyIsDown(&gEventHandlers.keyboard, SDLK_DOWN)) { camera.y += CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } // Also pan the camera based on middle mouse drag if (MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_MIDDLE)) { camera = Vec2iAdd(camera, Vec2iMinus( gEventHandlers.mouse.previousPos, gEventHandlers.mouse.currentPos)); result.Redraw = result.RemakeBg = true; } camera.x = CLAMP(camera.x, 0, Vec2iCenterOfTile(mission->Size).x); camera.y = CLAMP(camera.y, 0, Vec2iCenterOfTile(mission->Size).y); } bool hasQuit = false; if (gEventHandlers.keyboard.modState & (KMOD_ALT | KMOD_CTRL)) { result.Redraw = true; switch (c) { case 'z': // Undo // Do this by swapping the current mission with the last mission // This requires a bit of copy-acrobatics; because missions // are saved in Setup(), but by this stage the mission has already // changed, _two_ mission caches are used, copied in sequence. // That is, if the current mission is at state B, the first cache // is still at state B (copied after the mission has changed // already), and the second cache is at state A. // If we were to perform an undo and still maintain functionality, // we need to copy such that the states change from B,B,A to // A,A,B. // However! The above is true only if we have "baked" changes // The editor has been optimised to perform some changes // without reloading map files; that is, the files are actually // in states C,B,A. // In this case, another set of "acrobatics" is required if (sHasUnbakedChanges) { MissionCopy(&lastMission, mission); // B,A,Z -> B,A,B } else { MissionCopy(mission, &lastMission); // B,B,A -> A,B,A MissionCopy(&lastMission, ¤tMission); // A,B,A -> A,B,B } fileChanged = 1; Setup(0); // A,B,B -> A,A,B break; case 'x': MissionTerminate(scrap); MissionCopy(scrap, mission); Delete(*xc, *yc); break; case 'c': MissionTerminate(scrap); MissionCopy(scrap, mission); break; case 'v': // Use map size as a proxy to whether there's a valid scrap mission if (!Vec2iEqual(scrap->Size, Vec2iZero())) { InsertMission(&gCampaign, scrap, gCampaign.MissionIndex); fileChanged = 1; Setup(0); } break; case 'q': hasQuit = true; break; case 'n': InsertMission(&gCampaign, NULL, gCampaign.Setting.Missions.size); gCampaign.MissionIndex = gCampaign.Setting.Missions.size - 1; fileChanged = 1; Setup(0); break; case 'o': if (!fileChanged || ConfirmScreen( "File has been modified, but not saved", "Open anyway? (Y/N)")) { Open(); } break; case 's': Save(); break; case 'm': result.WillDisplayAutomap = true; break; case 'e': EditCharacters(&gCampaign.Setting); Setup(0); UIObjectUnhighlight(sObjs); CArrayTerminate(&sDrawObjs); break; } } else { if (c != 0) { result.Redraw = true; } switch (c) { case SDLK_F1: HelpScreen(); break; case SDLK_HOME: if (gCampaign.MissionIndex > 0) { gCampaign.MissionIndex--; } Setup(0); break; case SDLK_END: if (gCampaign.MissionIndex < (int)gCampaign.Setting.Missions.size) { gCampaign.MissionIndex++; } Setup(0); break; case SDLK_INSERT: switch (*yc) { case YC_CHARACTERS: if (gCampaign.Setting.characters.OtherChars.size > 0) { int ch = 0; CArrayPushBack(&mission->Enemies, &ch); CharacterStoreAddBaddie(&gCampaign.Setting.characters, ch); *xc = mission->Enemies.size - 1; } break; case YC_SPECIALS: if (gCampaign.Setting.characters.OtherChars.size > 0) { int ch = 0; CArrayPushBack(&mission->SpecialChars, &ch); CharacterStoreAddSpecial(&gCampaign.Setting.characters, ch); *xc = mission->SpecialChars.size - 1; } break; case YC_ITEMS: { int item = 0; CArrayPushBack(&mission->Items, &item); CArrayPushBack(&mission->ItemDensities, &item); *xc = mission->Items.size - 1; } break; default: if (*yc >= YC_OBJECTIVES) { AddObjective(mission); } else { InsertMission(&gCampaign, NULL, gCampaign.MissionIndex); } break; } fileChanged = 1; Setup(0); break; case SDLK_DELETE: Delete(*xc, *yc); break; case SDLK_PAGEUP: if (Change(o, *yc, 1)) { fileChanged = 1; } Setup(0); break; case SDLK_PAGEDOWN: if (Change(o, *yc, -1)) { fileChanged = 1; } Setup(0); break; case SDLK_ESCAPE: hasQuit = true; break; case SDLK_BACKSPACE: fileChanged |= UIObjectDelChar(sObjs); break; default: c = KeyGetTyped(&gEventHandlers.keyboard); if (c) { fileChanged |= UIObjectAddChar(sObjs, (char)c); } break; } } if (gEventHandlers.HasQuit) { hasQuit = true; } if (hasQuit && (!fileChanged || ConfirmScreen( "File has been modified, but not saved", "Quit anyway? (Y/N)"))) { result.Done = true; } return result; }
int main (int argc, char ** argv) { int arg; int status; int count; int silent = FALSE; /* default is to be verbose 2/10/1998 jhrg */ fin = stdin; fout = stdout; /* Scan command line for parameters */ for (arg=1; arg<argc; arg++) { if (*argv[arg] == '-') { /* Buffer size */ if (!strcmp(argv[arg], "-b")) { buffer_size = (arg+1 < argc && *argv[arg+1] != '-') ? atoi(argv[++arg]) : DEFAULT_BUFFER_SIZE; buffer_size = MAX(buffer_size, 256); /* Compression rate */ } else if (!strcmp(argv[arg], "-c")) { compression_rate = (arg+1 < argc && *argv[arg+1] != '-') ? atoi(argv[++arg]) : DEFAULT_COMPRESSION; compression_rate = MAX(compression_rate, Z_BEST_SPEED); compression_rate = MIN(compression_rate, Z_BEST_COMPRESSION); /* Print the help screen and exit */ } else if (!strcmp(argv[arg], "-h")) { HelpScreen(*argv); exit(0); } else if (!strcmp(argv[arg], "-s")) { silent = TRUE; } else { HelpScreen(*argv); exit(-1); } } else { HelpScreen(*argv); exit(-1); } } if ((input_buffer = (unsigned char *) calloc(1, buffer_size)) == NULL || (output_buffer = (unsigned char *) calloc(1, buffer_size)) == NULL) { fprintf(stderr, "Not enough memory\n"); exit(-1); } deflateInit(&z, compression_rate); z.avail_in = 0; z.next_out = output_buffer; z.avail_out = buffer_size; for ( ; ; ) { if ( z.avail_in == 0 ) { z.next_in = input_buffer; z.avail_in = fread( input_buffer, 1, buffer_size, fin ); } if ( z.avail_in == 0 ) { status = deflate( &z, Z_FINISH ); count = buffer_size - z.avail_out; if ( count ) fwrite( output_buffer, 1, count, fout ); break; } status = deflate( &z, Z_NO_FLUSH ); count = buffer_size - z.avail_out; if ( count ) fwrite( output_buffer, 1, count, fout ); z.next_out = output_buffer; z.avail_out = buffer_size; } if (!silent) fprintf(stderr, "Compressing data: raw data %lu, compressed %lu, factor %.2f, compression level (default = -1) %d, buffer size %d\n", z.total_in, z.total_out, z.total_in == 0 ? 0.0 : (double)z.total_out / z.total_in, compression_rate, buffer_size); deflateEnd(&z); fflush(stdout); if (input_buffer) free(input_buffer); if (output_buffer) free(output_buffer); return 0; }