前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
// ラジオボタン
void radioButton_Click(object sender, EventArgs e)
{ int i;
for(i=0; i<5; i++)
if (radioButton[i].Checked) break;
if (i<5) Set_Mode(i);
}
|
private void Set_Mode(int mode)
{
DialogResult rc;
int md;
md = mode;
if (m_Top == null)
{ m_Top = new CELL(0);
m_Num = 1;
}
if (m_PT == null)
{ m_PT = m_Top;
if (md<2) md = 3;
}
if (m_Top.car == null && m_Top.cdr == null && md<2) md = 3;
radioButton[md].Checked = true;
m_Mode = md;
switch(md)
{ case 0: //再生モード
CELL.Reset(m_Top);
m_PT = m_Top;
Play(m_Top); // 現在までの手順を再現
Invalidate();
break;
case 1: //詰碁モード
m_Timg = 0;
CELL.Reset(m_Top);
for(m_PT=m_Top; m_PT!=null && m_PT.teban!=1; Set_Next(m_Pos));
Set_Back();
Play(m_Top); // 現在までの手順を再現
Invalidate();
break;
case 2: //出題図モード
m_PT = m_Top;
m_Ban = (short[,])m_St.Clone();
Invalidate();
break;
case 3: //棋譜入力モード
if (m_PT.car != null || m_PT.cdr != null)
{
rc = MessageBox.Show("以降の手順が書き換えられます", "選択",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rc == DialogResult.No)
{
radioButton[0].Checked = true;
Set_Mode(0);
return;
}
}
m_Ishi = (short)(0-m_PT.teban);
if (m_Ishi==0) m_Ishi = 1;
Play(m_Top);
Invalidate();
break;
case 4: //分岐手順の開始
rc = MessageBox.Show("分岐手順(コピー手順)を作成します", "選択",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rc == DialogResult.No)
{
radioButton[0].Checked = true;
Set_Mode(0);
return;
}
m_Copy = new CELL(0);
m_wp = m_Copy;
m_Ishi = 1;
break;
}
}
|
private void OnMyMouseDown(object sender, MouseEventArgs e)
{ Point pos = new Point(e.X, e.Y);
CELL wp;
int i;
DialogResult rc;
ClickPos(ref pos);
switch (m_Mode)
{
case 0: // 棋譜再生モード
if (m_PT == null) break;
if (e.Button == MouseButtons.Left)
{ Set_Next(pos); }
if (e.Button == MouseButtons.Right)
{ Set_Back(); }
break;
case 1: // 詰碁モード
if (m_PT == null) break;
m_Timg = 0;
if (e.Button == MouseButtons.Right)
{
Set_Back();
// 最後が黒番(次が白番)の時
if (m_PT.teban == 1)
{
m_Sn++;
Set_Back();
}
break;
}
Set_List(); // 黒番の候補リストを作成
for(i=0; m_Sel[i]!=null; i++)
{ if (m_Sel[i].pos.X==pos.X && m_Sel[i].pos.Y==pos.Y)
{ Set_Next(m_Sel[i]);
break;
}
}
if (m_Sel[i]==null)
{ m_Timg = 1;
break;
}
Set_List(); // 白番の候補リストを作成
if (m_Sel[1] != null) m_Timg = 2;
if (m_Sel[m_Sn] == null) m_Sn = 0;
Set_Next(m_Sel[m_Sn]);
break;
case 2: // 出題図モード
if (pos.X<0) break;
if (e.Button == MouseButtons.Left)
{
if (m_St[pos.X, pos.Y] == 1)
{ m_St[pos.X, pos.Y] = 0; }
else
{ m_St[pos.X, pos.Y] = 1; }
}
if (e.Button == MouseButtons.Right)
{
if (m_St[pos.X, pos.Y] == -1)
{ m_St[pos.X, pos.Y] = 0; }
else
{ m_St[pos.X, pos.Y] = -1; }
}
m_Ban = (short[,])m_St.Clone(); // 出題図を盤に設定
break;
case 3: // 棋譜入力モード
if (e.Button == MouseButtons.Right)
{
rc = MessageBox.Show("入力モードを終了しますか", "選択",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rc == DialogResult.Yes)
{ Set_Mode(0);
return;
}
}
Append(pos, m_Ishi);
m_Ishi = (short)(0 - m_Ishi);
break;
case 4: // 手順入力モード
if (e.Button == MouseButtons.Right)
{
cdr_Link();
Set_Mode(0);
return;
}
if (pos.X<0) break;
wp = new CELL(m_Num++); // 基本セルを生成
wp.pos = pos;
wp.teban = m_Ishi;
m_wp.car = wp;
m_wp = wp;
m_Ban[pos.X, pos.Y] = m_Ishi;
m_Ishi = (short)(0 - m_Ishi);
break;
}
Invalidate();
}
|
private void Set_List()
{ int i, n;
CELL wp;
for(i=0; i<19; i++) m_Sel[i] = null;
if (m_PT==null) return;
if (m_PT.car!=null)
{ m_Sel[0] = m_PT.car;
return;
}
if (m_PT.cdr!=null)
{ n = m_PT.level+1;
for(i=0, wp=m_PT.cdr; wp!=null; wp=wp.cdr)
{ if (wp!=null && wp.level==n) m_Sel[i++] = wp;
}
}
}
|
![]()