Вы находитесь на странице: 1из 15

OF

Snake game

Submitted in the partial fulfillment of the Degree of Bachelor of Technology (Integrated) In Computer Science and Engineering S B!ITTED B"#$ &ame 'nkit(uttkar)h +egd, &o -./.-0.12 -./..334 +ollno (complete)+506B70(+506B74 % IDED B"# !i)) Sukhdilpreet *aur

S B!ITTED TO Department of Computer Science and Engineering 8o9ely :rofe))ional ni9er)ity :hag;ara

ACKNOWLEDGEMENT I take thi) opportunity to pre)ent my 9ote) of thank) to all tho)e guidepo)t ;ho really acted a) lightening pillar) to enlighten our ;ay throughout thi) pro<ect that ha) led to )ucce))ful and )ati)factory completion of thi) )tudy, =e are really grateful to our >OD !r, +ohit Dhand for pro9iding u) ;ith an opportunity to undertake thi) pro<ect in thi) uni9er)ity and pro9iding u) ;ith all the facilitie), =e are highly thankful to !i)) Sukhdilpreet *aur for her acti9e )upport2 9aluable time and ad9ice2 ;hole$hearted guidance2 )incere cooperation and pain)$ taking in9ol9ement during the )tudy and in completing the a))ignment of preparing the )aid pro<ect ;ithin the time )tipulated, 8a)tly2 =e are thankful to all tho)e2 particularly the 9ariou) friend) 2 ;ho ha9e been in)trumental in creating proper2 healthy and conducti9e en9ironment and including ne; and fre)h inno9ati9e idea) for u) during the pro<ect2 their help2 it ;ould ha9e been e?tremely difficult for u) to prepare the pro<ect in a time bound frame;ork, &ame 'nkit chopra uttkar)ha )ingh -./..334 +506B74 +egd,&o-./.-0.1 +ollno+506B70,

TABLE OF CONTENTS -, 5, Introduction :ropo)ed )y)tem i, De)cription ii, Sy)tem re@uirement) 7, +e@uirement 'naly)i) 0, Sy)tem De)ign 4, Source code 6, Te)ting 3, Future )cope of pro<ect

I&T+OD CTIO&
The follo;ing i) an e?ample game ;ritten in C ba)ed on the game called A)nakeA ;hich ha) been around )ince the earlie)t day) of home computing (I can remember ;riting a 9er)ion of it for my BC/-)2 and ha) re$emerged in recent year) on mobile phone), It i)nAt the ;orldA) greate)t game2 but it doe) gi9e you an idea of ;hat you can achie9e ;ith a relati9ely )imple C program2 and perhap) the ba)i) by ;hich to e?tend the principle) and create more intere)ting game) of your o;n,
,

Playing the game


"ou can do;nload the e?ecutable to try out the game ;ithout ha9ing to compile it if you ;i)h, Do;nload it by clicking here $ it i) about -57k in length,&ote that on fa)ter :C)2 it ;ill be unplayably fa)t2 )o you ;ill need to re$compile it ;ith the pau)eDlength con)tant )et to a higher 9alue, !y :C i) about 74.!>E and it i) O*,To mo9e the )nake2 u)e AaA for up2 AEA for do;n2 AoA for left and ApA for right, 'gain2 there are con)tant) you can change if you ;ant to alter the)e )etting), :re)) A?A to e?it the game at any time, The aim of the game i) to collect the dot) (food) and a9oid the ob)tacle) (cro))e)2 border)2 and the )nake it)elf), ') you collect food2 the )nake get) longer2 )o increa)ing your likelihood of cra)hing into your)elf, =hen you ha9e collected enough food2 you progre)) onto the ne?t le9el2 ;here your )nake get) longer2 and the amount of food to collect to progre)) through the le9el get) larger,"ou get )cored according to the length of the )nake and the number of A?A ob)tacle) on the )creen,The )peed increa)e) e9ery 4 le9el),"ou get a bonu) ;hen you complete the le9el of -...2 increa)ing by -... each le9el (e,g, complete le9el 42 you get a 4... bonu)),There i) no concept of li9e), Once you hit an ob)tacle2 thatA) it2 game o9er,!ake )ure you do not ha9e the cap) lock on2 other;i)e the key) ;ill fail to re)pond

