Mời mọi người góp ý cho game đầu tay

https://drive.google.com/file/d/0B1ol__JYLTaaZXJ1SXRvb1pBS0E/view?usp=sharing

3 Likes

Không chạy được bạn ơi. Đăng lên file exe trong Release chứ không phải trong Debug nhé bạn

2 Likes
            #include <iostream>
            #include <dos.h>
            #include <windows.h>
            #include <conio.h>
            #include <time.h>
            #include <stdlib.h>
            using namespace std;

        void gotoxy(int x,int y)
        {    
        	HANDLE hConsoleOutput;    
        	COORD Cursor_an_Pos = {x-1,y-1};   
        	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);    
        	SetConsoleCursorPosition(hConsoleOutput , Cursor_an_Pos);
        }
        void textcolor(int x)
        {
        	HANDLE mau;
        	mau=GetStdHandle(STD_OUTPUT_HANDLE);
        	SetConsoleTextAttribute(mau,x);
        }
        void xoa (int x,int y){
        	textcolor(1);
        gotoxy(x,y);
        printf(" ");
        }
        void inramanhinh(int x,int y){
        gotoxy(x,y);
        printf(" ");
        }
        void manhinh(void){
        gotoxy(1,1);textcolor(155);
        int i=0,j=1;
        for(i=1;i<=40;i++) cout<< " ";
        printf("\n");
        for(j=1;j<=19;j++){
        	printf(" ");textcolor(1);
        	for(i=1;i<=38;i++) printf(" ");textcolor(155);
        	printf(" \n");
        }
        for(i=1;i<=40;i++) cout<< " ";
        }
        int ktra (int x, int y,int xmoi, int ymoi, int *diem){
        if (x>=40||x<=1||y>=21||y<=1) return 2;
        if (x==xmoi&&y==ymoi) {*diem=*diem+1;return 1;} else return 0;
        }
        void moi (int *xmoi,int *ymoi,int x,int y,int *toadox,int *toadoy,int diem){
        srand(time(0));
        int i;
        *xmoi=100; *ymoi=100;
        while (*xmoi>=40||*xmoi<=1&&*ymoi>=20||*ymoi<=1){
           *xmoi=rand()%37+2;if(x==*xmoi) *xmoi=100;
	       *ymoi=rand()%16+3;if(y==*ymoi) *ymoi=100;
	       if(x==*xmoi&&y==*ymoi) {*xmoi=100;*ymoi=100;}
	       for(i=0;i<=diem;i++) if(*ymoi==toadoy[i]&&*xmoi==toadox[i])      {*xmoi=100;*ymoi=100;}    
}
} 
        void dieukhien (char huong, int *x,int *y){
        	if(huong=='a') *x=*x-1;
        	if(huong=='w') *y=*y-1;
        	if(huong=='d') *x=*x+1;
        	if(huong=='s') *y=*y+1;}
        int main()
        {    int muc=1;
        gotoxy(1,2);printf("Nhap 1 de chon muc de, 2 la muc trung binh, 3 la muc kho");gotoxy(1,3);
        printf("xin chon muc:");scanf("%d",&muc);
        if(muc==1) muc=300;if(muc==2) muc==200; if(muc==3) muc=100;
        batdau:
        	system("cls");
        	int toadox[100]={3,2},toadoy[100]={2,2},x=4,y=2,ymoi,xmoi,giatriktra=1,i=0,diem=1,tg=1;
        	char phim='d',saophim;
        	manhinh();tg=1;
        	while(giatriktra==1){
        		giatriktra=0;textcolor(5);gotoxy(45,2);printf("Diem:%d",diem-1);
        		moi(&xmoi,&ymoi,x,y,toadox,toadoy,diem);textcolor(194);
        		gotoxy(xmoi,ymoi); printf(" ");
        		while(giatriktra==0){tg++;if(tg==4) xoa(4,2);
        		textcolor(179);
        		inramanhinh(x,y);
        		for(i=0;i<=diem;i++) {textcolor(163);inramanhinh(toadox[i],toadoy[i]);}
        		Sleep(muc);saophim=phim;
        		xoa(toadox[diem],toadoy[diem]);
        		giatriktra=ktra(x,y,xmoi,ymoi,&diem);
        		for(i=0;i<=diem;i++) if(x==toadox[i]&&y==toadoy[i]) giatriktra=2;
        		for(i=diem;i>=1;i--){
        			toadox[i]=toadox[i-1];
        			toadoy[i]=toadoy[i-1];
        		}
        		toadox[0]=x;toadoy[0]=y;
        		if(kbhit()!=0){
        			phim=getch();
        			if(phim=='d'&&saophim=='a') phim='a';
        			if(phim=='w'&&saophim=='s') phim='s';
        			if(phim=='a'&&saophim=='d') phim='d';
        			if(phim=='s'&&saophim=='w') phim='w';}
        		dieukhien(phim,&x,&y);
        		}
        	
        	}
        	system("cls");textcolor(7);
        	printf("Thua!!!!!!!!!!!!!!!!\n");
        	system("pause");
        	system("cls");
        	char luachon;
        	printf("Ban co muon choi tiep? Nhap 'y' de tiep tuc, Nhan 'n' de thoat");
        	luachon=getch();
        	if(luachon=='y') goto batdau;
        			
        	


        }

code đây các bác

2 Likes

đây là code game. các bác coppy về rồi xài vietsual studio chạy nha. ko hỉu xao em làm bằng code blook thì hàm getch() ko hoạt động

1 Like

game j vậy bác @@ nhìn code rối vl

1 Like

game rắn săn mồi. em viết tất cả hàm cần dùng vào 1 file nên nhìn hơi kinh đó bác

1 Like

mà làm sao để code vào trong phần in đậm dành riêng cho code dc nhỉ bác

2 Likes

Bác chép code vô, quét chọn vùng code rồi Ctrl + Shift+C

#include <iosteam>
using namespace std;
int main()
{
cout<<"abcxyz";
return 0;
}
2 Likes

Liệu có phải bạn cố tình làm đống code nhồi thành một cục thế để người khác khỏi đọc hay chỉ đơn giản là bạn không biết trình bày code vậy? @@

trình bày thế nào bác. mỗi dòng lệnh 1 dòng à? hay chia các ct con thành các file riêng?, hay chia ct ra thành nhiều ct con hơn

Bạn tìm đọc trên mạng Các chuẩn và quy uớc lập trình để sửa đổi dần đi.

1 Like

tks bác. tại em mới học cấp 3 nên ko rõ cách trình bày cho lắm

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?