int char and Pointer

Hey guys. I want to test whether a point on a map consists of a char.Basicall I can only get the integer.Here is a sample map.

---------
.........
.........
...C.....
---------

Here I can only get the integer which C is in.Basically I want to do something like this.
if(player->height + x == 'C')//
{
.....
// you have C in the bottom space.Beware
}
Any suggestion would be welcomed.
Insufficient information. Please, tell more.
Basically I read a map say.
----------------
......C............
.......V..........
S................
.................
.................E
-------------

I then created the classes where the piece that represent them are.For example I created a Critter class where C is, A Valture class where V is.
But now I need to know what is where in order implement the attack.Basically the player should only be able to attack if it is only one block away.
eg
-------------------
......}.C.............. // Here the player should be able to attack the critter.
..........}..C........ //Here the player should "not" be able to attack the critter.
.......................E

But in order to do that I need to know the type of piece that is there.

Thanks.
I read a map

Then describe the data structure that you do use to store the information from the map.



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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
vector<Piece*> obstaclesVec; // Piece is the base class of all the pieces.
	vector<Position*> obstaclePosVec;
	
	i++;
	int x = 0;
	int y = 0;
	for(; i < content.length(); i++)
	{
		if(content[i] == '\n')
		{
			x++;
			continue;
		}
		if(content[i] == '\r')
			continue;
		
		if(content[i] == 'S')
		{
			obstaclesVec.push_back(new Waypoint('S'));
			obstaclePosVec.push_back(new Position(x, y));
		}
		else if(content[i] == 'B')
		{
			obstaclesVec.push_back(new Boulder('B'));
			obstaclePosVec.push_back(new Position(x, y));
	
		}
		else if(content[i] == '/')
		{
			obstaclesVec.push_back(new Wall('/'));
			obstaclePosVec.push_back(new Position(x, y));
		}
		else if(content[i] == 'C')
		{
			obstaclesVec.push_back(new Critter('C'));
			obstaclePosVec.push_back(new Position(x, y));
		}
		else if(content[i] == 'E')
		{
			obstaclesVec.push_back(new Waypoint('E'));
			obstaclePosVec.push_back(new Position(x, y));
		}
		
		y++;
		if(y >= width)
			y = 0;
	}

///////////////////////////////////////////////////////

this is where i print the map

//lelevel is declared as  Piece*** level;
	if(level[j][i] == 0)
				cout << ".";
			else
			{
				switch(level[j][i]->getType())
				{
					case BOULDER : // an enum
						cout<<static_cast<Boulder*>(level[j][i])->getBoulderType();
						break;
					case WAYPOINT: // an enum
						cout << static_cast<Waypoint*>(level[j][i])->getWaypointType(); 
						break;
					case WALL:			 // an enum		
						cout<<static_cast<Wall*>(level[j][i])->getWallType();
						break;
					case CRITTER:		// an enum			
						cout<<static_cast<Critter*>(level[j][i])->getCritterType();
						break;  // an enum
					case ASSASSIN:
						cout<<static_cast<Assassin*>(level[j][i])->getFacingDirection();
						break;
					case MAGE:
						cout<<static_cast<Mage*>(level[j][i])->getFacingDirection();
						break;
					case RANGER:
						cout<<static_cast<Sprite*>(level[j][i])->getFacingDirection();
						break;
					case WARRIOR:
						cout << static_cast<Sprite*>(level[j][i])->getFacingDirection();
						break;
				}
			}
		}


//all Position does 

Position(int newX, int newY)
		{
			x = newX;
			y = newY;
		}


Edit**
Let me know if you need more info.
Last edited on
You have a list of Pieces, a separate list of their (initial) positions, and some multi-dimensional array also pointing to pieces?

Does that mean that when you have a Critter, you will search from obstaclesVec the element pointing to that Critter, and then with the index of that element you pick a Position from obstaclePosVec? If so, then you could create Positions with x&y +/- 1, i.e. the neighbours, search each from the obstaclePosVec, and if found use index to retrieve Piece from obstaclesVec.

Option B: rethink your data structure.
Topic archived. No new replies allowed.