Skip to content
Snippets Groups Projects
Commit 8ed1f058 authored by HECKMANN CYRIL's avatar HECKMANN CYRIL :nerd:
Browse files

Modification client

parent 103291e0
No related merge requests found
......@@ -5,6 +5,7 @@ using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Windows.Forms;
namespace TronClient
{
......@@ -13,12 +14,17 @@ namespace TronClient
private Tron.Tron myTron; // Moteur du jeu
public byte frequence; // Temps du tour de jeu (en dixieme de s)
Socket clientSocket;
string serverIP;
int serverPort;
// constructeur : IP/Port du serveur
public Client(String myServerIP, int myServerPort)
{
// TODO : Creation de la socket d'écoute TCP
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
serverIP = myServerIP;
serverPort = myServerPort;
}
......@@ -26,16 +32,24 @@ namespace TronClient
public Tron.Tron Init()
{
System.Console.WriteLine("Init");
byte[] buffer = new byte[3];
// TODO Connexion au serveur
// TODO Connexion au serveur
clientSocket.Bind(new IPEndPoint(IPAddress.Any, 0));
IPEndPoint serv = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
clientSocket.Connect(serv);
// TODO Réception des paramètres
int nBytes = clientSocket.Receive(buffer, buffer.Length, SocketFlags.None);
// TODO Initialisation de la fréquence : frequence = <frequence>
frequence = 1;
// TODO Initialisation du moteur : myTron = new Tron(byte <taille terrain>, byte <nombre de joueurs>, byte <numéro du joueur>);
myTron = new Tron.Tron(60, 2, 0);
// buffer[1] = taille
// buffer[0] = nbJoueur
// buffer[2] = NumJoueur
myTron = new Tron.Tron(buffer[1], buffer[0], buffer[2]);
// Retourne le moteur
return myTron;
......@@ -46,16 +60,25 @@ namespace TronClient
{
System.Console.WriteLine("Routine");
byte[] bufferSend = new byte[2];
byte[] bufferReceive = new byte[Convert.ToInt32(myTron.getNJoueurs())];
// TODO Envoie de sa direction : myTron.getDirection()
bufferSend[0] = myTron.getMonNum();
bufferSend[1] = myTron.getDirection();
clientSocket.Send(bufferSend, 0, bufferSend.Length, SocketFlags.None);
// TOSO Reception de toutes les directions : myTron.setDirections(byte[] < toutes les directions>);
int nBytes = clientSocket.Receive(bufferReceive, bufferReceive.Length, SocketFlags.None);
myTron.setDirections(bufferReceive);
}
// Appelé à la fin de la partie
public void Conclusion()
{
System.Console.WriteLine("Conclusion");
clientSocket.Close();
// fermeture socket
}
......
......@@ -49,7 +49,7 @@
this.textBoxIP.Name = "textBoxIP";
this.textBoxIP.Size = new System.Drawing.Size(123, 20);
this.textBoxIP.TabIndex = 1;
this.textBoxIP.Text = "127.0.0.1";
this.textBoxIP.Text = "10.0.0.1";
//
// textBoxPort
//
......@@ -57,7 +57,7 @@
this.textBoxPort.Name = "textBoxPort";
this.textBoxPort.Size = new System.Drawing.Size(50, 20);
this.textBoxPort.TabIndex = 2;
this.textBoxPort.Text = "8000";
this.textBoxPort.Text = "8080";
//
// FormLobby
//
......
......@@ -112,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment