diff --git a/giphy.gif b/giphy.gif new file mode 100644 index 0000000..30e8d03 Binary files /dev/null and b/giphy.gif differ diff --git a/go01.rar b/go01.rar new file mode 100644 index 0000000..2538d59 Binary files /dev/null and b/go01.rar differ diff --git a/go01/App.config b/go01/App.config index 731f6de..4707094 100644 --- a/go01/App.config +++ b/go01/App.config @@ -1,6 +1,21 @@  + + +
+ + + + + + True + + + 50 + + + \ No newline at end of file diff --git a/go01/CreerPartieReseau_serv.Designer.cs b/go01/CreerPartieReseau_serv.Designer.cs new file mode 100644 index 0000000..c971c61 --- /dev/null +++ b/go01/CreerPartieReseau_serv.Designer.cs @@ -0,0 +1,262 @@ +using System; +using System.Net; +using System.Net.Sockets; + +namespace go01 +{ + partial class CreerPartieReseau_serv + { + + public string GetLocalIPAddress() + { + var host = Dns.GetHostEntry(Dns.GetHostName()); + foreach (var ip in host.AddressList) + { + if (ip.AddressFamily == AddressFamily.InterNetwork) + { + return ip.ToString(); + } + } + throw new Exception("No network adapters with an IPv4 address in the system!"); + } + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tbUid = new System.Windows.Forms.TextBox(); + this.lblUid = new System.Windows.Forms.Label(); + this.lblIp = new System.Windows.Forms.Label(); + this.tbIp = new System.Windows.Forms.TextBox(); + this.lblNomPartie = new System.Windows.Forms.Label(); + this.tbPartName = new System.Windows.Forms.TextBox(); + this.tbNomJoeur = new System.Windows.Forms.TextBox(); + this.lblNomJoeur = new System.Windows.Forms.Label(); + this.btnCreatePart = new System.Windows.Forms.Button(); + this.tbTaille = new System.Windows.Forms.TextBox(); + this.lblTaille = new System.Windows.Forms.Label(); + this.tbPionaAligner = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.cbNic = new System.Windows.Forms.ComboBox(); + this.lblPort = new System.Windows.Forms.Label(); + this.tbPort = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // tbUid + // + this.tbUid.Enabled = false; + this.tbUid.Location = new System.Drawing.Point(45, 12); + this.tbUid.Name = "tbUid"; + this.tbUid.ReadOnly = true; + this.tbUid.Size = new System.Drawing.Size(198, 20); + this.tbUid.TabIndex = 1; + this.tbUid.Text = "f89cf97049ed4e33925d712ec38890b6"; + // + // lblUid + // + this.lblUid.AutoSize = true; + this.lblUid.Location = new System.Drawing.Point(13, 15); + this.lblUid.Name = "lblUid"; + this.lblUid.Size = new System.Drawing.Size(26, 13); + this.lblUid.TabIndex = 10; + this.lblUid.Text = "UID"; + // + // lblIp + // + this.lblIp.AutoSize = true; + this.lblIp.Location = new System.Drawing.Point(350, 15); + this.lblIp.Name = "lblIp"; + this.lblIp.Size = new System.Drawing.Size(17, 13); + this.lblIp.TabIndex = 16; + this.lblIp.Text = "IP"; + // + // tbIp + // + this.tbIp.Enabled = false; + this.tbIp.Location = new System.Drawing.Point(278, 38); + this.tbIp.Name = "tbIp"; + this.tbIp.ReadOnly = true; + this.tbIp.Size = new System.Drawing.Size(152, 20); + this.tbIp.TabIndex = 3; + // + // lblNomPartie + // + this.lblNomPartie.AutoSize = true; + this.lblNomPartie.Location = new System.Drawing.Point(12, 100); + this.lblNomPartie.Name = "lblNomPartie"; + this.lblNomPartie.Size = new System.Drawing.Size(59, 13); + this.lblNomPartie.TabIndex = 12; + this.lblNomPartie.Text = "Nom Partie"; + // + // tbPartName + // + this.tbPartName.Location = new System.Drawing.Point(89, 97); + this.tbPartName.Name = "tbPartName"; + this.tbPartName.Size = new System.Drawing.Size(154, 20); + this.tbPartName.TabIndex = 5; + // + // tbNomJoeur + // + this.tbNomJoeur.Location = new System.Drawing.Point(326, 97); + this.tbNomJoeur.Name = "tbNomJoeur"; + this.tbNomJoeur.Size = new System.Drawing.Size(154, 20); + this.tbNomJoeur.TabIndex = 6; + // + // lblNomJoeur + // + this.lblNomJoeur.AutoSize = true; + this.lblNomJoeur.Location = new System.Drawing.Point(249, 100); + this.lblNomJoeur.Name = "lblNomJoeur"; + this.lblNomJoeur.Size = new System.Drawing.Size(55, 13); + this.lblNomJoeur.TabIndex = 15; + this.lblNomJoeur.Text = "Nom joeur"; + // + // btnCreatePart + // + this.btnCreatePart.Location = new System.Drawing.Point(15, 160); + this.btnCreatePart.Name = "btnCreatePart"; + this.btnCreatePart.Size = new System.Drawing.Size(465, 23); + this.btnCreatePart.TabIndex = 9; + this.btnCreatePart.Text = "Creer partie"; + this.btnCreatePart.UseVisualStyleBackColor = true; + this.btnCreatePart.Click += new System.EventHandler(this.btnCreatePart_Click); + // + // tbTaille + // + this.tbTaille.Location = new System.Drawing.Point(90, 123); + this.tbTaille.Name = "tbTaille"; + this.tbTaille.Size = new System.Drawing.Size(154, 20); + this.tbTaille.TabIndex = 7; + // + // lblTaille + // + this.lblTaille.AutoSize = true; + this.lblTaille.Location = new System.Drawing.Point(13, 126); + this.lblTaille.Name = "lblTaille"; + this.lblTaille.Size = new System.Drawing.Size(32, 13); + this.lblTaille.TabIndex = 13; + this.lblTaille.Text = "Taille"; + // + // tbPionaAligner + // + this.tbPionaAligner.Location = new System.Drawing.Point(326, 123); + this.tbPionaAligner.Name = "tbPionaAligner"; + this.tbPionaAligner.Size = new System.Drawing.Size(154, 20); + this.tbPionaAligner.TabIndex = 8; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(250, 126); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(71, 13); + this.label2.TabIndex = 14; + this.label2.Text = "Pion à aligner"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 42); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(25, 13); + this.label1.TabIndex = 11; + this.label1.Text = "NIC"; + // + // cbNic + // + this.cbNic.FormattingEnabled = true; + this.cbNic.Location = new System.Drawing.Point(45, 39); + this.cbNic.Name = "cbNic"; + this.cbNic.Size = new System.Drawing.Size(198, 21); + this.cbNic.TabIndex = 2; + this.cbNic.SelectedIndexChanged += new System.EventHandler(this.cbNic_SelectedIndexChanged); + // + // lblPort + // + this.lblPort.AutoSize = true; + this.lblPort.Location = new System.Drawing.Point(443, 15); + this.lblPort.Name = "lblPort"; + this.lblPort.Size = new System.Drawing.Size(26, 13); + this.lblPort.TabIndex = 0; + this.lblPort.Text = "Port"; + // + // tbPort + // + this.tbPort.Location = new System.Drawing.Point(436, 38); + this.tbPort.Name = "tbPort"; + this.tbPort.Size = new System.Drawing.Size(42, 20); + this.tbPort.TabIndex = 4; + this.tbPort.Text = "9999"; + // + // CreerPartieReseau_serv + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(490, 193); + this.Controls.Add(this.tbPort); + this.Controls.Add(this.lblPort); + this.Controls.Add(this.cbNic); + this.Controls.Add(this.label1); + this.Controls.Add(this.tbPionaAligner); + this.Controls.Add(this.label2); + this.Controls.Add(this.tbTaille); + this.Controls.Add(this.lblTaille); + this.Controls.Add(this.btnCreatePart); + this.Controls.Add(this.tbNomJoeur); + this.Controls.Add(this.lblNomJoeur); + this.Controls.Add(this.tbPartName); + this.Controls.Add(this.lblNomPartie); + this.Controls.Add(this.lblIp); + this.Controls.Add(this.tbIp); + this.Controls.Add(this.lblUid); + this.Controls.Add(this.tbUid); + this.Name = "CreerPartieReseau_serv"; + this.Text = "CreerPartieReseau_serv"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox tbUid; + private System.Windows.Forms.Label lblUid; + private System.Windows.Forms.Label lblIp; + private System.Windows.Forms.TextBox tbIp; + private System.Windows.Forms.Label lblNomPartie; + private System.Windows.Forms.TextBox tbPartName; + private System.Windows.Forms.TextBox tbNomJoeur; + private System.Windows.Forms.Label lblNomJoeur; + private System.Windows.Forms.Button btnCreatePart; + private System.Windows.Forms.TextBox tbTaille; + private System.Windows.Forms.Label lblTaille; + private System.Windows.Forms.TextBox tbPionaAligner; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox cbNic; + private System.Windows.Forms.Label lblPort; + private System.Windows.Forms.TextBox tbPort; + } +} \ No newline at end of file diff --git a/go01/CreerPartieReseau_serv.cs b/go01/CreerPartieReseau_serv.cs new file mode 100644 index 0000000..96eec79 --- /dev/null +++ b/go01/CreerPartieReseau_serv.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace go01 +{ + public partial class CreerPartieReseau_serv : Form + { + socketPlateau serveur; + + public CreerPartieReseau_serv() + { + InitializeComponent(); + this.tbUid.Text = Guid.NewGuid().ToString(); + this.tbUid.Select(0, 0); + socketPlateau.net_adapters(cbNic); + //serveur = new socketPlateau() + + + } + + private void btnCreatePart_Click(object sender, EventArgs e) + { + btnCreatePart.Enabled = false; + tbPartName.Enabled = false; + tbNomJoeur.Enabled = false; + + + var startTimeSpan = TimeSpan.Zero; + var periodTimeSpan = TimeSpan.FromSeconds(5); + socketPlateau.ConfigGo_S config = new socketPlateau.ConfigGo_S(tbUid.Text, tbPartName.Text, "", tbNomJoeur.Text, int.Parse(tbTaille.Text), int.Parse(tbPionaAligner.Text), IPAddress.Parse(tbIp.Text), int.Parse(tbPort.Text)); + serveur = new socketPlateau(socketPlateau.TypeSocket_E.Serveur, config, null); + serveur.AttenteJoueur(); + serveur.onJoinServ += new socketPlateau.OnJoinServ(JoueurRejoinServeur); + + + } + private void JoueurRejoinServeur(object o, socketPlateauServArgs e) + { + Console.WriteLine($"{e.ConfigGo.NomJoeurClient} vs {e.ConfigGo.NomJoeurServeur}"); + } + private void broadcast() + { + var Client = new UdpClient(); + var RequestData = Encoding.ASCII.GetBytes($"{tbUid.Text};{tbPartName.Text};{tbNomJoeur.Text};{tbTaille.Text};{tbPionaAligner.Text}"); + + Client.EnableBroadcast = true; + Client.Send(RequestData, RequestData.Length, new IPEndPoint(IPAddress.Broadcast, 8888)); + + Client.Close(); + } + + private void cbNic_SelectedIndexChanged(object sender, EventArgs e) + { + var local = NetworkInterface.GetAllNetworkInterfaces().Where(i => i.Name == cbNic.SelectedItem.ToString()).FirstOrDefault(); + + + foreach (UnicastIPAddressInformation ip in local.GetIPProperties().UnicastAddresses) + { + if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) + { + tbIp.Text = ip.Address.ToString(); + } + } + + } + } +} diff --git a/go01/CreerPartieReseau_serv.resx b/go01/CreerPartieReseau_serv.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/go01/CreerPartieReseau_serv.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/go01/FAccueil.pdf b/go01/FAccueil.pdf new file mode 100644 index 0000000..5a51a14 Binary files /dev/null and b/go01/FAccueil.pdf differ diff --git a/go01/Form1.Designer.cs b/go01/Form1.Designer.cs deleted file mode 100644 index 375fc4e..0000000 --- a/go01/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace go01 -{ - partial class Form1 - { - /// - /// Variable nécessaire au concepteur. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Nettoyage des ressources utilisées. - /// - /// true si les ressources managées doivent être supprimées ; sinon, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Code généré par le Concepteur Windows Form - - /// - /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas - /// le contenu de cette méthode avec l'éditeur de code. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Text = "Form1"; - } - - #endregion - } -} - diff --git a/go01/Form1.cs b/go01/Form1.cs deleted file mode 100644 index a5527c2..0000000 --- a/go01/Form1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace go01 -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/go01/Goban.cs b/go01/Goban.cs new file mode 100644 index 0000000..320403d --- /dev/null +++ b/go01/Goban.cs @@ -0,0 +1,435 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + + +namespace go01 +{ + public class Goban + { + public PictureBox Conteneur; + int nombreDePionAAligne; + int ptBlanc = 0, ptNoir = 0; + public Plateau Fenetre; + bool win = false; + public int dim; + Label LabelPlayerTurn; + public string PlayerTurn { get { return this.LabelPlayerTurn.Text; } } + string playerWName, playerBName; + List pboxList = new List(); + Joueur_E tour; + Joueur_E Tour + { + get + { + return tour; + } + set + { + tour = value; + try + { + this.LabelPlayerTurn.Text = (tour == Joueur_E.Blanc) ? playerWName : playerBName; + this.LabelPlayerTurn.ForeColor = (tour == Joueur_E.Blanc) ? Color.Gray : Color.Black; + this.LabelPlayerTurn.Location = new Point(Conteneur.Location.X + Conteneur.Width + ((Fenetre.ClientSize.Width - Conteneur.Location.X - Conteneur.Width - LabelPlayerTurn.Width) / 2), Conteneur.Location.Y); + } + catch + { + Console.WriteLine("ERROR GOBAN LabelPlayerTurn "); + } + } + } + Occupant_E[,] tableauOccupation; + + + [Flags] + enum Deplacement_E + { + SG = 0b00000001, + S = 0b00000010, + SD = 0b00000100, + G = 0b00001000, + D = 0b00010000, + IG = 0b00100000, + I = 0b01000000, + ID = 0b10000000 + } + [Serializable] + public struct sauvegarde_S + { + public string nomBlanc, nomNoir; + public int ptBlanc, ptNoir; + public int dimGoban, nbAlignementToWin; + public bool win; + public Goban.Occupant_E[,] tableauOccupation; + public Goban.Joueur_E tour; + public sauvegarde_S(string nomBlanc, string nomNoir, int pointBlanc, int pointNoir, int nbAlignementToWin, int dimGoban, Goban.Occupant_E[,] tableauOccupation, Goban.Joueur_E tour, bool win) + { + this.nomBlanc = nomBlanc; this.nomNoir=nomNoir; + this.ptBlanc = pointBlanc; this.ptNoir = pointNoir; + this.dimGoban = dimGoban; this.nbAlignementToWin = nbAlignementToWin; + this.win = win; + this.tableauOccupation = tableauOccupation; + this.tour = tour; + } + } + struct carrefour_S + { + public Point point; + public Deplacement_E SensDeDeplacment; + public carrefour_S(Point p, Deplacement_E sens) + { + point = p; + SensDeDeplacment = sens; + } + } + public enum Occupant_E { Vide, Blanc, Noir, LAST} + public enum Joueur_E { Blanc, Noir, LAST} + + + public Goban(Plateau fenetre, PictureBox conteneur, sauvegarde_S s) + { + tableauOccupation = s.tableauOccupation; + playerBName = s.nomNoir; + playerWName = s.nomBlanc; + nombreDePionAAligne = s.nbAlignementToWin; + dim = s.dimGoban; + + this.Conteneur = conteneur; + this.Fenetre = fenetre; + + fenetre.lblBlanc = playerWName + ":0"; + fenetre.lblNoir = playerBName + ":0"; + + GenerationPlateau(false); + //redrawAllpb(); + } + public Goban(Plateau fenetre, PictureBox conteneur, int dim, int nbPionAlignn, string playerW, string playerB) + { + int x = 0; + nombreDePionAAligne = nbPionAlignn; + this.Conteneur = conteneur; + this.dim = dim; + this.Fenetre = fenetre; + + playerWName = playerW; + playerBName = playerB; + + fenetre.lblBlanc = playerB + ":0"; + fenetre.lblNoir = playerW + ":0"; + + + + Tour = Joueur_E.Noir; + + //gen des tab + tableauOccupation = new Occupant_E[dim, dim]; + GenerationPlateau(); + } + public void PaintPb(object sender, PaintEventArgs e) + { + PictureBox pb = (PictureBox)sender; + String[] xy = ((PictureBox)sender).Name.Split(';'); + Console.WriteLine($"Click sur {xy[0]};{xy[1]} par {Tour}"); + int x = int.Parse(xy[0]), y = int.Parse(xy[1]); + if (tableauOccupation[x, y] != Occupant_E.Vide && !win) + { + //tableauOccupation[x, y] = (Tour == Joueur_E.Blanc) ? Occupant_E.Blanc : Occupant_E.Noir; + + Graphics gr = e.Graphics; + SolidBrush b = (tableauOccupation[x, y] == Occupant_E.Blanc) ? new SolidBrush(Color.White) : new SolidBrush(Color.Black); ; + if (b != null) + gr.FillEllipse(b, 1, 0, pb.ClientSize.Width - 2, pb.ClientSize.Height - 1); + else + gr.DrawImage(pb.Image, 0, 0, pb.Width, pb.Height); + + } + } + private void pictureBox1_Click(object sender, EventArgs e) + { + PictureBox pb = (PictureBox)sender; + String[] xy = ((PictureBox)sender).Name.Split(';'); + Console.WriteLine($"Click sur {xy[0]};{xy[1]} par {Tour}"); + int x = int.Parse(xy[0]), y = int.Parse(xy[1]); + if (tableauOccupation[x, y] == Occupant_E.Vide && !win) + { + tableauOccupation[x, y] = (Tour == Joueur_E.Blanc) ? Occupant_E.Blanc : Occupant_E.Noir; + + using (Graphics gr = Graphics.FromHwnd((pb.Handle))) + { + SolidBrush b = (Tour == Joueur_E.Blanc)?new SolidBrush(Color.White):new SolidBrush(Color.Black);; + if (b != null) + gr.FillEllipse(b, 1, 0, pb.ClientSize.Width - 2, pb.ClientSize.Height - 1); + else + gr.DrawImage(pb.Image, 0, 0, pb.Width, pb.Height); + } + bool fin = win = RechercheTeritoir(x, y); + if (fin) + { + + x=((Tour == Joueur_E.Blanc)) ? ptNoir++:ptBlanc++; + Win(true); + MessageBox.Show("YOUR WIN" + ((Tour == Joueur_E.Blanc) ? playerWName : playerBName)); + } + Console.WriteLine(fin); + if(!win) + Tour = (Tour + 1 == Joueur_E.LAST) ? Joueur_E.Blanc : Tour + 1; + } + } + private int[] GetXY(int i) + { + return new int[2] { i % dim, i / dim }; + } + private int[] GetXYStr(string s) + { + String[] xy = s.Split(';'); + return new int[2] { int.Parse(xy[0]), int.Parse(xy[1]) }; + } + private int GetX(int i) + { + return i % dim; + } + private int GetY(int i) + { + return i / dim; + } + + bool RechercheTeritoir(int x, int y) + { + Point origine = new Point(x, y); + + int pionAligneDsRecherche = 1; + + int[,] tmpParcour = new int[dim, dim]; + tmpParcour[origine.X, origine.Y] = 1; + ListpointsSuivant = RecherchePointsSuivant(origine,(Deplacement_E)0xff);//Recherche les point autour du pion + if (pointsSuivant.Count == 0) + return false; + foreach (carrefour_S point in pointsSuivant) + { + pionAligneDsRecherche = 2; + tmpParcour[point.point.X, point.point.Y] = 1; + List parcour = RecherchePointsSuivant(point.point, point.SensDeDeplacment); + while(parcour.Count > 0) + { + pionAligneDsRecherche++; + tmpParcour[parcour[0].point.X, parcour[0].point.Y] = 1; + parcour = RecherchePointsSuivant(parcour[0].point, parcour[0].SensDeDeplacment); + printTab(tmpParcour); + } + Console.WriteLine(pionAligneDsRecherche); + if (pionAligneDsRecherche >= nombreDePionAAligne*(Math.Ceiling((double)pionAligneDsRecherche/(double)nombreDePionAAligne))) + return true; + } + return false; + } + bool RechercheTeritoir(Point p) + { + return RechercheTeritoir(p.X, p.Y); + } + List RecherchePointsSuivant(Point p, Deplacement_E deplacement) + { + List PointsTrouver = new List(); + Occupant_E occupant = (Tour == Joueur_E.Blanc)?Occupant_E.Blanc:Occupant_E.Noir; + if (p.Y-1>=0 && tableauOccupation[p.X,p.Y-1] == occupant && (deplacement & Deplacement_E.S) == Deplacement_E.S) + { + PointsTrouver.Add(new carrefour_S(new Point(p.X,p.Y-1),Deplacement_E.S)); + } + if (p.Y - 1 >= 0 && p.X+1 < dim && tableauOccupation[p.X+1,p.Y-1] == occupant && (deplacement & Deplacement_E.SD) == Deplacement_E.SD) + { + PointsTrouver.Add(new carrefour_S(new Point(p.X+1,p.Y-1),Deplacement_E.SD)); + } + if (p.X + 1 < dim && tableauOccupation[p.X+1,p.Y] == occupant && (deplacement & Deplacement_E.D) == Deplacement_E.D) + { + PointsTrouver.Add(new carrefour_S(new Point(p.X+1,p.Y),Deplacement_E.D)); + } + if (p.X + 1 < dim && p.Y+1=0 && p.Y + 1 < dim && tableauOccupation[p.X-1,p.Y+1] == occupant && (deplacement & Deplacement_E.IG) == Deplacement_E.IG) + { + PointsTrouver.Add(new carrefour_S(new Point(p.X-1,p.Y+1),Deplacement_E.IG)); + } + if (p.X - 1 >= 0 && tableauOccupation[p.X-1,p.Y] == occupant && (deplacement & Deplacement_E.G) == Deplacement_E.G) + { + PointsTrouver.Add(new carrefour_S(new Point(p.X-1,p.Y),Deplacement_E.G)); + } + if (p.Y - 1 >= 0 && p.X - 1 >= 0 && tableauOccupation[p.X-1,p.Y-1] == occupant && (deplacement & Deplacement_E.SG) == Deplacement_E.SG) + { + PointsTrouver.Add(new carrefour_S(new Point(p.X-1,p.Y-1),Deplacement_E.SG)); + } + return PointsTrouver; + } + Boolean ptEgal(Point ptBlanc, Point ptNoir) + { + return ptBlanc.X == ptNoir.X && ptBlanc.Y == ptNoir.Y; + } + + void printTab(int[,] Tab) + { + for(int y = 0;y + /// Variable nécessaire au concepteur. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Nettoyage des ressources utilisées. + /// + /// true si les ressources managées doivent être supprimées ; sinon, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Code généré par le Concepteur Windows Form + + /// + /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas + /// le contenu de cette méthode avec l'éditeur de code. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.button1 = new System.Windows.Forms.Button(); + this.lblPtBlanc = new System.Windows.Forms.Label(); + this.LblPtNoir = new System.Windows.Forms.Label(); + this.btnContinuer = new System.Windows.Forms.Button(); + this.ofd = new System.Windows.Forms.OpenFileDialog(); + this.sfd = new System.Windows.Forms.SaveFileDialog(); + this.btnEnreg = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); + // + // pictureBox2 + // + this.pictureBox2.Image = global::go01.Properties.Resources.giphy; + this.pictureBox2.Location = new System.Drawing.Point(495, 152); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(300, 168); + this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox2.TabIndex = 1; + this.pictureBox2.TabStop = false; + this.pictureBox2.Visible = false; + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(13, 13); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(448, 448); + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(702, 390); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 2; + this.button1.Text = "Reset"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click_1); + // + // lblPtBlanc + // + this.lblPtBlanc.AutoSize = true; + this.lblPtBlanc.Location = new System.Drawing.Point(492, 136); + this.lblPtBlanc.Name = "lblPtBlanc"; + this.lblPtBlanc.Size = new System.Drawing.Size(48, 13); + this.lblPtBlanc.TabIndex = 3; + this.lblPtBlanc.Text = "Joeur1:0"; + // + // LblPtNoir + // + this.LblPtNoir.AutoSize = true; + this.LblPtNoir.Location = new System.Drawing.Point(669, 136); + this.LblPtNoir.Name = "LblPtNoir"; + this.LblPtNoir.Size = new System.Drawing.Size(48, 13); + this.LblPtNoir.TabIndex = 4; + this.LblPtNoir.Text = "Joeur2:0"; + // + // btnContinuer + // + this.btnContinuer.Enabled = false; + this.btnContinuer.Location = new System.Drawing.Point(510, 390); + this.btnContinuer.Name = "btnContinuer"; + this.btnContinuer.Size = new System.Drawing.Size(105, 23); + this.btnContinuer.TabIndex = 5; + this.btnContinuer.Text = "Continuer à jouer"; + this.btnContinuer.UseVisualStyleBackColor = true; + this.btnContinuer.Click += new System.EventHandler(this.btnContinuer_Click); + // + // ofd + // + this.ofd.FileName = "openFileDialog1"; + // + // btnEnreg + // + this.btnEnreg.Location = new System.Drawing.Point(510, 352); + this.btnEnreg.Name = "btnEnreg"; + this.btnEnreg.Size = new System.Drawing.Size(75, 23); + this.btnEnreg.TabIndex = 6; + this.btnEnreg.Text = "Enregistrer"; + this.btnEnreg.UseVisualStyleBackColor = true; + this.btnEnreg.Click += new System.EventHandler(this.btnEnreg_Click); + // + // Plateau + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(837, 474); + this.Controls.Add(this.btnEnreg); + this.Controls.Add(this.btnContinuer); + this.Controls.Add(this.LblPtNoir); + this.Controls.Add(this.lblPtBlanc); + this.Controls.Add(this.button1); + this.Controls.Add(this.pictureBox2); + this.Controls.Add(this.pictureBox1); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "Plateau"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.Text = "Morpion"; + this.Load += new System.EventHandler(this.Plateau_Load); + this.Shown += new System.EventHandler(this.Plateau_Shown); + this.Paint += new System.Windows.Forms.PaintEventHandler(this.Plateau_Paint); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label lblPtBlanc; + private System.Windows.Forms.Label LblPtNoir; + private System.Windows.Forms.Button btnContinuer; + private System.Windows.Forms.OpenFileDialog ofd; + private System.Windows.Forms.SaveFileDialog sfd; + private System.Windows.Forms.Button btnEnreg; + } +} + diff --git a/go01/Plateau.cs b/go01/Plateau.cs new file mode 100644 index 0000000..80922ec --- /dev/null +++ b/go01/Plateau.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace go01 +{ + public partial class Plateau : Form + { + TextWriter _writer = null; + StreamWriter _writerConsole = null; + enum CouleurVoulue { Red, Green, Blue, Black, LAST } + CouleurVoulue[,] tableauCouleur = new CouleurVoulue[19,19]; + List pboxList = new List(); + Goban g; + + public Plateau(Goban.sauvegarde_S s) + { + InitializeComponent(); + this.Text = $"Morpion {s.dimGoban}x{s.dimGoban}"; + g = new Goban(this, pictureBox1, s); + } + public Plateau(int dim, int nbPionAlign, string playerW, string playerB) + { + InitializeComponent(); + this.Text = $"Morpion {dim}x{dim}"; + g = new Goban(this, pictureBox1,dim,nbPionAlign, playerW, playerB); + } + + private void pictureBox1_Click(object sender, EventArgs e) + { + String[] xy = ((PictureBox)sender).Name.Split(';'); + if (++tableauCouleur[int.Parse(xy[0]), int.Parse(xy[1])] == CouleurVoulue.LAST) + tableauCouleur[int.Parse(xy[0]), int.Parse(xy[1])] = CouleurVoulue.Red; + ((PictureBox)sender).BackColor = Color.FromName((tableauCouleur[int.Parse(xy[0]),int.Parse(xy[1])]).ToString()); + Console.WriteLine(((PictureBox)sender).Name); + } + + private void chkBxDbg_CheckedChanged(object sender, EventArgs e) + { + // Settings1.Default.dbg = chkBxDbg.Checked; + Settings1.Default.Save(); + } + + private void txtBoxTmpAnim_TextChanged(object sender, EventArgs e) + { + int tmp; + //Settings1.Default.vitesseAnimDBG = int.TryParse(txtBoxTmpAnim.Text, out tmp) ?tmp: Settings1.Default.vitesseAnimDBG; + Settings1.Default.Save(); + } + + private void Plateau_Load(object sender, EventArgs e) + { + //base.OnLoad(e); + + this.DoubleBuffered = true; + } + + private void txtConsole_TextChanged(object sender, EventArgs e) + { + // set the current caret position to the end + //txtConsole.SelectionStart = txtConsole.Text.Length; + // scroll it automatically + //txtConsole.ScrollToCaret(); + } + + private void txtAffConsole_CheckedChanged(object sender, EventArgs e) + { + /*f(txtAffConsole.Checked) + { + _writer = new TextBoxStreamWriter(txtConsole); + Console.SetOut(_writer); + + Console.WriteLine("Now redirecting output to the text box"); + } + else + { + _writerConsole = new StreamWriter(Console.OpenStandardOutput()); + _writerConsole.AutoFlush = true; + Console.SetOut(_writerConsole); + }*/ + } + + private void button1_Click(object sender, EventArgs e) + { + g.resetGoban(); + } + public void pictureBox2WinVisible(bool t) + { + pictureBox2.Visible = t; + } + + private void button1_Click_1(object sender, EventArgs e) + { + g.resetGoban(); + } + public string lblNoir + { + set { this.lblPtBlanc.Text = value; } + } + public string lblBlanc + { + set { this.LblPtNoir.Text = value; } + } + public bool btnContinuerEnable + { + set + { + this.btnContinuer.Enabled = value; + } + } + + private void btnContinuer_Click(object sender, EventArgs e) + { + g.ContinuerAjouer(); + } + + private void btnEnreg_Click(object sender, EventArgs e) + { + Stream myStream = null; + SaveFileDialog openFileDialog1 = new SaveFileDialog(); + + openFileDialog1.InitialDirectory = "c:\\"; + openFileDialog1.Filter = "bin files (*.bin)|*.bin|All files (*.*)|*.*"; + openFileDialog1.FilterIndex = 2; + openFileDialog1.RestoreDirectory = true; + + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + WriteToBinaryFile(openFileDialog1.FileName, g.sauvegarder()); + } + + } + public static void WriteToBinaryFile(string filePath, T objectToWrite, bool append = false) + { + using (Stream stream = File.Open(filePath, append ? FileMode.Append : FileMode.Create)) + { + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + binaryFormatter.Serialize(stream, objectToWrite); + } + } + + /// + /// Reads an object instance from a binary file. + /// + /// The type of object to read from the binary file. + /// The file path to read the object instance from. + /// Returns a new instance of the object read from the binary file. + public static T ReadFromBinaryFile(string filePath) + { + using (Stream stream = File.Open(filePath, FileMode.Open)) + { + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + return (T)binaryFormatter.Deserialize(stream); + } + } + + private void Plateau_Shown(object sender, EventArgs e) + { + + } + + private void pictureBox1_Paint(object sender, PaintEventArgs e) + { + + } + + private void Plateau_Paint(object sender, PaintEventArgs e) + { + + } + } +} diff --git a/go01/Plateau.resx b/go01/Plateau.resx new file mode 100644 index 0000000..f4c24d1 --- /dev/null +++ b/go01/Plateau.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 172, 17 + + + 242, 17 + + + 60 + + \ No newline at end of file diff --git a/go01/Program.cs b/go01/Program.cs index bc293e7..5dde9c8 100644 --- a/go01/Program.cs +++ b/go01/Program.cs @@ -1,4 +1,6 @@ -using System; +#define DEBUG + +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -16,7 +18,7 @@ namespace go01 { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new mainWin()); } } } diff --git a/go01/Properties/Resources.Designer.cs b/go01/Properties/Resources.Designer.cs index 55d9aa4..dba2a82 100644 --- a/go01/Properties/Resources.Designer.cs +++ b/go01/Properties/Resources.Designer.cs @@ -1,71 +1,173 @@ //------------------------------------------------------------------------------ // -// Ce code a été généré par un outil. -// Version du runtime :4.0.30319.42000 +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // -// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si -// le code est régénéré. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ -namespace go01.Properties -{ - - +namespace go01.Properties { + using System; + + /// - /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. + /// A strongly-typed resource class, for looking up localized strings, etc. /// - // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder - // à l'aide d'un outil, tel que ResGen ou Visual Studio. - // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen - // avec l'option /str ou régénérez votre projet VS. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// - /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. + /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("go01.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// - /// Remplace la propriété CurrentUICulture du thread actuel pour toutes - /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap b { + get { + object obj = ResourceManager.GetObject("b", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap bl { + get { + object obj = ResourceManager.GetObject("bl", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap br { + get { + object obj = ResourceManager.GetObject("br", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap giphy { + get { + object obj = ResourceManager.GetObject("giphy", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap hoshi { + get { + object obj = ResourceManager.GetObject("hoshi", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap l { + get { + object obj = ResourceManager.GetObject("l", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap m { + get { + object obj = ResourceManager.GetObject("m", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap r { + get { + object obj = ResourceManager.GetObject("r", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap t { + get { + object obj = ResourceManager.GetObject("t", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap tl { + get { + object obj = ResourceManager.GetObject("tl", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap tr { + get { + object obj = ResourceManager.GetObject("tr", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/go01/Properties/Resources.resx b/go01/Properties/Resources.resx index af7dbeb..64f0e0d 100644 --- a/go01/Properties/Resources.resx +++ b/go01/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,43 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\resources\m.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\tl.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\tr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\bl.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\b.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\t.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\l.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\hoshi.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\r.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\br.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\giphy.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/go01/RejoindrePartieReseau_client.Designer.cs b/go01/RejoindrePartieReseau_client.Designer.cs new file mode 100644 index 0000000..f05c544 --- /dev/null +++ b/go01/RejoindrePartieReseau_client.Designer.cs @@ -0,0 +1,209 @@ +namespace go01 +{ + partial class RejoindrePartieReseau_client + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dgvPart = new System.Windows.Forms.DataGridView(); + this.tbIpServ = new System.Windows.Forms.TextBox(); + this.lblIpServ = new System.Windows.Forms.Label(); + this.tbPlayername = new System.Windows.Forms.TextBox(); + this.lblPlayerName = new System.Windows.Forms.Label(); + this.tbPort = new System.Windows.Forms.TextBox(); + this.lblPort = new System.Windows.Forms.Label(); + this.btnJoin = new System.Windows.Forms.Button(); + this.uid = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.partName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.playerName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ip = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.port = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.timeStamp = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dgvPart)).BeginInit(); + this.SuspendLayout(); + // + // dgvPart + // + this.dgvPart.AllowUserToAddRows = false; + this.dgvPart.AllowUserToDeleteRows = false; + this.dgvPart.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvPart.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.uid, + this.partName, + this.playerName, + this.ip, + this.port, + this.timeStamp}); + this.dgvPart.Location = new System.Drawing.Point(12, 12); + this.dgvPart.Name = "dgvPart"; + this.dgvPart.ReadOnly = true; + this.dgvPart.RowHeadersVisible = false; + this.dgvPart.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dgvPart.Size = new System.Drawing.Size(505, 426); + this.dgvPart.TabIndex = 1; + this.dgvPart.Click += new System.EventHandler(this.dgvPart_Click); + // + // tbIpServ + // + this.tbIpServ.Location = new System.Drawing.Point(611, 12); + this.tbIpServ.Name = "tbIpServ"; + this.tbIpServ.Size = new System.Drawing.Size(154, 20); + this.tbIpServ.TabIndex = 16; + // + // lblIpServ + // + this.lblIpServ.AutoSize = true; + this.lblIpServ.Location = new System.Drawing.Point(534, 15); + this.lblIpServ.Name = "lblIpServ"; + this.lblIpServ.Size = new System.Drawing.Size(60, 13); + this.lblIpServ.TabIndex = 17; + this.lblIpServ.Text = "Ip serveur :"; + // + // tbPlayername + // + this.tbPlayername.Location = new System.Drawing.Point(611, 64); + this.tbPlayername.Name = "tbPlayername"; + this.tbPlayername.Size = new System.Drawing.Size(154, 20); + this.tbPlayername.TabIndex = 18; + // + // lblPlayerName + // + this.lblPlayerName.AutoSize = true; + this.lblPlayerName.Location = new System.Drawing.Point(534, 67); + this.lblPlayerName.Name = "lblPlayerName"; + this.lblPlayerName.Size = new System.Drawing.Size(55, 13); + this.lblPlayerName.TabIndex = 19; + this.lblPlayerName.Text = "Nom joeur"; + // + // tbPort + // + this.tbPort.Location = new System.Drawing.Point(611, 38); + this.tbPort.Name = "tbPort"; + this.tbPort.Size = new System.Drawing.Size(154, 20); + this.tbPort.TabIndex = 20; + // + // lblPort + // + this.lblPort.AutoSize = true; + this.lblPort.Location = new System.Drawing.Point(534, 41); + this.lblPort.Name = "lblPort"; + this.lblPort.Size = new System.Drawing.Size(26, 13); + this.lblPort.TabIndex = 21; + this.lblPort.Text = "Port"; + // + // btnJoin + // + this.btnJoin.Location = new System.Drawing.Point(537, 93); + this.btnJoin.Name = "btnJoin"; + this.btnJoin.Size = new System.Drawing.Size(228, 23); + this.btnJoin.TabIndex = 22; + this.btnJoin.Text = "Join"; + this.btnJoin.UseVisualStyleBackColor = true; + this.btnJoin.Click += new System.EventHandler(this.btnJoin_Click); + // + // uid + // + this.uid.DataPropertyName = "uid"; + this.uid.HeaderText = "uid"; + this.uid.Name = "uid"; + this.uid.ReadOnly = true; + // + // partName + // + this.partName.DataPropertyName = "partName"; + this.partName.HeaderText = "Nom partie"; + this.partName.Name = "partName"; + this.partName.ReadOnly = true; + // + // playerName + // + this.playerName.DataPropertyName = "playerName"; + this.playerName.HeaderText = "Nom joeur adverse"; + this.playerName.Name = "playerName"; + this.playerName.ReadOnly = true; + // + // ip + // + this.ip.DataPropertyName = "ip"; + this.ip.HeaderText = "ip"; + this.ip.Name = "ip"; + this.ip.ReadOnly = true; + // + // port + // + this.port.DataPropertyName = "port"; + this.port.HeaderText = "port"; + this.port.Name = "port"; + this.port.ReadOnly = true; + // + // timeStamp + // + this.timeStamp.DataPropertyName = "timeStamp"; + this.timeStamp.HeaderText = "timeStamp"; + this.timeStamp.Name = "timeStamp"; + this.timeStamp.ReadOnly = true; + this.timeStamp.Visible = false; + // + // RejoindrePartieReseau_client + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(777, 450); + this.Controls.Add(this.btnJoin); + this.Controls.Add(this.tbPort); + this.Controls.Add(this.lblPort); + this.Controls.Add(this.tbPlayername); + this.Controls.Add(this.lblPlayerName); + this.Controls.Add(this.tbIpServ); + this.Controls.Add(this.lblIpServ); + this.Controls.Add(this.dgvPart); + this.Name = "RejoindrePartieReseau_client"; + this.Text = "RejoindrePartieReseau_client"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.RejoindrePartieReseau_client_FormClosing); + this.Load += new System.EventHandler(this.RejoindrePartieReseau_client_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvPart)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.DataGridView dgvPart; + private System.Windows.Forms.TextBox tbIpServ; + private System.Windows.Forms.Label lblIpServ; + private System.Windows.Forms.TextBox tbPlayername; + private System.Windows.Forms.Label lblPlayerName; + private System.Windows.Forms.TextBox tbPort; + private System.Windows.Forms.Label lblPort; + private System.Windows.Forms.Button btnJoin; + private System.Windows.Forms.DataGridViewTextBoxColumn uid; + private System.Windows.Forms.DataGridViewTextBoxColumn partName; + private System.Windows.Forms.DataGridViewTextBoxColumn playerName; + private System.Windows.Forms.DataGridViewTextBoxColumn ip; + private System.Windows.Forms.DataGridViewTextBoxColumn port; + private System.Windows.Forms.DataGridViewTextBoxColumn timeStamp; + } +} \ No newline at end of file diff --git a/go01/RejoindrePartieReseau_client.cs b/go01/RejoindrePartieReseau_client.cs new file mode 100644 index 0000000..ae91a3c --- /dev/null +++ b/go01/RejoindrePartieReseau_client.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace go01 +{ + public partial class RejoindrePartieReseau_client : Form + { + Thread ecouteThread; + System.Threading.Timer timerTTLdtListPart; + private DataTable dtListPart; + System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + + /*public struct partie_S + { + public string uid, partName, joueurAdverseName, ip; + public int taille, pionAaligner; + public partie_S(string uid, string partName, string joueurAdverseName, string ip, int taille, int pionAaligner) + { + this.uid = uid; + this.partName = partName; + this.joueurAdverseName = joueurAdverseName; + this.taille = taille; + this.pionAaligner = pionAaligner; + this.ip = ip; + } + public partie_S(string[] s, string ip) + { + this.uid = s[0]; + this.partName = s[1]; + this.joueurAdverseName = s[2]; + this.taille = int.Parse(s[3]); + this.pionAaligner = int.Parse(s[4]); + this.ip = ip; + } + public override string ToString() + { + return uid; + } + public static implicit operator string(partie_S part) + { + return part.ToString(); + } + }*/ + + public RejoindrePartieReseau_client() + { + InitializeComponent(); + + dtListPart = new DataTable(); + + dtListPart.Columns.Add("uid", typeof(string)); + dtListPart.Columns.Add("partName", typeof(socketPlateau.ConfigGo_S)); + dtListPart.Columns.Add("playerName", typeof(string)); + dtListPart.Columns.Add("ip", typeof(string)); + dtListPart.Columns.Add("port", typeof(int));//timeStamp + dtListPart.Columns.Add("timeStamp", typeof(DateTime)); + + ecouteThread = new Thread(() => + { + Thread.CurrentThread.IsBackground = true; + Listen(); + }); + ecouteThread.Start(); + + var startTimeSpan = TimeSpan.Zero; + var periodTimeSpan = TimeSpan.FromSeconds(1); + timerTTLdtListPart = new System.Threading.Timer((ee) => + { + + TTLdtListPart(); + }, null, startTimeSpan, periodTimeSpan); + + } + + private void Listen() + { + var Server = new UdpClient(8888); + while (1==1) + { + var ClientEp = new IPEndPoint(IPAddress.Any, 0); + byte[] ClientRequestData = Server.Receive(ref ClientEp); + using (MemoryStream ms = new MemoryStream(ClientRequestData)) + { + socketPlateau.ConfigGo_S cfgGo = (socketPlateau.ConfigGo_S)binaryFormatter.Deserialize(ms); + Invoke(new Action(() => { ajoutPartie(cfgGo, ClientEp.Address.ToString()); })); + } + + string ClientRequest = Encoding.ASCII.GetString(ClientRequestData); + Console.WriteLine("Recived {0} from {1}, sending response", ClientRequest, ClientEp.Address.ToString()); + + + + } + } + public void ajoutPartie(socketPlateau.ConfigGo_S cfgGo, string ip) + { + + if(dtListPart.Select($"uid = '{cfgGo.Uid}'").Length==0) + dtListPart.Rows.Add(cfgGo.Uid, cfgGo, cfgGo.NomJoeurServeur, cfgGo.IpServeur, cfgGo.port, DateTime.Now); + //lock (DgvPart) ; + dtListPart.Select($"uid = '{cfgGo.Uid}'")[0]["timeStamp"] = DateTime.Now; + DgvPart.DataSource = dtListPart; + + } + public void TTLdtListPart() + { + foreach(DataGridViewRow row in dgvPart.Rows) + { + if(((DateTime)row.Cells["timeStamp"].Value).AddSeconds(10) <= DateTime.Now) + { + Invoke(new Action(() => { + dgvPart.Rows.Remove(row); + dgvPart.Refresh(); + })); + + } + } + } + + private void RejoindrePartieReseau_client_Load(object sender, EventArgs e) + { + + } + + private void RejoindrePartieReseau_client_FormClosing(object sender, FormClosingEventArgs e) + { + ecouteThread.Abort(); + } + + public DataGridView DgvPart + { + get { return this.dgvPart; } + set { } + } + + private void dgvPart_Click(object sender, EventArgs e) + { + if (dgvPart.SelectedRows.Count <= 0) + return; + socketPlateau.ConfigGo_S cfg = (socketPlateau.ConfigGo_S)dgvPart.SelectedRows[0].Cells["partName"].Value; + tbIpServ.Text = cfg.IpServeur.ToString(); + tbPort.Text = cfg.port.ToString(); + } + + private void btnJoin_Click(object sender, EventArgs e) + { + if (dgvPart.SelectedRows.Count <= 0) + return; + socketPlateau.ConfigGo_S cfg = (socketPlateau.ConfigGo_S)dgvPart.SelectedRows[0].Cells["partName"].Value; + cfg.NomJoeurClient = tbPlayername.Text; + socketPlateau sc = new socketPlateau(socketPlateau.TypeSocket_E.Client, cfg, null); + sc.senCmd(new socketPlateau.CommandeSocket_S(socketPlateau.commande_E.Join, cfg)); + } + } +} diff --git a/go01/RejoindrePartieReseau_client.resx b/go01/RejoindrePartieReseau_client.resx new file mode 100644 index 0000000..090703e --- /dev/null +++ b/go01/RejoindrePartieReseau_client.resx @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/go01/Settings1.Designer.cs b/go01/Settings1.Designer.cs new file mode 100644 index 0000000..09c0ed4 --- /dev/null +++ b/go01/Settings1.Designer.cs @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 +// +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. +// +//------------------------------------------------------------------------------ + +namespace go01 { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0")] + internal sealed partial class Settings1 : global::System.Configuration.ApplicationSettingsBase { + + private static Settings1 defaultInstance = ((Settings1)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings1()))); + + public static Settings1 Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool dbg { + get { + return ((bool)(this["dbg"])); + } + set { + this["dbg"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("50")] + public int vitesseAnimDBG { + get { + return ((int)(this["vitesseAnimDBG"])); + } + set { + this["vitesseAnimDBG"] = value; + } + } + } +} diff --git a/go01/Settings1.settings b/go01/Settings1.settings new file mode 100644 index 0000000..d1e7d14 --- /dev/null +++ b/go01/Settings1.settings @@ -0,0 +1,12 @@ + + + + + + True + + + 50 + + + \ No newline at end of file diff --git a/go01/TextBoxStreamWriter.cs b/go01/TextBoxStreamWriter.cs new file mode 100644 index 0000000..f8ef111 --- /dev/null +++ b/go01/TextBoxStreamWriter.cs @@ -0,0 +1,29 @@ +using System; +using System.Text; +using System.IO; +using System.Windows.Forms; + +namespace go01 +{ + public class TextBoxStreamWriter : TextWriter + { + RichTextBox _output = null; + + public TextBoxStreamWriter(RichTextBox output) + { + _output = output; + } + + public override void Write(char value) + { + base.Write(value); + _output.AppendText(value.ToString().Replace('\n', ' ')); + + } + + public override Encoding Encoding + { + get { return System.Text.Encoding.UTF8; } + } + } +} diff --git a/go01/go01.csproj b/go01/go01.csproj index 47bdc49..692ff23 100644 --- a/go01/go01.csproj +++ b/go01/go01.csproj @@ -34,6 +34,7 @@ + @@ -43,16 +44,55 @@ + + ..\..\GestionDeDommerceInformatique\packages\VisualPlus.0.4.1.4-beta\lib\VisualPlus\NET4\VisualPlus.dll + - + Form - - Form1.cs + + CreerPartieReseau_serv.cs + + + Form + + + Plateau.cs + + + + Form + + + mainWin.cs + + Form + + + RejoindrePartieReseau_client.cs + + + True + True + Settings1.settings + + + + + + CreerPartieReseau_serv.cs + + + Plateau.cs + + + mainWin.cs + ResXFileCodeGenerator Resources.Designer.cs @@ -61,7 +101,11 @@ True Resources.resx + True + + RejoindrePartieReseau_client.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -71,9 +115,46 @@ Settings.settings True + + SettingsSingleFileGenerator + Settings1.Designer.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/go01/mainWin.Designer.cs b/go01/mainWin.Designer.cs new file mode 100644 index 0000000..ea75216 --- /dev/null +++ b/go01/mainWin.Designer.cs @@ -0,0 +1,188 @@ +namespace go01 +{ + partial class mainWin + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblJoeur1 = new System.Windows.Forms.Label(); + this.tbJoeur1 = new System.Windows.Forms.TextBox(); + this.tbJoueur2 = new System.Windows.Forms.TextBox(); + this.lblJoeur2 = new System.Windows.Forms.Label(); + this.btnConfim = new System.Windows.Forms.Button(); + this.lblTaille = new System.Windows.Forms.Label(); + this.txtBoxTaille = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.txtBoxPionAlign = new System.Windows.Forms.TextBox(); + this.btnLoad = new System.Windows.Forms.Button(); + this.btnChercherPartie = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // lblJoeur1 + // + this.lblJoeur1.AutoSize = true; + this.lblJoeur1.Location = new System.Drawing.Point(13, 13); + this.lblJoeur1.Name = "lblJoeur1"; + this.lblJoeur1.Size = new System.Drawing.Size(48, 13); + this.lblJoeur1.TabIndex = 8; + this.lblJoeur1.Text = "Joeur 1 :"; + // + // tbJoeur1 + // + this.tbJoeur1.Location = new System.Drawing.Point(67, 10); + this.tbJoeur1.Name = "tbJoeur1"; + this.tbJoeur1.Size = new System.Drawing.Size(100, 20); + this.tbJoeur1.TabIndex = 0; + // + // tbJoueur2 + // + this.tbJoueur2.Location = new System.Drawing.Point(67, 36); + this.tbJoueur2.Name = "tbJoueur2"; + this.tbJoueur2.Size = new System.Drawing.Size(100, 20); + this.tbJoueur2.TabIndex = 1; + // + // lblJoeur2 + // + this.lblJoeur2.AutoSize = true; + this.lblJoeur2.Location = new System.Drawing.Point(13, 39); + this.lblJoeur2.Name = "lblJoeur2"; + this.lblJoeur2.Size = new System.Drawing.Size(48, 13); + this.lblJoeur2.TabIndex = 7; + this.lblJoeur2.Text = "Joeur 2 :"; + // + // btnConfim + // + this.btnConfim.Location = new System.Drawing.Point(15, 115); + this.btnConfim.Name = "btnConfim"; + this.btnConfim.Size = new System.Drawing.Size(151, 23); + this.btnConfim.TabIndex = 4; + this.btnConfim.Text = "Confirmer"; + this.btnConfim.UseVisualStyleBackColor = true; + this.btnConfim.Click += new System.EventHandler(this.btnConfim_Click); + // + // lblTaille + // + this.lblTaille.AutoSize = true; + this.lblTaille.Location = new System.Drawing.Point(12, 69); + this.lblTaille.Name = "lblTaille"; + this.lblTaille.Size = new System.Drawing.Size(80, 13); + this.lblTaille.TabIndex = 6; + this.lblTaille.Text = "Taille du goban"; + // + // txtBoxTaille + // + this.txtBoxTaille.Location = new System.Drawing.Point(98, 66); + this.txtBoxTaille.Name = "txtBoxTaille"; + this.txtBoxTaille.Size = new System.Drawing.Size(69, 20); + this.txtBoxTaille.TabIndex = 2; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(16, 92); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(76, 13); + this.label1.TabIndex = 5; + this.label1.Text = "Nb Pion aligne"; + // + // txtBoxPionAlign + // + this.txtBoxPionAlign.Location = new System.Drawing.Point(98, 89); + this.txtBoxPionAlign.Name = "txtBoxPionAlign"; + this.txtBoxPionAlign.Size = new System.Drawing.Size(69, 20); + this.txtBoxPionAlign.TabIndex = 3; + // + // btnLoad + // + this.btnLoad.Location = new System.Drawing.Point(16, 144); + this.btnLoad.Name = "btnLoad"; + this.btnLoad.Size = new System.Drawing.Size(150, 23); + this.btnLoad.TabIndex = 9; + this.btnLoad.Text = "Charger"; + this.btnLoad.UseVisualStyleBackColor = true; + this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); + // + // btnChercherPartie + // + this.btnChercherPartie.Location = new System.Drawing.Point(16, 173); + this.btnChercherPartie.Name = "btnChercherPartie"; + this.btnChercherPartie.Size = new System.Drawing.Size(150, 23); + this.btnChercherPartie.TabIndex = 10; + this.btnChercherPartie.Text = "Chercher une partie"; + this.btnChercherPartie.UseVisualStyleBackColor = true; + this.btnChercherPartie.Click += new System.EventHandler(this.btnChercherPartie_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(16, 202); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(150, 23); + this.button2.TabIndex = 11; + this.button2.Text = "Creer une partie en réseau"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // mainWin + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(181, 237); + this.Controls.Add(this.button2); + this.Controls.Add(this.btnChercherPartie); + this.Controls.Add(this.btnLoad); + this.Controls.Add(this.txtBoxPionAlign); + this.Controls.Add(this.label1); + this.Controls.Add(this.txtBoxTaille); + this.Controls.Add(this.lblTaille); + this.Controls.Add(this.btnConfim); + this.Controls.Add(this.tbJoueur2); + this.Controls.Add(this.lblJoeur2); + this.Controls.Add(this.tbJoeur1); + this.Controls.Add(this.lblJoeur1); + this.Name = "mainWin"; + this.Text = "mainWin"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lblJoeur1; + private System.Windows.Forms.TextBox tbJoeur1; + private System.Windows.Forms.TextBox tbJoueur2; + private System.Windows.Forms.Label lblJoeur2; + private System.Windows.Forms.Button btnConfim; + private System.Windows.Forms.Label lblTaille; + private System.Windows.Forms.TextBox txtBoxTaille; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtBoxPionAlign; + private System.Windows.Forms.Button btnLoad; + private System.Windows.Forms.Button btnChercherPartie; + private System.Windows.Forms.Button button2; + } +} \ No newline at end of file diff --git a/go01/mainWin.cs b/go01/mainWin.cs new file mode 100644 index 0000000..8bb4c5d --- /dev/null +++ b/go01/mainWin.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace go01 +{ + public partial class mainWin : Form + { + public mainWin() + { + InitializeComponent(); + //cbTaille.SelectedIndex = 0; + } + + private void btnConfim_Click(object sender, EventArgs e) + { + int taille = 5; + int pionAlign = 5; + taille = (int.TryParse(txtBoxTaille.Text, out taille)) ? taille : 5; + pionAlign = (int.TryParse(txtBoxPionAlign.Text, out pionAlign)) ? pionAlign : 3; + Plateau win = new Plateau(taille, pionAlign, tbJoueur2.Text, tbJoeur1.Text); + this.Hide(); + win.ShowDialog(); + this.Close(); + } + + private void btnLoad_Click(object sender, EventArgs e) + { + Stream myStream = null; + OpenFileDialog openFileDialog1 = new OpenFileDialog(); + + // openFileDialog1.InitialDirectory = "c:\\"; + openFileDialog1.Filter = "bn files (*.bn)|*.bn"; + openFileDialog1.FilterIndex = 1; + openFileDialog1.RestoreDirectory = true; + + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + Goban.sauvegarde_S s = ReadFromBinaryFile(openFileDialog1.FileName); + Plateau win = new Plateau(s); + this.Hide(); + win.ShowDialog(); + this.Close(); + } + } + public static T ReadFromBinaryFile(string filePath) + { + using (Stream stream = File.Open(filePath, FileMode.Open)) + { + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + return (T)binaryFormatter.Deserialize(stream); + } + } + + private void button2_Click(object sender, EventArgs e) + { + CreerPartieReseau_serv win = new CreerPartieReseau_serv(); + this.Hide(); + win.ShowDialog(); + this.Close(); + } + + private void btnChercherPartie_Click(object sender, EventArgs e) + { + RejoindrePartieReseau_client win = new RejoindrePartieReseau_client(); + this.Hide(); + win.ShowDialog(); + this.Close(); + } + } +} diff --git a/go01/mainWin.resx b/go01/mainWin.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/go01/mainWin.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/go01/resources/b.png b/go01/resources/b.png new file mode 100644 index 0000000..0692ea3 Binary files /dev/null and b/go01/resources/b.png differ diff --git a/go01/resources/bl.png b/go01/resources/bl.png new file mode 100644 index 0000000..b544329 Binary files /dev/null and b/go01/resources/bl.png differ diff --git a/go01/resources/br.png b/go01/resources/br.png new file mode 100644 index 0000000..9b6666b Binary files /dev/null and b/go01/resources/br.png differ diff --git a/go01/resources/giphy.gif b/go01/resources/giphy.gif new file mode 100644 index 0000000..30e8d03 Binary files /dev/null and b/go01/resources/giphy.gif differ diff --git a/go01/resources/hoshi.png b/go01/resources/hoshi.png new file mode 100644 index 0000000..a945231 Binary files /dev/null and b/go01/resources/hoshi.png differ diff --git a/go01/resources/l.png b/go01/resources/l.png new file mode 100644 index 0000000..b9ce803 Binary files /dev/null and b/go01/resources/l.png differ diff --git a/go01/resources/m.png b/go01/resources/m.png new file mode 100644 index 0000000..52b661b Binary files /dev/null and b/go01/resources/m.png differ diff --git a/go01/resources/r.png b/go01/resources/r.png new file mode 100644 index 0000000..e68f6f1 Binary files /dev/null and b/go01/resources/r.png differ diff --git a/go01/resources/t.png b/go01/resources/t.png new file mode 100644 index 0000000..9036063 Binary files /dev/null and b/go01/resources/t.png differ diff --git a/go01/resources/tl.png b/go01/resources/tl.png new file mode 100644 index 0000000..8dfc6e8 Binary files /dev/null and b/go01/resources/tl.png differ diff --git a/go01/resources/tr.png b/go01/resources/tr.png new file mode 100644 index 0000000..55798da Binary files /dev/null and b/go01/resources/tr.png differ diff --git a/go01/socketPlateau.cs b/go01/socketPlateau.cs new file mode 100644 index 0000000..bf0e97a --- /dev/null +++ b/go01/socketPlateau.cs @@ -0,0 +1,313 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Net; +using System.IO; +using System.Threading; +using System.Net.NetworkInformation; + +namespace go01 +{ + public class socketPlateau + { + #region enum + public enum TypeSocket_E { NONE, Serveur, Client, LAST } + public enum commande_E { Join, Leave, Place, Win, WhoTurn, LAST } // ConfigGo_S ; null ; Point ; Goban.PlayerTuen(string) ; Goban.Joueur_E(Tour) + #endregion + #region struct + [Serializable] + public struct CommandeSocket_S + { + public commande_E commande; + public object data; + public CommandeSocket_S(commande_E cmd, object dt) + { + commande = cmd; + data = dt; + } + } + [Serializable] + public struct ConfigGo_S + { + private string uid; + public string Uid { get { return uid; } } + private string partName; + public string PartName { get { return partName; } } + public string NomJoeurClient; + private string nomJoeurServeur; + public string NomJoeurServeur { get { return nomJoeurServeur; } } + private int taille; + public int Taille { get { return taille; } } + private int pionaAligner; + public int PionAligner { get { return pionaAligner; } } + private IPAddress ipServeur; + public IPAddress IpServeur { get => ipServeur; } + public readonly int port; + + public ConfigGo_S(string Uid, string PartName, string NomJoeurClient, string NomJoeurServeur, int Taille, int PionaAligner, IPAddress ipServeur, int port) + { + this.uid = Uid; + this.partName = PartName; + this.NomJoeurClient = NomJoeurClient; + this.nomJoeurServeur = NomJoeurServeur; + this.taille = Taille; + this.pionaAligner = PionaAligner; + this.ipServeur = ipServeur; + this.port = port; + } + public override string ToString() + { + return partName; + } + public static implicit operator string(ConfigGo_S part) + { + return part.ToString(); + } + } + #endregion + #region variable + private Socket socServ, socCli; + private Socket SocCli + { + get + { + if(socFlag == TypeSocket_E.Serveur && socCli != null || socFlag == TypeSocket_E.Client) + { + return socCli; + } + else + { + return null; + } + } + set + { + socCli = value; + } + } + private TypeSocket_E socFlag = 0; + IPAddress adresseIpCourante; + int port; + private static Boolean connexionEtablie = false; + System.Threading.Timer timerBroadcast; + Goban plateauDeJeu; + System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + ConfigGo_S cfgGo; + #endregion + #region event + public delegate void OnJoinServ(object myObject, socketPlateauServArgs myArgs); + + public event OnJoinServ onJoinServ; + #endregion + + public socketPlateau(TypeSocket_E socF, ConfigGo_S cfgGo, Goban g) + { + plateauDeJeu = g; + adresseIpCourante = cfgGo.IpServeur; + socFlag = socF; + this.port = cfgGo.port; + this.cfgGo = cfgGo; + if(socFlag == TypeSocket_E.Client) + { + socFlag = TypeSocket_E.Client; + try + { + socCli = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + //socCli.Blocking = false; + //IPAddress IPDist = Verifier(cfgGo.IpServeur.ToString()); + socCli.BeginConnect(new IPEndPoint(cfgGo.IpServeur, port), new AsyncCallback(SurConnection), socCli); + + } + catch (Exception ee) + { + //controle(true); + MessageBox.Show("Connexion impossible : " + ee.Message); + } + } + else if(socFlag == TypeSocket_E.Serveur) + { + //AttenteJoueur(); + } + } + #region serveur + public void AttenteJoueur() + { + if (socFlag != TypeSocket_E.Serveur) + return; + var startTimeSpan = TimeSpan.Zero; + var periodTimeSpan = TimeSpan.FromSeconds(5); + + timerBroadcast = new System.Threading.Timer((ee) => + { + broadcast(); + }, null, startTimeSpan, periodTimeSpan); + + socFlag = TypeSocket_E.Serveur; + socServ = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + + socServ.Bind(new IPEndPoint(adresseIpCourante, port)); + socServ.Listen(1); + socServ.BeginAccept(new AsyncCallback(SurDemandeDeCo), socServ); + } + private void SurDemandeDeCo(IAsyncResult iAR) + { + if (socFlag == TypeSocket_E.Serveur && !socketPlateau.connexionEtablie) + { + Socket sTmp = (Socket)iAR.AsyncState; + socCli = sTmp.EndAccept(iAR); + +#if DEBUG + Console.WriteLine($"Connexion effectuée par {((IPEndPoint)socCli.RemoteEndPoint).Address}"); +#endif + connexionEtablie = true; + timerBroadcast.Dispose(); + InitialiserReception(socCli); + } + else if(socFlag == TypeSocket_E.Serveur && socketPlateau.connexionEtablie) + { + Socket sTmp = (Socket)iAR.AsyncState; + socCli = sTmp.EndAccept(iAR); + socCli.Send(Encoding.Unicode.GetBytes("Serveur en cours de partie !")); + socCli.Close(); + } + } + private void broadcast() + { + if (socFlag != TypeSocket_E.Serveur) + return; + var Client = new UdpClient(); + using (MemoryStream ms = new MemoryStream()) + { + binaryFormatter.Serialize(ms, cfgGo); + Client.EnableBroadcast = true; + byte[] RequestData = ms.ToArray(); + Client.Send(RequestData, RequestData.Length, new IPEndPoint(IPAddress.Broadcast, 8888)); + + } + // byte[] RequestData = { }; /*= Encoding.ASCII.GetBytes($"{cfgGo.Uid};{cfgGo.PartName};{cfgGo.NomJoeurAdverse};{cfgGo.Taille};{cfgGo.PionaAligner}");*/; + + + + Client.Close(); + } + #endregion + + #region client + public void rejoindrePartie(IPAddress IPServeur, int port) + { + socFlag = TypeSocket_E.Client; + try + { + socCli = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + IPAddress IPDist = IPServeur; + socCli.BeginConnect(new IPEndPoint(IPDist, port), new AsyncCallback(SurConnection), socCli); + + } + catch (Exception ee) + { + MessageBox.Show("Connexion impossible : " + ee.Message); + } + } + private void SurConnection(IAsyncResult iAR) + { + + Socket sTmp = (Socket)iAR.AsyncState; + if (sTmp.Connected) { connexionEtablie = true; InitialiserReception(sTmp); senCmd(new CommandeSocket_S(commande_E.Join, cfgGo)); } + else { MessageBox.Show("Serveur innacessible"); } + + } + #endregion + + #region commun + private void InitialiserReception(Socket sArg) + { + try + { + var netStream = new NetworkStream(sArg, true); + + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + CommandeSocket_S cmd = (CommandeSocket_S)binaryFormatter.Deserialize(netStream); + switch (cmd.commande) + { + case commande_E.Join: + onJoinServ(this, new socketPlateauServArgs((ConfigGo_S)cmd.data)); + break; + case commande_E.Leave: + break; + case commande_E.Place: + break; + case commande_E.WhoTurn: + break; + case commande_E.Win: + break; + } + InitialiserReception(sArg); + } + catch (Exception e) + { + Console.WriteLine("Réception imossible : " + e.Message); + } + } + + public void senCmd(CommandeSocket_S cmd) + { + var netStream = new NetworkStream(socCli, true); + + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + binaryFormatter.Serialize(netStream, cmd); + } + #endregion + + #region outil + public static void net_adapters(ComboBox cb) + { + List values = new List(); + foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) + { + cb.Items.Add(nic.Name); + } + } + + public static IPAddress Verifier(string sAdresse) + { + IPAddress rep = null; + if (sAdresse.Trim().Length > 0) + { + IPAddress[] ipVerifs = Dns.GetHostEntry(sAdresse).AddressList; + for (int i = 0; i < ipVerifs.Length; i++) + { + //rep += ipVerifs[0].ToString(); + if (ipVerifs[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) + { + if (ipVerifs[i] != new IPAddress(0X0100007F)) + { + Ping pVerif = new Ping(); + PingReply pRepon = pVerif.Send(ipVerifs[i]); + if (pRepon.Status == IPStatus.Success) + { + rep = ipVerifs[i]; + Console.WriteLine(ipVerifs[i] + "Ping réussi"); + break; + } + else + { + Console.WriteLine(ipVerifs[i] + "Ping KO"); + } + } + } + } + + } + else + { + Console.WriteLine("Renseigner une adresse"); + } + return rep; + } + #endregion + } +} diff --git a/go01/socketPlateauServArgs.cs b/go01/socketPlateauServArgs.cs new file mode 100644 index 0000000..271f71b --- /dev/null +++ b/go01/socketPlateauServArgs.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace go01 +{ + public class socketPlateauServArgs : EventArgs + { + public socketPlateau.ConfigGo_S ConfigGo; + public socketPlateauServArgs(socketPlateau.ConfigGo_S cfg) + { + this.ConfigGo = cfg; + } + } +} diff --git a/goban.xcf b/goban.xcf new file mode 100644 index 0000000..ac141ba Binary files /dev/null and b/goban.xcf differ