Dungeon Crawl assignment

Pages: 12
^
|
|

Anyone?
closed account (Dy7SLyTq)
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
char movM(){//Sets up monster movement
char Mgrid[g][g];
   int i,j,x=0,r=rand()%100;


    for (i=0;i<g;i++){//find monster
        for(j=0;j<g;j++){
            r=rand()%4+1;
            if (grid[i][j]=='M'){
                //25% chance to move monster in one of four directions
                if(r==1 && i>0 && 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:
1
2
3
4
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:

1
2
3
4
5
6
7
8
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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");
closed account (Dy7SLyTq)
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?
closed account (Dy7SLyTq)
curses
ncurses
pdcurses
Topic archived. No new replies allowed.
Pages: 12