Commit avent modif
This commit is contained in:
parent
ed3fc9d6d2
commit
960e870171
|
@ -1,6 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="go01.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
<userSettings>
|
||||
<go01.Settings1>
|
||||
<setting name="dbg" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="vitesseAnimDBG" serializeAs="String">
|
||||
<value>50</value>
|
||||
</setting>
|
||||
</go01.Settings1>
|
||||
</userSettings>
|
||||
</configuration>
|
|
@ -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!");
|
||||
}
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Binary file not shown.
|
@ -1,39 +0,0 @@
|
|||
namespace go01
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Variable nécessaire au concepteur.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Nettoyage des ressources utilisées.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
|
||||
/// le contenu de cette méthode avec l'éditeur de code.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<PictureBox> pboxList = new List<PictureBox>();
|
||||
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;
|
||||
List<carrefour_S>pointsSuivant = 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<carrefour_S> 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<carrefour_S> RecherchePointsSuivant(Point p, Deplacement_E deplacement)
|
||||
{
|
||||
List<carrefour_S> PointsTrouver = new List<carrefour_S>();
|
||||
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<dim && tableauOccupation[p.X+1,p.Y+1] == occupant && (deplacement & Deplacement_E.ID) == Deplacement_E.ID)
|
||||
{
|
||||
PointsTrouver.Add(new carrefour_S(new Point(p.X+1,p.Y+1),Deplacement_E.ID));
|
||||
}
|
||||
if (p.Y + 1 < dim && tableauOccupation[p.X,p.Y+1] == occupant && (deplacement & Deplacement_E.I) == Deplacement_E.I)
|
||||
{
|
||||
PointsTrouver.Add(new carrefour_S(new Point(p.X,p.Y+1),Deplacement_E.I));
|
||||
}
|
||||
if (p.X-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<dim;y++)
|
||||
{
|
||||
for (int x = 0; x < dim; x++)
|
||||
{
|
||||
Console.ForegroundColor = (Tab[x, y] !=0 ) ? ConsoleColor.Green : ConsoleColor.White;
|
||||
Console.Write(Tab[x, y]);
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
}
|
||||
int xyToi(int x, int y)
|
||||
{
|
||||
return x + dim* y;
|
||||
}
|
||||
|
||||
public void redrawAllpb()
|
||||
{
|
||||
for(int i=0;i<dim*dim;i++)
|
||||
{
|
||||
if (tableauOccupation[GetX(i), GetY(i)] != Occupant_E.Vide)
|
||||
{
|
||||
|
||||
//Tour = (Tour+1 == Joueur_E.LAST) ? Joueur_E.Blanc : Tour+1;
|
||||
using (Graphics gr = Graphics.FromHwnd((pboxList [i].Handle)))
|
||||
{
|
||||
SolidBrush b = null;
|
||||
switch (tableauOccupation[GetX(i), GetY(i)])
|
||||
{
|
||||
case Occupant_E.Blanc:
|
||||
b = new SolidBrush(Color.White);
|
||||
break;
|
||||
case Occupant_E.Noir:
|
||||
b = new SolidBrush(Color.Black);
|
||||
break;
|
||||
case Occupant_E.Vide:
|
||||
b = null;
|
||||
break;
|
||||
}
|
||||
if (b != null)
|
||||
gr.FillEllipse(b, 1, 0, pboxList[i].ClientSize.Width - 2, pboxList[i].ClientSize.Height - 1);
|
||||
else
|
||||
gr.DrawImage(pboxList[i].Image, 0, 0, pboxList[i].Width, pboxList[i].Height);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void resetGoban()
|
||||
{
|
||||
for (int x = 0; x < dim; x++)
|
||||
for (int y = 0; y < dim; y++)
|
||||
tableauOccupation[x, y] = Occupant_E.Vide;
|
||||
redrawAllpb();
|
||||
win = false;
|
||||
Fenetre.pictureBox2WinVisible(false);
|
||||
}
|
||||
public void ContinuerAjouer()
|
||||
{
|
||||
win = false;
|
||||
Fenetre.pictureBox2WinVisible(false);
|
||||
Fenetre.btnContinuerEnable = false;
|
||||
Tour = (Tour + 1 == Joueur_E.LAST) ? Joueur_E.Blanc : Tour + 1;
|
||||
}
|
||||
|
||||
public sauvegarde_S sauvegarder()
|
||||
{
|
||||
sauvegarde_S s = new sauvegarde_S(playerWName, playerBName, ptBlanc,ptNoir, nombreDePionAAligne, dim, tableauOccupation, tour, win);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static sauvegarde_S sauvegarder(Goban g)
|
||||
{
|
||||
sauvegarde_S s = new sauvegarde_S(g.playerWName, g.playerBName, g.ptBlanc, g.ptNoir, g.nombreDePionAAligne, g.dim, g.tableauOccupation, g.tour, g.win);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public void GenerationPlateau(bool initTableauOccupation)
|
||||
{
|
||||
//label qui indique à qui le tour
|
||||
LabelPlayerTurn = new System.Windows.Forms.Label();
|
||||
this.LabelPlayerTurn.AutoSize = true;
|
||||
this.LabelPlayerTurn.Font = new System.Drawing.Font("Matura MT Script Capitals", 40F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.LabelPlayerTurn.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.LabelPlayerTurn.Location = new System.Drawing.Point(529, 13);
|
||||
this.LabelPlayerTurn.Name = "LabelPlayerTurn";
|
||||
this.LabelPlayerTurn.TabIndex = 1;
|
||||
this.LabelPlayerTurn.Text = "playerW";
|
||||
Fenetre.Controls.Add(this.LabelPlayerTurn);
|
||||
|
||||
for (int i = 0; i < dim * dim; i++) //Genération du goban
|
||||
{
|
||||
|
||||
pboxList.Add(new PictureBox());
|
||||
//pboxList[i].Paint += new PaintEventHandler(this.PaintPb);
|
||||
pboxList[i].Location = new Point((i % dim) * (Conteneur.Width / dim), (i / dim) * (Conteneur.Height / dim));
|
||||
pboxList[i].Width = Conteneur.Width / dim;
|
||||
pboxList[i].Height = Conteneur.Height / dim;
|
||||
pboxList[i].SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
|
||||
if (GetX(i) == 0)
|
||||
if (GetY(i) == 0)
|
||||
pboxList[i].Image = global::go01.Properties.Resources.tl;
|
||||
else if (GetY(i) == dim - 1)
|
||||
pboxList[i].Image = global::go01.Properties.Resources.bl;
|
||||
else
|
||||
pboxList[i].Image = global::go01.Properties.Resources.l;
|
||||
else if (GetY(i) == 0)
|
||||
if (GetX(i) == dim - 1)
|
||||
pboxList[i].Image = global::go01.Properties.Resources.tr;
|
||||
else
|
||||
pboxList[i].Image = global::go01.Properties.Resources.t;
|
||||
else if (GetY(i) == dim - 1)
|
||||
if (GetX(i) == dim - 1)
|
||||
pboxList[i].Image = global::go01.Properties.Resources.br;
|
||||
else
|
||||
pboxList[i].Image = global::go01.Properties.Resources.b;
|
||||
else if (GetX(i) == dim - 1)
|
||||
pboxList[i].Image = global::go01.Properties.Resources.r;
|
||||
else
|
||||
pboxList[i].Image = global::go01.Properties.Resources.m;
|
||||
if (initTableauOccupation)
|
||||
{
|
||||
tableauOccupation[i % dim, i / dim] = Occupant_E.Vide;
|
||||
|
||||
}
|
||||
pboxList[i].Name = (i % dim).ToString() + ";" + (i / dim).ToString();
|
||||
pboxList[i].Click += new System.EventHandler(this.pictureBox1_Click);
|
||||
pboxList[i].Paint += new PaintEventHandler(this.PaintPb);
|
||||
Conteneur.Controls.Add(pboxList[i]);
|
||||
pboxList[i].Invalidate();
|
||||
}
|
||||
Conteneur.Invalidate();
|
||||
//redrawAllpb();
|
||||
}
|
||||
|
||||
public void GenerationPlateau()
|
||||
{
|
||||
GenerationPlateau(true);
|
||||
}
|
||||
public void Win(bool status)
|
||||
{
|
||||
Fenetre.pictureBox2WinVisible(status);
|
||||
Fenetre.lblBlanc = playerBName + ":"+(ptBlanc).ToString();
|
||||
Fenetre.lblNoir = playerWName + ":"+ptNoir.ToString();
|
||||
Fenetre.btnContinuerEnable = status;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
namespace go01
|
||||
{
|
||||
partial class Plateau
|
||||
{
|
||||
/// <summary>
|
||||
/// Variable nécessaire au concepteur.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Nettoyage des ressources utilisées.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
|
||||
/// le contenu de cette méthode avec l'éditeur de code.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<PictureBox> pboxList = new List<PictureBox>();
|
||||
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<Goban.sauvegarde_S>(openFileDialog1.FileName, g.sauvegarder());
|
||||
}
|
||||
|
||||
}
|
||||
public static void WriteToBinaryFile<T>(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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an object instance from a binary file.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to read from the binary file.</typeparam>
|
||||
/// <param name="filePath">The file path to read the object instance from.</param>
|
||||
/// <returns>Returns a new instance of the object read from the binary file.</returns>
|
||||
public static T ReadFromBinaryFile<T>(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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||