PROPOSED SYSTEM The follo;ing documentation i) a pro<ect the F&ame of the term paper allottedG, It i) a detailed )ummary of all the dra;back) of the old )y)tem and ho; the ne; propo)ed )y)tem o9ercome) the)e )hortcoming), The ne; )y)tem take) into account the 9ariou) factor) ;hile de)igning a ne; )y)tem, It keep) into the account the Economical band;idth a9ailable for the ne; )y)tem, The foremo)t thing that i) taken care of i) the &eed and +e@uirement) of the )er, DESCRIPTION Before de9eloping )oft;are ;e keep follo;ing thing) in mind that ;e can de9elop po;erful and @uality )oft;are :+OB8E! ST'TE!E&T o :roblem )tatement ;a) to de)ign a module# o =hich i) u)er friendly o =hich ;ill re)trict the u)er from acce))ing other u)erH) data, o =hich ;ill help u)er in 9ie;ing hi) data and pri9ilege), o =hich ;ill help the admini)trator to handle all the change), F &CTIO&S TO BE :+OIIDED# The )y)tem ;ill be u)er friendly and completely menu dri9en )o that the u)er) )hall ha9e no problem in u)ing all option), o The )y)tem ;ill be efficient and fa)t in re)pon)e, o The )y)tem ;ill be cu)tomiEed according to need), o It i) a game ;hich can play by anyone o It i) ea)y to u)e

SYSTEM REQ IRMENTS Operating )y)tem# !S =indo;) C: or =indo;) Ii)ta 8anguage# C 8anguage :roce))or# :entium II :roce))or +'!# 4-5 !B >ard di)k# 4 %B

REQ IREMENT ANALYSIS Thi) proce)) i) adopted ;hen management of the )y)tem de9elopment2 :er)onnel decide that the particular )y)tem need) impro9ement, The )y)tem de9elopment life cycle i) the )et of acti9itie)2 carried out by the analy)t2 de)igner) and u)er) to de9elop and implement a )y)tem, The )y)tem) that are pre)ent in the nature follo; common life cycle pattern, For e?ample con)ider the raining )y)tem, Initially the rain fall) into the ri9er2 ri9er flo;) into )ea2 the )ea ;ater e9aporate) to form 9apor)2 the 9apor) form cloud) ;hich again bring rain, Similarly con)ider a man made )y)tem initially a )y)tem i) analyEed2 de)igned and made operational by the effort) of )y)tem analy)i), 'fter )ucce))ful operation or a number of u)er)2 the )y)tem become) le)) and le)) effecti9e by change in the en9ironment, So the)e change) ha9e to be incorporated in to the )y)tem by minor modification), So the general acti9itie) from the life cycle of the )y)tem are gi9en belo;# Select ion and identification of the )y)tem to be )tudied :reliminary )tudy Defining the )y)tem De)ign and de9elopment of the )y)tem Implementation of the )y)tem

SYSTEM DESIGN Then ;e began ;ith the de)ign pha)e of the )y)tem, Sy)tem de)ign i) a )olution2 a F>O= TOG approach to the creation of a ne; )y)tem, It tran)late) )y)tem re@uirement) into ;ay) by ;hich they can be made operational, It i) a tran)lational from a u)er oriented document to a document oriented programmer), For that2 it pro9ide) the under)tanding and procedural detail) nece))ary for the implementation, >ere ;e u)e Flo;chart to )upplement the ;orking of the ne; )y)tem, The )y)tem thu) made )hould be reliable2 durable and abo9e all )hould ha9e lea)t po))ible maintenance co)t), It )hould o9ercome all the dra;back) of the Old e?i)ting )y)tem and mo)t important of all meet the u)er re@uirement), ST'+T

enter the main menu of )nake game

Enter your

choice J

Enter name

:lay game

@uit

Do you ;ant to continueJ

STO:

