BÁO cáo bài tập lớn cấu TRÚC dữ LIỆU và GIẢI THUẬT đề tài CORONA VIRUS FIGHTER GAME

19 8 0
BÁO cáo bài tập lớn cấu TRÚC dữ LIỆU và GIẢI THUẬT đề tài  CORONA VIRUS FIGHTER GAME

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI VIỆN ĐIỆN TỬ - VIỄN THÔNG BÁO CÁO BÀI TẬP LỚN CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT Đề tài : CORONA VIRUS FIGHTER GAME Giáo viên hướng dẫn : T.S Trần Thị Thanh Hải Sinh viên Lê Tuấn Anh Hoàng Đức Nghi Nguyễn Duy Ninh Hà Nội, ngày 20 tháng 12 năm 2020 download by : skknchat@gmail.com NỘI DUNG I Giới thiệu thư viện Graphic.h II Mô tả luật chơi: III Thiết kế: IV Code: KẾT LUẬN 17 download by : skknchat@gmail.com PHÂN CÔNG NHIỆM VỤ Lê Tuấn Anh Hoàng Đức Nghi Nguyễn Duy Ninh Menu+ Class Item Class Person Class Virus NỘI DUNG ****************** I Giới thiệu thư viện Graphic.h Page | download by : skknchat@gmail.com AI Mô tả luật chơi: Game gồm người, di chuyển (lên xuống, phải, trái) đường gặp chướng ngại vật virus chất dinh dưỡng Nếu người ăn dinh dưỡng tăng thêm mạng Khi va vào chướng ngại vật (virus) bị trừ mạng Với chướng ngại vật (virus) người chơi né người chơi cộng 10 điểm Khi số mạng người chơi trị chơi kết thúc III Thiết kế: Để phục vụ chương trình nêu nhóm định sử dụng lớp lớp Person, Virus,Item *Tạo class Person class Person { public: int xPos, yPos; // vị trí nhân vật Page | download by : skknchat@gmail.com int speed; // tốc độ di chuyển int life; mạng sống nhân vật public: Person(int x,int y,int speed);//constructor void draw(); // Vẽ nhân vật void move(); // Di chuyển nhân vật }; class Virus { public: int xPos, yPos; // vị trí nhân vật int speed; // tốc độ di chuyển public: Virus(int x,int y,int speed); //constructor void draw(); // Vẽ virus void move(); // Di chuyển virus void resetPos(); // reset vị trí virus checkCollusion(Person *person, int& life) ; // Kiểm tra va chạm virus người chơi }; class Item { public: int xPos, yPos; // vị trí vật phẩm int speed; // tốc độ di chuyển bool isColision; // va chạm với person hay chưa ? public: Item(int x,int y,int speed); //constructor void draw(); // Vẽ vât phẩm void move(); // Di chuyển vật phẩm void resetItem(); // reset vị trí vật phẩm checkCollusion(Person *person, int& life) ; // Kiểm tra va chạm vật phẩm người chơi }; Page | download by : skknchat@gmail.com *Khai báo cấu trúc Player , lưu thông tin điểm người chơi vào mảng Player typedef struct Player_s { char name[50]; int point; } Player; Player player[50]; // mảng người chơi int player_index = 0; // số thứ tự người chơi *Các hàm bổ sung // sap xep diem so void swap(Player &x, Player &y); void sortArray(Player A[], int n); Ngồi cịn số hàm xử lý khác để giúp chương trình hoạt động : play() ,menu(), highScore() ,vvv IV Code: #include #include #include #include #include #include #define LEFT 75 #define RIGHT 77 #define UP 72 #define DOWN 80 #define ENTER 13 #define leftEdge 180 #define rightEdge 420 Page | download by : skknchat@gmail.com using namespace std; typedef struct Player_s { char name[50]; int point; } Player; Player player[50]; int player_index = 0; class Person { public: int xPos,yPos; int speed; int life; public: Person(int x,int y,int speed) { xPos = x; yPos = y; this->speed = speed; life = 3; } void move() { if (GetAsyncKeyState(VK_LEFT)) { if ( xPos > leftEdge ) { xPos -= speed; } } else if (GetAsyncKeyState(VK_RIGHT)) { if ( xPos < rightEdge ) Page | download by : skknchat@gmail.com { xPos += speed; } } else if (GetAsyncKeyState(VK_UP)) { if(yPos>20) { yPos-=speed; } } else if (GetAsyncKeyState(VK_DOWN)) { if(yPosspeed =speed; } void resetPos() { if(yPos>=480+35) xPos = 180+35 + rand() % (420- (180+35)+1); } void draw() { const int a =20; const int b =35; setfillstyle( 1, RED ); bar( xPos-a, yPos-a, xPos + a, yPos + a ); setcolor(GREEN); setfillstyle(1, 2); sector(xPos-10,yPos -5,0,360,5,5); sector(xPos+10,yPos -5,0,360,5,5); fillellipse(xPos,yPos+10,10,5); setcolor(WHITE); line(xPos-a,yPos-a,xPos-b,yPos-b); line(xPos-a,yPos+a,xPos-b,yPos+b); line(xPos+a,yPos-a,xPos+b,yPos-b); line(xPos+a,yPos+a,xPos+b,yPos+b); } void move() { if ( yPos < 480+35 ) { yPos += speed; } else { srand(time(NULL)); yPos = 0; speed = 10 + rand()%(25-5+1); } } void checkCollusion(Person *person, int& life) Page | download by : skknchat@gmail.com { int m = -10; if((person->xPos > xPos-30-35-m && person->xPos < xPos+30+35+m) && (person->yPos < yPos+35+20+m && person>yPos > yPos-35-20-m)) { life ; yPos = -20; } } }; class Item { public: int xPos,yPos; int speed; bool isColision; public: Item(int x,int y,int speed) { xPos = x; yPos = y; this->speed = speed; isColision = false; } void resetItem(int &pointMarker,int point) { if(yPos>480+20 || point == pointMarker*2|| isColision == true) { yPos=-20; pointMarker*=2; isColision= false; xPos = 180+35 + rand() % (420- (180+35)+1); } } Page | download by : skknchat@gmail.com & void move() { yPos+=speed; } void draw() { setcolor(2); setfillstyle(1,2); sector(xPos,yPos,0,360,10,10); } void checkCollusion(Person *Person, int &life) { if((Person->xPos -20 < xPos && Person->xPos +20 > xPos) (Person->yPos-20 < yPos && Person->yPos + 30 > yPos)) { life +=1; cout= pointMarker) { item1->move(); item1->draw(); item1->resetItem(pointMarker,point); } //corona3 cc3.resetPos(); cc3.draw(); cc3.move(); //kiểm tra va chạm cc1.checkCollusion(&person,life); cc3.checkCollusion(&person,life); / điều kiện kết thúc game mạng sống = if(life == 0) { isRunning = false; } increasePoint(cc1,point); increasePoint(cc3,point); / item1>checkCollusion(&person,life); //hien thi diem so char text2[30]="Life: 3"; sprintf(text2, "Life: %d", life); setcolor(GREEN); Page | 12 download by : skknchat@gmail.com outtextxy(5, 55, text2); char text1[30]="Point: 0"; sprintf(text1, "Point: %d", point); setcolor(GREEN); outtextxy(5, 30, text1); Sleep(60); } if(isRunning==false) { Sleep(1000); system("cls"); fflush(stdin); cout 140 ) { p -= 30; s ; } break; case DOWN: if ( p < 220 ) { p += 30; s++; }; break; case ENTER: a = 1; Page | 14 download by : skknchat@gmail.com break; default: break; } } while ( a != ); switch ( s ) { case 1: play(); break; case 2: highScore(); break; case 3: about(); break; case 4: exit(0); break; } } while ( t == ); } int main() { int gdriver = DETECT, gmode; initgraph( &gdriver, &gmode, "C:\\TC\\bgi" ); menu(); play(); } Page | 15 download by : skknchat@gmail.com KẾT LUẬN ************************ Phần mềm đạt số mục tiêu định nhiên nhiều khuyết điểm tính hạn chế Gặp vài lỗi trình chạy Tuy nhiên thu từ sau tập lớn lần giúp chúng em tự tin để tiếp tục đam mê ngành lập trình Chúng em mong nhận quan tâm góp ý từ phía cơ! Chúng em xin chân thành cảm ơn! Page | 16 download by : skknchat@gmail.com ... "!! !GAME OVER!!!" ); Sleep(1000); } void about() Page | download by : skknchat@gmail.com { cleardevice(); Person person = Person(180,300,10); Virus cc1 =Virus( 180+35,100,10); Virus cc3 =Virus( 330,100,5);... class Virus { public: int xPos, yPos; // vị trí nhân vật int speed; // tốc độ di chuyển public: Virus( int x,int y,int speed); //constructor void draw(); // Vẽ virus void move(); // Di chuyển virus. .. vật phẩm người chơi }; Page | download by : skknchat@gmail.com *Khai báo cấu trúc Player , lưu thông tin điểm người chơi vào mảng Player typedef struct Player_s { char name[50]; int point; }

Ngày đăng: 25/04/2022, 08:52

Tài liệu cùng người dùng

Tài liệu liên quan