From a741bb5786cd25ccf3ae12db48ffff206576efe4 Mon Sep 17 00:00:00 2001 From: MysticJ <37102399+MysticJ@users.noreply.github.com> Date: Sun, 25 Mar 2018 17:58:33 +0800 Subject: [PATCH] Add files via upload --- Functions.h | 158 ++++++++++++++++++++++++++++------------------------ LAB6.cpp | 117 +++++++++++++++++++++++++++----------- 2 files changed, 168 insertions(+), 107 deletions(-) diff --git a/Functions.h b/Functions.h index bcf0832..27aa2a7 100644 --- a/Functions.h +++ b/Functions.h @@ -1,7 +1,7 @@ /* * Functions.h * - * Created on: 2018�~3��22�� + * Created on: 2018¦~3¤ë22¤é * Author: Mystic */ @@ -12,151 +12,161 @@ #include using namespace std; -void CheckWin(){} -void CheckCrash(bool& crash, int count, int Me_Row, int Me_Col, int Mon_Row[], int Mon_Col[]){ +bool CheckCrash(bool crash, int count, int MePosition[], int Mon_Row[], int Mon_Col[]){ for (int i=0; i<=count; i++){ - if ((Me_Row==Mon_Row[i])&&(Me_Col==Mon_Col[i])){ + if ((MePosition[0]==Mon_Row[i])&&(MePosition[1]==Mon_Col[i])){ crash=true; + break; } } - cout<<"crash: "<0)? 1:-1; - addcol= ((Mel_Col-Mon_Col[i])>0)? 1:-1; + addrow= ((MePosition[0]-Mon_Row[i])>0)? 1:-1; + addcol= ((MePosition[1]-Mon_Col[i])>0)? 1:-1; Mon_Row[i]=((Mon_Row[i]+addrow==-1)||(Mon_Row[i]+addrow==15))? Mon_Row[i]:Mon_Row[i]+addrow; Mon_Col[i]=((Mon_Col[i]+addcol==-1)||(Mon_Col[i]+addcol==15))? Mon_Col[i]:Mon_Col[i]+addcol; //cout<<"Mon_Row"<>direction; while ((direction!='a')&&(direction!='s')&&(direction!='d')&&(direction!='w')&&(direction!='b')){ - cout<<"Give a right direction: "; + cout<<"not in scope."<>direction; } - switch (direction){ - case 'a': - Me_Col=(Me_Col==0)? Me_Col:Me_Col-1; - break; - case 's': - Me_Row=(Me_Row==14)? Me_Row:Me_Row+1; - break; - case 'd': - Me_Col=(Me_Col==14)? Me_Col:Me_Col+1; - break; - case 'w': - Me_Row=(Me_Row==0)? Me_Row:Me_Row-1; - break; - case 'b': - if(count_b<4) - Bomb(Mon_Row,Mon_Col,count, Me_Row, Me_Col); - else - cout< using namespace std; -void CheckCrash(bool& crash, int count, int Me_Row, int Me_Col, int Mon_Row[], int Mon_Col[]); +bool CheckCrash(bool crash, int count, int MePosition[], int Mon_Row[], int Mon_Col[]); void NewMonster(int Mon_Row[], int Mon_Col[], int count, int Me_Row, int Me_Col); void MoveMonster(int Mon_Row[], int Mon_Col[], int count); -//void MoveMonster2(int Mon_Row[], int Mon_Col[], int count, int Mel_Row, int Mel_Col); -char Move(int Mon_Row[], int Mon_Col[], int count, int& Me_Row, int& Me_Col, int& count_b); -void Construct(int Map[][15],int Mon_Row[], int Mon_Col[], int count, int& Me_Row, int& Me_Col); -void Display(int Map[][15],int Mon_Row[], int Mon_Col[], int count, int& Me_Row, int& Me_Col); +void Move(int MePosition[], int count, int Mon_Row[], int Mon_Col[], int& count_b); +//int CountNum(int Mon_Row[], int Mon_Col[], int count, int row, int col); +void Display(int Map[][15], int Mon_Row[], int Mon_Col[], int count, int MePosition[]); +void Construct(int Map[][15],int Mon_Row[], int Mon_Col[], int count, int MePosition[], bool get_d); + int main() { srand(time(NULL)); - // Evil Monsters[225]; - int Mon_Row[225], Mon_Col[225], Me_Row=14, Me_Col=0; - int count = 0; - int count_b=0; // number of bombs - char dir; - bool crash = false; - int Map[15][15]; - - Construct(Map,Mon_Row,Mon_Col,count,Me_Row, Me_Col); - Display(Map,Mon_Row, Mon_Col,count,Me_Row,Me_Col); - - while (crash == false){ - //MoveMonster2(Mon_Row, Mon_Col, count, Me_Row, Me_Col); - - dir=Move(Mon_Row, Mon_Col, count, Me_Row, Me_Col, count_b); // cin direction or bomb - // in normal situation - if (dir!='b'){ - cout<<"count: "<