SO RCE CODE #include K)tdlib,hL Minclude K)tdio,hL Minclude Kconio,hL NO prototype) ON 9oid dra;Dline(int col2 int ro;)P 9oid )ho;D)core()P 9oid addD)egment()P 9oid )etupDle9el()P NO con)tant) ON con)t int ma?ro;Q-42 ma?colQ33P con)t int )nakeD)tartDcolQ772)nakeD)tartDro;Q3P con)t char upDkeyQAaA2 do;nDkeyQAEA2 leftDkeyQAoA2 rightDkeyQApAP con)t int pau)eDlengthQ4.....P NO global 9ariable) ON int )core2 )nakeDlength2 )peed2 ob)tacle)2 le9el2 fir)tpre))2 highD)coreQ.P char )creenDgridRma?ro;SRma?colSP char direction Q rightDkeyP )truct )nakeD)egment T int ro;2colP U )nakeR-..SP 9oid main() T NO Iariable declaration) ;ithin main() only ON char keypre))P do NO re)tart game loop ON T ob)tacle)Q0P le9elQ-P )coreQ.P )peedQ-0P randomiEe()P NO En)ure random )eed initiated ON )etupDle9el()P NO main loop ON do T for (int iQ.PiK()peedOpau)eDlength)PiVV) int <Q-ViP NOpau)eON NO If key ha) been hit2 then check it i) a direction key $ if )o2 change direction ON if (kbhit()) T keypre))Q(char)getch()P if((keypre))QQrightDkey)WW(keypre))QQleftDkey)WW (keypre))QQupDkey)WW(keypre))QQdo;nDkey)) direction Q keypre))P U NO 'dd a )egment to the end of the )nake ON addD)egment()P

NO Blank la)t )egment of )nake ON goto?y()nakeR.S,col2)nakeR.S,ro;)P cprintf(X X)P NO ,,, and remo9e it from the array ON for (int iQ-PiKQ)nakeDlengthPiVV) )nakeRi$-SQ)nakeRiSP NO Di)play )nake in yello; ON te?tcolor("E88O=)P for (int iQ.PiKQ)nakeDlengthPiVV) T goto?y()nakeRiS,col2)nakeRiS,ro;)P cprintf(XOX)P U NO keep) cur)or fla)hing in one place in)tead of follo;ing )nake ON goto?y(-2-)P NO If fir)t pre)) on each le9el2 pau)e until a key i) pre))ed ON if (fir)tpre))) T ;hile(Ykbhit())P fir)tpre)) Q .P U NO Colli)ion detection $ ;all) (badY) ON if (()nakeR)nakeDlength$-S,ro;Lma?ro;V-)WW()nakeR)nakeDlength$-S,ro;KQ-)WW ()nakeR)nakeDlength$-S,colLma?colV-)WW()nakeR)nakeDlength$-S,colKQ-)WW NO Colli)ion detection $ ob)tacle) (badY) ON ()creenDgridR)nakeR)nakeDlength$-S,ro;$5SR)nakeR)nakeDlength$-S,col$5SQQA?A)) keypre))QA?AP NO i,e, e?it loop $ game o9er ON NO Colli)ion detection $ )nake (badY) ON for (int iQ.PiK)nakeDlength$-PiVV) if ( ()nakeR)nakeDlength$-S,ro;)QQ()nakeRiS,ro;) (( ()nakeR)nakeDlength$-S,col)QQ()nakeRiS,col)) T keypre))QA?AP NO i,e, e?it loop $ game o9er ON breakP NO no need to check any more )egment) ON U NO Colli)ion detection $ food (goodY) ON if ()creenDgridR)nakeR)nakeDlength$-S,ro;$5SR)nakeR)nakeDlength$-S,col$5SQQA,A) T NO increa)e )core and length of )nake ON )coreVQ)nakeDlengthOob)tacle)P )ho;D)core()P )nakeDlengthVVP addD)egment()P NO if length of )nake reache) certain )iEe2 onto ne?t le9el ON if ()nakeDlengthQQ(le9elV7)O5) T )coreVQle9elO-...P ob)tacle)VQ5P le9elVVP NO add to ob)tacle) ON if ((le9elZ4QQ.)((()peedL-)) )peed$$P NO increa)e )peed e9ery 4 le9el) ON )etupDle9el()P NO di)play ne?t le9el ON U U U ;hile (keypre))YQA?A)P

NO game o9er me))age ON if ()core L highD)core) highD)core Q )coreP )ho;D)core()P goto?y(7.26)P te?tcolor(8I%>T+ED)P cprintf(X% ' ! E O I E +X)P goto?y(7.21)P te?tcolor("E88O=)P cprintf(X'nother %ame yNn)J X)P do keypre))Qgetch()P ;hile((keypre))YQAyA)(((keypre))YQAnA))P U ;hile (keypre))QQAyA)P 9oid )etupDle9el() T NO 9ariable) local to )etupDle9el() ON int ro;2colP NO Set up global 9ariable) for ne; le9el ON )nakeDlengthQle9elV0P direction Q rightDkeyP fir)tpre)) Q -P NO Fill grid ;ith blank) ON for(ro;Q.Pro;Kma?ro;Pro;VV) for(colQ.PcolKma?colPcolVV) )creenDgridRro;SRcolSQ A AP NO Fill grid ;ith C) and food ON for(int iQ.PiKob)tacle)O5PiVV) T ro;Q rand()Zma?ro;P colQ rand()Zma?colP if(iKob)tacle)) )creenDgridRro;SRcolSQA?AP el)e )creenDgridRro;SRcolSQA,AP U NO Create )nake array of length )nakeDlength ON for(int iQ.PiK)nakeDlengthPiVV) T )nakeRiS,ro;Q)nakeD)tartDro;P )nakeRiS,colQ)nakeD)tartDcolViP U NO Dra; playing board ON dra;Dline(-2-)P for(ro;Q.Pro;Kma?ro;Pro;VV) T goto?y(-2ro;V5)P te?tcolor(8I%>TB8 E)P cprintf(XWX)P te?tcolor(=>ITE)P for(colQ.PcolKma?colPcolVV) cprintf(XZcX2)creenDgridRro;SRcolS)P te?tcolor(8I%>TB8 E)P

