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; int dim; int nbPionAlign; string playerW; string playerB; 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}"; this.dim = dim; this.nbPionAlign = nbPionAlign; this.playerW = playerW; this.playerB = 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); g = new Goban(this, pictureBox1, dim, nbPionAlign, playerW, playerB); 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) { } } }