/***************************************/
/*★ 盤を表示して石を置く 前田 稔 ★*/
/***************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
int m_Width, m_Height, m_Hp, m_Wp;
Rectangle m_Rect;
short[,] m_Ban = new short[19, 19];
public MyForm()
{
this.Width = 800;
this.Height = 540;
Paint += new PaintEventHandler(MyHandler);
Load += new System.EventHandler(this.Form_Load);
Resize += new System.EventHandler(this.FormResize);
}
// Form Load
private void Form_Load(object sender, EventArgs e)
{
m_Width = this.Width;
m_Height = this.Height;
m_Ban.Initialize();
}
// Form のサイズ変更
private void FormResize(object sender, EventArgs e)
{
m_Width = this.Width;
m_Height = this.Height;
Invalidate();
}
// ウインドウの描画
private void MyHandler(object sender, PaintEventArgs e)
{ int width,height,i;
Color cor = Color.FromArgb(255, 210, 170, 50);
m_Hp = m_Height / 23;
m_Wp = (m_Hp*43)/45; //縦45:横43
width = m_Wp * 20;
height = m_Hp * 20;
// 碁盤の枠を設定して、塗りつぶす
m_Rect = new Rectangle(300, 24, m_Wp * 18, m_Hp * 18);
Rectangle rect = new Rectangle(m_Rect.X-m_Wp, m_Rect.Y-m_Hp, m_Rect.Width+m_Wp*2, m_Rect.Height+m_Hp*2);
Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(cor), rect);
// 罫線を描画
for(i=0; i<19; i++)
{
WLine(g, new Pen(Color.Black), m_Rect.X, i*m_Hp+m_Rect.Y, m_Rect.Width);
HLine(g, new Pen(Color.Black), i*m_Wp+m_Rect.X, m_Rect.Y, m_Rect.Height);
}
// マークを描画
int j, xp, yp;
yp = m_Hp * 3 + m_Rect.Y;
for(i=0; i<3; i++)
{
xp = m_Wp * 3 + m_Rect.X;
for (j = 0; j < 3; j++)
{
g.FillEllipse(new SolidBrush(Color.Black), xp - 3, yp - 3, 6, 6);
xp += m_Wp * 6;
}
yp+= m_Hp*6;
}
// 盤上に石を置く
m_Ban[0, 0] = 1;
m_Ban[3, 5] = 1;
m_Ban[3, 6] = 1;
m_Ban[4, 5] = -1;
m_Ban[4, 6] = -1;
View(g);
}
// 横線,縦線を引く
private void WLine(Graphics g, Pen p, int x, int y, int l)
{
g.DrawLine(p, x, y, x + l, y);
}
private void HLine(Graphics g, Pen p, int x, int y, int l)
{
g.DrawLine(p, x, y, x, y + l);
}
// m_Ban[,] の駒を描画
private void View(Graphics g)
{
int i, j;
for(i=0; i < 19; i++)
for (j = 0; j < 19; j++)
{ Put(g, i, j, m_Ban[i, j]); }
}
// 駒を一個描画
private void Put(Graphics g, int x, int y, int typ)
{
int xp, yp;
xp = (m_Wp*x) + m_Rect.X-m_Wp/2;
yp = (m_Hp*y) + m_Rect.Y-m_Hp/2;
if (typ==1)
g.FillEllipse(new SolidBrush(Color.Black), xp, yp, m_Wp-1, m_Wp-1);
if (typ == -1)
g.FillEllipse(new SolidBrush(Color.White), xp, yp, m_Wp - 1, m_Wp - 1);
}
}
class Draw
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|