embeddedlibrary
reusable software modules for embedded systems
Game Management / Helper Module

Game Management / Helper Module. More...

Data Structures

struct  char_object_t
 Char Object. More...
 
struct  player_info_t
 Player info structure to hold player settings. More...
 

Macros

#define TRANSPARENT_CHAR   '`'
 transparent character for drawing tiles
 

Functions

uint8_t Game_Register (char *name, char *description, void(*play)(void), void(*help)(void))
 Game_Register registers a game by adding it to the games[] array. More...
 
void Game_RegisterCallback (uint8_t game_id, void(*callback)(int argc, char *argv[]))
 
void Game_RegisterHighscoreCallback (uint8_t game_id, void(*callback)(void))
 
void Game_Log (uint8_t game_id, char *str,...)
 
void Game_EnableMultiPlayer (uint8_t game_id, uint8_t num)
 
void Game_RegisterPlayer1Receiver (charReceiver_t rx)
 
void Game_RegisterPlayer2Receiver (charReceiver_t rx)
 Register Player 2 UART Channel. More...
 
void Game_UnregisterPlayer1Receiver (charReceiver_t rx)
 Unregister Player 1 UART Channel receiver. More...
 
void Game_UnregisterPlayer2Receiver (charReceiver_t rx)
 Unregister Player 2 UART Channel receiver. More...
 
void Game_CharXY (char c, char x, char y)
 Write a character to a coordinate of the terminal. More...
 
void Game_Player1CharXY (char c, char x, char y)
 
void Game_Player2CharXY (char c, char x, char y)
 
void Game_Printf (char *str,...)
 
void Game_Player1Printf (char *str,...)
 
void Game_Player2Printf (char *str,...)
 
void Game_HideCursor (void)
 Hide the cursor for player 1 (and player2 if a two player game) More...
 
void Game_ShowCursor (void)
 Show the cursor for player 1 (and player2 if a two player game) More...
 
void Game_SetColor (enum term_color color)
 
void Game_DrawTile (char *tile[], char x, char y)
 
void Game_DrawRect (char x_min, char y_min, char x_max, char y_max)
 
void Game_FillRect (char c, char x_min, char y_min, char x_max, char y_max)
 
void Game_ScrollDown (void)
 
void Game_ScrollUp (void)
 
void Game_ClearScreen (void)
 
uint8_t Game_IsTransmitting (void)
 
void Game_Bell (void)
 

Detailed Description

Game Management / Helper Module.

This module helps manage multiple game modules running on a single system as well as implementing several helper functions and structures.

Command list:

Notes for developing a game using this game management module:

Author
Michael Muhlbaier
Todo:

MM add "$game player1 ..." and "$game player2 ..." command support

MM implement transparent character support

Function Documentation

void Game_Bell ( void  )
Warning
KC 8/10

This is used to print out an "\a" within the game. The "\a" is used to represent a bell that sounds an alarm

void Game_CharXY ( char  c,
char  x,
char  y 
)

Write a character to a coordinate of the terminal.

Game_CharXY writes a character to the terminal. If there are multiple players it will write to all available terminals

Parameters
cis the character you wish to print to the terminal
xdefines where to print the character on the x axis
ydefines where to print the character on the y axis
Warning
MM 9/10
void Game_ClearScreen ( void  )
Todo:
Atharva A. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_DrawRect ( char  x_min,
char  y_min,
char  x_max,
char  y_max 
)

Draws the border of a rectangle using the following character codes: 186, 187, 188, 200, 201, 205

Parameters
x_minThe smallest horizontal location to begin drawing.
y_minThe smallest vertical direction to begin drawing.
x_maxThe largest horizontal location to begin drawing.
y_maxThe largest vertical direction to begin drawing.
Warning
Remember that the coordinate system starts in the upper left corner and is positive down the screen for the y axis.
GL 10/10
void Game_DrawTile ( char *  tile[],
char  x,
char  y 
)

Convenience function for writing a tile (2D array of characters) to the screen at a specified X, Y coordinate. This function maps characters in the beginning of the array to the top of the screen and the end to a lower portion of the screen. A null terminated array signals the end of the array.

Parameters
tileAn array of character pointers with null termination
xThe horizontal location to begin drawing the tile
yThe vertical location to begin drawing the tile
Warning
GL 10/10
void Game_EnableMultiPlayer ( uint8_t  game_id,
uint8_t  num 
)
Parameters
game_id
num
Todo:
Jon W. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_FillRect ( char  c,
char  x_min,
char  y_min,
char  x_max,
char  y_max 
)
Warning
AA 10/10

This function can be used to fill up a rectangular area with a passed character

Parameters
c- Some character
x_min- minimum value of x
y_min- minimum value of y
x_max- maximum value of x
y_max- maximum value of y Example code:
1 #include <stdio.h>
2 #include <stdlib.h>
3 .
4 .
5 .
6 int main()
7 {
8 .
9 .
10 .
11 Game_FillRect('C', 1, 1, 10, 10)
12 .
13 .
14 .
15  return 0;
16 }
void Game_HideCursor ( void  )

Hide the cursor for player 1 (and player2 if a two player game)

Hide the cursor and, if echo is on, turn echo off.

uint8_t Game_IsTransmitting ( void  )

