2018-12-14 14:08:07 +01:00
|
|
|
|
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;
|
2019-01-03 11:20:16 +01:00
|
|
|
|
int dim; int nbPionAlign; string playerW; string playerB;
|
2018-12-14 14:08:07 +01:00
|
|
|
|
public Plateau(Goban.sauvegarde_S s)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-01-04 11:28:58 +01:00
|
|
|
|
this.Text = $"Morpion {s.cfg.taille}x{s.cfg.taille}";
|
2018-12-14 14:08:07 +01:00
|
|
|
|
g = new Goban(this, pictureBox1, s);
|
|
|
|
|
}
|
|
|
|
|
public Plateau(int dim, int nbPionAlign, string playerW, string playerB)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.Text = $"Morpion {dim}x{dim}";
|
2019-01-03 11:20:16 +01:00
|
|
|
|
this.dim = dim;
|
|
|
|
|
this.nbPionAlign = nbPionAlign;
|
|
|
|
|
this.playerW = playerW;
|
|
|
|
|
this.playerB = playerB;
|
|
|
|
|
|
2018-12-14 14:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2019-01-03 11:20:16 +01:00
|
|
|
|
g = new Goban(this, pictureBox1, dim, nbPionAlign, playerW, playerB);
|
2018-12-14 14:08:07 +01:00
|
|
|
|
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)
|
|
|
|
|
{
|
2019-01-03 11:20:16 +01:00
|
|
|
|
|
2018-12-14 14:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void pictureBox1_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
2019-01-03 11:20:16 +01:00
|
|
|
|
|
2018-12-14 14:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Plateau_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
2019-01-03 11:20:16 +01:00
|
|
|
|
|
2018-12-14 14:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|