int Position = 4; // Start at the middle square
// Create all the square structures
Square TopLeftSquare, TopMiddleSquare, TopRightSquare,
CenterLeftSquare, CenterMiddleSquare, CenterRightSquare,
BottomLeftSquare, BottomMiddleSquare, BottomRightSquare;
// Put all the squares into an array for later use.
Square grid[9] = { TopLeftSquare, TopMiddleSquare, TopRightSquare,
CenterLeftSquare, CenterMiddleSquare, CenterRightSquare,
BottomLeftSquare, BottomMiddleSquare, BottomRightSquare };
Square *grid[9] = { &TopLeftSquare, &TopMiddleSquare, &TopRightSquare,
&CenterLeftSquare, &CenterMiddleSquare, &CenterRightSquare,
&BottomLeftSquare, &BottomMiddleSquare, &BottomRightSquare };
int num_columns = 3;
int num_rows = 3;
int
get_cindex (int gx, int gy, int dir)
{
int x_offset = 0;
int y_offset = 0;
switch(dir)
{
case 0: // right
x_offset=(gx+1 < num_columns);
break;
case 1: // up
y_offset=-(gy-1 >= 0);
break;
case 2: // left
x_offset=-(gx-1 >= 0);
break;
case 3: // down
y_offset=(gy+1 < num_rows);
break;
}
if(x_offset+y_offset != 0) // square is valid (would return 0 if square isn't valid)
{
// gets the cloneindex of position (gx,gy)
return ((gy+y_offset)*num_columns + (gx+x_offset));
}
return -1; // does not exist
}
int xValueArray [100];
int yValueArray [100];
char NameArray [100] [27];
Type TypeArray1 [100];
Type TypeArray2 [100];
int CreateNewArrays(int oldSize, int newSize)
{
int xValueArrayTemp;
Allocate memory for xValueArrayTemp of newSize;
check to see if Memory was allocated if not return failed;
Transfer values from xValueArray to xValueArrayTemp;
free xValueArray;
Allocate memory for xValueArray of newSize;
check to see if Memory was allocated if not try allocating space of oldSize;
check to see if Memory was allocated if not free xValueArrayTemp, return failed and begin ending game;
The game must end because there is no array for xValueArray so functions cannot run properly;
Otherwise:
Transfer values from xValueArrayTemp to xValueArray;
Then start the process over for every array;
}
typedef struct MyElement
{
int x;
int y;
char name;
Type TypeVar1;
Type TypeVar2;
struct MyElement * NextElement;
} MyElement;
MyElement * FirstElement;
MyElement * LastElement;
int NewElement(int x, int y, char *name, Type TypeVar1, TypeVar2)
{
Allocate space for new element
check to see if space was allocated if not return failed
Set values of the struct
LastElement->NextElement = NewElement;
return success
}
void InitializeLinkedList()
{
Allocate space for FirstElement if failed endgame because if there isn't enough space to create the first item then there isn't a game, we just started.
LastElement = FirstElement;
for(number of elements)
{
if(!NewElement(variables))
{ end game because there isn't enough memory to run the game}
}
}
typedef struct MyElement
{
int x;
int y;
char name;
Type TypeVar1;
Type TypeVar2;
} MyElement;
MyElement ElementArray [100];
typedef struct MyElement
{
int x;
int y;
char name;
Type TypeVar1;
Type TypeVar2;
} MyElement;
MyElement * ElementArray [100];
skydereign wrote:Sounds like that was somewhat said towards me. The negative grid position was something that foleyjo was doing in the ged that was posted (foleyjo asked why it wasn't working). So, if you did think I was talking about your system, I wasn't.
Users browsing this forum: No registered users and 1 guest