看你有多色

时间:2024-09-14 08:20:09编辑:花茶君

【C++这段代码是什么意思?求解……】

{ ifstream in("Poker.txt");//读取文件 if(!in){ //文件不存在 cout>name; //读取名字 in>>color; // 读取颜色 in>>num; //读取数量 switch(color){ case 0: //颜色值为0表示方块 suit=Diamond; break; case 1://颜色值为1表示红桃 suit=Heart; break; case 2://颜色值为2表示梅花 suit=Club; break; case 3://颜色值为3表示黑桃 suit=Spade; break; default://没有读到颜色值 suit=NoSuit; break; } //下面根据读取到的名字来创建不同的牌 if(name=="杀"){ newpoker=new Slash(suit,name,num); }else if(name=="闪"){ newpoker=new Jink(suit,name,num); }else if(name=="桃"){ newpoker=new Peach(suit,name,num); }else if(name=="乐不思蜀"){ newpoker=new Indulgence(suit,name,num); }else if(name=="闪电"){ newpoker=new Lightning(suit,name,num); }else if(name=="借刀杀人"){ newpoker=new Collateral(suit,name,num); }else if(name=="无懈可击"){ newpoker=new Nullification(suit,name,num); }else if(name=="无中生有"){ newpoker=new ExNihilo(suit,name,num); }else if(name=="过河拆桥"){ newpoker=new Dismantlement(suit,name,num); }else if(name=="决斗"){ newpoker=new Duel(suit,name,num); }else if(name=="五谷丰登"){ newpoker=new AmazingGrace(suit,name,num); }else if(name=="顺手牵羊"){ newpoker=new Snatch(suit,name,num); }else if(name=="南蛮入侵"){ newpoker=new SavageAssault(suit,name,num); }else if(name=="桃园结义"){ newpoker=new GodSalvation(suit,name,num); }else if(name=="万箭齐发"){ newpoker=new ArcheryAttack(suit,name,num); }else if(name=="八卦阵"){ newpoker=new Armor(suit,name,num); }else if(name=="仁王盾"){ newpoker=new Armor(suit,name,num); }else if(name=="赤兔-1"){ newpoker=new OffensiveHorse(suit,name,num); }else if(name=="紫骍-1"){ newpoker=new OffensiveHorse(suit,name,num); }else if(name=="大宛-1"){ newpoker=new OffensiveHorse(suit,name,num); }else if(name=="的卢+1"){ newpoker=new DefensiveHorse(suit,name,num); }else if(name=="绝影+1"){ newpoker=new DefensiveHorse(suit,name,num); }else if(name=="爪黄飞电+1"){ newpoker=new DefensiveHorse(suit,name,num); }else if(name=="诸葛连弩1"){ newpoker=new Weapon(suit,name,num); }else if(name=="贯石斧3"){ newpoker=new Weapon(suit,name,num); }else if(name=="方天画戟4"){ newpoker=new Weapon(suit,name,num); }else if(name=="雌雄双股剑2"){ newpoker=new Weapon(suit,name,num); }else if(name=="丈八蛇矛3"){ newpoker=new Weapon(suit,name,num); }else if(name=="青釭剑2"){ newpoker=new Weapon(suit,name,num); }else if(name=="青龙偃月刀3"){ newpoker=new Weapon(suit,name,num); }else if(name=="麒麟弓5"){ newpoker=new Weapon(suit,name,num); }else if(name=="寒冰剑2"){ newpoker=new Weapon(suit,name,num); }//else if(name==""){} else{newpoker=NULL; } //从函数名判断这句是把最后一张读到的牌作为手上最上面的一张牌 this->setPokerToTop(newpoker); }//end of while // //下面是初始化随机数,但是没有调用,可能只是让系统随机消耗一些CPU时间 srand(unsigned(time(NULL))); //下面是将unused中的对象随机排列 random_shuffle(Unused.begin(),Unused.end()); }


C++ 游戏 (看你有多色) 代码

/* 看你有多色小游戏 * * 曙光 2014年11月19日16:18*/#include #include #include #ifndef _T#ifdef UNICODE#define _T(str) L ## str#else#define _T(str) str#endif // UNICODE#endif // _T#if ! __STDC_WANT_SECURE_LIB__#define strcpy_s(DstText, TextLen, SrcText) strcpy(DstText, SrcText) #define strcat_s(DstText, TextLen, SrcText) strcat(DstText, SrcText) #define _itoa_s(Val, Text, TextLen, Radix) itoa(Val, Text, Radix)#endif// 全局变量HWND MainWindow; // 主窗口int TruthX, TruthY; // 正确答案坐标int ArraySize, Level; // 颜色块矩阵边长、级别COLORREF ColorDef, ColorTruth;// 默认颜色与正确答案颜色// 画矩形BOOL PolyRect(HDC hdc, LONG left, LONG top, LONG width, LONG hight) {POINT point[4];point[0].x = left;point[0].y = top;point[1].x = left + width;point[1].y = top;point[2].x = left + width;point[2].y = top + hight;point[3].x = left;point[3].y = top + hight;return Polygon(hdc, point, 4);}// 重绘窗口事件void PaintWindow(void) {HBRUSH hBrush, hOldBrush;PAINTSTRUCT ps;HDC hdc;RECT rect;int x, y;double w, h;ArraySize = ArraySize 100) {MessageBox(MainWindow, _T("您已经通关了,在下佩服!"), _T("通关提示"), 0);}lev = lev 100 ? 1 : lev;ArraySize = lev / 10 + 2;Level = lev;TruthX = rand() % ArraySize;TruthY = rand() % ArraySize;r = rand() & 0x7f;g = rand() & 0x7f;b = rand() & 0x7f;ColorDef = RGB(r, g, b);ColorTruth = RGB(r + 51 - lev / 2, g + 51 - lev / 2, b + 51 - lev / 2);InvalidateRect(MainWindow, NULL, TRUE);strcpy_s(text, sizeof(text), "看你有多色 - 第");_itoa_s(lev, text + strlen(text), 4, 10);strcat_s(text, sizeof(text), "关");SetWindowTextA(MainWindow, text);}// 点击事件响应void WindowClick(int x, int y) {char text[1024];RECT rect;double w, h;GetClientRect(MainWindow, &rect);w = (double) (rect.right - rect.left) / ArraySize;h = (double) (rect.bottom - rect.top) / ArraySize;x = x / (int) w;y = y / (int) h;if (x == TruthX && y == TruthY) {NewGame(Level + 1);} else {strcpy_s(text, sizeof(text), "你点错了哦,正确答案:");_itoa_s(TruthX + 1, text + strlen(text), 3, 10);strcat_s(text, sizeof(text), ",");_itoa_s(TruthY + 1, text + strlen(text), 3, 10);MessageBoxA(MainWindow, text, "重新开始", 0);NewGame(1);}}// 窗口消息响应LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch (uMsg) {case WM_DESTROY: // 窗口销毁PostQuitMessage(0);break;case WM_SIZE: // 窗口大小被改变InvalidateRect(hWnd, NULL, TRUE);break;case WM_PAINT: // 重绘窗口PaintWindow();break;case WM_LBUTTONDOWN: // 鼠标左键按下WindowClick(LOWORD(lParam), HIWORD(lParam));break;default:return DefWindowProc(hWnd, uMsg, wParam, lParam);}return 0;}// 入口函数int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow) {WNDCLASSEX wce;MSG msg;// 注册窗口类wce.cbSize = sizeof(wce);wce.style = 0;wce.lpfnWndProc = (WNDPROC) WndProc; // 窗口消息处理函数wce.cbClsExtra = wce.cbWndExtra = 0;wce.hInstance = hInstance;wce.hCursor = LoadCursor(NULL,IDC_ARROW);wce.hbrBackground = (HBRUSH) COLOR_BTNSHADOW;wce.hIcon = wce.hIconSm = LoadIcon(NULL,IDI_APPLICATION);wce.lpszClassName = _T("ShuGuang");wce.lpszMenuName = NULL;RegisterClassEx(&wce);MainWindow = CreateWindowEx(0, _T("ShuGuang"), _T("看你有多色"), WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, hInstance, NULL);ShowWindow(MainWindow, nCmdShow);UpdateWindow(MainWindow);srand(GetTickCount());NewGame(1);// 消息循环while (GetMessage(&msg, NULL, 0, 0)) {TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}水平有限,可以参考 呵呵

上一篇:daring in the franxx

下一篇:没有了