#include <stdio.h>#include<stdlib.h>#include<conio.h>#include<windows.h>intHigh, width;//Game Screen SizeintBird_x, bird_y;//Bird's coordinatesintBar1_y, Bar1_xdown, bar1_xtop;//obstaclesintScore;//score, passing the number of obstaclesvoidGotoxy (intXintY) {//similar to the clear screen functionHANDLE HANDLE =GetStdHandle (Std_output_handle); COORD POS; Pos. X=x; Pos. Y=y; SetConsoleCursorPosition (handle, POS);}voidstartup () { high= the; Width= -; Bird_x=3; Bird_y= width/3; Bar1_y= width/2; Bar1_xdown= High/3; Bar1_xtop= High/2; Score=0;}voidShow () {Gotoxy (0,0);//Clear Screen intI, J; for(i =0; I < high; i++){ for(j =0; J < width; J + +){ if((i = = bird_x) && (j = =bird_y)) printf ("@");//Output Bird Else if((j = = bar1_y) && ((i < bar1_xdown) | | (I >bar1_xtop))) printf ("*");//Output Wall Elseprintf (" "); } printf ("\ n"); } printf ("Score:%d\n", score);}voidUpdatewithoutinput () {bird_x++; Bar1_y--; if(Bird_y = =bar1_y) { if((bird_x >= bar1_xdown) && (bird_x <=bar1_xtop)) Score++; Else{printf ("failed\n"); System ("Pause"); Exit (0); } } if(Bar1_y <=0){//To regenerate into an obstacle .Bar1_y =width; inttemp = rand ()% (int) high*0.8; Bar1_xdown= Temp-high/Ten; Bar1_xtop= temp + high/Ten; } Sleep ( Max);}voidUpdatewithinput () {Charinput; if(Kbhit ()) {input=Getch (); if(Input = =' ') {bird_x-=2; } }}voidMain () {startup (); while(1) {show (); Updatewithoutinput (); Updatewithinput (); }}
4 Flappy Bird