Bao cao - Báo cáo bài tập lớn ngôn ngữ lập trình PDF

Title Bao cao - Báo cáo bài tập lớn ngôn ngữ lập trình
Author Lê Tuấn Anh
Course Ngôn ngữ lập trình
Institution Trường Đại học Bách khoa Hà Nội
Pages 18
File Size 337.7 KB
File Type PDF
Total Downloads 414
Total Views 782

Summary

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘIVIỆN ĐIỆN TỬ - VIỄN THÔNGBÁO CÁO BÀI TẬP LỚNCẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬTĐề tài :CORONA VIRUS FIGHTER GAMEGiáo viên hướng dẫn : T Trần Thị Thanh HảiSinh viên MSSV Lê Tuấn Anh 20172404 Hoàng Đức Nghi 20172716 Nguyễn Duy Ninh 20172739Hà Nội, ngày 20 tháng 12 năm 2020NỘI...


Description

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

MSSV 20172404 20172716 20172739

Hà Nội, ngày 20 tháng 12 năm 2020

NỘI DUNG.................................................................................1 I.

Giới thiệu về thư viện Graphic.h...................................1

II.

Mô tả luật chơi:...............................................................2

III. Thiết kế:...........................................................................2 IV. Code:................................................................................4 KẾT LUẬN...............................................................................17

PHÂN CÔNG NHIỆM VỤ Menu+ Class Item Class Person Class Virus

Lê Tuấn Anh Hoàng Đức Nghi Nguyễn Duy Ninh NỘI DUNG ******************

I.

Giới thiệu về thư viện Graphic.h

Page | 1

II.

Mô tả luật chơi:

Game gồm 1 người, có thể di chuyển (lên xuống, phải, trái) trên đường đi gặp các chướng ngại vật là virus hoặc các chất dinh dưỡng. Nếu người đó ăn được dinh dưỡng thì sẽ tăng thêm 1 mạng . Khi va vào chướng ngại vật (virus) thì sẽ bị trừ 1 mạng. Với mỗi chướng ngại vật (virus) người chơi né được thì người chơi sẽ được cộng 10 điểm. Khi số mạng của người chơi về 0 thì trò chơi sẽ kết thúc. III. Thiết kế: Để phục vụ chương trình nêu trên nhóm đã quyết định sử dụng 3 lớp đó là lớp Person, Virus,Item. *Tạo class Person class Person { public: int xPos, yPos; // vị trí của nhân vật Page | 2

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í của 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 giữa virus và người chơi }; class Item { public: int xPos, yPos; // vị trí của 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 giữa vật phẩm và người chơi }; Page | 3

*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); Ngoài ra còn 1 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 | 4

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 | 5

{ 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 | 7

{ 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 | 8

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 khi mạng sống = 0 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

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

break; default: break; } } while ( a != 1 ); switch ( s ) { case 1: play(); break; case 2: highScore(); break; case 3: about(); break; case 4: exit(0); break; } } while ( t == 0 ); } int main() { int gdriver = DETECT, gmode; initgraph( &gdriver, &gmode, "C:\\TC\\bgi" ); menu(); play(); }

Page | 15

KẾT LUẬN ************************ Phần mềm đạt một số mục tiêu nhất định tuy nhiên còn nhiều khuyết điểm như tính năng hạn chế. Gặp một vài lỗi trong quá trình chạy. Tuy nhiên những gì thu được từ sau bài tập lớn lần này giúp chúng em tự tin hơn để tiếp tục đam mê trong ngành lập trình. Chúng em rất mong nhận được sự quan tâm và góp ý từ phía cô! Chúng em xin chân thành cảm ơn!

Page | 16...


Similar Free PDFs