Game_IsTransmitting is used to determine whether the game is currently transmitting data to UART This allows the user to check that the game screen is fully updated before allowing the game to advances forward

Returns
1 if the UART for the specified player is being updated, 0 if no values are being written to UART
Warning
DB 9/10
void Game_Log ( uint8_t  game_id,
char *  str,
  ... 
)
Parameters
game_idID of game (returned when Game_Register() is called)
strpointer to null terminated string
...variable argument list to be used with any replacement flags in the string

Similar to LogMsg() except with the addition of the game name to the message.

Warning
CR 7/10
void Game_Player1CharXY ( char  c,
char  x,
char  y 
)
Parameters
c
x
y
Todo:
Anthony M. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_Player1Printf ( char *  str,
  ... 
)
Parameters
strpointer to string to be printed (must be null terminated)
...variable argument list to be used with any replacement flags in the string

Function: Game_Printf(*str)

This function is passed a pointer to a string and prints that string to player 1's terminal using UART_vprintf. The function supports printf style replacement flags.

Warning
TM 9/10
void Game_Player2CharXY ( char  c,
char  x,
char  y 
)
Parameters
c
x
y
Todo:
Anthony M. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_Player2Printf ( char *  str,
  ... 
)

Sending a Player 2 specific message

Parameters
stris a string which is to be printed to player 2's screen.
...variable argument list to be used with any replacement flags in the string
1 Game_Player2Printf("Your score is: %d", score);

This function is passed a pointer to a string and prints that string to player 2's terminal using UART_vprintf. The function supports printf style replacement flags.

Warning
RT 8/10
void Game_Printf ( char *  str,
  ... 
)
Parameters
strpointer to string to be printed (must be null terminated)
...variable argument list to be used with any replacement flags in the string

Function: Game_Printf(*str)

This function is passed a pointer to a string and prints that string to the terminal using UART_vprintf. The function supports printf style replacement flags. Can output messages from multiple UART channels if more than one person is playing.

Warning
TM 9/10
uint8_t Game_Register ( char *  name,
char *  description,
void(*)(void)  play,
void(*)(void)  help 
)

Game_Register registers a game by adding it to the games[] array.

Game_Register will take input pointers and copy it onto the corresponding variable pointers in game_t struct. Will also initialize num_players, score, and callback.

Parameters
name- Pointer to start of character array containing name of game
description- Pointer to start of character array containing description of game
play- Pointer to function that initiates playing the game
help- Pointer to function that displays help info
Returns
returns 0xFF if games[] array is at MAX_GAMES length Otherwise returns index of registered game in games[] array
void Game_RegisterCallback ( uint8_t  game_id,
void(*)(int argc, char *argv[])  callback 
)

This function takes in an id for the game along with the callback, and saves it in the array of games. The index of the array the callback is stored in is the game_id, so this number must be less than the size of the games array.

Parameters
game_idID of the game. Also used as the array index.
callbackThe callback pointer
Warning
JR 10/10
void Game_RegisterHighscoreCallback ( uint8_t  game_id,
void(*)(void)  callback 
)
Parameters
game_id
callback
Todo:
Andrew R. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_RegisterPlayer1Receiver ( charReceiver_t  rx)

Game_RegisterPlayer1Receiver will register the UART char receiver function for player 1

Game_RegisterPlayer1Receiver registers the UART char receiver function for player 1. PLAYER1_UART defines the channel of the UART to be registered.

Parameters
rxPointer to UART char receiver function
Warning
Make sure to Game_UnregisterPlayer1Receiver() when game play is over
JWi 10/10
void Game_RegisterPlayer2Receiver ( charReceiver_t  rx)

Register Player 2 UART Channel.

Game_RegisterPlayer2Receiver() registers a second UART channel to be used by a second player. Only use if you game allows a for a second player

Parameters
rxis a function pointer that calls a function when a character is received in the UART channel
Warning
Make sure to Game_UnregisterPlayer2Receiver() when game play is over
TG 10/10
void Game_ScrollDown ( void  )
Todo:
Gerald V. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_ScrollUp ( void  )
Todo:
Gerald V. Document this function (when done change this line to "@todo MM check <your names> documentation"
void Game_SetColor ( enum term_color  color)

This function sets the color for the game and can be either the foreground or the background depending on the user input. If there is a second channel, it will also set the corresponding color specifications to the second UART channel.

Parameters
coloris one of the elements within the enumeration defined in terminal.h.
Warning
RT 10/10
void Game_ShowCursor ( void  )

Show the cursor for player 1 (and player2 if a two player game)

Show the cursor and, if echo was on, turn echo back on.

void Game_UnregisterPlayer1Receiver ( charReceiver_t  rx)

Unregister Player 1 UART Channel receiver.

Game_UnregisterPlay1Receiver() unregisters the UART channel associated with player 1.

Parameters
rxis a function pointer that calls a function when a character is received in the UART channel
Warning
TG 10/10
void Game_UnregisterPlayer2Receiver ( charReceiver_t  rx)

Unregister Player 2 UART Channel receiver.

Game_UnregisterPlayer2Receiver() unregisters the UART channel that has been assigned to Player 2.

Parameters
rxis a function pointer that calls the desired function when the UART channel receives a character.
Warning
MM 9/10