Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 80 additions and 3 deletions
File added
File added
File added
File added
File added
File added
......@@ -16,7 +16,7 @@ namespace TronServeur
Tron.Tron myTron; // Moteur du jeu
byte nJoueurs = 2; // Nombre de joueurs
byte frequence = 10; // Temps du tour de jeu (en dixieme de s)
byte frequence = 2; // Temps du tour de jeu (en dixieme de s)
byte taille = 60; // Taille du terrain
// ************************************* Intitialisation partie
......@@ -24,16 +24,49 @@ namespace TronServeur
// TODO Creation de la socket d'écoute TCP
Socket listenSocket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
// TODO Creation du tableau des sockets connectées
Socket[] tabSocketCo = new Socket[nJoueurs];
// Creation du tableau des sockets déconnectés
Socket[] tabSocketDeco = new Socket[nJoueurs];
// Creation du moteur de jeu
myTron = new Tron.Tron(nJoueurs, taille);
// TODO Bind et listen
listenSocket.Bind(new IPEndPoint(IPAddress.Any, 11111));
// On la positionne en mode "ecoute" pour 10 clients en attente maximum
listenSocket.Listen(10);
// TODO Acceptation des clients
for(int i = 0; i < nJoueurs; i++)
{
Socket connectedSocket = listenSocket.Accept();
tabSocketCo[i] = connectedSocket;
Console.WriteLine("Nouveau client connecte : " + connectedSocket.RemoteEndPoint);
}
// TODO Envoie des paramètres
for(int i = 0; i<nJoueurs; i++)
{
// Création du Buffer
byte[] bufferInfoPartie = new byte[4];
bufferInfoPartie[3] = frequence;
bufferInfoPartie[0] = taille;
bufferInfoPartie[1] = nJoueurs;
bufferInfoPartie[2] = (byte)i;
// Envoie des infos
int nBytes = tabSocketCo[i].Send(bufferInfoPartie);
}
// ************************************* Routine à chaque tour
System.Console.WriteLine("Routine");
......@@ -41,11 +74,43 @@ namespace TronServeur
// Tant que la partie n'est pas finie
while (!myTron.IsFinished())
{
byte[] direction = new byte[nJoueurs];
// TODO Réception de la direction de chaque joueur
for (int i = 0; i < nJoueurs; i++)
{
if(tabSocketDeco[i] == null)
{
byte[] bufferDirection = new byte[1];
tabSocketCo[i].ReceiveTimeout = 1000;
try
{
tabSocketCo[i].Receive(bufferDirection,0,bufferDirection.Length, SocketFlags.None);
direction[i] = bufferDirection[0];
}
catch(System.Net.Sockets.SocketException e)
{
direction[i] = 4;
tabSocketDeco[i] = tabSocketCo[i];
}
}
}
// TODO Calcul collision : myTron.Collision(byte[] <toutes les directions>);
myTron.Collision(direction);
// TODO Envoie des directions de tous les joueurs à tous les clients
for(int i = 0; i < nJoueurs; i++)
{
try
{
int nBytes = tabSocketCo[i].Send(direction);
}
catch(System.Net.Sockets.SocketException e)
{
}
}
}
......@@ -53,9 +118,14 @@ namespace TronServeur
System.Console.WriteLine("Conclusion");
// TODO Fermeture des sockets connectées
Console.WriteLine("Fermeture Socket...");
for(int i = 0; i < nJoueurs; i++)
{
tabSocketCo[i].Close();
}
// TODO Fermeture socket d'écoute
listenSocket.Close();
}
}
}
File added
File added
899dfdc5d77f0b6c8f58e468779667cbc2bd60d5
U:\Documents\DeuxiemeAnnee\S32\Projet\Tron\TronServeur\TronServeur\bin\Debug\TronServeur.exe
U:\Documents\DeuxiemeAnnee\S32\Projet\Tron\TronServeur\TronServeur\bin\Debug\TronServeur.pdb
U:\Documents\DeuxiemeAnnee\S32\Projet\Tron\TronServeur\TronServeur\obj\Debug\TronServeur.csprojAssemblyReference.cache
U:\Documents\DeuxiemeAnnee\S32\Projet\Tron\TronServeur\TronServeur\obj\Debug\TronServeur.csproj.CoreCompileInputs.cache
U:\Documents\DeuxiemeAnnee\S32\Projet\Tron\TronServeur\TronServeur\obj\Debug\TronServeur.exe
U:\Documents\DeuxiemeAnnee\S32\Projet\Tron\TronServeur\TronServeur\obj\Debug\TronServeur.pdb
File added
File added
File added
File added
File added