cprintf(XWX)P U dra;Dline(-2ma?ro;V5)P )ho;D)core()P goto?y(52ma?ro;V4)P te?tcolor(8I%>T+ED)P cprintf(X[[ S&'*E %'!E[[ 8eft# Zc2 +ight# Zc2 p# Zc2 Do;n# Zc2 E?it# ?, 'ny key to )tart,X2 leftDkey2rightDkey2upDkey2do;nDkey)P U 9oid dra;Dline(int col2 int ro;) T goto?y(col2ro;)P te?tcolor(8I%>TB8 E)P for (int colQ.PcolKma?colV5PcolVV) cprintf(XQX)P U 9oid )ho;D)core() T te?tcolor(8I%>TC"'&)P goto?y(52ma?ro;V7)P cprintf(X8e9el# Z.4dX2le9el)P goto?y(0.2ma?ro;V7)P te?tcolor(8I%>T%+EE&)P cprintf(XScore# Z.4dX2)core)P goto?y(6.2ma?ro;V7)P te?tcolor(8I%>T!'%E&T')P cprintf(X>igh Score# Z.4dX2highD)core)P U 9oid addD)egment() T );itch(direction) T ca)e(rightDkey)# )nakeR)nakeDlengthS,ro;Q)nakeR)nakeDlength$-S,ro;P )nakeR)nakeDlengthS,colQ)nakeR)nakeDlength$-S,colV-P breakP ca)e(leftDkey) # )nakeR)nakeDlengthS,ro;Q)nakeR)nakeDlength$-S,ro;P )nakeR)nakeDlengthS,colQ)nakeR)nakeDlength$-S,col$-P breakP ca)e(upDkey) # )nakeR)nakeDlengthS,ro;Q)nakeR)nakeDlength$-S,ro;$-P )nakeR)nakeDlengthS,colQ)nakeR)nakeDlength$-S,colP breakP ca)e(do;nDkey) # )nakeR)nakeDlengthS,ro;Q)nakeR)nakeDlength$-S,ro;V-P )nakeR)n )nakeDlengthS,colQ)nakeR)nakeDlength$-S,colP U U

TESTING Te)ting i) the ma<or control mea)ure u)ed during )oft;are de9elopment, It) ba)ic function i) to detect error) in the )oft;are, During re@uirement analy)i) and de)ign2 the output i) a document that i) u)ually te?tual and no e?ecutable, 'fter the coding pha)e2 computer program) are a9ailable that can be e?ecuted for te)ting purpo)e, Thi) implie) that te)ting not only2 ha) to unco9er error) introduced during coding2 but al)o error) introduced during pre9iou) pha)e, Thu) the goal of te)ting i) to unco9er the re@uirement)2 de)ign and coding error) in the program), So after te)ting the output) of my pro<ect are a) follo;)# Main men! "#$een

I% "na&e #$'""e" the line then it te$minate

F T RE SCOPE OF T(E PRO)ECT Our pro<ect ;ill be able to implement in future after making )ome change) and modification) a) ;e make our pro<ect at a 9ery lo; le9el, So the modification) that can be done in our pro<ect are# IT can be made ;ith good graphic), 'nd ;e can add more option)

Вам также может понравиться