2014年11月27日 星期四

2014/11/28


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        Random num = new Random();

        private void button1_Click(object sender, EventArgs e)
        {

        }
        Button[,] buttons = new Button[4, 4];
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    this.Controls.Add(buttons[i, j]);
                    buttons[i, j].Size = new Size(50, 50);
                    buttons[i, j].Text = Convert.ToString(num.Next(1, 16));

                }
            }
        }
    }
}

2014/10/31 圈叉判斷輸贏

private void judge()
{
if ((button1.Text == "O" && button2.Text == "O" && button3.Text == "O")||
(button4.Text == "O" && button5.Text == "O" && button6.Text == "O")||
(button7.Text == "O" && button8.Text == "O" && button9.Text == "O")||
(button1.Text == "O" && button4.Text == "O" && button7.Text == "O")||
(button2.Text == "O" && button5.Text == "O" && button8.Text == "O")||
(button3.Text == "O" && button6.Text == "O" && button9.Text == "O")||
(button1.Text == "O" && button5.Text == "O" && button9.Text == "O")||
(button3.Text == "O" && button5.Text == "O" && button7.Text == "O"))
MessageBox.Show("P1 WIN!");
else if ((button1.Text == "X" && button2.Text == "X" && button3.Text == "X") ||
(button4.Text == "X" && button5.Text == "X" && button6.Text == "X") ||
(button7.Text == "X" && button8.Text == "X" && button9.Text == "X") ||
(button1.Text == "X" && button4.Text == "X" && button7.Text == "X") ||
(button2.Text == "X" && button5.Text == "X" && button8.Text == "X") ||
(button3.Text == "X" && button6.Text == "X" && button9.Text == "X") ||
(button1.Text == "X" && button5.Text == "X" && button9.Text == "X") ||
(button3.Text == "X" && button5.Text == "X" && button7.Text == "X"))
MessageBox.Show("P2 WIN!!");
}

2014/10/24 井字遊戲


九宮格點擊顯示圈叉連線即可獲勝

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
int c;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button1.Text = "O";
else if (r == 0)
button1.Text = "X";
button1.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button2.Text = "O";
else if (r == 0)
button2.Text = "X";
button2.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button3.Text = "O";
else if (r == 0)
button3.Text = "X";
button3.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}

2014年11月24日 星期一

2014/11/14 九九乘法表 ( c# 和 excel )


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[10, 10];
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Size = new Size(51, 51);
buttons[i, j].Location = new Point(i * 45, j * 45);
buttons[i, j].Text = Convert.ToString(i * j);
this.Controls.Add(buttons[i, j]);
}
}
}
}
}

2014/10/17 丟骰子-步數-獲勝



設兩個物件擲骰子累積步數判斷獲勝

private void button1_Click(object sender, EventArgs e)
        {
            int d1, d2, dsum;
         
            Random irand = new Random();
            d1 = irand.Next(1, 7);
            d2 = irand.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum = d1 + d2;
            
            for (int i = 1; i <= dsum; i++)
            {

                button2.Left = i + ssum1;
                Thread.Sleep(100); //Delay 1秒
                Application.DoEvents();
            }
            ssum1 = ssum1 + dsum;
            textBox1.Text = Convert.ToString(ssum1);              

        }

        private void button3_Click(object sender, EventArgs e)
        {
            int d1, d2, dsum;

            Random irand = new Random();
            d1 = irand.Next(1, 7);
            d2 = irand.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum = d1 + d2;

            for (int i = 1; i <= dsum; i++)
            {

                button4.Left = i + ssum2;
                Thread.Sleep(100); //Delay 1秒
                Application.DoEvents();
            }
            ssum2 = ssum2 + dsum;
            textBox1.Text = Convert.ToString(ssum2);
        }
    }
}

2014/10/03 按按鈕左右跑


假設BUTTON為兩個車子
使其往左右邊界開       


 public partial class Form1 : Form
        {
            int c ;
            int b ;
            public Formal()
            {
                      InitializeComponent();
             }
              private void timer1_Click(object sender, EventArgs e)
          {
                  if (button1.Left > 345)
                        {
                             b = -1 ;
                        if button1.Left <= 0) 
                        {
                            b = 1 ;
                        }
                        c = c + b ;
              }
        }

2014/09/26 叫我姐姐-三個燈轉換+timer


2014/9/19 拉出button 及配置message