diff --git a/Cavalier_Euler/Cavalier_Euler.csproj b/Cavalier_Euler/Cavalier_Euler.csproj
index e5e48fd..bd35539 100644
--- a/Cavalier_Euler/Cavalier_Euler.csproj
+++ b/Cavalier_Euler/Cavalier_Euler.csproj
@@ -63,6 +63,9 @@
Form1.cs
+
+ Form2.cs
+
ResXFileCodeGenerator
Resources.Designer.cs
diff --git a/Cavalier_Euler/Form1.cs b/Cavalier_Euler/Form1.cs
index 6a564d6..3b7b689 100644
--- a/Cavalier_Euler/Form1.cs
+++ b/Cavalier_Euler/Form1.cs
@@ -138,17 +138,38 @@ private void button1_Click(object sender, EventArgs e)
myButton.Enabled = false;
coups.Add(position);
if (testPositionAvailable() == 0)
+ {
label2.Text = "Fin du game, vous avez perdu en " + compteur + " essais !";
- //finDuGame();
-
+ //finDuGame();
+ }
}
}
+
private void finDuGame()
+ {
+ Button buttonRejouer = new Button();
+ buttonRejouer.Text = "Voulez vous rejouer ?";
+ buttonRejouer.Location = new System.Drawing.Point(900, 300);
+ buttonRejouer.Name = ";";
+ buttonRejouer.Size = new System.Drawing.Size(60, 60);
+ buttonRejouer.UseVisualStyleBackColor = true;
+ buttonRejouer.Click += new System.EventHandler(this.buttonRejouer_Click);
+ buttonRejouer.Visible = true;
+ this.Controls.Add(buttonRejouer);
+ }
+
+ private void buttonRejouer_Click(object sender, EventArgs e)
+ {
+ initGame();
+ }
+
+ private void initGame()
{
coups = new List();
compteur = 0; //nombre de coups
+ compteurAnnulation = 10;
stateInit = false;
position = 0; // ou est mon cavalier
trigger = false;
diff --git a/Cavalier_Euler/Form2.Designer.cs b/Cavalier_Euler/Form2.Designer.cs
index f1fa994..0995155 100644
--- a/Cavalier_Euler/Form2.Designer.cs
+++ b/Cavalier_Euler/Form2.Designer.cs
@@ -28,12 +28,91 @@ protected override void Dispose(bool disposing)
///
private void InitializeComponent()
{
- this.components = new System.ComponentModel.Container();
+ this.label1 = new System.Windows.Forms.Label();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.listBox1 = new System.Windows.Forms.ListBox();
+ this.listBox2 = new System.Windows.Forms.ListBox();
+ this.SuspendLayout();
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(597, 31);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(111, 13);
+ this.label1.TabIndex = 0;
+ this.label1.Text = "Choisir ou commencer";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(514, 115);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 2;
+ this.button1.Text = "Manuel";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.button1_Click_1);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(650, 115);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(75, 23);
+ this.button2.TabIndex = 3;
+ this.button2.Text = "Aleatoire";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.button2_Click);
+ //
+ // listBox1
+ //
+ this.listBox1.FormattingEnabled = true;
+ this.listBox1.Items.AddRange(new object[] {
+ "pas-a-pas",
+ "pas-de-5",
+ "Itinéraire-non-stop"});
+ this.listBox1.Location = new System.Drawing.Point(514, 177);
+ this.listBox1.Name = "listBox1";
+ this.listBox1.Size = new System.Drawing.Size(120, 95);
+ this.listBox1.TabIndex = 4;
+ this.listBox1.Visible = false;
+ //
+ // listBox2
+ //
+ this.listBox2.FormattingEnabled = true;
+ this.listBox2.Items.AddRange(new object[] {
+ "1s",
+ "3s",
+ "5s"});
+ this.listBox2.Location = new System.Drawing.Point(668, 177);
+ this.listBox2.Name = "listBox2";
+ this.listBox2.Size = new System.Drawing.Size(120, 95);
+ this.listBox2.TabIndex = 5;
+ this.listBox2.Visible = false;
+ //
+ // Form2
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.listBox2);
+ this.Controls.Add(this.listBox1);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.label1);
+ this.Name = "Form2";
this.Text = "Form2";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
}
#endregion
+
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.ListBox listBox1;
+ private System.Windows.Forms.ListBox listBox2;
}
}
\ No newline at end of file
diff --git a/Cavalier_Euler/Form2.cs b/Cavalier_Euler/Form2.cs
index 25406ef..0b8e870 100644
--- a/Cavalier_Euler/Form2.cs
+++ b/Cavalier_Euler/Form2.cs
@@ -13,79 +13,229 @@ namespace Cavalier_Euler
public partial class Form2 : Form
{
- static int[,] echec = new int[12, 12];
-
- static int[] depi = new int[] { 2, 1, -1, -2, -2, -1, 1, 2 };
- static int[] depj = new int[] { 1, 2, 2, 1, -1, -2, -2, -1 };
+ Button[] grille;
+ Image cavalier;
+ List coups;
+ List coupsFutur;
+ int compteur;
+ int compteurAnnulation;
+ bool stateInit;
+ bool trigger;
+ bool cheatCode;
+ int position;
public Form2()
{
+ coups = new List();
+ coupsFutur = new List();
+ cavalier = Image.FromFile("img\\cavalierEchec.jpg");
+ compteur = 0; //nombre de coups
+ compteurAnnulation = 10;
+ stateInit = false;
+ position = 0; // ou est mon cavalier
+ trigger = false;
+ cheatCode = false;
InitializeComponent();
- //codeProf();
+ int x = 2;
+ int y = 2;
+ this.grille = new Button[64];
+ for (int i = 0; i < grille.Length; ++i)
+ {
+ grille[i] = new Button();
+ grille[i].Text = "";
+ grille[i].Location = new System.Drawing.Point(x, y);
+ grille[i].Name = "button" + (i + 1);
+ grille[i].Size = new System.Drawing.Size(60, 60);
+ grille[i].TabIndex = i;
+ grille[i].UseVisualStyleBackColor = true;
+ grille[i].Click += new System.EventHandler(this.button1_Click);
+ grille[i].Visible = true;
+ this.Controls.Add(grille[i]);
+ x += 60;
+ if ((i + 1) % 8 == 0 && i != 0)
+ {
+ y += 60;
+ x = 2;
+ }
+ }
+
}
- private void codeProf()
+ private void button1_Click(object sender, EventArgs e)
{
- int nb_fuite, min_fuite, lmin_fuite = 0;
- int i, j, k, l, ii, jj;
-
- Random random = new Random();
- ii = random.Next(1, 8);
- jj = random.Next(1, 8);
- // ii et jj evoluent de 1 à 8 !
- Console.WriteLine("Case de départ: " + ii + " " + jj);
+ Button myButton = (Button)sender;
+ if(compteur == 0)
+ {
+ int myIndice = getIndiceButton(myButton);
+ compteur++;
+ position = myIndice;
+ coups.Add(position);
+ myButton.Text = compteur.ToString();
+ myButton.BackgroundImage = cavalier;
+ myButton.BackgroundImageLayout = ImageLayout.Stretch;
+ myButton.BackColor = Color.Yellow;
+ myButton.Enabled = false;
+ stateInit = true;
+ label1.Text = "Veuillez choisir le mode de simulation";
+ listBox1.Visible = true;
+ listBox2.Visible = true;
+ testPositionAvailable();
+ coups.Add(position);
+
+ Button buttonGo = new Button();
+ buttonGo.Text = "Go";
+ buttonGo.Location = new System.Drawing.Point(600, 300);
+ buttonGo.Name = "buttonGo";
+ buttonGo.Size = new System.Drawing.Size(60, 60);
+ buttonGo.UseVisualStyleBackColor = true;
+ buttonGo.Click += new System.EventHandler(this.buttonGo_Click);
+ buttonGo.Visible = true;
+ this.Controls.Add(buttonGo);
+ }
+
+ }
- for (i = 0; i < 12; i++)
- for (j = 0; j < 12; j++)
- echec[i, j] = ((i < 2 | i > 9 | j < 2 | j > 9) ? -1 : 0);
+ private void button1_Click_1(object sender, EventArgs e)
+ {
+ label1.Text = "Veuillez cliquer sur la case ou vous souhaitez commencer";
+ foreach (Button b in grille)
+ {
+ b.Enabled = true;
+ }
+ button1.Visible = false;
+ button2.Visible = false;
+ }
+ private void button2_Click(object sender, EventArgs e)
+ {
+ Button myButton = (Button)sender;
+ Random r = new Random();
+ int rd = r.Next(0, 63);
+ myButton.Visible = false;
+ foreach (Button b in grille)
+ {
+ b.Enabled = true;
+ }
+ stateInit = true;
+ compteur++;
+ label1.Text = "Veuillez choisir le mode de simulation";
+ position = rd;
+ coups.Add(position);
+ grille[position].Text = compteur.ToString();
+ grille[position].BackColor = Color.Yellow;
+ grille[position].BackgroundImage = cavalier;
+ grille[position].BackgroundImageLayout = ImageLayout.Stretch;
+ grille[position].Enabled = false;
+ button1.Visible = false;
+ button2.Visible = false;
+ listBox1.Visible = true;
+ listBox2.Visible = true;
+
+ Button buttonGo = new Button();
+ buttonGo.Text = "Go";
+ buttonGo.Location = new System.Drawing.Point(600, 300);
+ buttonGo.Name = "buttonGo";
+ buttonGo.Size = new System.Drawing.Size(60, 60);
+ buttonGo.UseVisualStyleBackColor = true;
+ buttonGo.Click += new System.EventHandler(this.buttonGo_Click);
+ buttonGo.Visible = true;
+ this.Controls.Add(buttonGo);
+ }
- i = ii + 1; j = jj + 1;
- echec[i, j] = 1;
+ private void buttonGo_Click(object sender, EventArgs e)
+ {
+ if (listBox1.SelectedItem == null || listBox2.SelectedItem == null)
+ return;
+ label1.Text = "sa marche !!!!!";
+ string type = listBox1.SelectedItem.ToString();
+ string time = listBox2.SelectedItem.ToString();
- for (k = 2; k <= 64; k++)
+ if(type == "pas-a-pas")
{
- for (l = 0, min_fuite = 11; l < 8; l++)
- {
- ii = i + depi[l]; jj = j + depj[l];
+ Task.Delay(20000000);
+ label1.Text = "omggggggggggggg";
+ }
+ }
- nb_fuite = ((echec[ii, jj] != 0) ? 10 : fuite(ii, jj));
- if (nb_fuite < min_fuite)
- {
- min_fuite = nb_fuite; lmin_fuite = l;
- }
- }
- if (min_fuite == 9 & k != 64)
+ private int getIndiceButton(Button bp)
+ {
+ for (int i = 0; i < grille.Length; ++i)
+ {
+ if (bp.Name == grille[i].Name)
{
- Console.WriteLine("*** IMPASSE ***");
- break;
+ return i;
}
- i += depi[lmin_fuite]; j += depj[lmin_fuite];
- echec[i, j] = k;
}
- for (i = 2; i < 10; i++)
+ return 0;
+ }
+
+ private int testPositionAvailable()
+ {
+ int nbPos = 0;
+ coupsFutur.Clear();
+ for (int i = 0; i < 64; ++i)
{
- for (j = 2; j < 10; j++)
+ if ((testCoup(i) == 1) && (grille[i].Enabled == true))
{
- Console.Write(echec[i, j] + " ");
+ //Console.WriteLine("i = " + i);
+ nbPos++;
+ coupsFutur.Add(i);
}
- Console.WriteLine();
+ if (cheatCode == true)
+ fcheatCode();
+
+ }
+ return nbPos;
+
+ }
+
+ private void fcheatCode()
+ {
+ // on reset les precedentes cases d'aide
+ for (int i = 0; i < grille.Length; ++i)
+ {
+ // colorié en bleu les autres cases
+ if (grille[i].Text == "")
+ grille[i].BackColor = default;
+ // colorié en jaune les cases déja joué
+ if (coups.Contains(grille[i].TabIndex))
+ grille[i].BackColor = Color.Yellow;
+ }
+ // on marque les cases ou on peut se deplacer
+ for (int i = 0; i < coupsFutur.Count; ++i)
+ {
+ grille[coupsFutur[i]].BackColor = Color.Red;
}
- Console.ReadKey();
}
- static int fuite(int i, int j)
+ private int testCoup(int indice)
{
- int n, l;
+ // position de mon coups actuel dans la grille
+ int x = indice % 8;
+ int y = indice / 8;
- for (l = 0, n = 8; l < 8; l++)
- if (echec[i + depi[l], j + depj[l]] != 0) n--;
+ // position de mon cavalier
+ int px = position % 8;
+ int py = position / 8;
+
+ // algo qui check le déplacement du cavalier
+ if ((x == px + 2 && y == py + 1) || (x == px + 2 && y == py - 1) || (x == px - 2 && y == py + 1) || (x == px - 2 && y == py - 1) || (x == px + 1 && y == py + 2) || (x == px + 1 && y == py - 2) || (x == px - 1 && y == py + 2) || (x == px - 1 && y == py - 2))
+ {
+ return 1;
+ }
+ //label2.Visible = true;
+ //label2.Text = "x : " + x + " y : " + y;
+ return 0;
+ }
+
+ private void algoEuler()
+ {
- return (n == 0) ? 9 : n;
}
}
+
}
diff --git a/Cavalier_Euler/Form2.resx b/Cavalier_Euler/Form2.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/Cavalier_Euler/Form2.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