#include <ClientSJ.h>
Collaboration diagram for ClientSJ:
Public Member Functions | |
ClientSJ (string adresse, unsigned int port, string login) | |
Constructeur de la classe. | |
~ClientSJ () | |
Private Member Functions | |
void | Traitement (string login) |
Méthode gérant le protocole de communication (appel aux autres méthodes). | |
void | SendHello () |
Etablissement du protocole. | |
void | SendLogin (string login) |
void | SendRole () |
void | TraitementDeplacement () |
Méthode traitant le déplacement (boucle tant que le jeu n'est pas terminé). | |
unsigned int | UintAleat (unsigned int min, unsigned int max) |
Private Attributes | |
Socket * | mSocket |
Pointeur sur la socket de communication. | |
AffichageGrille * | mAG |
Pointeur sur le thread que l'on créé pour afficher la grille. | |
Mutex * | mVerrou |
Pointeur sur le mutex. |
Definition at line 39 of file ClientSJ.h.
ClientSJ::ClientSJ | ( | string | adresse, | |
unsigned int | port, | |||
string | login | |||
) |
Constructeur de la classe.
adresse | Adresse du serveur de jeu | |
port | Port du serveur de jeu | |
login | Login a utiliser. |
Definition at line 23 of file ClientSJ.cpp.
References mSocket, mVerrou, and Traitement().
00023 { 00024 mVerrou=new Mutex; 00025 mSocket=new SocketTCP(adresse,port); 00026 Traitement(login); 00027 }
Here is the call graph for this function:
ClientSJ::~ClientSJ | ( | ) |
void ClientSJ::Traitement | ( | string | login | ) | [private] |
Méthode gérant le protocole de communication (appel aux autres méthodes).
login |
Definition at line 35 of file ClientSJ.cpp.
References SendHello(), SendLogin(), SendRole(), and TraitementDeplacement().
Referenced by ClientSJ().
00035 { 00036 SendHello(); 00037 SendLogin(login); 00038 SendRole(); 00039 TraitementDeplacement(); 00040 }
Here is the call graph for this function:
void ClientSJ::SendHello | ( | ) | [private] |
Etablissement du protocole.
Definition at line 42 of file ClientSJ.cpp.
References Socket::Ecouter(), Socket::Envoyer(), and mSocket.
Referenced by Traitement().
00042 { 00043 cout<<"Initialisation du protocole avec le serveur"<<endl; 00044 cout<<endl<<">> HELLO"<<endl; 00045 mSocket->Envoyer("HELLO"); 00046 cout<<"ClientSJ: <<: "<<mSocket->Ecouter()<<endl; 00047 }
Here is the call graph for this function:
void ClientSJ::SendLogin | ( | string | login | ) | [private] |
Definition at line 49 of file ClientSJ.cpp.
References Socket::Ecouter(), Socket::Envoyer(), and mSocket.
Referenced by Traitement().
00049 { 00050 cout<<"Envoi du login au serveur"<<endl; 00051 while(login==""){ 00052 cout<<"Login: "; cin>>login; cout<<endl; 00053 } 00054 string reponse="LOGIN "; reponse+=login; 00055 mSocket->Envoyer(reponse); 00056 cout<<mSocket->Ecouter()<<endl; 00057 }
Here is the call graph for this function:
void ClientSJ::SendRole | ( | ) | [private] |
Definition at line 59 of file ClientSJ.cpp.
References Socket::Ecouter(), Socket::Envoyer(), and mSocket.
Referenced by Traitement().
00059 { 00060 cout<<"Attente des places disponibles"<<endl; 00061 string place=mSocket->Ecouter(); 00062 istringstream iss(place); 00063 string cmd,code, reponse; 00064 getline(iss,cmd,' '); 00065 if(cmd=="BUSY"){ 00066 getline(iss,code,' '); 00067 cout<<"Le serveur nous propose les rôles suivant:"<<endl; 00068 if(code[0]=='0') cout<<"\t1) Fantome 0"<<endl; 00069 if(code[1]=='0') cout<<"\t2) Fantome 1"<<endl; 00070 if(code[2]=='0') cout<<"\t3) Fantome 2"<<endl; 00071 if(code[3]=='0') cout<<"\t4) Pacman"<<endl; 00072 bool stop=true; 00073 while(1){ 00074 unsigned int choix; string role; 00075 cout<<"Role: "; cin>>choix; 00076 switch(choix){ 00077 case 4:{ 00078 role="PACMAN"; break; 00079 } 00080 case 1:{ 00081 role="F1"; break; 00082 } 00083 case 2:{ 00084 role="F2"; break; 00085 } 00086 case 3:{ 00087 role="F3"; break; 00088 } 00089 default: stop=false; 00090 } 00091 reponse="GET "; reponse+=role; 00092 mSocket->Envoyer(reponse); 00093 if(mSocket->Ecouter()!="ERROR GET ROLE") break; 00094 } 00095 } 00096 00097 }
Here is the call graph for this function:
void ClientSJ::TraitementDeplacement | ( | ) | [private] |
Méthode traitant le déplacement (boucle tant que le jeu n'est pas terminé).
Definition at line 100 of file ClientSJ.cpp.
References Thread::Demarrer(), Socket::Ecouter(), Socket::Envoyer(), AffichageGrille::GameOver(), Mutex::Lock(), mAG, mSocket, mVerrou, and Mutex::Unlock().
Referenced by Traitement().
00100 { 00101 cout<<"On attend les autres joueurs..."<<endl; 00102 if(mSocket->Ecouter()=="READY"){ 00103 cout<<"Le serveur est prêt à commencer la partie..."<<endl; 00104 mAG=new AffichageGrille(mSocket, mVerrou); 00105 mAG->Demarrer(); 00106 while(!mAG->GameOver()){ 00107 char dep=cin.get(); 00108 mVerrou->Lock(); 00109 switch(dep){ 00110 case '8': { 00111 mSocket->Envoyer("HAUT"); 00112 break; 00113 } 00114 case '2' : { 00115 mSocket->Envoyer("BAS"); 00116 break; 00117 } 00118 case '4' : { 00119 mSocket->Envoyer("GAUCHE"); 00120 break; 00121 } 00122 case '6' : { 00123 mSocket->Envoyer("DROITE"); 00124 break; 00125 } 00126 default: mSocket->Envoyer("BIDON"); 00127 } 00128 if(mSocket->Ecouter()=="GAME OVER") { 00129 printf( "\n\e[30;47m\e[33mGAME OVER\e[m\e[m\n\n"); 00130 break; 00131 } 00132 mVerrou->Unlock(); 00133 } 00134 } 00135 }
Here is the call graph for this function:
unsigned int ClientSJ::UintAleat | ( | unsigned int | min, | |
unsigned int | max | |||
) | [private] |
Definition at line 137 of file ClientSJ.cpp.
00137 { 00138 static bool first=true; 00139 //On initialise le générateur en fonction de l'horloge 00140 if(first) { 00141 srand((unsigned)time(NULL)); 00142 first=false; 00143 } 00144 unsigned int nb=(unsigned)rand(); 00145 //on tire un nombre au hasard et on le place sur le bon intervalle. 00146 unsigned int final=(unsigned int)(min+((float)rand()/RAND_MAX*(max))); 00147 if(final==0) return 1; 00148 return final; 00149 }
Socket* ClientSJ::mSocket [private] |
Pointeur sur la socket de communication.
Definition at line 75 of file ClientSJ.h.
Referenced by ClientSJ(), SendHello(), SendLogin(), SendRole(), TraitementDeplacement(), and ~ClientSJ().
AffichageGrille* ClientSJ::mAG [private] |
Pointeur sur le thread que l'on créé pour afficher la grille.
Definition at line 80 of file ClientSJ.h.
Referenced by TraitementDeplacement(), and ~ClientSJ().
Mutex* ClientSJ::mVerrou [private] |
Pointeur sur le mutex.
Definition at line 85 of file ClientSJ.h.
Referenced by ClientSJ(), TraitementDeplacement(), and ~ClientSJ().