You are using a version without Ads of this website. Please, consider donating:

### Dungeon Crawl assignment

Pages: 12
^
|
|

Anyone?
just have a function that prints out the boxes with a space in the middle where each space corresponds to an element of a vector

as to the box:
___
| |
|___|
@TheIdeasMan
My IDE's the same way. As for your idea with the nested for loop and switch...I couldn't imagine how I would go about that. I did get it looking better:

 ``1234567891011121314151617181920212223242526272829`` ``````char movM(){//Sets up monster movement char Mgrid[g][g]; int i,j,x=0,r=rand()%100; for (i=0;i0 && grid[i-1][j] == '.'){//check whether there is monster,trap, or end of array in new location grid[i][j]='.'; Mgrid[i-1][j]='M';//move monster to new location on temp grid } else if(r==2 && i<(g-1) && grid[i+1][j] == '.'){ grid[i][j]='.'; Mgrid[i+1][j]='M'; } else if(r==3 && j<(g-1) && grid[i][j+1] == '.'){ grid[i][j]='.'; Mgrid[i][j+1]='M'; } else if(r==4 && j>0 && grid[i][j-1] == '.'){ grid[i][j]='.'; Mgrid[i][j-1]='M'; } } } }``````

I'm still trying to figure out how to make the hero and monsters different colors...The setcolor function I'm using just makes everything the same color:
 ``1234`` ``````int setcolor(unsigned short color){ HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hcon,color); }``````

Any ideas on that would be appreciated.
With the for loop - it's easy to do one that checks a 3 by 3 area:

 ``12345678`` ``````const int ADJSIZE = 3; for (int AdjRow = 0; AdjRow < ADJSIZE; AdjRow++){ for (int AdjCol = 0; AdjCol < ADJSIZE; AdjCol++){ //your code here //ignore current tile [1][1] } }``````

So you just need to start this at [Row-1][Col-1].

The switch is also easy:

 ``123456789101112131415161718`` ``````switch (TileValue){ case 'M' : //no break statements case 'T' : //so these are all lumped together case 'X' : //similar for any other enemy or problem continue; break; case '.' : //empty tile //move there break; default: //catch any bad values break; } ``````

So all you have to do is combine these ideas together.

As for colours, I don't use windows - so no idea there I am afraid.

Hope all goes well.

 I'm still trying to figure out how to make the hero and monsters different colors...The setcolor function I'm using just makes everything the same color:

re-write your `char dispgrid()` function

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243`` ``````enum ConsoleColor { //from http://www.cplusplus.com/articles/2ywTURfi/ BLACK=0, DARK_BLUE=1, DARK_GREEN=2, DARK_AQUA,DARK_CYAN=3, DARK_RED=4, DARK_PURPLE=5,DARK_PINK=5,DARK_MAGENTA=5, DARK_YELLOW=6, DARK_WHITE=7, GRAY=8,GREY=8, BLUE=9, GREEN=10, AQUA=11,CYAN=11, RED=12, PURPLE=13,PINK=13,MAGENTA=13, YELLOW=14, WHITE=15 }; char dispgrid() //Displays the grid { for (int i=0;i<10;i++) { cout << "\n"; for(int j=0;j<10;j++) { char color; char tileValue = grid[i][j]; switch (tileValue) { case 'M': color = ...; //choose a color from ConsoleColor, ex. color = RED; break; case 'H': color = ...; //choose a color from ConsoleColor, ex. color = GREEN; break; default: color = GRAY; break; } cout << setcolor(color) << tileValue << " "; } } }``````
Last edited on
By the way if you use colours then look at this http://www.cplusplus.com/forum/beginner/95215/
use concol.h

and setcolor("front color","background");
well actually greenleaf, thats very static in that its windows only. if you use *curses then the code becomes cross compatible if you include pdcurses on windows, which you can just include in the directory
*curses?
curses
ncurses
pdcurses
Topic archived. No new replies allowed.
Pages: 12

You are using a version without Ads of this website. Please, consider donating: