Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <ctime>
- using namespace std;
- char array[40][30];
- 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 XoamanHinh(){
- HANDLE hOut;
- COORD Position;
- hOut=GetStdHandle(STD_OUTPUT_HANDLE);
- Position.X=0;
- Position.Y=0;
- SetConsoleCursorPosition(hOut,Position);
- }
- void textcolor(int x){
- HANDLE mau;
- mau=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(mau,x);
- }
- //void Ve_Hinh(int x,int y,int color,string str){
- // gotoxy(x,y);
- // textcolor(color);
- // cout<<str;
- //
- //}
- void DuongDua(){
- for (int i=0;i<25;i++){
- array[i][0]='|';
- array[i][29]='|';
- for (int j=1;j<29;j++){
- array[i][j]=' ';
- }
- }
- }
- int VeVat(int x,int y){
- array[x-1][y]='X';//dau
- //than
- array[x][y]='X';
- array[x][y-1]='X';
- array[x][y+1]='X';
- //duoi
- array[x+1][y-1]='X';
- array[x+1][y-2]='X';
- array[x+1][y]='X';
- array[x+1][y+1]='X';
- array[x+1][y+2]='X';
- }
- void DiChuyenVat(int &x,int &y){
- if (GetAsyncKeyState(VK_LEFT)){
- if (y>3){
- array[x-1][y]=' ';//dau
- //than
- array[x][y]=' ';
- array[x][y-1]=' ';
- array[x][y+1]=' ';
- //duoi
- array[x+1][y-1]=' ';
- array[x+1][y-2]=' ';
- array[x+1][y]=' ';
- array[x+1][y+1]=' ';
- array[x+1][y+2]=' ';
- y--;
- VeVat(x,y);
- }
- }
- if (GetAsyncKeyState(VK_RIGHT)){
- if (y<26){
- array[x-1][y]=' ';//dau
- //than
- array[x][y]=' ';
- array[x][y-1]=' ';
- array[x][y+1]=' ';
- //duoi
- array[x+1][y-1]=' ';
- array[x+1][y-2]=' ';
- array[x+1][y]=' ';
- array[x+1][y+1]=' ';
- array[x+1][y+2]=' ';
- y++;
- VeVat(x,y);
- }
- }
- if (GetAsyncKeyState(VK_UP)){
- if (x>1){
- array[x-1][y]=' ';//dau
- //than
- array[x][y]=' ';
- array[x][y-1]=' ';
- array[x][y+1]=' ';
- //duoi
- array[x+1][y-1]=' ';
- array[x+1][y-2]=' ';
- array[x+1][y]=' ';
- array[x+1][y+1]=' ';
- array[x+1][y+2]=' ';
- x--;
- VeVat(x,y);
- }
- }
- if (GetAsyncKeyState(VK_DOWN)){
- if (x<23){
- array[x-1][y]=' ';//dau
- //than
- array[x][y]=' ';
- array[x][y-1]=' ';
- array[x][y+1]=' ';
- //duoi
- array[x+1][y-1]=' ';
- array[x+1][y-2]=' ';
- array[x+1][y]=' ';
- array[x+1][y+1]=' ';
- array[x+1][y+2]=' ';
- x++;
- VeVat(x,y);
- }
- }
- }
- void VeChuongNgaiVat(int x1,int y1){
- array[x1][y1]='o';
- array[x1][y1+1]='o';
- array[x1][y1-1]='o';
- array[x1+1][y1]='o';
- }
- void ChuongNgaiVatChay(int x1,int y1){
- array[x1][y1]=' ';
- array[x1][y1+1]=' ';
- array[x1][y1-1]=' ';
- array[x1+1][y1]=' ';
- x1++;
- VeChuongNgaiVat(x1,y1);
- }
- int ketQua_Tra_ve(int &x1,int &y1,int x,int y){
- if ((x1+2==x&&y1==y)||(x1==x+1&&y1==y+3)||(x1==x+1&&y1==y-3)||(x1==x&&y1==y+2)||(x1==x&&y1==y-2)){
- Sleep(1000);
- textcolor(114);
- gotoxy(35,25);
- cout<<"GAMEOVER"<<endl<<endl;
- return 0;
- }
- if (x1==30){
- x1=2;
- y1=3+rand() % (26),x1=2;
- }
- }
- void VeDuongdua(int x,int y){
- int i,j,score=0;
- for (i=0;i<25;i++){
- cout<<"\t\t\t";
- for (j=0;j<30;j++){
- if (j==0||j==29) {
- textcolor(134);
- cout<<array[i][j];
- textcolor(7);
- }
- else if (array[i][j]=='X'){
- textcolor(124);
- cout<<array[i][j];
- }
- else if(array[i][j]=='o'){
- textcolor(112);
- cout<<array[i][j];
- textcolor(119);
- }
- else if (array[i][j]=='0'){
- textcolor(112);
- cout<<array[i][j];
- textcolor(119);
- }
- else{
- textcolor(119);
- cout<<array[i][j];
- }
- }
- cout<<endl;
- score++;
- //return score;
- }
- }
- int playAgain(){
- cout<<"Do you want play again(1=yes/2=no): ";
- int answer;
- cin>>answer;
- if (answer==1) {
- XoamanHinh();
- return 1;;
- }
- else return 0;
- }
- int Score(int score){
- gotoxy(35,13);
- cout<<"Score: "<<score/2;
- for (int k=0;k<13;k++){
- cout<<endl;
- }
- textcolor(7);
- }
- void intro(){
- textcolor(7);
- cout<<"EVERWING"<<endl;
- Sleep(1000);
- XoamanHinh();
- }
- int Skill(int &d1,int &d2){
- array[d1][d2]='0';
- }
- int Ban(int d1,int d2){
- array[d1][d2]=' ';
- d1=d1-2;
- Skill(d1,d2);
- }
- int AnDiem(int x1,int y1,int d1,int d2){
- if ((x1+1==d1&&y1==d2)||(x1==d1&&y1-1==d2)||(x1=d1&&y1+1==d2)){
- array[x1][y1]=' ';
- array[x1][y1+1]=' ';
- array[x1][y1-1]=' ';
- array[x1+1][y1]=' ';
- return 1;
- }
- }
- int text(int &x1,int &y1,int x,int y,int score){
- if (ketQua_Tra_ve(x1,y1,x,y)==0) {
- Score(score);
- score=0;
- if (playAgain()==1){
- return 1;
- }
- else {
- // gotoxy(34,28);
- // cout<<"BYE BYE!!!";
- return 0;
- }
- }
- }
- int main(){
- intro();
- int n=0,score=0;
- int x=18,y=15;
- srand(time(0));
- int y1=3+rand() % (26),x1=2;
- //int y2=3+rand() % (26),x2=2;
- int d1,d2;
- bool check=false;
- do{
- d1=x-1;
- d2=y;
- while (true){
- VeDuongdua(x,y);
- XoamanHinh();
- VeVat(x,y);
- DiChuyenVat(x,y);
- ChuongNgaiVatChay(x1,y1);
- x1++;
- // ChuongNgaiVatChay(x2,y2);
- // x2++;
- score++;
- Skill(d1,d2);
- if(d1==1){
- array[d1][d2]=' ';
- d1=x-1;
- d2=y;
- }
- Ban(d1,d2);
- d1=d1-2;
- // AnDiem(x1,y1,d1,d2);
- // AnDiem(x2,y2,d1,d2);
- if (AnDiem(x1,y1,d1,d2)==1){
- x1=2;
- y1=7;
- array[x1][y1]=' ';
- array[x1][y1+1]=' ';
- array[x1][y1-1]=' ';
- array[x1+1][y1]=' ';
- score=score+10;
- }
- // if (AnDiem(x2,y2,d1,d2)==1){
- // x2=2;
- // y2=7;
- // array[x1][y1]=' ';
- // array[x1][y1+1]=' ';
- // array[x1][y1-1]=' ';
- // array[x1+1][y1]=' ';
- // score=score+10;
- // }
- // text(x1,y1,x,y,score);
- // text(x2,y2,x,y,score);
- // if (text(x1,y1,x,y,score)==1||text(x2,y2,x,y,score)==1){
- // continue;
- // }
- // if (text(x1,y1,x,y,score)==0||text(x2,y2,x,y,score)==0){
- // gotoxy(34,28);
- // cout<<"BYE BYE!!!";
- // break;
- // }
- if (ketQua_Tra_ve(x1,y1,x,y)==0) {
- Score(score);
- score=0;
- if (playAgain()==1){
- continue;
- }
- else {
- gotoxy(34,28);
- cout<<"BYE BYE!!!";break;
- }
- }
- if (n>20) n=0;
- }
- }while(check);
- return 0;
- }
Add Comment
Please, Sign In to add comment