Main Page   Data Structures   File List   Globals  

start_game.c File Reference

Starts the network game. More...

#include "white_interface.h"

Go to the source code of this file.

Functions

int strcmp (const char *str1, const char *str2)
 C standard library function. More...

char * strcpy (char *to, const char *from)
 C standard library function. More...

void poin_entry_Init ()
 VCC Init function. More...

void poin_entry_Run ()
 VCC Run function. More...


Variables

char player_name_array [20][20]
 An array of player names. More...

char player_count = 0
 The number of other players on the network. More...


Detailed Description

Starts the network game.

This block is the core of the lobby module. If the user selects an opponent in the lobby screen, start_game sends a lobby_message asking to start a game with the chosen player. It then assigns a player number to the local core module (this will be 0 as this lobby module has initiated the network game). Finally the screen is cleared and a trigger is sent to the relay_MouseClicks block so that user input is forwarded to the input module rather than the lobby.

start_game also waits for requests from other players to play a network game with them. If a lobby_message is received asking the local user to play, a player number of 1 is assigned to the core module (because this lobby did not initiate the game). As before, the screen is cleared and mouse input is redirected to the input module.

The final possibility is that a lobby_message is received that requests a game between 2 other players. In this case, the local machine should observe the game. It does this by assigning a player number of 2 to the core. The core then does nothing except display the moves of other players.

Definition in file start_game.c.


Function Documentation

void poin_entry_Init  
 

VCC Init function.

This function runs when the VCC simulation is first started.

Definition at line 68 of file start_game.c.

00069 {
00070 }

void poin_entry_Run  
 

VCC Run function.

This runs whenever a message arrives at any of the start_game block's input ports.

Definition at line 78 of file start_game.c.

References player_count, player_name_array, strcmp, and strcpy.

00079 {
00080   int other_player;
00081   lobby_message request_play;
00082   lobby_message message_in;
00083 
00084   /* if a player name arrives from get_other_players,
00085      add it to the array of player names and update
00086      the count of other players on the network. */
00087 
00088   if (players_in_Enabled())
00089   {
00090     player_count++;
00091     strcpy(player_name_array[player_count], players_in_Value());
00092   }
00093 
00094   /* if a line number arrives from mouse_input, indicating
00095      that the user has clicked the name of an opponent,
00096      start a game with that player. */
00097 
00098   if (line_in_Enabled())
00099   {
00100     other_player = line_in_Value();
00101     if (other_player <= player_count)
00102     {
00103       /* first tell the other player that you want to play him */
00104 
00105       request_play.player_name = MyName_Value();
00106       request_play.message = player_name_array[other_player];
00107       net_out_Post(&request_play);
00108 
00109       /* now send player number to input module (player 0 as
00110          initiating the game.  */
00111 
00112       player_no_out_Post(0);
00113 
00114       /* Pass mouse clicks through to the input module rather than
00115          the lobby.  */
00116 
00117       trigger_out_Post(1);
00118 
00119       /* Finally clear the screen */
00120 
00121       clear_out_Post(1);
00122     }
00123   }
00124 
00125   /* If a play request arrives from another player,
00126      examine the message and either play the game
00127      or observe it. */
00128   
00129   if (net_in_Enabled())
00130   {
00131     message_in = *net_in_Value();
00132 
00133     if (strcmp(message_in.message, "name") != 0)
00134     {
00135       if (strcmp(message_in.message, MyName_Value()) == 0)
00136       {
00137         /* message is asking me to play, so play. */
00138 
00139         /* now send player number to input module (player 1 as
00140            not initiating the game.  */
00141 
00142         player_no_out_Post(1);
00143       }
00144       else
00145       {
00146         /* message is asking another player to play,
00147            so just watch. */
00148 
00149         /* now send player number to input module (player 2 as
00150            just observing the game  */
00151 
00152         player_no_out_Post(2);
00153       }
00154 
00155       /* Pass mouse clicks through to the input module rather than
00156          the lobby.  */
00157 
00158       trigger_out_Post(1);
00159 
00160       /* Finally clear the screen */
00161 
00162       clear_out_Post(1);
00163     }
00164   }
00165 }

int strcmp const char *    str1,
const char *    str2
 

C standard library function.

Compares two strings.

Parameters:
str1  A pointer to the first string.
str2  A pointer to the second string.
Returns:
An integer (0 if the string are equal).

Referenced by poin_entry_Run.

char* strcpy char *    to,
const char *    from
 

C standard library function.

Copies one string to another.

Parameters:
to  A pointer to the destination string.
from  A pointer to the source string.
Returns:
A pointer to the string.

Referenced by poin_entry_Run.


Variable Documentation

char player_count = 0
 

The number of other players on the network.

This stores the number of player name messages that have been received and should be equal to the number of other players on the wireless network.

Definition at line 60 of file start_game.c.

Referenced by poin_entry_Run.

char player_name_array[20][20]
 

An array of player names.

This stores the names of the other players on the network as an array of strings.

Definition at line 52 of file start_game.c.

Referenced by poin_entry_Run.


Copyright © 2002 Andrew Bates
Last Updated 04/04/02