void InitMap(void) 
{
	int i = 0;
	int iLength = 0;
	ptagLevelCollection pCollection;
	iLength = sizeof(level_data_level);

	theMap = (ptagMap)calloc(1, sizeof(Map));

	theMap->iNoOfCollection = 0;
	theMap->head = NULL;
	theMap->tail = NULL;
	theMap->currentLevel = NULL;
	while( i < iLength ) {
		if (LineType(i) == LINE_TYPE_COLLECTION_BEGIN) {
			pCollection = InitACollection(&i);
			//Insert the struct in the doube list.
			if (theMap->head == NULL) {
				theMap->head = pCollection;
				theMap->tail = theMap->head;
				pCollection->next = pCollection;
				pCollection->prev = pCollection;
			} else {
				pCollection->next = theMap->tail->next;
				pCollection->next->prev = pCollection;
				pCollection->prev = theMap->tail;
				theMap->tail->next = pCollection;
				theMap->tail = pCollection;
			}
			theMap->iNoOfCollection++;
		} else 
			GotoNextLine(&i);
	}
	theMap->current = theMap->head;
	for (i = 0; i < BACK_STEP_SIZE; i++)
		theMap->pSteps[i] = NULL;
	PlayRestart();
}
//align at alphabit
static ptagLevelCollection InitACollection(int * i)
{
	ptagLevelCollection pCollection;
	char * name;
	int  iNameLength = 0;
	int  j = *i;
	char a;
	ptagLevel pLevel;
	int iLevel = 1;
	int iType;

	pCollection = (ptagLevelCollection)calloc(1, sizeof(LevelCollection));
	pCollection->iNoOfLevels = 0;
	pCollection->strName = (char *)calloc(MAX_COLLECTION_NAME, sizeof(char));
	name = pCollection->strName;
	pCollection->head = NULL;
	pCollection->tail = NULL;

	assert (LineType(j) == LINE_TYPE_COLLECTION_BEGIN); 

	//first get the name
	do {
		a = (char)level_data_level[j];
		if((isalpha(a)) || (a == '_')){
			name[iNameLength++] = a;
			j++;
		} 
		else
			break;	
	} while(1);

	GotoNextLine(&j);
	name[iNameLength] = '\0';


	while(1) {
		iType = LineType(j);
		if (iType == LINE_TYPE_COLLECTION_BEGIN) 
			break; //finished this collection
		
		if (iType == LINE_TYPE_LEVEL_BEGIN){  	
			pLevel = InitALevel(&j);
			pLevel->iNo = iLevel++;
			if (pCollection->head == NULL) {
				pCollection->head = pLevel;
				pCollection->tail = pCollection->head;
				pLevel->next = pLevel;
				pLevel->prev = pLevel;
			} else {
				pLevel->next = pCollection->tail->next;
				pLevel->next->prev = pLevel;
				pLevel->prev = pCollection->tail;
				pCollection->tail->next = pLevel;
				pCollection->tail = pLevel;
			}
			pCollection->iNoOfLevels++;
		} else
			GotoNextLine(&j);
	}	
	*i = j;
	pCollection->current = pCollection->head;
	return pCollection;
}
Example #3
0
	LineType dc() const { return LineType(d, c); }
//we begin at the begin of a line
static ptagLevel InitALevel(int *i) 
{
	ptagLevel pLevel;
	int j = *i;
	int iLineBegin = 0;
	int iLineEnd = 0;
	int iRow = 0;
	int iCol = 0;
	char a;
	int *pInt;
	int k;
	int b;

	assert (LineType(j) == LINE_TYPE_LEVEL_BEGIN); 

	//first decide how many line rows
	iLineBegin = j;
	while(1) {
		//we are now at the begin of the line
		
		a = (char)level_data_level[j];
		while (a != 0x0a) {
			if (a == '#')
				iLineEnd = j;
			a = (char)level_data_level[++j];
		}
		
		if (iLineEnd == 0) //There are no '#'s in this line.
			break;

		if (iLineEnd -iLineBegin + 1 > iCol)
			iCol = iLineEnd - iLineBegin + 1;

		iRow ++; 
		j++; 
		iLineEnd = 0;
		iLineBegin = j;
	}


	//Init a structure
	pLevel = (ptagLevel)calloc(1, sizeof(Level));
	pLevel->row = iRow;
	pLevel->col = iCol;
	pLevel->data = (int *)calloc(iRow*iCol, sizeof(int));
	pInt = pLevel->data;
	
	//set value to pLevel->data	
	j = *i;

	for(iRow = 0; iRow < pLevel->row; iRow++)
	{
		iLineEnd = FindLineEnd(j);
		for(k = 0; k <= iLineEnd; k++) 
		{
			b = level_data_level[j++];
			switch (b) {
			case '@':
				pLevel->manx = k;
				pLevel->many = iRow;	
				pInt[iRow*iCol+k] = B_MAN;
				break;
			case '$':
				pInt[iRow*iCol+k] = B_OBJECT;
				break;
			case '.':
				pInt[iRow*iCol+k] = B_GOAL;
				break;
			case '*':
				pInt[iRow*iCol+k] = B_TREASURE;
				break;
			case '+':
				pLevel->manx = k;
				pLevel->many = iRow;	
				pInt[iRow*iCol+k] = B_SAVEMAN;
				break;
			case '#':
				pInt[iRow*iCol+k] = B_STONE;
				break;
			default:
				pInt[iRow*iCol+k] = B_NOTHING;
			}
		}
		for ( ; k < iCol; k++)
			pInt[iRow*iCol+k] = B_NOTHING;
		GotoNextLine(&j);
	}
	
	*i = j;
	return pLevel;
}
Example #5
0
	LineType da() const { return LineType(d, a); }
Example #6
0
	LineType db() const { return LineType(d, b); }
Example #7
0
	LineType cb() const { return LineType(c, b); }
Example #8
0
	LineType cd() const { return LineType(c, d); }
Example #9
0
	LineType bd() const { return LineType(b, d); }
Example #10
0
	LineType ca() const { return LineType(c, a); }
Example #11
0
	LineType bc() const { return LineType(b, c); }
Example #12
0
	LineType ba() const { return LineType(b, a); }
Example #13
0
	LineType ad() const { return LineType(a, d); }
Example #14
0
	LineType ac() const { return LineType(a, c); }
Example #15
0
	//Tetrahedron specific
	//edges
	LineType ab() const { return LineType(a, b); }