Main Page   Data Structures   File List   Globals  

start_game.c

Go to the documentation of this file.
00001 #include "white_interface.h"
00002 
00036 int strcmp(const char *str1, const char *str2);
00037 
00045 char * strcpy (char *to, const char *from);
00046 
00052 char player_name_array[20][20];
00053 
00060 char player_count = 0;
00061 
00062 
00067 /* Init Function */
00068 void poin_entry_Init()
00069 {
00070 }
00071 
00072 
00077 /* Run Function */
00078 void poin_entry_Run()
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 }

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