版本比较
C++ 小游戏汇总
正文
增加 359 行删除 359 行
896 行未改动全部展开8978988999009019019029039049051,103 行未改动全部展开2009201020112012201320132014201520152016201720182019202020212022202120222023202420252024202520262027202820292030203020312032203320342035203620362037203820392039204020412042204220432044204520462047204820492050205020512052205320544 行未改动20592060206120622063206320642065206620673 行未改动20712072207320742075207520762077207820794 行未改动20842085208620872088208820892090209120922093209420952096209720972098209921002101210221032104210421052106210721082109211021112111211221132114211512 行未改动2128212921302131213221322133213421352136213721382139213921402141214221432144214521462147214821482149215021512152215321542155215621572158215821592160216121622163216321642165216621672168216921702170217121722173217415 行未改动219021912192219321942194219521962196219721982199219922002201220222032204220422052206220722089 行未改动2218221922202221222222222223222422252226222622272228222922305 行未改动223622372238223922402240224122422243224422452246224722482249224822492250225122522253225422552256225722582257225822592260226022612262226322643 行未改动2268226922702271227222722273227422742275227622772278227922792280228122822283228322842285228622872287228822892290229122922293229422952295229622972298229922992300230123022303230423042305230623062307230823092310231023112312231323142 行未改动23172318231923202321232123222323232423252326232623272328232923302 行未改动2333233423352336233723372338233923402341234223432344234523462346234723482349234923502351235223532354235523562356235723582358235923602361236223632364236423652366236723682369237023712372237223732374237523762376237723782379238023812382238323842385238523862387238723882389239023913 行未改动2395239623972398239923992400240124022403240424052405240624072408240924102411241124122413241324142415241624174 行未改动24222423242424252426242624272428242924302431243224332433243424352436243724382438243924402441244224432443244424452446244724482449244924502451245224535 行未改动245924602461246224632463246424652466246724672468246924702471247224732474247424752476247724782 行未改动24812482248324842485248524862487248824896 行未改动249624972498249925002500250125022503250425052506250625072508250925102511251125122513251425154 行未改动25202521252225232524252425252526252725282529252925302531253225332 行未改动25362537253825392540254025412542254325442545254625472548254825492550255125525 行未改动25582559256025612562256225632564256525667 行未改动25742575257625772578257825792580258125822583258225832584258525862586258725882589258925902591259225934 行未改动25982599260026012602260226032604260526062 行未改动260926102611261226132613261426152616261726182619262026212622262226232624262526262626262726282629263026312631263226332634263526362637263826382639264026412642264326432644264526462646264726482649265031 行未改动268226832684268526862686268726882689269026912692269326932694269526962697129 行未改动全部展开28272828282928302831283128322833283428351,723 行未改动全部展开4559456045614562456345634564456545664567555 行未改动全部展开51235124512551265127512751285129513051315132513351345135513651375137513851395140514136 行未改动5178517951805181518251825183518451855186518751885189518951905191519251935193519451955196519751985199519952005201520252033 行未改动52075208520952105211521152125213521452155216521652175218521952202 行未改动522352245225522652275227522852295230523152325232523352345235523621 行未改动525852595260526152625262526352645264526552665266526752685269526952705271527252725273527452755275527652775277527852795280528125 行未改动530753085309531053115311531253135314531511 行未改动532753285329533053315331533253335334533518 行未改动53545355535653575358535853595360536153625363536453655365536653675368536910 行未改动53805381538253835384538453855386538753882 行未改动539153925393539453955395539653975398539954005400540154025403540426 行未改动5431543254335434543554355436543754375438543954395440544154425443544454455446544754485449544954505451545254536 行未改动546054615462546354645464546554665467546812 行未改动548154825483548454855485548654875488548918 行未改动55085509551055115512551255135514551555164 行未改动5521552255235524552555255526552755285529553055315532553355345535553555365537553855395540554055415542554355444 行未改动55495550555155525553555355545555555655575558555955605561556255635563556455655566556716 行未改动558455855586558755885588558955905591559227 行未改动56205621562256235624562456255626562756282,668 行未改动全部展开8297829882998300830183018302830383048305362 行未改动全部展开8668866986708671867286728673867486758676135 行未改动全部展开881288138814881588168816881788188819882013 行未改动88348835883688378838883888398840884188429 行未改动8852885388548855885688568857885888598860489 行未改动全部展开9350935193529353935493549355935693569357935893599360936193629363936293639364936593669365936693679368936993709371937193729373937493759376937793779378937993809380938193829383938393849385938693879388938993909391939193929393939493954 行未改动94009401940294039404940494059406940794083 行未改动94129413941494159416941694179418941994204 行未改动94259426942794289429942994309431943294339434943594369437943894389439944094419442944394449445944594469447944894499450945194529452945394549455945612 行未改动9469947094719472947394739474947594769477947894799480948094819482948394849485948694879488948994899490949194929493949494959496949794989499949995009501950295039504950495059506950795089509951095119511951295139514951515 行未改动953195329533953495359535953695379537953895399540954095419542954395449545954595469547954895499 行未改动9559956095619562956395639564956595669567956795689569957095715 行未改动957795789579958095819581958295839584958595869587958895899590958995909591959295939594959595969597959895999598959996009601960196029603960496053 行未改动9609961096119612961396139614961596159616961796189619962096209621962296239624962496259626962796289628962996309631963296339634963596369636963796389639964096409641964296439644964596459646964796479648964996509651965196529653965496552 行未改动96589659966096619662966296639664966596669667966796689669967096712 行未改动9674967596769677967896789679968096819682968396849685968696879687968896899690969096919692969396949695969696979697969896999699970097019702970397049705970597069707970897099710971197129713971397149715971697179717971897199720972197229723972497259726972697279728972897299730973197323 行未改动9736973797389739974097409741974297439744974597469746974797489749975097519752975297539754975497559756975797584 行未改动97639764976597669767976797689769977097719772977397749774977597769777977897799779978097819782978397849784978597869787978897899790979097919792979397945 行未改动980098019802980398049804980598069807980898089809981098119812981398149815981598169817981898192 行未改动98229823982498259826982698279828982998306 行未改动983798389839984098419841984298439844984598469847984798489849985098519852985298539854985598564 行未改动98619862986398649865986598669867986898699870987098719872987398742 行未改动98779878987998809881988198829883988498859886988798889889988998909891989298935 行未改动98999900990199029903990399049905990699077 行未改动99159916991799189919991999209921992299239924992399249925992699279927992899299930993099319932993399344 行未改动99399940994199429943994399449945994699472 行未改动995099519952995399549954995599569957995899599960996199629963996399649965996699679967996899699970997199729972997399749975997699779978997999799980998199829983998499849985998699879987998899899990999131 行未改动10023100241002510026100271002710028100291003010031100321003310034100341003510036100371003810 行未改动1004910050100511005210053100531005410055100561005710 行未改动10068100691007010071100721007310072100731007410075100751007610077100771007810079100801008110082100831008410085100861008710087100881008910090100911009210091100921009310094100951009610097100971009810099101001010110102101031010410104101051010610107101081010910110101111011210113101131011410115101161011718 行未改动1013610137101381013910140101411014010141101421014310144101452 行未改动1014810149101501015110152101521015310154101551015610 行未改动101671016810169101701017110171101721017310174101754 行未改动101801018110182101831018410184101851018610187101881018910190101911019210192101931019410195101969 行未改动1020610207102081020910210102101021110212102121021310214102151021610216102171021810219102201022110222102231022110222102231022410225102261022713 行未改动102411024210243102441024510245102461024710248102498 行未改动10258102591026010261102621026210263102641026510266102661026710268102691027010271102721027310274102751027410275102761027710278102792 行未改动1028210283102841028510286102861028710288102881028910290102911029010291102921029310294102953 行未改动102991030010301103021030310303103041030510306103076 行未改动10314103151031610317103181031810319103201032110322103231032410325103261032710327103281032910330103311033210331103321033310334103351033616 行未改动10353103541035510356103571035710358103591036010361103621036310364103651036510366103671036810369103701037110372103731037410375103751037610377103781037910 行未改动103901039110392103931039410394103951039610397103971039810399104001040110401104021040310404104051040610407104081040810409104101041110412104131041410415104161041710417104181041910420104213 行未改动10425104261042710428104291043010429104301043110432104321043310434104341043510436104371043820 行未改动1045910460104611046210463104631046410465104661046710468104691047010470104711047210473104741047510476104721047310474104751047610477104781047910480104801048110482104831048410484104851048610487104881048910490104911049210493104931049410495104961049710498104981049910500105011050213 行未改动1051610517105181051910520105201052110522105231052410525105251052610527105281052916 行未改动10546105471054810549105501055010551105521055310554105551055610557105581055910560105601056110562105631056410565105661056610567105681056910570105701057110572105731057456 行未改动1063110632106331063410635106351063610637106381063915 行未改动106551065610657106581065910659106601066110662106621066310664106651066614 行未改动1068110682106831068410685106851068610687106881068915 行未改动1070510706107071070810709107091071010711107111071210713107141071517 行未改动107331073410735107361073710737107381073910740107419 行未改动1075110752107531075410755107551075610757107571075810759107601076110762107631076410764107651076610767107681076910770107711077210773107731077410775107761077715 行未改动10793107941079510796107971079710798107991080010800108011080210803108047 行未改动10812108131081410815108161081710818108161081710818108191082010821108223 行未改动1082610827108281082910830108301083110832108331083310834108351083610836108371083810839108401084110842108431084410845108381083910840108411084210843108441084510846108471084810849108501085110850108511085210853108541085510856108571085810859108601085810859108601086110862108631086410864108651086610867108681086910869108701087110872108721087310874108751087647 行未改动109241092510926109271092810928109291093010931109322 行未改动10935109361093710938109391093910940109411094210942109431094410945109461094710948109491095010951109511095210953109541095510956109571095710958109591096010961109611096210963109641096510965109661096710968109681096910970109711097210 行未改动109831098410985109861098710988109891098710988109891099010991109921099328 行未改动1102211023110241102511026110261102711028110291103010 行未改动110411104211043110441104511045110461104711048110495 行未改动11055110561105711058110591105911060110611106211063110641106511066110671106811068110691107011071110723 行未改动11076110771107811079110801108011081110821108311084250 行未改动全部展开11335113361133711338113391133911340113411134211343644 行未改动全部展开1198811989119901199111992119921199311994119951199622 行未改动12019120201202112022120231202312024120251202612027120281202912030120301203112032120331203412 行未改动12047120481204912050120511205112052120531205412055120551205612057120581205911 行未改动120711207212073120741207512075120761207712078120798 行未改动1208812089120901209112092120921209312094120951209610 行未改动121071210812109121101211112111121121211312114121151211512116121171211812119197 行未改动全部展开896 行未改动全部展开 } B[i].life = 0; } }
if (B[i].what == 8) { if (B[i].x > X && B[i].vx < 1.2) B[i].vx += fmax((float)0, 0.2 - B[i].t / 25); if (B[i].x < X && B[i].vx > -1.2) B[i].vx -= fmax((float)0, 0.2 - B[i].t / 25); if (B[i].y > Y && B[i].vy < 1.2) B[i].vy += fmax((float)0, 0.2 - B[i].t / 25);1,103 行未改动全部展开#include<conio.h>#include<time.h>#include<string>using namespace std;
/*=============== all the structures ===============*/
typedef struct Frame{ COORD position[2]; int flag;}Frame;
/*=============== all the functions ===============*/ void SetPos(COORD a)// set cursor
void SetPos(COORD a)// set cursor{ HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(out, a);}
void SetPos(int i, int j)// set cursor{ COORD pos={i, j}; SetPos(pos);}
void HideCursor(){ CONSOLE_CURSOR_INFO cursor_info = {1, 0}; CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);}
//把第y行,[x1, x2) 之间的坐标填充为 chvoid drawRow(int y, int x1, int x2, char ch){ SetPos(x1,y); for(int i = 0; i <= (x2-x1); i++) cout<<ch;}
//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 chvoid drawRow(COORD a, COORD b, char ch){ if(a.Y == b.Y)4 行未改动 cout<<"error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等"; system("pause"); }}
//把第x列,[y1, y2] 之间的坐标填充为 chvoid drawCol(int x, int y1, int y2, char ch){ int y=y1;3 行未改动 cout<<ch; y++; }}
//在a, b 横坐标相同的前提下,把坐标 [a, b] 之间填充为 chvoid drawCol(COORD a, COORD b, char ch){ if(a.X == b.X)4 行未改动 cout<<"error code 02:无法填充列,因为两个坐标的横坐标(y)不相等"; system("pause"); }}
//左上角坐标、右下角坐标、用row填充行、用col填充列void drawFrame(COORD a, COORD b, char row, char col){ drawRow(a.Y, a.X+1, b.X-1, row); drawRow(b.Y, a.X+1, b.X-1, row); drawCol(a.X, a.Y+1, b.Y-1, col); drawCol(b.X, a.Y+1, b.Y-1, col);}
void drawFrame(int x1, int y1, int x2, int y2, char row, char col){ COORD a={x1, y1}; COORD b={x2, y2}; drawFrame(a, b, row, col);}
void drawFrame(Frame frame, char row, char col){ COORD a = frame.position[0]; COORD b = frame.position[1]; drawFrame(a, b, row, col);}
void drawPlaying(){ drawFrame(0, 0, 48, 24, '=', '|');// draw map frame; drawFrame(49, 0, 79, 4, '-', '|');// draw output frame12 行未改动 cout<<" p 暂停游戏。"; SetPos(52,16); cout<<" e 退出游戏。";}
//在[a, b)之间产生一个随机整数int random(int a, int b){ int c=(rand() % (a-b))+ a; return c;}
//在两个坐标包括的矩形框内随机产生一个坐标COORD random(COORD a, COORD b){ int x=random(a.X, b.X); int y=random(a.Y, b.Y); COORD c={x, y}; return c;}
bool judgeCoordInFrame(Frame frame, COORD spot){ if(spot.X>=frame.position[0].X) if(spot.X<=frame.position[1].X) if(spot.Y>=frame.position[0].Y) if(spot.Y<=frame.position[0].Y) return true; return false;}
void printCoord(COORD a){ cout <<"( "<<a.X<<" , "<<a.Y<<" )";}
void printFrameCoord(Frame a){ printCoord(a.position[0]); cout <<" - "; printCoord(a.position[1]);}
int drawMenu(){ SetPos(30, 1); cout<<"P l a n e W a r";15 行未改动 cout<<"制作:LJF神犇"; int j=11; SetPos(12, j); cout<<">>";
//drawFrame(45, 9, 79, 17, '=', '|');
while(1) { if( _kbhit() ) { { char x=_getch(); switch (x) { case 'w' : { { if( j == 13) { SetPos(12, j); cout<<" ";9 行未改动 } break; } case 's' : { { if( j == 11 ) { SetPos(12, j); cout<<" "; cout<<" "; j = 13; SetPos(12, j); cout<<">>"; SetPos(51, 13);5 行未改动 } break; } case 'k' : { { if (j == 8) return 1; else return 2; } } } }} /*
/*DWORD WINAPI MusicFun(LPVOID lpParamte){//DWORD OBJ;sndPlaySound(TEXT("bgm.wav"), SND_FILENAME|SND_ASYNC);return 0;}*/
/*================== the Game Class ==================*/
class Game{public: COORD position[10];3 行未改动 int rank; int rankf; string title; int flag_rank;
Game ();
//初始化所有 void initPlane(); void initBullet(); void initEnemy();
//初始化其中一个 //void initThisBullet( COORD ); //void initThisEnemy( Frame );
void planeMove(char); void bulletMove(); void enemyMove();
//填充所有 void drawPlane(); void drawPlaneToNull(); void drawBullet(); void drawBulletToNull(); void drawEnemy(); void drawEnemyToNull();
//填充其中一个 void drawThisBulletToNull( COORD ); void drawThisEnemyToNull( Frame );
void Pause(); void Playing(); void judgePlane(); void judgeEnemy();
void Shoot();
void GameOver(); void printScore();};
Game::Game(){ initPlane(); initBullet();2 行未改动 rank = 25; rankf = 0; flag_rank = 0;}
void Game::initPlane(){ COORD centren={39, 22}; position[0].X=position[5].X=position[7].X=position[9].X=centren.X; position[1].X=centren.X-2; position[1].X=centren.X-2; position[2].X=position[6].X=centren.X-1; position[3].X=position[8].X=centren.X+1; position[4].X=centren.X+2; for(int i=0; i<=4; i++)2 行未改动 position[i].Y=centren.Y+1; position[5].Y=centren.Y-1; position[9].Y=centren.Y-2;}
void Game::drawPlane(){ for(int i=0; i<9; i++) { SetPos(position[i]); if(i!=5) cout<<"O"; else if(i==5) cout<<"|"; cout<<"|"; }}
void Game::drawPlaneToNull(){ for(int i=0; i<9; i++) { SetPos(position[i]); cout<<" "; } }}
void Game::initBullet(){ for(int i=0; i<10; i++) bullet[i].Y = 30;}
void Game::drawBullet(){ for(int i=0; i<10; i++) { if( bullet[i].Y != 30) { SetPos(bullet[i]); cout<<"^"; cout<<"^"; } }}
void Game::drawBulletToNull(){ for(int i=0; i<10; i++) if( bullet[i].Y != 30 ) { COORD pos={bullet[i].X, bullet[i].Y+1}; SetPos(pos); cout<<" "; } }}
void Game::initEnemy(){ COORD a={1, 1}; COORD b={45, 15};3 行未改动 enemy[i].position[1].X = enemy[i].position[0].X + 3; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; }}
void Game::drawEnemy(){ for(int i=0; i<8; i++) drawFrame(enemy[i].position[0], enemy[i].position[1], '-', '|');}
void Game::drawEnemyToNull(){ for(int i=0; i<8; i++) { drawFrame(enemy[i].position[0], enemy[i].position[1], ' ', ' '); } }}
void Game::Pause(){ SetPos(61,2); cout<<" ";4 行未改动 c=_getch(); SetPos(61,2); cout<<" ";}
void Game::planeMove(char x){ if(x == 'a') if(position[1].X != 1) for(int i=0; i<=9; i++) position[i].X -= 2;
if(x == 's') if(position[7].Y != 23) for(int i=0; i<=9; i++) position[i].Y += 1;
if(x == 'd') if(position[4].X != 47) for(int i=0; i<=9; i++) position[i].X += 2;
if(x == 'w') if(position[5].Y != 3) for(int i=0; i<=9; i++) position[i].Y -= 1;}
void Game::bulletMove(){ for(int i=0; i<10; i++) {5 行未改动 COORD pos={bullet[i].X, bullet[i].Y+1}; drawThisBulletToNull( pos ); bullet[i].Y=30; }
} }}
void Game::enemyMove(){ for(int i=0; i<8; i++) { for(int j=0; j<2; j++) enemy[i].position[j].Y++;
if(24 == enemy[i].position[1].Y) { COORD a={1, 1}; COORD b={45, 3};2 行未改动 enemy[i].position[1].Y = enemy[i].position[0].Y + 2; } }}
void Game::judgePlane(){ for(int i = 0; i < 8; i++) for(int j=0; j<9; j++)6 行未改动 GameOver(); break; }}
void Game::drawThisBulletToNull( COORD c){ SetPos(c); cout<<" ";}
void Game::drawThisEnemyToNull( Frame f ){ drawFrame(f, ' ', ' ');}
void Game::judgeEnemy(){ for(int i = 0; i < 8; i++) for(int j = 0; j < 10; j++)4 行未改动 COORD a={1, 1}; COORD b={45, 3}; enemy[i].position[0] = random(a, b); enemy[i].position[1].X = enemy[i].position[0].X + 3; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; drawThisBulletToNull( bullet[j] ); bullet[j].Y = 30; }}
void Game::Shoot(){ for(int i=0; i<10; i++) if(bullet[i].Y == 30)2 行未改动 bullet[i].Y = position[5].Y-1; break; }}
void Game::printScore(){ if(score == 120 && flag_rank == 0) { rank -= 3; flag_rank = 1; }
else if( score == 360 && flag_rank == 1) { rank -= 5; flag_rank = 2;5 行未改动 } int x=rank/5; SetPos(60, 6); cout<<score;
if( rank!=rankf ) { SetPos(60, 7); if( x == 5)7 行未改动 cout<<title; } rankf = rank;}
void Game::Playing(){ //HANDLE MFUN; //MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL); //MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL);
drawEnemy(); drawPlane();
int flag_bullet = 0; int flag_enemy = 0;
while(1) { Sleep(8); if(_kbhit())4 行未改动 drawPlaneToNull(); planeMove(x); drawPlane(); judgePlane(); } } else if ('p' == x) Pause(); else if( 'k' == x) Shoot();2 行未改动 //CloseHandle(MFUN); GameOver(); break; }
} /* 处理子弹 */ if( 0 == flag_bullet ) { bulletMove(); drawBulletToNull(); drawBullet(); judgeEnemy(); } } flag_bullet++; if( 5 == flag_bullet ) flag_bullet = 0;
/* 处理敌人 */ if( 0 == flag_enemy ) { drawEnemyToNull(); enemyMove(); enemyMove(); drawEnemy(); judgePlane(); } flag_enemy++; if( flag_enemy >= rank ) flag_enemy = 0;
/* 输出得分 */ printScore(); }}
void Game::GameOver(){ system("cls"); system("cls"); COORD p1={28,9}; COORD p2={53,15}; drawFrame(p1, p2, '=', '|'); SetPos(36,12);31 行未改动 game.Playing(); } else goto as;}
/*================== the main function ==================*/int main(){ //游戏准备 srand((int)time(0)); //随机种子 HideCursor(); //隐藏光标
Game game; int a = drawMenu(); if(a == 2) game.rank = 20;129 行未改动全部展开 cout<<"you win!!!!!"; Sleep(2000); return 0; } } }}
```## 三国杀1,723 行未改动全部展开 pai p1; int sha = 1; int y = -1, i, t = ((*w1).shoupaishu) - 1; for (;; t--) {
if ((*w1).juese) { printf("\n电脑当前手牌数:%d\n", ((*w2).shoupaishu)); (*w2).Kanzhuangbei(); (*w1).Kanshoupai();555 行未改动全部展开public: int x, y; Node(int x1, int y1);};
class UserData {public: string name; long long score; int gt; int gr; UserData(string s, long long sc,int gametime,int grade); friend bool operator < (UserData a, UserData b);};
#define RIGHT 0x4d#define LEFT 0x4b#define UP 0x48#define DOWN 0x5036 行未改动bool GameMenu(); //游戏菜单void ShowRanking(); //排行榜void ShowAbout(); //相关信息void InputData(); //输入玩家名字
int main() { while (true) { if (!GameMenu()) return 0; } return 0;}
Node::Node(int x1, int y1) { //构造Node对象 x = x1; y = y1;}
int SuiJi(){srand((unsigned)time(NULL));return (rand()*rand()+rand()*rand())%14;}
bool operator < (UserData a, UserData b) { //重载运算符,按分数由大到小排列 if(a.score != b.score) return a.score > b.score; if(a.gt !=b.gt)3 行未改动}UserData::UserData(string s, long long sc,int gametime_,int _grade) { //构造UserData对象 name = s; score = sc; gt=gametime_; gr=_grade;}
void color(WORD A){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), A);}
void Color(int a){ switch (a%4) {2 行未改动 case 2:color(YELLOW);break; case 3:color(PURPLE);break; }}
void GoTo(short x, short y) { //定位光标 COORD coord = { x, y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);}
void ShowInformation() { //输出游戏信息 color(YELLOW); GoTo(78, 5); printf("贪吃蛇游戏");21 行未改动 GoTo(78,25); printf("剩余时间:%d秒",20+(snakeLen-3)*5-gametime); sysj=20+(snakeLen-3)*5-gametime;}
void DrawBoard() { //绘制墙体
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //获得输出句柄
CONSOLE_CURSOR_INFO cursor_info = { 1, 0 }; //光标信息 SetConsoleCursorInfo(hOut, &cursor_info); //隐藏光标
COORD size = { 120, 30 }; SetConsoleScreenBufferSize(hOut, size); //重设缓冲区大小
SMALL_RECT rc = { 0 , 0, 120, 30 }; SetConsoleWindowInfo(hOut, true, &rc); //重设窗口大小
SetConsoleTextAttribute(hOut, CYAN);
for (int i = STARTX - 2; i <= ENDX + 2; i += 2) { //横向墙体 GoTo(i, STARTY - 1); printf("■"); GoTo(i, ENDY + 1);25 行未改动 mj=clock(); point=20; sysj=20;}
void RunSnake(int x, int y) { //绘制蛇身 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); score += snakeLen + 1; if (x == foodx && y == foody) {11 行未改动 isSnake[back.y][back.x] = false; GoTo(back.x, back.y); printf(" ");}
void Try(int& x, int& y) { //试走 int key, cnt = 100; while (cnt--) { //多次检测键盘状态 if (_kbhit()) {18 行未改动 else if (curDiraction == 2) ++y; else if (curDiraction == 3) x -= 2; else x += 2;}
bool IsGoodCoord(int x, int y) { //判断光标是否合法 if (x <= ENDX && y <= ENDY && x >= STARTX && y >= STARTY) return true; else return false;}
void AddFood() { //增加食物 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), PURPLE); srand((unsigned)time(NULL)); while (true) {10 行未改动 printf("#"); else printf("&");}
void EartFood() { //吃东西 point+=4; int sb=gametime=(clock()-mj)/1000; sysj=point-sb;2 行未改动 snake.push_front(Node(foodx, foody)); isSnake[foody][foodx] = true; ++snakeLen; if (speed >= 55) speed -= 5;
GoTo(foodx, foody); draw(); AddFood();}
void InitSnake() { //初始化蛇身 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); snakeLen = 3, gox = 18, goy = 14; snake.clear();26 行未改动 } else key = getch(); }}
bool StartGame() { //启动游戏
Init();
while (sysj>0) { //开挂 RunSnake(gox, goy); ShowInformation(); Try(gox, goy); Sleep(speed); } InputData(); return true;}
bool GameMenu() { //游戏菜单 system("cls"); DrawBoard(); GoTo(STARTX + 22, STARTY + 4);6 行未改动 GoTo(STARTX + 24, STARTY + 14); printf("3: 关于游戏"); GoTo(STARTX + 24, STARTY + 16); printf("4: 退出游戏");
while (true) { if (_kbhit()) { char key = getch(); switch (key) {12 行未改动 } } }}
void ShowRanking() { //展示排行榜 vector<UserData> vu; FILE *fp = fopen("Gamedata2.txt", "r"); if (fp == NULL) fp = fopen("Gamedata2.txt", "w+");18 行未改动 printf("生存时间"); GoTo(STARTX + 44, STARTY + 2); printf("排行"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);
for (int i = 0; i < len && i < 10; ++i) { //打印前十名用户数据 char const *p = vu[i].name.c_str(); Color(score); GoTo(STARTX + 8, STARTY + 4 + i);4 行未改动 printf("%d秒", vu[i].gt); GoTo(STARTX + 44, STARTY + 4 + i); printf(" %d", i + 1); }
GoTo(STARTX + 4, ENDY - 2); printf("----------------- 按'1'返回游戏菜单 ---------------"); while (true) { if (_kbhit()) { char key = getch(); if (key == '1') break; } }}
void ShowAbout() { //展示游戏相关 system("cls"); DrawBoard(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);
GoTo(STARTX + 4, STARTY + 2); printf("------------------- 贪吃蛇游戏 -------------------"); GoTo(STARTX + 10,STARTY + 8); printf("贪吃蛇游戏");4 行未改动 GoTo(STARTX + 10,STARTY + 14); printf("吃的越多,蛇就越长,您的等级也将越高"); GoTo(STARTX + 10,STARTY + 16); printf("当蛇吃到自己或撞上墙时,游戏结束。");
GoTo(STARTX + 4, ENDY - 2); printf("----------------- 按'1'返回游戏菜单 ---------------"); while (true) { if (_kbhit()) { char key = getch(); if (key == '1') break; } }}
void InputData() { //用户输入名字 char name[20]; if(score>=1000) {16 行未改动 cout<<"哟!这分数也能上榜??"<<endl; Sleep(1000); } EndGame();
}```## 斗地主```cpp27 行未改动void p2qipai(int k);void p3qipai(int k);void init();int main() {
init(); //初始化 printf("\n"); if (p1dizhu()) { //分配地主 dizhu = 1;2,668 行未改动全部展开using namespace std;int Your = 6, Other = 6;string daojuname[] = {"放大镜", "手铐", "小刀", "烟", "饮料"};double Yourmoney;
int shi, kong;int q[10], qlen; //1 实 2 空int Rand(int x, int y) { int A = rand(), B = rand();362 行未改动全部展开 } printf("\n"); printf("现在是恶魔的回合\n"); Sleep(1500);
if (Other != 6) { if (daoju1[3]) { daoju1[3]--; daojulen1--;135 行未改动全部展开 Sleep(1145); system("cls"); } if (x == 1) {
} else { for (int i = 1; i <= 3; i++) { printf("."); Sleep(1000);13 行未改动 printf("饮料:可以退一发子弹\n"); system("pause"); system("cls"); }
printf("好吧\n"); Sleep(1145); printf("游戏将要开始了哦\n"); Sleep(1145);9 行未改动 printf("玩家A赢了\n玩家A获得了奖金$%.2lf\n", Yourmoney); system("pause"); exit(0); }
}void build_gun_duo() { kong = Rand(1, 4); shi = Rand(1, 4);489 行未改动全部展开#include<conio.h>#include<time.h>#include<string>using namespace std;
/*=============== all the structures ===============*/
typedef struct Frame{ COORD position[2]; int flag;}Frame;
/*=============== all the functions ===============*/ void SetPos(COORD a)// set cursor
void SetPos(COORD a)// set cursor{ HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(out, a);}
void SetPos(int i, int j)// set cursor{ COORD pos={i, j}; SetPos(pos);}
void HideCursor(){ CONSOLE_CURSOR_INFO cursor_info = {1, 0}; CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);}
//把第y行,[x1, x2) 之间的坐标填充为 chvoid drawRow(int y, int x1, int x2, char ch){ SetPos(x1,y); for(int i = 0; i <= (x2-x1); i++) cout<<ch;}
//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 chvoid drawRow(COORD a, COORD b, char ch){ if(a.Y == b.Y)4 行未改动 cout<<"error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等"; system("pause"); }}
//把第x列,[y1, y2] 之间的坐标填充为 chvoid drawCol(int x, int y1, int y2, char ch){ int y=y1;3 行未改动 cout<<ch; y++; }}
//在a, b 横坐标相同的前提下,把坐标 [a, b] 之间填充为 chvoid drawCol(COORD a, COORD b, char ch){ if(a.X == b.X)4 行未改动 cout<<"error code 02:无法填充列,因为两个坐标的横坐标(y)不相等"; system("pause"); }}
//左上角坐标、右下角坐标、用row填充行、用col填充列void drawFrame(COORD a, COORD b, char row, char col){ drawRow(a.Y, a.X+1, b.X-1, row); drawRow(b.Y, a.X+1, b.X-1, row); drawCol(a.X, a.Y+1, b.Y-1, col); drawCol(b.X, a.Y+1, b.Y-1, col);}
void drawFrame(int x1, int y1, int x2, int y2, char row, char col){ COORD a={x1, y1}; COORD b={x2, y2}; drawFrame(a, b, row, col);}
void drawFrame(Frame frame, char row, char col){ COORD a = frame.position[0]; COORD b = frame.position[1]; drawFrame(a, b, row, col);}
void drawPlaying(){ drawFrame(0, 0, 48, 24, '=', '|');// draw map frame; drawFrame(49, 0, 79, 4, '-', '|');// draw output frame12 行未改动 cout<<" p 暂停游戏。"; SetPos(52,16); cout<<" e 退出游戏。";}
//在[a, b)之间产生一个随机整数int random(int a, int b){ int c=(rand() % (a-b))+ a; return c;}
//在两个坐标包括的矩形框内随机产生一个坐标COORD random(COORD a, COORD b){ int x=random(a.X, b.X); int y=random(a.Y, b.Y); COORD c={x, y}; return c;}
bool judgeCoordInFrame(Frame frame, COORD spot){ if(spot.X>=frame.position[0].X) if(spot.X<=frame.position[1].X) if(spot.Y>=frame.position[0].Y) if(spot.Y<=frame.position[0].Y) return true; return false;}
void printCoord(COORD a){ cout <<"( "<<a.X<<" , "<<a.Y<<" )";}
void printFrameCoord(Frame a){ printCoord(a.position[0]); cout <<" - "; printCoord(a.position[1]);}
int drawMenu(){ SetPos(30, 1); cout<<"P l a n e W a r";15 行未改动 cout<<"制作:LJF神犇"; int j=11; SetPos(12, j); cout<<">>";
//drawFrame(45, 9, 79, 17, '=', '|');
while(1) { if( _kbhit() ) { { char x=_getch(); switch (x) { case 'w' : { { if( j == 13) { SetPos(12, j); cout<<" ";9 行未改动 } break; } case 's' : { { if( j == 11 ) { SetPos(12, j); cout<<" "; cout<<" "; j = 13; SetPos(12, j); cout<<">>"; SetPos(51, 13);5 行未改动 } break; } case 'k' : { { if (j == 8) return 1; else return 2; } } } }} /*
/*DWORD WINAPI MusicFun(LPVOID lpParamte){//DWORD OBJ;sndPlaySound(TEXT("bgm.wav"), SND_FILENAME|SND_ASYNC);return 0;}*/
/*================== the Game Class ==================*/
class Game{public: COORD position[10];3 行未改动 int rank; int rankf; string title; int flag_rank;
Game ();
//初始化所有 void initPlane(); void initBullet(); void initEnemy();
//初始化其中一个 //void initThisBullet( COORD ); //void initThisEnemy( Frame );
void planeMove(char); void bulletMove(); void enemyMove();
//填充所有 void drawPlane(); void drawPlaneToNull(); void drawBullet(); void drawBulletToNull(); void drawEnemy(); void drawEnemyToNull();
//填充其中一个 void drawThisBulletToNull( COORD ); void drawThisEnemyToNull( Frame );
void Pause(); void Playing(); void judgePlane(); void judgeEnemy();
void Shoot();
void GameOver(); void printScore();};
Game::Game(){ initPlane(); initBullet();2 行未改动 rank = 25; rankf = 0; flag_rank = 0;}
void Game::initPlane(){ COORD centren={39, 22}; position[0].X=position[5].X=position[7].X=position[9].X=centren.X; position[1].X=centren.X-2; position[1].X=centren.X-2; position[2].X=position[6].X=centren.X-1; position[3].X=position[8].X=centren.X+1; position[4].X=centren.X+2; for(int i=0; i<=4; i++)2 行未改动 position[i].Y=centren.Y+1; position[5].Y=centren.Y-1; position[9].Y=centren.Y-2;}
void Game::drawPlane(){ for(int i=0; i<9; i++) { SetPos(position[i]); if(i!=5) cout<<"O"; else if(i==5) cout<<"|"; cout<<"|"; }}
void Game::drawPlaneToNull(){ for(int i=0; i<9; i++) { SetPos(position[i]); cout<<" "; } }}
void Game::initBullet(){ for(int i=0; i<10; i++) bullet[i].Y = 30;}
void Game::drawBullet(){ for(int i=0; i<10; i++) { if( bullet[i].Y != 30) { SetPos(bullet[i]); cout<<"^"; cout<<"^"; } }}
void Game::drawBulletToNull(){ for(int i=0; i<10; i++) if( bullet[i].Y != 30 ) { COORD pos={bullet[i].X, bullet[i].Y+1}; SetPos(pos); cout<<" "; } }}
void Game::initEnemy(){ COORD a={1, 1}; COORD b={45, 15};3 行未改动 enemy[i].position[1].X = enemy[i].position[0].X + 3; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; }}
void Game::drawEnemy(){ for(int i=0; i<8; i++) drawFrame(enemy[i].position[0], enemy[i].position[1], '-', '|');}
void Game::drawEnemyToNull(){ for(int i=0; i<8; i++) { drawFrame(enemy[i].position[0], enemy[i].position[1], ' ', ' '); } }}
void Game::Pause(){ SetPos(61,2); cout<<" ";4 行未改动 c=_getch(); SetPos(61,2); cout<<" ";}
void Game::planeMove(char x){ if(x == 'a') if(position[1].X != 1) for(int i=0; i<=9; i++) position[i].X -= 2;
if(x == 's') if(position[7].Y != 23) for(int i=0; i<=9; i++) position[i].Y += 1;
if(x == 'd') if(position[4].X != 47) for(int i=0; i<=9; i++) position[i].X += 2;
if(x == 'w') if(position[5].Y != 3) for(int i=0; i<=9; i++) position[i].Y -= 1;}
void Game::bulletMove(){ for(int i=0; i<10; i++) {5 行未改动 COORD pos={bullet[i].X, bullet[i].Y+1}; drawThisBulletToNull( pos ); bullet[i].Y=30; }
} }}
void Game::enemyMove(){ for(int i=0; i<8; i++) { for(int j=0; j<2; j++) enemy[i].position[j].Y++;
if(24 == enemy[i].position[1].Y) { COORD a={1, 1}; COORD b={45, 3};2 行未改动 enemy[i].position[1].Y = enemy[i].position[0].Y + 2; } }}
void Game::judgePlane(){ for(int i = 0; i < 8; i++) for(int j=0; j<9; j++)6 行未改动 GameOver(); break; }}
void Game::drawThisBulletToNull( COORD c){ SetPos(c); cout<<" ";}
void Game::drawThisEnemyToNull( Frame f ){ drawFrame(f, ' ', ' ');}
void Game::judgeEnemy(){ for(int i = 0; i < 8; i++) for(int j = 0; j < 10; j++)4 行未改动 COORD a={1, 1}; COORD b={45, 3}; enemy[i].position[0] = random(a, b); enemy[i].position[1].X = enemy[i].position[0].X + 3; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; drawThisBulletToNull( bullet[j] ); bullet[j].Y = 30; }}
void Game::Shoot(){ for(int i=0; i<10; i++) if(bullet[i].Y == 30)2 行未改动 bullet[i].Y = position[5].Y-1; break; }}
void Game::printScore(){ if(score == 120 && flag_rank == 0) { rank -= 3; flag_rank = 1; }
else if( score == 360 && flag_rank == 1) { rank -= 5; flag_rank = 2;5 行未改动 } int x=rank/5; SetPos(60, 6); cout<<score;
if( rank!=rankf ) { SetPos(60, 7); if( x == 5)7 行未改动 cout<<title; } rankf = rank;}
void Game::Playing(){ //HANDLE MFUN; //MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL); //MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL);
drawEnemy(); drawPlane();
int flag_bullet = 0; int flag_enemy = 0;
while(1) { Sleep(8); if(_kbhit())4 行未改动 drawPlaneToNull(); planeMove(x); drawPlane(); judgePlane(); } } else if ('p' == x) Pause(); else if( 'k' == x) Shoot();2 行未改动 //CloseHandle(MFUN); GameOver(); break; }
} /* 处理子弹 */ if( 0 == flag_bullet ) { bulletMove(); drawBulletToNull(); drawBullet(); judgeEnemy(); } } flag_bullet++; if( 5 == flag_bullet ) flag_bullet = 0;
/* 处理敌人 */ if( 0 == flag_enemy ) { drawEnemyToNull(); enemyMove(); enemyMove(); drawEnemy(); judgePlane(); } flag_enemy++; if( flag_enemy >= rank ) flag_enemy = 0;
/* 输出得分 */ printScore(); }}
void Game::GameOver(){ system("cls"); system("cls"); COORD p1={28,9}; COORD p2={53,15}; drawFrame(p1, p2, '=', '|'); SetPos(36,12);31 行未改动 game.Playing(); } else goto as;}
/*================== the main function ==================*/int main(){ //游戏准备 srand((int)time(0)); //随机种子 HideCursor(); //隐藏光标
Game game; int a = drawMenu(); if(a == 2) game.rank = 20;10 行未改动using namespace std;const int daytime=0,night=1;int day=0, during_time=daytime, player_number, my_number;HWND hwnd=GetForegroundWindow();const int blue=0,yellow=1,red=2,green=3,purple=4,white=5;//颜色常量 const int blue=0,yellow=1,red=2,green=3,purple=4,white=5;//颜色常量void color(int c){ switch(c){ case red:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);break; case green:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);break;10 行未改动 position.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);}void init_Show_Window(){ system("mode con lines=60 cols=188"); ShowWindow(hwnd,SW_MAXIMIZE);//窗口最大化 system("mode con lines=60 cols=188"); ShowWindow(hwnd,SW_MAXIMIZE);//窗口最大化 DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND); DrawMenuBar(GetConsoleWindow());//删除×字符 DrawMenuBar(GetConsoleWindow());//删除×字符}
/*玩家类*/const int nvwu=0,cunmin=1,yuyanjia=2,langren=3,lieren=4,shouwei=5,good=6,die=1,life=2;class player{public: int type; int die_or_life; int how(){ return die_or_life; } int is_light;//是否已经公布 int is_light;//是否已经公布 int killer;};player players[1000]; /*转换白天模式*/
/*转换白天模式*/void change_daytime(){ during_time=daytime; day++;}
/*转换黑夜模式*/void change_night(){ during_time=night;}int nnvwu=0,ncunmin=0,nyuyanjia=0,nlangren=0,nlieren=0,nshouwei=0;int idxnvwu,idxshouwei,idxyuyanjia,idxlieren,idxlangren[4]={-1,-1,-1,-1};
/*b是否在Arr中*/bool is_include(int arr[],int b,int l){ for(int i=0;i<l;i++){ if(arr[i]==b) return true; } return false;}
/*初始化人数*/void init_players(){ my_number=rand()%player_number; if(player_number==12) nlangren=4;18 行未改动 if(player_number==12) { do{ idxshouwei=rand()%player_number; }while(players[idxshouwei].type!=-1); players[idxshouwei].type=shouwei; }while(players[idxshouwei].type!=-1); players[idxshouwei].type=shouwei; } do{ idxnvwu=rand()%player_number; }while(players[idxnvwu].type!=-1);2 行未改动 { do{ idxlieren=rand()%player_number; }while(players[idxlieren].type!=-1); players[idxlieren].type=lieren; players[idxlieren].type=lieren; } do{ idxyuyanjia=rand()%player_number; }while(players[idxyuyanjia].type!=-1);10 行未改动 } } players[my_number].is_light=1;}
/*在屏幕上打印东西*/void print(){ gotoxy(0,0); cout<<"作者:洛谷393864";4 行未改动 color(blue); printf("第%d天 | ",day); if(during_time==night) cout<<"黑夜"; else cout<<"白天";
gotoxy(0,3); color(blue); cout<<" 我的号位:"<<my_number+1; for(int i=0;i<player_number;i++){ gotoxy(i*8+1,4); if(i==idx_police) color(yellow); else color(blue); cout<<i+1<<"号位"; cout<<i+1<<"号位"; gotoxy(i*8+1,5); if(players[i].how()==die){ color(red); cout<<"死 亡";9 行未改动 case nvwu: cout<<"女 巫";break; case yuyanjia: cout<<"\b预言家";break; case cunmin: cout<<"村 民";break; case langren:cout<<"狼 人"; break; case lieren:cout<<"猎 人"; break; case lieren:cout<<"猎 人"; break; case shouwei:cout<<"守 卫"; break; } } }else{ cout<<"好人"; }
}else{ cout<<"未知"; } } }
}
/*判断是否结束,没结束返回0 好人胜利返回1 狼人胜利返回2 平局返回3*/int is_end(){ int die_bad=0; int die_people=0;13 行未改动 if(die_people>=ncunmin||die_god>=(player_number>=10 ? 3:2)) return 2; return 0;}
/*游戏开始前的骚操作*/void before_game(){ srand(time(NULL)); init_Show_Window();8 行未改动 for(int i=0;i<6;i++){ for(int j=0;j<12;j++){ cout<<"."; Sleep(50); } } cout<<"\b\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b"; } system("cls");
init_players(); cout<<"我的号位:"<<my_number+1<<endl <<"我的身份:"; switch(players[my_number].type){ case nvwu: cout<<"女巫\n";break; case yuyanjia: cout<<"预言家\n";break; case cunmin: cout<<"村民\n";break; case langren:cout<<"狼人\n";break; case lieren:cout<<"猎人\n"; break; case langren:cout<<"狼人\n";break; case lieren:cout<<"猎人\n"; break; case shouwei:cout<<"守卫\n";break; } change_daytime(); system("pause");2 行未改动 for(int i=0;i<ppppp;i++){ for(int j=0;j<6;j++){ cout<<"."; Sleep(rand()%100+150); } } cout<<"\b\b\b\b\b\b \b\b\b\b\b\b"; } } print();} }
/*每一天开始前的操作*/void something_before_everyday(){ change_night(); system("cls");3 行未改动 gotoxy(0,8); color(white); cout<<"天黑~请闭眼~~~\n";}
/*守卫操作*/int shouweishou=0;int ShouWei(){ color(blue);6 行未改动 cout<<"请重新输入!\n"; cin>>shouweishou; } cout<<"你今晚要守护的是"<<shouweishou<<"号\n"; Sleep(1500); Sleep(1500); shouweishou--; }else{ if(players[idxshouwei].die_or_life == life){ shouweishou=rand()%10; while(!(shouweishou>=1&&shouweishou<=player_number&&players[shouweishou-1].die_or_life == life)){ shouweishou=rand()%10; } } } } Sleep(2000); cout<<"守卫请闭眼"<<endl<<endl; return shouweishou;} }
/*狼人操作*/int LangRen(){ int langrensha=-1; color(red);16 行未改动 } cout<<"狼人请~闭眼~~\n\n"; return langrensha;}
/*女巫操作*/int nvwujiu=0,nvwudu=0,is_nvwujiu=0,is_nvwudu=0;int NvWu(int langrensha){ color(purple); cout<<"女巫~~请睁眼~~\n"; Sleep(2000); if(players[my_number].type==nvwu&&players[my_number].die_or_life == life){ if(is_nvwujiu) if(is_nvwujiu) cout<<"你已经用过解药\n",Sleep(1500); else { cout<<"今晚"<<langrensha+1<<"号死了,你想用解药吗?(1想 / 2不想)\n"; int is_nvwujie=0; cin>>is_nvwujie; while(is_nvwujie!=1&&is_nvwujie!=2){ cout<<"请重新输入\n"; cin>>is_nvwujie; } } if(is_nvwujie==1) { Sleep(1000); cout<<"已经解救"<<langrensha+1<<"号\n"; nvwujiu=langrensha;10 行未改动 cin>>is_nvwudu; while(is_nvwudu!=1&&is_nvwudu!=2){ cout<<"请重新输入\n"; cin>>is_nvwudu; } } if(is_nvwudu==1){ Sleep(1500); cout<<"你想毒谁?\n"; cout<<"你想毒谁?\n"; cin>>nvwudu; while(!(nvwudu>=1&&nvwudu<=player_number&&players[nvwudu].die_or_life==life)){ cout<<"请重新输入\n"; cin>>nvwudu; cin>>nvwudu; } nvwudu--; Sleep(1500); cout<<"已经毒死了"<<nvwudu+1<<"号\n"; } ::is_nvwudu=1; } } }else{ if(players[idxnvwu].die_or_life == life){ if(!is_nvwujiu) { int is_jiu=rand()%8; if(is_jiu==0){ nvwujiu=langrensha; is_nvwujiu=1; } } } if(!is_nvwudu) { int is_du=rand()%4;3 行未改动 is_nvwudu=1; } } } }
} cout<<"女巫~请闭眼~~\n\n"; return nvwujiu*10000+nvwudu;//传回两个变量,“加密”操作 return nvwujiu*10000+nvwudu;//传回两个变量,“加密”操作}
int yuyanjiabixutoupiao=-1;/*预言家操作*/void YuYanJia(){ color(green);20 行未改动 }else{ int p=-1; while(p==-1||players[p].die_or_life==die||p==idxlieren) p=rand()%player_number; if(players[p].type==langren)//锁定目标! if(players[p].type==langren)//锁定目标! { yuyanjiabixutoupiao=p; } } cout<<"预言家~~请闭眼~~\n";}
/*黑夜操作*/int LANGRENSHA=-1,NVWUDU=-1,NVWUJIU=-1,SHOUWEISHOU=-1; void Night(){ LANGRENSHA=-1,NVWUDU=-1,NVWUJIU=-1,SHOUWEISHOU=-1; //如果有12人局,添加守卫 int LANGRENSHA=-1,NVWUDU=-1,NVWUJIU=-1,SHOUWEISHOU=-1;void Night(){ LANGRENSHA=-1,NVWUDU=-1,NVWUJIU=-1,SHOUWEISHOU=-1;
//如果有12人局,添加守卫 if(player_number==12){ SHOUWEISHOU=ShouWei(); Sleep(2000); } } /*狼人部分*/ LANGRENSHA=LangRen(); Sleep(3500); /*女巫部分*/ /*女巫部分*/ int nvwu=NvWu(LANGRENSHA); NVWUDU=nvwu%10+nvwu/10%10; NVWUJIU=nvwu/10000%10+nvwu/100000%10; Sleep(3000); /*预言家部分*/ YuYanJia(); Sleep(2000);}
/*猎人操作*/void Lieren(){ int lierendai=-1; cout<<idxlieren+1<<"号是猎人\n";
players[idxlieren].is_light = 1; Sleep(1000); if(idxlieren==my_number){ cout<<"你想带走几号?\n";13 行未改动 cout<<"猎人选择带走"<<lierendai+1<<"号\n"; Sleep(2000); players[lierendai].die_or_life = die;}
void police_die();/*判断谁死了*/void panduansiwang(){ system("cls"); print(); print(); gotoxy(0,7); cout<<"________________________\n"; Sleep(3000); color(white);16 行未改动 if(players[i].type==lieren) is_die_lieren=false; players[i].killer=-1; players[i].die_or_life=life; is_die[i]=false; } } } } bool is_police_die=false; for(int i=0;i<player_number;i++) { if(is_die[i]) { if(flag) cout<<"和"<<i+1<<"号"; else cout<<i+1<<"号",flag=true; if(i==idx_police) if(i==idx_police) is_police_die=true; } } if(flag) cout<<"死了\n"; else cout<<"是平安夜\n";
if(is_die_lieren) Lieren(); if(is_police_die) police_die();}
/*选警长*/void choose_police(){ system("cls"); print();56 行未改动 for(int i=0;i<len;i++) { if(i==len-1) { cout<<maxn_arr[i]+1<<"号平票\n"; cout<<maxn_arr[i]+1<<"号平票\n"; } else { cout<<maxn_arr[i]+1<<"号,";15 行未改动 Sleep(3000); idx_police=idx_max; return;}
/*投票*/int toupiao(){ int tong[100]={0},cannot[100]={},must[100]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int tong[100]={0},cannot[100]={},must[100]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; memset(cannot,-1,sizeof(cannot)); gotoxy(0,7); color(blue); cout<<"________________________\n";14 行未改动 cin>>n; } Sleep(2000); cout<<setw(2)<<my_number+1<<"号投了"<<setw(2)<<n<<"号"; if(my_number==n-1) color(red),cout<<"快来看!这有个疯子投自己!"; if(my_number==n-1) color(red),cout<<"快来看!这有个疯子投自己!"; if(i==idx_police) color(yellow),cout<<"(警长)\n"; else cout<<"\n"; if(i==idx_police) tong[n-1]++; tong[n-1]++; }else{15 行未改动 } cout<<setw(2)<<i+1<<"号"<<"投了"<<setw(2)<<t+1<<"号"; if(i==idx_police) cout<<"(警长2票)\n"; else cout<<"\n"; if(i==idx_police) tong[t]++; tong[t]++; tong[t]++; }
Sleep(rand()%1000+1000); } } int idx_max=-1,maxn=-1,len=0;17 行未改动 for(int i=0;i<len;i++) { if(i==len-1) { cout<<maxn_arr[i]+1<<"号平票\n"; cout<<maxn_arr[i]+1<<"号平票\n"; } else { cout<<maxn_arr[i]+1<<"号,";9 行未改动 must[i]=-1; } color(white); goto TOUPIAO;
}
cout<<idx_max+1<<"号"<<"出局\n"; Sleep(4000); players[idx_max].die_or_life = die; players[idx_max].killer = good; return idx_max;}
/*警长死亡*/void police_die(){ color(yellow); int type; if(idx_police==my_number) { Sleep(1550); cout<<"你是想撕毁警徽还是移交警徽?(撕毁输入1,移交输入2)";
cin>>type; while(!(type==1||type==2)) { cout<<"请重新输入!\n";15 行未改动 while(lucky==-1||players[lucky].die_or_life==die) lucky=rand()%player_number; cout<<"警长选择把警徽移交给"<<lucky+1<<"号\n"; Sleep(1500); idx_police=lucky; idx_police=lucky; }}
/*故事的最后*/void the_end(){ system("cls"); switch(is_end()){7 行未改动 case nvwu: cout<<"女巫\t";break; case yuyanjia: cout<<"预言家\t";break; case cunmin: cout<<"村民\t";break; case langren:cout<<"狼人\t";break; case lieren:cout<<"猎人\t"; break; case shouwei:cout<<"守卫\t";break; } case lieren:cout<<"猎人\t"; break; case shouwei:cout<<"守卫\t";break; } cout<<"最终"; switch(players[i].killer){ case nvwu:cout<<"被女巫毒死\n"; break; case langren:cout<<"被狼人杀死\n"; break;3 行未改动 } cout<<endl; }}
/*主函数*/int main(){ int wheel=0; int wheel=0; before_game(); while(!is_end()){ //黑夜准备 //黑夜准备 something_before_everyday(); Sleep(1500); //黑夜部分 Night(); //进入黑夜! change_daytime(); //换天 //天亮了 panduansiwang();//判断谁死了 Sleep(1500);
//黑夜部分 Night(); //进入黑夜! change_daytime(); //换天
//天亮了 panduansiwang();//判断谁死了 Sleep(2000); system("cls"); print(); if(is_end()) break; //选警长
//选警长 if(!wheel&&player_number==12) { choose_police(); system("cls"); print(); } //投票环节 int idx_max=toupiao();//票数最多的人
//投票环节 int idx_max=toupiao();//票数最多的人 if(idx_max==idx_police){ police_die(); } if(players[idx_max].type==lieren){//启动猎人程序 if(players[idx_max].type==lieren){//启动猎人程序 Lieren(); if(is_end()) break; } system("cls"); print(); print(); wheel++; }
the_end(); system("pause"); return 0;}47 行未改动
int main () { MessageBox (NULL, "欢迎来到俄罗斯方块游戏!", "温馨提示", MB_OK); system ("mode con cols=70 lines=35");
int map[21][12]; int blockA[4][4];//候选区的方块 int blockB[4][4];//下落中的方块 int positionX, positionY;//方块左上角的坐标2 行未改动 int val;//用来控制下落速度 int fraction;//用来存储得分 int checkpoint;//用来存储关卡 int times;
HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);//获取标准输出设备句柄 initialWindow (hOut);
initial: gotoXY (hOut, 0, 0); initialPrint (hOut); check = true; val = 50; fraction = 0; checkpoint = 1; times = val;
for (int i = 0; i < 20; i++) { for (int j = 1; j < 11; j++) { map[i][j] = 0; } }
for (int i = 0; i < 20; i++) { map[i][0] = map[i][11] = 1; }
for (int i = 0; i < 12; i++) { map[20][i] = 1; }
srand ((unsigned) time (NULL)); roundBlock (hOut, blockA);
while (true) { if (check) { eliminateRow (hOut, map, val, fraction, checkpoint); check = false;10 行未改动 gameOver (hOut, blockA, map); goto initial; } } printBlock(hOut, blockB, positionX, positionY);
printBlock(hOut, blockB, positionX, positionY);
if (_kbhit ()) { key = _getch (); switch (key) { case 72:28 行未改动 default: break; } }
Sleep (20); if (--times == 0) { switch (myDown (hOut, blockB, map, positionX, positionY)) { case 0:10 行未改动 } times = val; } }
cin.get (); return 0;}
5 行未改动 SetConsoleWindowInfo (hOut, true, &rc); CONSOLE_CURSOR_INFO cursor_info = { 1, 0 }; SetConsoleCursorInfo (hOut, &cursor_info);}
void initialPrint(HANDLE hOut) { SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); for (int i = 0; i < 20; i++) { // 明确绘制左右边界 gotoXY(hOut, 0, i); // 左边界(列0) cout << "■"; gotoXY(hOut, 2*11, i); // 右边界(列11) cout << "■";
// 填充中间活动区域和右侧信息区 gotoXY(hOut, 2, i); cout << " "; gotoXY(hOut, 24, i);3 行未改动 gotoXY(hOut, 0, 20); cout << "■■■■■■■■■■■■"; gotoXY(hOut, 24, 20); cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆";
gotoXY (hOut, 26, 0); gotoXY (hOut, 0, 20); cout << "■■■■■■■■■■■■☆☆☆☆☆☆☆☆☆☆☆☆☆"; gotoXY (hOut, 26, 1);250 行未改动全部展开 for (int j = 0; j < 4; j++) { int col = y + j; if (block[i][j] == 1) { // 清除下一个方块时不限制列范围 if (x != 5 && (col < 1 || col > 10)) { if (x != 5 && (col < 1 || col > 10)) { continue; } gotoXY(hOut, 2 * col, row); cout << " ";644 行未改动全部展开 if(y==202) { SetPos(pig[a].X,pig[a].Y);cout<<" "; if((pig[a].W==2||pig[a].W==3)&&pig[a].X>=2) SetPos(pig[a].X-2,pig[a].Y);cout<<" ",SetPos(pig[a].X-1,pig[a].Y);cout<<" "; if(pig[a].W==4) SetPos(pig[a].X,pig[a].Y-1),cout<<" "; if(pig[a].W==4) SetPos(pig[a].X,pig[a].Y-1),cout<<" "; if(pig[a].W==5) SetPos(pig[a].X-1,pig[a].Y),cout<<" ",SetPos(pig[a].X-1,pig[a].Y-1),cout<<" "; } if(a==2) for(int i=0;i<=40;i++)22 行未改动 if(blt[a].W2==0) { for(int i=0;i<=blt[a].vx/2+1;i++) { if(blt[a].vx>0&&m[toint(blt[a].X)+i][toint(blt[a].Y)]==1) //上反弹 if(blt[a].vx>0&&m[toint(blt[a].X)+i][toint(blt[a].Y)]==1) //上反弹 { if(blt[a].W!=5) blt[a].boom=1; blt[a].X=toint(blt[a].X)+i-1,blt[a].Y+=blt[a].vy/2,blt[a].vx=-blt[a].vx*0.4,blt[a].vy=blt[a].vy*0.8; if(blt[a].W==3) blt[a].ax=0.5;if(blt[a].W==7) blt[a].vx*=2; if(blt[a].W==10) blt[a].go=1,Bot++,boo[Bot].X=blt[a].X,boo[Bot].Y=blt[a].Y,boo[Bot].S=1,boo[Bot].mS=4; } if(blt[a].vx<0&&m[toint(blt[a].X)-i][toint(blt[a].Y)]==1) //下反弹 if(blt[a].vx<0&&m[toint(blt[a].X)-i][toint(blt[a].Y)]==1) //下反弹 { if(blt[a].W!=5) blt[a].boom=1; blt[a].X=toint(blt[a].X)+i+1,blt[a].Y+=blt[a].vy/2,blt[a].vx=-blt[a].vx,blt[a].vy=blt[a].vy*0.8; if(blt[a].W==3) blt[a].ax=0.5;if(blt[a].W==7) blt[a].vx*=2;12 行未改动{ if(pig[a].go==0&&pig[a].W!=2&&pig[a].W!=3&&pig[a].Y<16) Cout(a,202,202),pig[a].Y=16; if(pig[a].go==0&&pig[a].W==4&&pig[a].Y<20) pig[a].W=1; int R=rand()%50;Cout(a,202,202); /////////清除猪猪 /////////清除猪猪 pig[a].X+=pig[a].vx/2;pig[a].Y+=pig[a].vy/2;pig[a].vx+=pig[a].ax/2;pig[a].vy+=pig[a].ay/2; for(int i=-2;i<=pig[a].vx/2+1;i++) { if(m[toint(pig[a].X)+i][toint(pig[a].Y)]==1) //上反弹 if(m[toint(pig[a].X)+i][toint(pig[a].Y)]==1) //上反弹 pig[a].X=toint(pig[a].X)+i-1,pig[a].Y+=pig[a].vy/2,pig[a].vx=-pig[a].vx*0.5,pig[a].vy=pig[a].vy*0.8; } for(int i=Blt-10;i<=Blt;i++) {11 行未改动 } if((pig[a].W==2||pig[a].W==3)&&blt[i].go==0&&abs(pig[a].X-2-blt[i].X)<=1&&abs(pig[a].Y-blt[i].Y)<=1) {m[toint(pig[a].X)][toint(pig[a].Y)]=2,pig[a].go=1,Pig--,Sco+=10;break;} if((pig[a].W==2||pig[a].W==3)&&m[toint(pig[a].X-2)][toint(pig[a].Y)]>=2&&m[toint(pig[a].X-2)][toint(pig[a].Y)]<30) {pig[a].go=1,Pig--,Sco+=10;break;} } /////////弄死猪猪 /////////弄死猪猪 if(pig[a].go==0) { if(pig[a].go==0&&pig[a].W!=2&&pig[a].W!=3&&pig[a].Y<16) Cout(a,202,202),pig[a].Y=16; if(pig[a].go==0&&pig[a].W==4&&pig[a].Y<20) pig[a].W=1;8 行未改动 SetPos(pig[a].X-1,pig[a].Y),Color(8);SetPos(pig[a].X-1,pig[a].Y-1),cout<<"▁"; if(pig[a].W2==0)cout<<"▅";if(pig[a].W2==1)cout<<"▃";if(pig[a].W2==2)cout<<"▂";if(pig[a].W2==3) pig[a].W=1,pig[a].W2=0,SetPos(pig[a].X-1,pig[a].Y-1),cout<<" "; } } /////////输出猪猪 /////////输出猪猪 if(pig[a].W==2&&pig[a].X>pig[a].S) pig[a].W=3,pig[a].ax=-0.4,pig[a].vx=1.5; else if(pig[a].W==3&&pig[a].X<=pig[a].S) pig[a].W=2,pig[a].ax=0.4,pig[a].vx=-1.5; if((pig[a].W==2||pig[a].W==3)&&(pig[a].Y<=10||pig[a].Y>=38)) pig[a].vy*=-1; if(pig[a].W==4&&R==0&&pig[a].X==20) pig[a].vx=-((rand()%40)/10);10 行未改动 for(int i=Pit-50;i<=Pit;i++) if(pig[i].go==0&&toint(pig[i].Y)==j&&abs(pig[i].X-pig[a].X)<=2) pig[i].vy=-1; } } } /////////移动猪猪 /////////移动猪猪 if(pig[a].go==0&&pig[a].W!=2&&pig[a].W!=3&&pig[a].Y<16) Cout(a,202,202),pig[a].Y=16; if(pig[a].go==0&&pig[a].W==4&&pig[a].Y<20) pig[a].W=1; if(pig[a].X>20||pig[a].Y>38||pig[a].X<0||pig[a].Y<=0) pig[a].go=1,Pig--,Cout(a,202,202); /////////清除猪猪 /////////清除猪猪 }}void Creat(int a,int p){197 行未改动全部展开