214 lines
9.0 KiB
C#
214 lines
9.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace go01
|
|
{
|
|
class Goban
|
|
{
|
|
public PictureBox Conteneur;
|
|
public Form Fenetre;
|
|
public int dim;
|
|
Label LabelPlayerTurn;
|
|
string playerWName, playerBName;
|
|
enum Occupant_E { Vide, Blanc, Noir, LAST}
|
|
public enum Joueur_E { Blanc, Noir, LAST}
|
|
Joueur_E tour;
|
|
Joueur_E Tour
|
|
{
|
|
get
|
|
{
|
|
return tour;
|
|
}
|
|
set
|
|
{
|
|
tour = value;
|
|
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);
|
|
/*using (Graphics gr = Graphics.FromHwnd(Fenetre.Handle))
|
|
{
|
|
Font fbg = new System.Drawing.Font("Matura MT Script Capitals", 40F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
Font f = new System.Drawing.Font("Matura MT Script Capitals", 38F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
//gr.DrawString((tour == Joueur_E.Blanc) ? playerWName : playerBName, fbg, new SolidBrush(Color.Black), 0, 0);
|
|
SizeF stringSizebg = new SizeF();
|
|
SizeF stringSize = new SizeF();
|
|
stringSizebg = gr.MeasureString((tour == Joueur_E.Blanc) ? playerWName : playerBName, fbg);
|
|
stringSize = gr.MeasureString((tour == Joueur_E.Blanc) ? playerWName : playerBName, f);
|
|
|
|
gr.DrawString((tour == Joueur_E.Blanc) ? playerWName : playerBName, fbg, new SolidBrush(Color.Black), new Point((int)(Conteneur.Location.X + Conteneur.Width + ((Fenetre.ClientSize.Width - Conteneur.Location.X - Conteneur.Width - stringSizebg.Width) / 2)), Conteneur.Location.Y));
|
|
gr.DrawString((tour == Joueur_E.Blanc) ? playerWName : playerBName, f, new SolidBrush(Color.White), new Point((int)(Conteneur.Location.X + Conteneur.Width + ((Fenetre.ClientSize.Width - Conteneur.Location.X - Conteneur.Width - stringSizebg.Width) / 2) + (stringSizebg.Width - stringSize.Width) / 2), (int)(Conteneur.Location.Y + ((stringSizebg.Height - stringSize.Height) / 2))));
|
|
}*/
|
|
}
|
|
}
|
|
|
|
Occupant_E[,] tableauOccupation;
|
|
Boolean[,] tabTeritoirBlanc, tabTeritoirNoir;
|
|
List<PictureBox> pboxList = new List<PictureBox>();
|
|
public Goban(Form fenetre, PictureBox conteneur, int dim, string playerW, string playerB)
|
|
{
|
|
this.Conteneur = conteneur;
|
|
this.dim = dim;
|
|
this.Fenetre = fenetre;
|
|
|
|
playerWName = playerW;
|
|
playerBName = playerB;
|
|
|
|
//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);
|
|
Tour = Joueur_E.Noir;
|
|
|
|
//gen des tab
|
|
tableauOccupation = new Occupant_E[dim, dim];
|
|
tabTeritoirBlanc = new bool[dim, dim];
|
|
tabTeritoirNoir = new bool[dim, dim];
|
|
for (int i = 0; i < dim * dim; i++) //Genération du goban
|
|
{
|
|
pboxList.Add(new PictureBox());
|
|
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) == 3 && GetY(i) == 3 || GetX(i) == dim / 2 && GetY(i) == 3 || GetX(i) == dim - 4 && GetY(i) == 3 ||
|
|
GetX(i) == 3 && GetY(i) == dim / 2 || GetX(i) == dim / 2 && GetY(i) == dim / 2 || GetX(i) == dim - 4 && GetY(i) == dim / 2 ||
|
|
GetX(i) == 3 && GetY(i) == dim - 4 || GetX(i) == dim / 2 && GetY(i) == dim - 4 || GetX(i) == dim - 4 && GetY(i) == dim - 4)
|
|
pboxList[i].Image = global::go01.Properties.Resources.hoshi;
|
|
else 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;
|
|
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);
|
|
conteneur.Controls.Add(pboxList[i]);
|
|
}
|
|
}
|
|
|
|
private void pictureBox1_Click(object sender, EventArgs e)
|
|
{
|
|
PictureBox pb = (PictureBox)sender;
|
|
String[] xy = ((PictureBox)sender).Name.Split(';');
|
|
Console.WriteLine($"{xy[0]};{xy[1]}");
|
|
if (tableauOccupation[int.Parse(xy[0]), int.Parse(xy[1])] == Occupant_E.Vide)
|
|
{
|
|
tableauOccupation[int.Parse(xy[0]), int.Parse(xy[1])] = (Tour == Joueur_E.Blanc) ? Occupant_E.Blanc : Occupant_E.Noir;
|
|
Tour = (Tour+1 == Joueur_E.LAST) ? Joueur_E.Blanc : Tour+1;
|
|
}
|
|
|
|
|
|
using (Graphics gr = Graphics.FromHwnd((pb.Handle)))
|
|
{
|
|
SolidBrush b = null;
|
|
switch(tableauOccupation[int.Parse(xy[0]), int.Parse(xy[1])])
|
|
{
|
|
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, pb.ClientSize.Width-2, pb.ClientSize.Height-1);
|
|
else
|
|
gr.DrawImage(pb.Image, 0, 0, pb.Width, pb.Height);
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
|
|
void RechercheTeritoir(int x, int y)
|
|
{
|
|
List<Point> carrefour = new List<Point>();
|
|
Point pointCourant = new Point(x, y);
|
|
Point pointPrecedent;
|
|
Point min = new Point(x, y), max = new Point(x, y);
|
|
}
|
|
Point RecherchePointSuivant(Point p, ref List<Point> carrefour)
|
|
{
|
|
bool trouver = false;
|
|
if ()
|
|
{
|
|
|
|
}
|
|
if ()
|
|
{
|
|
|
|
}
|
|
if ()
|
|
{
|
|
|
|
}
|
|
if ()
|
|
{
|
|
|
|
}
|
|
if ()
|
|
{
|
|
|
|
}
|
|
if ()
|
|
{
|
|
|
|
}
|
|
if ()
|
|
{
|
|
|
|
}
|
|
if ()
|
|
{
|
|
|
|
}
|
|
return p;
|
|
}
|
|
}
|
|
}
|