#include "white_interface.h"
#include <start_piece.h>
#include <piece.h>
#include <battlefield_piece.h>
#include "start_core.h"
#include "battle_core.h"
#include "start_core.c"
#include "battle_functions.c"
Defines | |
#define | TRUE 1 |
#define | FALSE 0 |
Functions | |
int | vccPrintPdxDebugInfo (const char *format,...) |
Function used for debugging. More... | |
int | strcmp (const char *s1, const char *s2) |
Compare two strings. More... | |
int | abs (int a) |
Get absolute value of parameter. More... | |
void | poin_entry_Init () |
Function called upon starting the simulation. More... | |
void | poin_entry_Begin () |
Main Function of core module. More... | |
Variables | |
int | battle_started |
int | player_no |
int | turn |
white.c is the equivalent of a main function in ANSI C. It has two main functions namely, poin_entry_Init() and poin_entry_Run()
The implementation of the game rules starts in this file. This is the basic implemenation of the module.
All functions and data structures in other files are referenced from here. When receiving an input from other modules
this file is run. The ports are checked to see if they are enabled. If a port is enabled, the code is executed and
the appropriate output signals are sent, either to bluetooth or to the graphics module. The white_interface.h file
describes the ports and functions used, which are declared automaticaly by VCC.
Inputs to the module are a move and a button. Outputs consist of a draw , a printSting to the graphics section, a Move and a button to bluetooth
|
Variable that translates the boolean known value FALSE to an integer 0. |
|
Variable that translates the boolean known value TRUE to an integer 1. |
|
Get absolute value of parameter.
Function that gets the absolute value of a number. Used to translate the negative coordinates received |
|
Main Function of core module.
This is the "driving force" of each core module. Inside this module, we can find the basic data flow and functionality of the game.
signals are ignored by the core module and therefore not sent to the network.
Then we compare the source of the command against the player identification of the module, which is the
00247 { 00248 00249 00250 int i , temp_y1 , tmp; 00251 int k; 00252 move result; 00253 DrawSprite draw; 00254 PrintString out; 00255 char print_out[100]; 00256 button pressed; 00257 start_piece f; 00258 char *tmpString; 00259 00260 while(TRUE) 00261 { 00262 00263 00264 vccAwait(); 00265 00266 00267 if (move_in_Enabled()){ 00268 result = *move_in_Value(); 00269 if (player_no != 2){ 00270 if (battle_started == FALSE){ /* we are in initialisation phase */ 00271 if (player_no == result.player){ 00272 00273 if (result.y1 > 0){ 00274 /* sprintf(print_out, "You must complete placement before starting to move pieces around"); */ 00275 vccPrintPdxDebugInfo("You must complete placement before starting to move pieces around\n"); 00276 out.text = "PLACE@ALL"; out.x = 0; out.y = 6; 00277 print_Post(&out); 00278 vccAwait(10.0); 00279 for (k=0; k<10; k++){ 00280 draw.bitmapno = 13; 00281 draw.x = k; 00282 draw.y = 6; 00283 draw_Post(&draw); 00284 vccAwait(10.0); 00285 } 00286 } 00287 00288 /* if placement process. */ 00289 if (result.y1 < 0){ 00290 00291 temp_y1 = abs(result.y1); /* make y positive... */ 00292 00293 if (start[result.x1][temp_y1].remaining == 0){ 00294 vccPrintPdxDebugInfo("You have already placed all %s on battlefield\n",start[result.x1][temp_y1].name); 00295 out.text = "ALL@PLACED"; out.x = 0; out.y = 6; 00296 print_Post(&out); 00297 vccAwait(10.0); 00298 for (k=0; k<10; k++){ 00299 draw.bitmapno = 13; 00300 draw.x = k; draw.y = 6; 00301 draw_Post(&draw); 00302 vccAwait(10.0); 00303 } 00304 } else if ( check_placement(player_no , result.y2) ){ 00305 if (battlefield[result.x2][result.y2].player == -1){ 00306 start[result.x1][temp_y1].remaining--; 00307 00308 update_battlefield( start[result.x1][temp_y1].name , result.player , result.x2 , result.y2); 00309 00310 vccPrintPdxDebugInfo("A %s was placed on the battlefield\n",battlefield[result.x2][result.y2].occupied.name); 00311 draw.bitmapno = get_bitmapno(start[result.x1][temp_y1].name); 00312 draw.x = result.x2; draw.y = result.y2; 00313 draw_Post(&draw); 00314 00315 move_out_Post(&result); 00316 00317 } else { 00318 vccPrintPdxDebugInfo("The square on the battlefield has already been used\n"); 00319 out.text = "OCCUPIED"; out.x = 0; out.y = 6; 00320 print_Post(&out); 00321 vccAwait(10.0); 00322 for (k=0; k<10; k++){ 00323 draw.bitmapno = 13; 00324 draw.x = k; draw.y = 6; 00325 draw_Post(&draw); 00326 vccAwait(10.0); 00327 } 00328 } 00329 } else {/* else if */ 00330 out.text = "AT@YOUR@END"; 00331 out.x = 0; out.y = 6; 00332 print_Post(&out); 00333 vccAwait(10.0); 00334 for (k=0; k<10; k++){ 00335 draw.bitmapno = 13; 00336 draw.x = k; draw.y = 6; 00337 draw_Post(&draw); 00338 vccAwait(10.0); 00339 } 00340 } /* else */ 00341 } /* if (result.y1 <= 0) */ 00342 } else { /* if player_no == result.player */ 00343 00344 temp_y1 = abs(result.y1); 00345 update_battlefield( start[result.x1][temp_y1].name , result.player , result.x2 , result.y2); 00346 00347 draw.bitmapno = 12; /* opponent draws a covered piece */ 00348 draw.x = result.x2; draw.y = result.y2; 00349 draw_Post(&draw); 00350 } /* else */ 00351 } else if (battle_started == TRUE){ 00352 if (player_no == result.player){ 00353 if (turn == 1){ 00354 if (check_piece_clicked(result.player , result.x1 , result.y1 , result.x2 , result.y2)){ 00355 if (attack_or_move(result.x2 , result.y2)){ /* if he attacked */ 00356 vccPrintPdxDebugInfo("%s attacking piece in [%d][%d] which is a %s\n",battlefield[result.x1][result.y1].occupied.name,result.x2,result.y2,battlefield[result.x2][result.y2].occupied.name); 00357 if (decide_winner(result.x1 , result.y1 , result.x2 , result.y2) == 1){ /* if piece in x1,y1 stronger */ 00358 vccPrintPdxDebugInfo("[%d][%d] won %s\n",result.x1,result.y1,battlefield[result.x1][result.y1].occupied.name); 00359 draw.bitmapno = get_bitmapno(battlefield[result.x1][result.y1].occupied.name); 00360 draw.x = result.x2; draw.y = result.y2; 00361 draw_Post(&draw); 00362 00363 vccAwait(5.0); 00364 00365 draw.bitmapno = 13; 00366 draw.x = result.x1; draw.y = result.y1; 00367 draw_Post(&draw); 00368 00369 perform_move(player_no , result.x1 , result.y1 , result.x2 , result.y2 , 1); 00370 turn = 0; 00371 00372 move_out_Post(&result); 00373 vccPrintPdxDebugInfo("%s piece in [%d][%d] is the winner\n",battlefield[result.x2][result.y2].occupied.name,result.x1,result.y1); 00374 } else if (decide_winner(result.x1 , result.y1 , result.x2 , result.y2) == 2){ /* piece in x2,y2 stronger */ 00375 /* make piece empty */ 00376 battlefield[result.x1][result.y1].occupied.name = "UNOCCUPIED"; 00377 battlefield[result.x1][result.y1].occupied.rank = -1; 00378 battlefield[result.x1][result.y1].occupied.revealed = -1; 00379 battlefield[result.x1][result.y1].player = -1; 00380 00381 /* clear attacking piece */ 00382 draw.bitmapno = 13; 00383 draw.x = result.x1; draw.y = result.y1; 00384 draw_Post(&draw); 00385 00386 /* also set winning piece's reveal flag to on */ 00387 battlefield[result.x2][result.y2].occupied.revealed == 1; 00388 00389 turn = 0; 00390 result.x2 = result.x1; result.y2 = result.y1; /* delete x1 , y1 piece */ 00391 move_out_Post(&result); 00392 vccPrintPdxDebugInfo("%s piece in [%d][%d] is the winner\n",battlefield[result.x2][result.y2].occupied.name,result.x2,result.y2); 00393 } else if (decide_winner(result.x1 , result.y1 , result.x2 , result.y2) == 3){ 00394 vccPrintPdxDebugInfo("%s and %s have equal rank. Both lose!\n",battlefield[result.x1][result.y1].occupied.name,battlefield[result.x2][result.y2].occupied.name); 00395 00396 /* make piece empty */ 00397 battlefield[result.x2][result.y2].occupied.name = "UNOCCUPIED"; 00398 battlefield[result.x2][result.y2].occupied.rank = -1; 00399 battlefield[result.x2][result.y2].occupied.revealed = -1; 00400 00401 battlefield[result.x2][result.y2].player = -1; 00402 00403 /* make piece empty */ 00404 battlefield[result.x1][result.y1].occupied.name = "UNOCCUPIED"; 00405 battlefield[result.x1][result.y1].occupied.rank = -1; 00406 battlefield[result.x1][result.y1].occupied.revealed = -1; 00407 battlefield[result.x1][result.y1].player = -1; 00408 00409 /* clear attacking piece */ 00410 draw.bitmapno = 13; 00411 draw.x = result.x1; draw.y = result.y1; 00412 draw_Post(&draw); 00413 00414 vccAwait(5.0); 00415 00416 /* clear defending piece */ 00417 draw.bitmapno = 13; 00418 draw.x = result.x2; draw.y = result.y2; 00419 draw_Post(&draw); 00420 00421 00422 00423 /* send the -1 signal indicating clearance of pieces to other player */ 00424 result.player = -1; 00425 turn = 0; 00426 move_out_Post(&result); 00427 } else if (decide_winner(result.x1 , result.y1 , result.x2 , result.y2) == 4){ 00428 vccPrintPdxDebugInfo("Flag Has been captured! Youuuuuhooouuuu\n"); 00429 out.text = "WINNER"; out.x = 0; out.y = 6; 00430 print_Post(&out); 00431 } /* else if decide_winner */ 00432 } else { /* if we have a move */ 00433 if (legal_move(result.x1 , result.y1 , result.x2 , result.y2)){ 00434 vccPrintPdxDebugInfo("Moving %s from [%d][%d] to [%d][%d]\n",battlefield[result.x1][result.y1].occupied.name , result.x1 , result.y1 , result.x2 , result.y2); 00435 00436 00437 draw.bitmapno = get_bitmapno(battlefield[result.x1][result.y1].occupied.name); 00438 draw.x = result.x2; draw.y = result.y2; 00439 draw_Post(&draw); 00440 00441 vccAwait(5.0); 00442 00443 /* clear defending piece */ 00444 draw.bitmapno = 13; 00445 draw.x = result.x1; draw.y = result.y1; 00446 draw_Post(&draw); 00447 00448 tmp = battlefield[result.x1][result.y1].occupied.revealed; /* has piece been previously revealed? */ 00449 perform_move(player_no , result.x1 , result.y1 , result.x2 , result.y2 , tmp); 00450 00451 turn = 0; 00452 move_out_Post(&result); 00453 }/* if */ 00454 }/* else */ 00455 }/* if */ 00456 } else { /* if turn = 1 */ 00457 out.text = "WAIT"; out.x = 0; out.y = -2; 00458 print_Post(&out); 00459 vccPrintPdxDebugInfo("\nIt is not your turn\n"); 00460 } /* else */ 00461 } else { /* if player_no == result.player */ 00462 if ( result.player == -1 ){ 00463 /* there has been an attack which was equal*/ 00464 /* make piece empty */ 00465 battlefield[result.x2][result.y2].occupied.name = "UNOCCUPIED"; 00466 battlefield[result.x2][result.y2].occupied.rank = -1; 00467 battlefield[result.x2][result.y2].occupied.revealed = -1; 00468 battlefield[result.x2][result.y2].player = -1; 00469 00470 /* make piece empty */ 00471 battlefield[result.x1][result.y1].occupied.name = "UNOCCUPIED"; 00472 battlefield[result.x1][result.y1].occupied.rank = -1; 00473 battlefield[result.x1][result.y1].player = -1; 00474 00475 /* clear attacking piece */ 00476 draw.bitmapno = 13; 00477 draw.x = result.x1; draw.y = result.y1; 00478 draw_Post(&draw); 00479 00480 vccAwait(5.0); 00481 00482 /* clear defending piece */ 00483 draw.bitmapno = 13; 00484 draw.x = result.x2; draw.y = result.y2; 00485 draw_Post(&draw); 00486 00487 } /* if */ 00488 else { 00489 00490 if ( (battlefield[result.x1][result.y1].player != -1) && (battlefield[result.x2][result.y2].player != -1) ){ 00491 if ( (battlefield[result.x1][result.y1].player) != (battlefield[result.x2][result.y2].player) ){ 00492 /* if two pieces moved are different then we know there was an attack so reveal pieces*/ 00493 vccPrintPdxDebugInfo("\nREVEAL\n"); 00494 battlefield[result.x1][result.y1].occupied.revealed = 1; 00495 } 00496 } 00497 00498 00499 if (battlefield[result.x1][result.y1].occupied.revealed == 1){ 00500 draw.bitmapno = get_bitmapno(battlefield[result.x1][result.y1].occupied.name); 00501 vccPrintPdxDebugInfo("\nBIT : %d\n",draw.bitmapno); 00502 } 00503 else draw.bitmapno = 12; 00504 00505 draw.x = result.x2; draw.y = result.y2; 00506 draw_Post(&draw); 00507 00508 vccAwait(5.0); 00509 00510 draw.bitmapno = 13; 00511 draw.x = result.x1; draw.y = result.y1; 00512 draw_Post(&draw); 00513 00514 perform_move(result.player , result.x1 , result.y1 , result.x2 , result.y2 , battlefield[result.x1][result.y1].occupied.revealed); 00515 turn = 1; /* other player played (no change if the observer since never gets inside */ 00516 } /* else */ 00517 } /* else */ 00518 } /* else if */ 00519 } else if (player_no == 2){ 00520 if (result.player != 2){ /* if this has been sent by observer then do nothing */ 00521 if (result.y1 < 0){ 00522 temp_y1 = abs(result.y1); 00523 00524 update_battlefield( start[result.x1][temp_y1].name , result.player , result.x2 , result.y2); 00525 00526 draw.bitmapno = get_bitmapno(start[result.x1][temp_y1].name); 00527 draw.x = result.x2; draw.y = result.y2; 00528 draw_Post(&draw); 00529 } else if ( result.player == -1 ){ 00530 /* there has been an attack which was equal*/ 00531 /* make piece empty */ 00532 battlefield[result.x2][result.y2].occupied.name = "UNOCCUPIED"; 00533 battlefield[result.x2][result.y2].occupied.rank = -1; 00534 battlefield[result.x2][result.y2].occupied.revealed = -1; 00535 battlefield[result.x2][result.y2].player = -1; 00536 00537 /* make piece empty */ 00538 battlefield[result.x1][result.y1].occupied.name = "UNOCCUPIED"; 00539 battlefield[result.x1][result.y1].occupied.rank = -1; 00540 battlefield[result.x1][result.y1].occupied.revealed = -1; 00541 battlefield[result.x1][result.y1].player = -1; 00542 00543 /* clear attacking piece */ 00544 draw.bitmapno = 13; 00545 draw.x = result.x1; draw.y = result.y1; 00546 draw_Post(&draw); 00547 00548 vccAwait(5.0); 00549 00550 /* clear defending piece */ 00551 draw.bitmapno = 13; 00552 draw.x = result.x2; draw.y = result.y2; 00553 draw_Post(&draw); 00554 00555 } else { 00556 draw.bitmapno = get_bitmapno(battlefield[result.x1][result.y1].occupied.name); 00557 00558 draw.x = result.x2; draw.y = result.y2; 00559 draw_Post(&draw); 00560 00561 vccAwait(5.0); 00562 00563 draw.bitmapno = 13; 00564 draw.x = result.x1; draw.y = result.y1; 00565 draw_Post(&draw); 00566 00567 perform_move(result.player , result.x1 , result.y1 , result.x2 , result.y2 , battlefield[result.x1][result.y1].occupied.revealed); 00568 turn = 1; /* other player played (no change if the observer since never gets inside */ 00569 } /* else */ 00570 } /* if result.player != 2 */ 00571 } /* else if player_no == 2 */ 00572 }/*if (move_in enabled) */ 00573 00574 if (button_in_Enabled()){/* if move_enabled */ 00575 pressed = *button_in_Value(); 00576 vccPrintPdxDebugInfo("\nButton pressed\n"); 00577 00578 if ((pressed.button_no == 1) && (player_no != 2)){ 00579 vccPrintPdxDebugInfo("\nStart button pressed"); 00580 if (pieces_placed()){ 00581 vccPrintPdxDebugInfo("\nStarting game\n"); 00582 out.text = "STARTING"; out.x = 0; out.y = -2; 00583 print_Post(&out); 00584 00585 battle_started = TRUE; 00586 } else { 00587 vccPrintPdxDebugInfo("\nYou have to place all pieces before starting the game\n"); 00588 out.text = "PLACE@ALL"; out.x = 0; out.y = 6; 00589 print_Post(&out); 00590 } 00591 }else if ((pressed.button_no == 2) && (player_no != 2)){ 00592 vccPrintPdxDebugInfo("Quit button pressed\n...EXITING..."); 00593 out.text = "QUITING"; out.x = 0; out.y = 6; 00594 print_Post(&out); 00595 } else if (pressed.button_no == 0){ 00596 player_no = pressed.player; 00597 turn = 1; 00598 vccPrintPdxDebugInfo("\nPlayer is: %d\n",player_no); 00599 } 00600 |
|
Function called upon starting the simulation.
This function is called directly when the simulation and VCC is started.
00143 { 00144 00145 00146 initialise_start(); 00147 initialise_battlefield(); 00148 battle_started = FALSE; 00149 00150 } |
|
Compare two strings. Function used to compare two strings. Declared in order to be used |
|
Function used for debugging. This function is the equivalent of printf in VCC. Has been used throughout the program for debugging |
|
Variable used to distinguish if the battle has began or not.
If battle has started then we use different structures and perform different actions compared to those used during the initialisation. |
|
Variable used to identify the player to whom this specific module belongs to.
This variable is set by a button signal that is sent by the Input module. |
|
Variable used to detect if it is a player's turn or not
This variable is set to 0 at the start and then to 1 when a player presses the start button. |