[Original] Greedy snake games made with C ++ (TC3.0) --- (3)

xiaoxiao2021-03-06  24

Class game {// Most critical game class public: void mainbody (); void gameinitialize (); void mapobstacle (obstacle ob [], int x); void graphicend (); void keywaiting (); Bool Continue (); void PressanyKey ();}; void game :: GameInitialize () {ScreenLayout P; Supercol brush; int midx, midy, i; p.graphchicstart (); p.ERRORDETECT (); midx = getmaxx () / 2; midy = getMaxy () / 2; brush.bar2 (MIDX-20 * fudu, MIDY-15 * fudu, MIDX 20 * fudu, Midy 15 * fudu, lightblue; brush.bar2 (MIDX-19 * fudu, MIDY-14 * Fudu, MIDX 19 * fudu, Midy 14 * fudu, black; brush.printword (MIDX-16 * fudu, MIDY-19 * fulu 5, "snake", 1, 0, lightgreen; brush. PrintWord (MIDX-2 * fudu, Midy-17 * fudu 10, "Made by: emilmatthew 05/1/16", 0, 0, 1, brown);} void game :: mapobstacle (Obstacle Ob [], int x) {supercol brush; int = 0; int midx = getmaxx () / 2, midy = getmaxy () / 2; for (i = 0; i

} void game :: Keywaiting () {gotoxy (5, 10); Printf ("pause"); while (bioskey (1) == 0) {;} gotoxy (5, 10); printf (");} Void Game :: PressanyKey () {gotoxy (5,10); Printf ("Press Any Key To Continue ... / N);} Bool Game :: Continue () {// Clrs CR (); char TMP; gotox; (5, 10); Printf (""); gotoxy (8, 11); Printf ("OH, You Failure / N"); gotoxy (8, 12); Printf ("TRY AGAIN? (Y / N) / N "); gotoxy (8, 13); scanf ("% c ", & tmp); if (tmp == 'y') return true; Else Return false;} void game :: mainbody () {// Declare Object or Variables screenLayOut Test; Drawhead sDh; Drawbody sDb; Cleantail sCt; DrawBean dou; Obstacle stock [5]; Bean douzi; int key = 0, index = 0; bool Gotbean = false, check; bool KeyPressed = false; // if The button is too fast, and the Direction TMDIR = Right; // set Start Data; Snake W (1, 0. Right, NULL); Snake B2 (2, 0, Right, & W); Snake B1 (3, 0, Right, & B2); Snake H (4, 0, Right, & B1); Snake TB1 [300]; // (0, 0, Right, Null); Snake TB2 (0, 0, Right, Null); Randomize () Stock [0] .flag = true; stock [0] .x = random (22) 5; stock [0] .y = Random (26) 1; douzi.flag = true; score = 0; mapobstacle (stock, 1); // Draw first snake. sdh.draw (H.GETX (), h.gety ()); sdb.draw (B1.GETX (), b1.get ()); sdb.draw (b2.getx (), b2.gety ()); // generate bean (stock, 5, douzi); // this Interface is not a good one, as i wisht Dou.draw (Douzi.x, Douzi.y); while (gameestatur == gaming) {while (Bioskey (1) == 0 && GameStatur == Gaming {if (gotbean) { // 1INSERT H.INSERT (& TB1 [Index]); SDB.DRAW (TB1 [Index] .GETX (), TB1 [Index] .gety ());

Index ; SDH.DRAW (H.GETX (), H.Gety ()); gotbean = false; // not so perfect. // add random make bean code etc. // w.settail (); h.makenewbean Stock, 1, Douzi; Dou.Draw (Douzi.x, Douzi.y);} else {// 2bian li // at first, you use this: * TB = & H, of Course It Just Stands for h, / / can't Work as your stay. TB2 = H; // if you use tb1 = h, there = = H. Bianlidir (); H.SETDIR (TMDIR); SDH.DRAW H.GETX (), h.gety ()); sdb.draw (tb2.getx (), tb2.draw ()); Sct.draw (w.GETX (), w.gety ());} delay2 ( 0.15, SecPERFRAME); // Collision Check // Eat Self if (H.EATSELF ()) {cout << "EAT Self" << Endl; pressAnyKey (); GameStatur = Failure; Break;} // Collision with Wall IF (h.hitwall ()) {cout << "Hit Wall" << Endl; PressanyKey (); GameStatur = Failure; Break; // Attention Here} // Collision With Obstacle IF (H.hitbrack (stock, 1)) {Cout << "Hitbrack" << Endl; pressAnyKey (); gameestatur = fail; IF (h.gotbean (douzi) {

Gotbean = true;} keypressed = false;} // check key key = bioskey (0); if (! Keypressed) {switch (key) {Case Keyup: IF (tmdir! = Down) {TMDIR = Up;} Break; Case keydown: if (tmdir! = up) {TMDIR = Down;} Break; Case Keyleft: IF (TMDIR! = Right) {TMDIR = Left;} Break; Case Keyright: IF (TMDIR! = Left) {TMDIR = Right } Break; Case KeyEnter: // Small Keywaiting Keywaiting (); Break; Case Keyesc: Gamestatur = exit;} keypressed: Break;}}

IF (GameStatur == Failure) {Check = Continue (); if (check) GameStatur = Gaming; else gamestatur = exit;}}

Void Game :: graphicend () {screenLayout P; p.graphicnd ();

void main (void) {// ScreenLayOut Gg; Game Director; while (GameStatur == Gaming) {Director.GameInitialize (); if (GameStatur = Exit!) Director.MainBody (); Director.GraphicEnd ();} getch ( }

void Delay2 (double Times, float SecPerFrame) {bool Running = true; double Tmptime = (double) clock () / (double) CLOCKS_PER_SEC; double caculate = 0, delaying = SecPerFrame; while (Running && caculate

转载请注明原文地址:https://www.9cbs.com/read-68616.html

New Post(0)