diogo1n23456 Posted February 13, 2006 at 03:20 PM Report Share #13894 Posted February 13, 2006 at 03:20 PM boas dias. gostaria de saber se é possivel elaborar um joguito da snake em c++... 😉 Link to comment Share on other sites More sharing options...
saramgsilva Posted February 13, 2006 at 03:36 PM Report Share #13895 Posted February 13, 2006 at 03:36 PM é possivel...pois ja joguei 1 feito em C++, podes encontrar o codigo fonte no livro de conceito basicos de C++, FCA e traz tb o .exe 😛 www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5 Link to comment Share on other sites More sharing options...
Ridelight Posted February 13, 2006 at 03:42 PM Report Share #13896 Posted February 13, 2006 at 03:42 PM Tens aqui um código. #include<stdio.h> #include<conio.h> #include<graphics.h> #include<stdlib.h> #include<dos.h> #include<iostream.h> #include<time.h> #define MAX_X 620 #define MIN_X 0 #define MAX_Y 400 #define MIN_Y 0 #define SCORE_RANGE 15 int speed; struct link { int left,top,right,botom; struct link *next; }; class list { private: struct link *head; char direction; char flg; int x,y; int score; public: list(); void creat(int); void move(int); void slide(); void topmove(struct link *); void leftmove(struct link *); void rightmove(struct link *); void botommove(struct link *); void deletelast(); void draw(); void lastoperation(struct link *); void onbeat(); void setfood(); void getfood(); void endscreen(); }; list::list() { head=NULL; direction='b'; flg='r'; x=-1; y=-1; score=0; } void list::creat(int i) { int j; struct link *temp,*tail; for(j=0;j!=i;j++) { temp=(struct link *)malloc(sizeof(struct link)); temp->next=NULL; temp->left=j*10+1; temp->top=1; temp->right=j*10+10; temp->botom=10; if(head==NULL) { head=temp; tail=temp; } else { tail->next=temp; tail=temp; } } setfood(); draw(); } void list::move(int key) { struct link *temp; if(key==13) endscreen(); if(direction=='t' || direction=='b') { if(key=='a'|| key=='A') { temp=(struct link *)malloc(sizeof(struct link)); temp->next=head; direction='l'; leftmove(temp); lastoperation(temp); } else if(key=='d'|| key=='D') { temp=(struct link *)malloc(sizeof(struct link)); temp->next=head; direction='r'; rightmove(temp); lastoperation(temp); } } else if(direction=='l' || direction=='r') { if(key=='w' || key=='W') { temp=(struct link *)malloc(sizeof(struct link)); temp->next=head; direction='t'; topmove(temp); lastoperation(temp); } else if(key=='s'|| key=='S') { temp=(struct link *)malloc(sizeof(struct link)); temp->next=head; direction='b'; botommove(temp); lastoperation(temp); } } } void list::slide() { struct link *temp; temp=(struct link *)malloc(sizeof(struct link)); temp->next=head; if(direction=='t') { topmove(temp); } else if(direction=='b') { botommove(temp); } else if(direction=='l') { leftmove(temp); } else if(direction=='r') { rightmove(temp); } lastoperation(temp); } void list::leftmove(struct link *temp) { if(head->left<=MIN_X+1) { temp->left=MAX_X+1; temp->right=MAX_X+10; } else { temp->left=head->left-10; temp->right=head->right-10; } temp->top=head->top; temp->botom=head->botom; } void list::topmove(struct link *temp) { temp->left=head->left; temp->right=head->right; if(head->top<=MIN_Y+1) { temp->top=MAX_Y+1; temp->botom=MAX_Y+10; } else { temp->top=head->top-10; temp->botom=head->botom-10; } } void list::rightmove(struct link *temp) { if(head->right>MAX_X) { temp->left=MIN_X+1; temp->right=MIN_X+10; } else { temp->left=head->left+10; temp->right=head->right+10; } temp->top=head->top; temp->botom=head->botom; } void list::botommove(struct link *temp) { temp->left=head->left; temp->right=head->right; if(head->botom>MAX_Y) { temp->top=MIN_Y+1; temp->botom=MIN_Y+10; } else { temp->top=head->top+10; temp->botom=head->botom+10; } } void list::deletelast() { struct link *temp,*tail; temp=head; while(temp->next->next!=NULL) temp=temp->next; //make node color black setcolor(0); rectangle(temp->next->left,temp->next->top,temp->next->right,temp->next->botom); tail=temp->next; temp->next=NULL; free(tail); setcolor(10); } void list::draw() { struct link *temp; for(temp=head;temp!=NULL;temp=temp->next) { rectangle(temp->left,temp->top,temp->right,temp->botom); if(temp!=head) if((head->left==temp->left)&&(head->top==temp->top)&&(head->right==temp->right)) onbeat(); if((head->left==x)&&(head->top==y)&&(head->right==x+9)) getfood(); } } void list::lastoperation(struct link *temp) { head=temp; if(flg=='r') deletelast(); else flg='r'; draw(); } void list::onbeat() { while(1) { if(kbhit()) if(getch()==13) break; setcolor(random(10)); rectangle(head->left-2,head->top-2,head->right+2,head->botom+2); setcolor(random(10)); rectangle(head->left-4,head->top-4,head->right+4,head->botom+4); setcolor(random(10)); rectangle(head->left-6,head->top-6,head->right+6,head->botom+6); delay(500); } endscreen(); } void list::setfood() { x=random((MAX_X-20)/10)*10+1; y=random((MAX_Y-20)/10)*10+1; setcolor(5); rectangle(x,y,x+9,y+9); setcolor(10); } void list::getfood() { flg='s'; x=y=-1; score+=random(SCORE_RANGE); gotoxy(70,28); cout<<score; setfood(); } void list::endscreen() { cleardevice(); setcolor(3); rectangle(MIN_X,MIN_Y,MAX_X+13,MAX_Y+73); setcolor(4); rectangle(MIN_X+3,MIN_Y+3,MAX_X+10,MAX_Y+70); setcolor(5); gotoxy(40,15); cout<<score; outtextxy(235,140,"G A M E S C O R E"); outtextxy(260,340,"Developed by"); outtextxy(187,385,"Email : priyank_modi@yahoo.co.in"); outtextxy(147,405,"Website : http://geocities.com/priyank_modi/"); setcolor(11); outtextxy(220,365,"P r i y a n k M o d i"); outtextxy(257,300,"S N A K E"); if(getch()==13) { closegraph(); exit(0); } } void startup() { char key; cleardevice(); setcolor(3); rectangle(MIN_X,MIN_Y,MAX_X+13,MAX_Y+73); setcolor(4); rectangle(MIN_X+3,MIN_Y+3,MAX_X+10,MAX_Y+70); setcolor(11); outtextxy(220,365,"P r i y a n k M o d i"); outtextxy(257,300,"S N A K E"); setcolor(5); outtextxy(225,140,"G A M E L E V E L S"); outtextxy(60,200,"Beginner=[b] - Easy=[E] - Normal=[N] - Difficult=[D] - Ultra=[u]"); outtextxy(260,340,"Developed by"); outtextxy(187,385,"Email : priyank_modi@yahoo.co.in"); outtextxy(147,405,"Website : http://geocities.com/priyank_modi/"); again: while(!kbhit()) { setcolor(7); outtextxy(210,255,"Press level selection key"); delay(400); setcolor(0); outtextxy(210,255,"Press level selection key"); delay(200); } key=getch(); if(key=='E'||key=='e') speed=120; else if(key=='B'||key=='b') speed=145; else if(key=='N'||key=='n') speed=95; else if(key=='D'||key=='d') speed=75; else if(key=='U'||key=='u') speed=55; else goto again; void main() { int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, ""); startup(); cleardevice(); setcolor(8); rectangle(MIN_X,MIN_Y,MAX_X+11,MAX_Y+11); rectangle(MIN_X,MAX_Y+27,MAX_X+11,MAX_Y+50); rectangle(MIN_X,MAX_Y+55,MAX_X+11,MAX_Y+75); line(500,MAX_Y+27,500,MAX_Y+50); setcolor(7); outtextxy(190,MAX_Y+62,"Developed by : Priyank Modi"); outtextxy(7,MAX_Y+36,"Keys : Top=[W], Left=[A], Right=[D], Bottom=[s], Exit=[ENTER] "); class list snk; randomize(); snk.creat(15); getch(); while(1) { if(kbhit()) snk.move(getch()); else snk.slide(); delay(speed); } } Regras do FÓRUM Link to comment Share on other sites More sharing options...
diogo1n23456 Posted February 13, 2006 at 03:48 PM Author Report Share #13897 Posted February 13, 2006 at 03:48 PM Ridelight tá a ar um erro no <graphics.h> edit 2: tenho k fazer um fixeiro pa fazer ligação?? Link to comment Share on other sites More sharing options...
diogo1n23456 Posted February 13, 2006 at 03:56 PM Author Report Share #13898 Posted February 13, 2006 at 03:56 PM Cannot open include file: 'graphics.h': No such file or directory ya é isso mm... tenho d fazer ligação a outro fixeiro :/ agr nao sei o codigo do outro fixeiro pa fazeer ligação ao graphics... Link to comment Share on other sites More sharing options...
saramgsilva Posted February 13, 2006 at 03:56 PM Report Share #13899 Posted February 13, 2006 at 03:56 PM existe 1 opção k diz modificar...e atraves disso podes modificar a tua mensagem...escreves 3 mensagens para o mesmo.... 😉 e eu corrigi... ? o MODIFICAR podes encontrar qdo les a mensagem do teu lado direito, no canto superior!! tambem compilei para executar...e deu me mtos erros... undeclared rectangle, setcolor, random... tv falte alguma bibilioteca... 😛 pois acabei de confirmar k me falta o graphics.h .... e deve ser este o teu erro tb!! :dontgetit: www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5 Link to comment Share on other sites More sharing options...
diogo1n23456 Posted February 13, 2006 at 04:00 PM Author Report Share #13900 Posted February 13, 2006 at 04:00 PM essa operacao aparce ond?? Link to comment Share on other sites More sharing options...
diogo1n23456 Posted February 13, 2006 at 04:14 PM Author Report Share #13901 Posted February 13, 2006 at 04:14 PM é k nao vejo... eu uso o microsoft visual c++ 6.0 . o teu deve ser diferente o compilador... Link to comment Share on other sites More sharing options...
saramgsilva Posted February 13, 2006 at 04:24 PM Report Share #13903 Posted February 13, 2006 at 04:24 PM eu uso o dev c++ , mas nunca trab com a parte grafica... http://img525.imageshack.us/img525/5669/modificar2ov.th.jpg desc se esta mto grande...mas foi a pressa!! 😉 www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5 Link to comment Share on other sites More sharing options...
vbmaster Posted February 13, 2006 at 07:24 PM Report Share #13924 Posted February 13, 2006 at 07:24 PM Em 13/02/2006 às 16:36, tofas disse: é possivel...pois ja joguei 1 feito em C++, podes encontrar o codigo fonte no livro de conceito basicos de C++, FCA e traz tb o .exe 😄 olha... no meu livro... mas ainda não cheguei lá.... 😛 Link to comment Share on other sites More sharing options...
diogo1n23456 Posted February 13, 2006 at 10:25 PM Author Report Share #13943 Posted February 13, 2006 at 10:25 PM com o turbo c tb me ta a dar erro... 3 erros Link to comment Share on other sites More sharing options...
QuickFire Posted February 13, 2006 at 10:53 PM Report Share #13948 Posted February 13, 2006 at 10:53 PM Tentem adicionar esta lib à pasta das libs e vejam o resultado 😉 http://sarien.sourceforge.net/sourcedoc/graphics_8h-source.html Link to comment Share on other sites More sharing options...
saramgsilva Posted February 14, 2006 at 02:12 PM Report Share #13971 Posted February 14, 2006 at 02:12 PM Tentem adicionar esta lib à pasta das libs e vejam o resultado 😛 http://sarien.sourceforge.net/sourcedoc/graphics_8h-source.html mesmo assim mtos erros 😉 www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5 Link to comment Share on other sites More sharing options...
diogo1n23456 Posted February 14, 2006 at 03:58 PM Author Report Share #13984 Posted February 14, 2006 at 03:58 PM ya. a mim ta me a dar 1 erro gravado em .h c:\documents and settings\alunos\desktop\snake\snake.cpp(3) : fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory se gravo em .cpp tens este erros --------------------Configuration: graphics - Win32 Debug-------------------- Compiling... graphics.cpp c:\documents and settings\alunos\desktop\graphics.cpp(39) : error C2629: unexpected 'void (' c:\documents and settings\alunos\desktop\graphics.cpp(39) : error C2238: unexpected token(s) preceding ';' c:\documents and settings\alunos\desktop\graphics.cpp(45) : error C2146: syntax error : missing ';' before identifier 'palette' c:\documents and settings\alunos\desktop\graphics.cpp(45) : fatal error C1004: unexpected end of file found Error executing cl.exe. graphics.exe - 4 error(s), 0 warning(s) isso tem de ficar guardado em ".h" ou ".cpp" com o nome graphics??? Link to comment Share on other sites More sharing options...
diogo1n23456 Posted February 21, 2006 at 03:56 PM Author Report Share #14849 Posted February 21, 2006 at 03:56 PM ninguem sabe??? Link to comment Share on other sites More sharing options...
saramgsilva Posted February 21, 2006 at 04:04 PM Report Share #14853 Posted February 21, 2006 at 04:04 PM ninguem sabe??? eu nao..nunca trabalhei com cenas com graficos... 😛 www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5 Link to comment Share on other sites More sharing options...
neon_prannock Posted February 21, 2006 at 06:27 PM Report Share #14867 Posted February 21, 2006 at 06:27 PM O melhor é aprenderes a usar alguma API gráfica para C++, e seres tu a fazer o Snake. Para 2D aconselho SDL: http://www.libsdl.org/index.php ou Hyper64: http://fozi.codingcorner.net/tutorials/h64pt/ http://sergiosantos.info http://ideias3.com http://takeoff.ideias3.com Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now