Go to the source code of this file.
Defines | |
#define | START_X_DIMENSIONS 6 |
#define | START_Y_DIMENSIONS 3 |
Functions | |
void | initialise_start () |
Function used to initialise the elements of the start array. More... | |
void | update_battlefield (char *name, int player, int x, int y) |
Update the battlefield array. More... | |
int | pieces_placed () |
Check if all pieces have been placed on the board. More... | |
int | check_placement (int player, int y2) |
Check if a placement is on the correct side of the board. More... | |
Variables | |
start_piece | start [START_X_DIMENSIONS][START_Y_DIMENSIONS] |
This header file serves as a declaration file for the functions used in the initialisation phase of the game and also
contains definitions of certain variables.
|
This definition is used in the start array variable definition. It is the x coordinate of the array. |
|
This definition is used in the start array variable definition. It is the y coordinate of the array. |
|
Check if a placement is on the correct side of the board. A function that checks if the player is placing his pieces on the correct end of the board.
debug information and returns FALSE. Exploiting the unique identification number that each player has, we check if player 0 has placed a piece in the bottom two rows and player 1 in the top two. For this reason only the y coordinate is used to perform the check. i.e. in squares in battlefield (y = 8,9) for player 1, and 0,1 for player 0
00123 { 00124 00125 if (player == 1){ 00126 if ( (y2 == 8) || (y2 == 9)) 00127 return TRUE; 00128 else { 00129 vccPrintPdxDebugInfo("Player 1 can only place pieces in the top part of the board\n"); 00130 return FALSE; 00131 } 00132 } else if (player == 0){ 00133 if ( (y2 == 0) || (y2 == 1)) 00134 return TRUE; 00135 else { 00136 vccPrintPdxDebugInfo("Player 0 can only place pieces in the bottom part of the board\n"); 00137 return FALSE; 00138 } 00139 } 00140 00141 return FALSE; 00142 } |
|
Function used to initialise the elements of the start array.
For example, start[0][1] is assigned to a Marshal. This element fills its fields with the below values:
marshal.name = "Marshal"; This function is automatically called by the poin_entry_Init function in the white.c file, when the game is commenced.
00004 { 00005 00006 /* first form structs of pieces to be added to array */ 00007 start_piece marshal , general , colonel , major , captain , lieutenant; 00008 start_piece sergeant , miner , scout , spy , bomb , flag; 00009 00010 /* marshal */ 00011 marshal.name = "Marshal"; 00012 marshal.remaining = 1; 00013 marshal.player = 0; 00014 00015 /* general */ 00016 general.name = "General"; 00017 general.remaining = 1; 00018 general.player = 0; 00019 00020 /* colonel */ 00021 colonel.name = "Colonel"; 00022 colonel.remaining = 2; 00023 colonel.player = 0; 00024 00025 /* major */ 00026 major.name = "Major"; 00027 major.remaining = 3; 00028 major.player = 0; 00029 00030 /* captain */ 00031 captain.name = "Captain"; 00032 captain.remaining = 4; 00033 captain.player = 0; 00034 00035 /* lieutenant */ 00036 lieutenant.name = "Lieutenant"; 00037 lieutenant.remaining = 4; 00038 lieutenant.player = 0; 00039 00040 /* sergeant */ 00041 sergeant.name = "Sergeant"; 00042 sergeant.remaining = 4; 00043 sergeant.player = 0; 00044 00045 /* miner */ 00046 miner.name = "Miner"; 00047 miner.remaining = 5; 00048 miner.player = 0; 00049 00050 /* scout */ 00051 scout.name = "Scout"; 00052 scout.remaining = 8; 00053 scout.player = 0; 00054 00055 /* spy */ 00056 spy.name = "Spy"; 00057 spy.remaining = 1; 00058 spy.player = 0; 00059 00060 /* bomb */ 00061 bomb.name = "Bomb"; 00062 bomb.remaining = 6; 00063 bomb.player = 0; 00064 00065 /* flag */ 00066 flag.name = "Flag"; 00067 flag.remaining = 1; 00068 flag.player = 0; 00069 00070 00071 /* Now place data (structs) on board */ 00072 00073 /* first row */ 00074 start[0][1] = marshal; 00075 start[1][1] = general; 00076 start[2][1] = colonel; 00077 start[3][1] = major; 00078 start[4][1] = captain; 00079 start[5][1] = lieutenant; 00080 00081 /* ...second row */ 00082 start[0][2] = sergeant; 00083 start[1][2] = miner; 00084 start[2][2] = scout; 00085 start[3][2] = spy; 00086 start[4][2] = bomb; 00087 start[5][2] = flag; 00088 } |
|
Check if all pieces have been placed on the board. A function that checks if all pieces are placed on board
presses the START button. i.e. whenever he tries to commence the game. The game rules point out that for a game to start the player must firstly place all pieces on the board. To check this, I have exploited the representation of a piece during the initialisation stage with the start array. In particular, the "remaining" field, which shows how many pieces are still to be placed on the board.
|
|
Update the battlefield array. A function that updates the battlefield array.
placed on the board two things occur:
00090 { 00091 00092 int index; 00093 00094 /* now update data on battlefield */ 00095 00096 index = getIndexInTable(name); 00097 00098 00099 battlefield[x][y].occupied = pieces_table[index]; 00100 00101 battlefield[x][y].player = player; 00102 } |
|
This array is used throughout the initialisation phase of the game, during which the players place their pieces |