void ShowMenu(void) { ConSetBackgroundColor(ConBlack); ConSetTextColor(ConRed); ConClear(); ConSetBackgroundColor(ConWhite); ConOutputString("\n"); ConOutputString("小怪兽 - version 1.0\n"); ConSetBackgroundColor(ConBlack); ConSetTextColor(ConWhite); ConSetPosition(1, 4); ConOutputString("你想干嘛!!!"); ConSetPosition(3, 6); ConOutputString("1 - 开始游戏 - 简单"); ConSetPosition(3, 7); ConOutputString("2 - 开始游戏 - 普通"); ConSetPosition(3, 8); ConOutputString("3 - 开始游戏 - 困难"); ConSetPosition(3, 10); ConOutputString("L - 加载游戏"); ConSetPosition(3, 12); ConOutputString("Q - 退出游戏"); }
void Show(void) { /* 初始化控制台 */ ConSetBackgroundColor(ConBlack); ConSetTextColor(ConWhite); ConClear(); switch(iGameStatus) { case GameMainMenu: ShowMenu(); break; case GameRunning: ShowGame(); break; case GameWon: ShowWon(); break; case GameLostLife: ShowLostLife(); break; case GameLost: ShowLost(); break; case GameExit: ShowExit(); break; case GameSplashScreen: ShowSplash(); break; default: break; }/* switch */ }
void ShowExit(void) { ConSetBackgroundColor(ConBlack); ConSetTextColor(ConWhite); ConClear(); ConOutputString("\n\t小怪兽 v 1.0\n\n\n"); ConOutputString("by: Wener ([email protected])\n"); ConOutputString("Bay!\n"); }
/* 显示相关信息 */ void ShowSplash(void) { ConClear(); ConOutputString("\t小怪兽 v 1.0\n\n"); ConOutputString("\t一个异常简单的小游戏咯!\n\n"); ConOutputString("游戏目标为消灭所有小怪兽,当两个\n"); ConOutputString("小怪兽进入到一个区域时,两个都被\n"); ConOutputString("消灭,当你和小怪兽同时进入一个区\n"); ConOutputString("域时,怪兽被消灭,你被降低一滴血\n"); ConOutputString("用小键盘的8个键进行移动,也可以\n"); ConOutputString("按 INSERT 键来进行随机的跳跃\n\n"); ConSetTextColor(ConRed); ConOutputString("注意:确认 NUMLOCK 是关闭的\n\n"); ConSetTextColor(ConWhite); ConOutputString("有以下难度可供选择:\n\n"); ConOutputString("简单: 怪兽数 = 10 区域 = 25*15\n"); ConOutputString(" 生命数 = 4 跳跃数 = 3\n"); ConOutputString("普通: 怪兽数 = 20 区域 = 35*18\n"); ConOutputString(" 生命数 = 3 跳跃数 = 2\n"); ConOutputString("困难: 怪兽数 = 30 区域 = 50*23\n"); ConOutputString(" 生命数 = 2 跳跃数 = 1\n"); }
void CConsoleTab::OnMaxtextConedit(void) { ConClear(); }
void DisplayHelp( const char * unrecognized_option ) { static const char *valid_help_requests[] = { "-help", "--help", "help", "-h", "/h", "/?", "-?", "?", "/help" }; static const char *helpheader[] = { "distributed.net v" CLIENT_VERSIONSTRING " client for " CLIENT_OS_NAME_EXTENDED, "Visit http://faq.distributed.net/ for in-depth command line help", "-------------------------------------------------------------------------" }; int headerlines, bodylines, footerlines; int startline, maxscreenlines, maxpagesize; int i, key, nopaging = (!ConIsScreen()); char linebuffer[128]; if (ConGetSize(NULL,&maxscreenlines) == -1) maxscreenlines = 25; headerlines = (sizeof(helpheader) / sizeof(char *)); bodylines = (sizeof(helpbody) / sizeof(char *)); footerlines = 2; startline = 0; maxpagesize = maxscreenlines - (headerlines + footerlines); #if defined(NO_INTERNAL_PAGING) nopaging = 1; #endif /* -------------------------------------------------- */ if (unrecognized_option && *unrecognized_option) { int goodopt = 0; for (i = 0; ((goodopt == 0) && (i < (int) (sizeof(valid_help_requests)/sizeof(char *)))); i++) { int n=0; for (;((valid_help_requests[i][n])!=0 && unrecognized_option[n]!=0);n++) { if (tolower(valid_help_requests[i][n])!=tolower(unrecognized_option[n])) break; } goodopt = ((valid_help_requests[i][n])==0 && unrecognized_option[n]==0); } if (!goodopt) { if (strlen(unrecognized_option) > 25) LogScreenRaw( "\nUnrecognized option '%25.25s...'\n\n", unrecognized_option); else LogScreenRaw( "\nUnrecognized option '%s'\n\n", unrecognized_option); LogScreenRaw( "The following list of command line switches may be obtained\n" "at any time by running the client with the '-help' option.\n\n"); if (!nopaging) { LogScreenRaw("Press enter to continue... "); key = ConInKey(-1); /* -1 == wait forever. returns zero if break. */ LogScreenRaw( "\r \r" ); if (CheckExitRequestTriggerNoIO()) return; if (key != '\n' && key != '\r' && key != ' ') return; } } } /* -------------------------------------------------- */ if (nopaging || (maxscreenlines > (headerlines+bodylines))) { for (i = 0; i < headerlines; i++) LogScreenRaw( "%s\n", helpheader[i] ); for (i = 0; i < bodylines; i++) LogScreenRaw( "%s\n", helpbody[i] ); return; } /* -------------------------------------------------- */ key = 0; do { if (key == 0) /* refresh required */ { ConClear(); for (i = 0; i < headerlines; i++) LogScreenRaw( "%s\n", helpheader[i] ); for (i = startline; i < (startline+maxpagesize); i++) LogScreenRaw( "%s\n", helpbody[i] ); LogScreenRaw("\n"); } if (startline == 0) strcpy( linebuffer, "Press '+' for the next page,"); else if (startline >= ((bodylines-maxpagesize)-1)) strcpy( linebuffer, "Press '-' for the previous page,"); else strcpy( linebuffer, "Press '+' or '-' for the next/previous page,"); strcat( linebuffer, " 'Esc' or 'Q' to quit... "); LogScreenRaw( linebuffer ); key = ConInKey(-1); linebuffer[i=strlen(linebuffer)]='\r'; linebuffer[i+1]=0; for (--i; i > 0; i--) linebuffer[i]=' '; linebuffer[0]='\r'; LogScreenRaw( linebuffer ); if (CheckExitRequestTriggerNoIO()) break; if (key == '+' || key == '=' || key == ' ' || key == 'f' || key == '\r' || key == '\n') { if (startline <= ((bodylines-maxpagesize) - 1)) { startline += maxpagesize; if ( startline >= (bodylines-maxpagesize)) startline = (bodylines-maxpagesize); key = 0; //refresh required } else if (key == ' ' || key == '\r' || key == '\n') { key = -1; // quit if space or enter pressed on last page } } else if (key == '-' || key == 'b') { if (startline > 0) { startline -= maxpagesize; if ( startline < 0 ) startline = 0; key = 0; //refresh required } } else { key = -1; //unknown keystroke, so quit } } while (key >= 0); return; }
int mainCRTStartup(void) { handle_t server, client; unsigned i; params_vid_t params; font_t *font; vid = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE); if (vid == NULL) { _wdprintf(L"console: " SYS_DEVICES L"/Classes/video0: %s\n", _wcserror(errno)); return errno; } memset(&mode, 0, sizeof(mode)); params.vid_setmode = mode; if (!FsRequestSync(vid, VID_SETMODE, ¶ms, sizeof(params), NULL)) { _wdprintf(L"console: failed to set video mode: %s\n", _wcserror(errno)); HndClose(vid); return errno; } mode = params.vid_setmode; if (mode.flags & VIDEO_MODE_TEXT) { _wdprintf(L"console: text mode not supported\n"); return 0; } if (mode.bitsPerPixel == 4) { vidmem = NULL; if (!AccelCreateSurface(&mode, vid, &surf)) { _wdprintf(L"console: AccelCreateSurface failed\n"); return errno; } } else { handle_t handle_vidmem; handle_vidmem = HndOpen(mode.framebuffer); if (handle_vidmem == 0) { _wdprintf(L"console: unable to open framebuffer %s\n", mode.framebuffer); return errno; } vidmem = VmmMapSharedArea(handle_vidmem, 0, VM_MEM_USER | VM_MEM_READ | VM_MEM_WRITE); HndClose(handle_vidmem); if (!FramebufCreateSurface(&mode, vidmem, &surf)) { _wdprintf(L"console: video mode not supported: %u bits per pixel\n", mode.bitsPerPixel); return errno; } } FontInit(); font = FontLoad(font_name, 10 * 64, mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH); if (font == NULL) { _wdprintf(L"console: failed to load font %s\n", font_name); return errno; } cookies[0] = (void*) 0x12345678; num_buffers = 1; LmuxInit(&lmux_consoles); for (i = 0; i < _countof(consoles); i++) { LmuxInit(&consoles[i].lmux); consoles[i].width = consoles[i].height = 0; consoles[i].fg_colour = consoles[i].default_fg_colour = 0xc0c0c0; consoles[i].bg_colour = consoles[i].default_bg_colour = 0x000000; consoles[i].cookie = cookies[0]; consoles[i].buf_chars = NULL; consoles[i].font = font; FontGetMaxSize(consoles[i].font, &consoles[i].char_width, &consoles[i].char_height); } num_consoles = _countof(consoles); ConTileBuffer(0); num_consoles = 0; current = consoles; for (i = 0; i < _countof(consoles); i++) ConClear(consoles + i); server = FsCreate(server_name, 0); ThrCreateThread(ConKeyboardThread, NULL, 16, L"ConKeyboardThread"); ThrCreateThread(ConCursorThread, NULL, 16, L"ConCursorThread"); ConDisplaySignonMessage(); while ((client = PortAccept(server, FILE_READ | FILE_WRITE))) { if (num_consoles < _countof(consoles)) { consoles[num_consoles].client = client; ThrCreateThread(ConClientThread, consoles + num_consoles, 15, L"ConClientThread"); num_consoles++; } else HndClose(client); } for (i = 0; i < _countof(consoles); i++) { LmuxDelete(&consoles[i].lmux); free(consoles[i].buf_chars); } LmuxDelete(&lmux_consoles); FontDelete(font); HndClose(server); if (vidmem != NULL) VmmFree(vidmem); HndClose(vid); return EXIT_SUCCESS; }
void ConDoEscape(console_t *console, int code, unsigned num, const unsigned *esc) { unsigned i; char buf[20]; colour_t temp_colour; static const colour_t ansi_to_colour[] = { 0x000000, /* black */ 0x800000, /* red */ 0x008000, /* green */ 0x808000, /* yellow */ 0x000080, /* blue */ 0x800080, /* magenta */ 0x008080, /* cyan */ 0xC0C0C0, /* white */ }; switch (code) { case 'H': /* ESC[PL;PcH - cursor position */ case 'f': /* ESC[PL;Pcf - cursor position */ if (num > 0) console->y = min(esc[0], console->height - 1); if (num > 1) console->x = min(esc[1], console->width - 1); break; case 'A': /* ESC[PnA - cursor up */ if (num > 0 && console->y >= esc[0]) console->y -= esc[0]; break; case 'B': /* ESC[PnB - cursor down */ if (num > 0 && console->y < console->height + esc[0]) console->y += esc[0]; break; case 'C': /* ESC[PnC - cursor forward */ if (num > 0 && console->x < console->width + esc[0]) console->x += esc[0]; break; case 'D': /* ESC[PnD - cursor backward */ if (num > 0 && console->x >= esc[0]) console->x -= esc[0]; break; case 's': /* ESC[s - save cursor position */ console->save_x = console->x; console->save_y = console->y; break; case 'u': /* ESC[u - restore cursor position */ console->x = console->save_x; console->y = console->save_y; break; case 'J': /* ESC[2J - clear screen */ ConClear(console); break; case 'K': /* ESC[K - erase line */ ConClearEol(console); break; case 'm': /* ESC[Ps;...Psm - set graphics mode */ if (num == 0) { console->fg_colour = console->default_fg_colour; console->bg_colour = console->default_bg_colour; } else for (i = 0; i < num; i++) { if (esc[i] <= 8) { switch (esc[i]) { case 0: /* all attributes off */ console->fg_colour = console->default_fg_colour; console->bg_colour = console->default_bg_colour; break; case 1: /* bold (high-intensity) */ console->fg_colour = ConColourLighter(console->default_fg_colour); break; case 4: /* underscore */ break; case 5: /* blink */ console->bg_colour = ConColourLighter(console->default_bg_colour); break; case 7: /* reverse video */ temp_colour = console->bg_colour; console->bg_colour = console->fg_colour; console->fg_colour = temp_colour; break; case 8: /* concealed */ console->fg_colour = console->bg_colour; break; } } else if (esc[i] >= 30 && esc[i] <= 37) /* foreground */ console->default_fg_colour = console->fg_colour = ansi_to_colour[esc[i] - 30]; else if (esc[i] >= 40 && esc[i] <= 47) /* background */ console->default_bg_colour = console->bg_colour = ansi_to_colour[esc[i] - 40]; } break; case 'h': /* ESC[=psh - set mode */ case 'l': /* ESC[=Psl - reset mode */ case 'p': /* ESC[code;string;...p - set keyboard strings */ /* not supported */ break; case 'n': /* ESC[Pnn - DSR - DEVICE STATUS REPORT */ switch (esc[0]) { case 6: /* send CPR - ACTIVE POSITION REPORT */ FsWrite(console->client, buf, 0, sprintf(buf, "\x1b[%u;%uR", console->y, console->x), NULL); break; } break; } }