1、int location2;struct map /* this is the map structure*/char data20;char add_data20;int amount;int x; /* this were the successor keeps its x & y values*/int y;struct location /*this structure is for the successor lister*/float height;char obj;void stats_update(int selected, struct rover *p_rover)swit
2、ch (selected)case 1:if(p_rover-pwr pwr) -= 7;You have destroyed the object!break;case 2: 3)else if(p_rover-strg 90)nnYou do not have enough storage space for this object!pwr) -= 3;strg) += 10;You have collected a sample of the object!case 3:p_rover-pwr -= 10; /*Distance around object- value gained f
3、rom mapper module. 1 square = -1 power*/You have avoided the object!case 4:pwr -= 2;You have driven through the obstacle!case 5:pwr = 100)nnYou do not need to charge up!pwr = 100;You have charged up your rover!default:nn*ERROR*nInvalid Selectionnnvoid action(char object, struct rover *p_rover)int se
4、lection;switch(object)nYou have encountered: A Sandy RocknnThis object can be:n1.tDestroyedn2.tCollectednPlease choose action 1 or 2:tscanf(%d, &selection);stats_update(selection, p_rover); A Solid Rocknnn1.tAvoidedn2.tCollectednPlease choose action 1 or 2:if (selection = 1)selection = 3; A Mountain
5、nnn1.tAvoidednPlease enter 1: Dustnnn1.tDriven throughn2.tCollectednPlease choose action 1 or 2:selection = 4; A Sheer Valleynncase 6: A Gentle Valleynnn1.tDriven throughn2.tAvoidednPlease choose action 1 or 2:if (selection = 2)case 7: A Martian Treennn1.tDestroyedn2.tCollectedn3.tAvoidednPlease cho
6、ose action 1, 2 or 3:case 8: Shallow Waternnn1.tDriven throughn2.tCollectedn3.tAvoidednPlease choose action 1, 2 or 3:case 9: Deep Waternncase 10: An Aggressive Aliennnn1.tDestroyednPlease enter 1:selection = 1;case 11: A Non-Aggressive Aliennncase 12: Another Rovernncase 13: A Power StationnnYou ca
7、n:n1.tCharge upn2.tAvoidnPlease choose action 1 or 2:selection = 5;nn*ERROR*nnvoid show_map(struct map *number, struct map *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst, struct object_fix *vshr, struct object_fix *vgnt, struct object_fix
8、*mtre, struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr, struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /*the show map function calling number and number_2 from the map structure to see if moveable objects are needed*/stru
9、ct map f_map88; /*8 by 8 map*/int i,j, rx, ry, object; /*this is your x and y value in your map (f_map)*/system(cls /* this is your x and y value in your map (f_map)*/srand(time(NULL); /*calling the time from include to gather random variables*/for(i=0;i8;i+) /*for loop to copy all your fixed object
10、 lists into f_map so they can be displayed*/for(j=0;jamount0) /*this is looking at the add function to see weather or not there are aliens in f_map*/number-amount;i+) /*allocating the number of aliens in f_map*/strcpy(f_maprand()%8rand()%8.data, anon-im); /*randomizing their position*/if(number_2-0)
11、 /*repeat of above just for rovers instead*/number_2-i+)strcpy(f_maprand()%8rand()%8.data, rvr-rx= p_rover-location0;ry= p_rover-location1;strcpy(f_map10.data, wdp-strcpy(f_map40.data, mnt-strcpy(f_map50.data, mnt-strcpy(f_map31.data, dst-strcpy(f_map41.data, dst-strcpy(f_map32.data, dst-strcpy(f_ma
12、p42.data, dst-strcpy(f_map03.data, mnt-strcpy(f_map13.data, mnt-strcpy(f_map33.data, vshr-strcpy(f_map43.data, dst-strcpy(f_map53.data, vgnt-strcpy(f_map34.data, vshr-strcpy(f_map44.data, dst-strcpy(f_map54.data, vgnt-strcpy(f_map25.data, wshl-strcpy(f_map35.data, wshl-strcpy(f_map45.data, wshl-strc
13、py(f_map16.data, pstn-strcpy(f_map26.data, wdp-strcpy(f_map36.data, wdp-strcpy(f_map46.data, wshl-strcpy(f_map76.data, mnt-strcpy(f_map07.data, mnt-strcpy(f_map17.data, wdp-strcpy(f_map27.data, wshl-strcpy(f_map37.data, wshl-strcpy(f_map67.data, mnt-strcpy(f_maprxry.data, p_rover-if(rx = 1 & ry = 0)
14、 | (rx = 2 & ry = 6) |(rx = 3 & ry = 6) |(rx = 1 & ry = 7)object = 9;action(object, p_rover);else if(rx = 4 & ry = 0) | (rx = 5 & ry = 0) | (rx = 0 & ry = 3) | (rx = 1 & ry = 3) | (rx = 7 & ry = 6) | (rx = 0 & ry = 7) | (rx = 6 &object = 3;else if(rx = 3 & ry= 1) | (rx = 4 & ry = 1) | (rx = 3 & ry=
15、2) | (rx = 4 & ry = 2) | (rx = 4 & ry = 3) | (rx = 4 & ry = 4)object = 4; ry = 3) | (rx = 3 &object = 5;else if(rx = 5 & ry = 3) | (rx = 5 &object = 6;else if(rx = 2 & ry = 5) | (rx = 3 & ry = 5 ) | (rx = 4 & ry = 5) | (rx = 4 & ry = 6) |(rx = 2 & ry = 7) | (rx = 3 &object = 8;else if(rx = 1 & ry =
16、6)object = 13;i=0; /*re-allocate i to 0 so map is printed from start*/i+) /*8 by 8 map*/ +-+-+-+-+-+-+-+-+nj+) /*8 by 8 map*/if(strlen(f_mapij.data)!=0) /*if function to print nothing but 4 spaces if there in nothing allocated in ij*/|%4s,f_mapij.data);| /*end of coloumn visible map*/ |n /*end of la
17、st coloumn visible map*/ /*bottom of map*/n270Group Bnvoid add_obj(struct map *number, struct map *number_2, struct object_fix *rsny, struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /* add movable object function, *number=aliens, *number_2=rovers*/int object, t, f;char alien;char rover;This is the add movable object functionnhow many aliens would you like?sc
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1