2014年12月29日 星期一

推格子遊戲

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public System.Windows.Forms.Button Button1, Button2, Button3, Button4, Button5;
        Button[,] buttons = new Button[50, 50];
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Visible = false;
            Button1 = new Button();
            Button1.Location = new Point(150, 60);
            Button1.Size = new Size(170, 50);
            Button1.Text = "EASY";
            Button1.BackColor = Color.White;
            this.Controls.Add(Button1);
            Button1.Click += new EventHandler(Button1_Click);
            Button2 = new Button();
            Button2.Location = new Point(150, 130);
            Button2.Size = new Size(170, 50);
            Button2.Text = "NORMAL";
            Button2.BackColor = Color.White;
            this.Controls.Add(Button2);
            Button2.Click += new EventHandler(Button2_Click);
            Button3 = new Button();
            Button3.Location = new Point(150, 200);
            Button3.Size = new Size(170, 50);
            Button3.Text = "HARD";
            Button3.BackColor = Color.White;
            this.Controls.Add(Button3);
            Button3.Click += new EventHandler(Button3_Click);
           
        }      

        private void Button1_Click(object sender, EventArgs e)
        {
            Button1.Visible = false;
            Button2.Visible = false;
            Button3.Visible = false;
            Button4 = new Button();
            Button4.Location = new Point(200, 20);
            Button4.Size = new Size(80, 30);
            Button4.Text = "檢測輸贏";
            Button4.BackColor = Color.White;
            this.Controls.Add(Button4);
            Button4.Click += new EventHandler(b_Click);
            Button5 = new Button();
            Button5.Location = new Point(200, 50);
            Button5.Size = new Size(80, 30);
            Button5.Text = "重新開始";
            Button5.BackColor = Color.White;
            this.Controls.Add(Button5);
            Button5.Click += new EventHandler(c_Click);
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 4; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(40 + 30 * (i - 1), 103 + 30 * (j - 1));
                    buttons[i, j].Size = new Size(30, 30);
                    buttons[i, j].Text = " ";
                    buttons[i, j].BackColor = Color.White;
                    this.Controls.Add(buttons[i, j]);
                    buttons[i, j].Click += new EventHandler(a1_Click);
                }
            }
            for (int j = 1; j < 4; j++)
            {
                buttons[1, j].Text = "O";
                buttons[13, j].Text = "X";
                buttons[1, j].Enabled = false;
                buttons[13, j].Enabled = false;
            }
            label2.Text = "3";          
        }
        int c1 = 0;
        private void a1_Click(object sender, EventArgs e)
        {
            int x, y;
            x = Form1.ActiveForm.Location.X + 50;
            y = Form1.ActiveForm.Location.Y + 140;
            c1++;
            //MessageBox.Show(Convert.ToString(c));
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 4; j++)
                {
                    if (MousePosition.X >= x + (i - 1) * 30 && MousePosition.X < x + i * 30 && MousePosition.Y >= y + (j - 1) * 30 && MousePosition.Y < y + j * 30)
                    {
                        if (c1 % 2 == 1)
                        {
                            for (int a = 1; a <= i; a++)
                            {
                                buttons[a, j].Text = " ";
                                buttons[a, j].Enabled = false;
                            }
                            buttons[i, j].Text = "O";
                        }
                        if (c1 % 2 == 0)
                        {
                            for (int a = 13; a >= i; a--)
                            {
                                buttons[a, j].Text = " ";
                                buttons[a, j].Enabled = false;
                            }
                            buttons[i, j].Text = "X";
                        }
                    }                  
                }
            }
            //MessageBox.Show(Convert.ToString(MousePosition)+Convert.ToString(Form1.ActiveForm.Location));
            Button4.Enabled = true;
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 4; j++)
                {
                    if (buttons[i, j].Enabled == true)
                        Button4.Enabled = false;
                }
            }
            label1.Text = Convert.ToString(c1);
        }
        private void Button2_Click(object sender, EventArgs e)
        {   Button1.Visible = false;
            Button2.Visible = false;
            Button3.Visible = false;
            Button4 = new Button();
            Button4.Location = new Point(200, 20);
            Button4.Size = new Size(80, 30);
            Button4.Text = "檢測輸贏";
            Button4.BackColor = Color.White;
            this.Controls.Add(Button4);
            Button4.Click += new EventHandler(b_Click);
            Button5 = new Button();
            Button5.Location = new Point(200, 50);
            Button5.Size = new Size(80, 30);
            Button5.Text = "重新開始";
            Button5.BackColor = Color.White;
            this.Controls.Add(Button5);
            Button5.Click += new EventHandler(c_Click);
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 6; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(40 + 30 * (i - 1), 103 + 30 * (j - 1));
                    buttons[i, j].Size = new Size(30, 30);
                    buttons[i, j].Text = " ";
                    buttons[i, j].BackColor = Color.White;
                    this.Controls.Add(buttons[i, j]);
                    buttons[i, j].Click += new EventHandler(a2_Click);
                }
            }
            for (int j = 1; j < 6; j++)
            {
                buttons[1, j].Text = "O";
                buttons[13, j].Text = "X";
                buttons[1, j].Enabled = false;
                buttons[13, j].Enabled = false;
            }
            label2.Text = "5";          
        }
        int c2 = 0;
        private void a2_Click(object sender, EventArgs e)
        {
            int x, y;
            x = Form1.ActiveForm.Location.X + 50;
            y = Form1.ActiveForm.Location.Y + 140;
            c2++;
            //MessageBox.Show(Convert.ToString(c));
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 6; j++)
                {
                    if (MousePosition.X >= x + (i - 1) * 30 && MousePosition.X < x + i * 30 && MousePosition.Y >= y + (j - 1) * 30 && MousePosition.Y < y + j * 30)
                    {
                        if (c2 % 2 == 1)
                        {
                            for (int a = 1; a <= i; a++)
                            {
                                buttons[a, j].Text = " ";
                                buttons[a, j].Enabled = false;
                            }
                            buttons[i, j].Text = "O";
                        }
                        if (c2 % 2 == 0)
                        {
                            for (int a = 13; a >= i; a--)
                            {
                                buttons[a, j].Text = " ";
                                buttons[a, j].Enabled = false;
                            }
                            buttons[i, j].Text = "X";
                        }
                    }
                }
            }
            //MessageBox.Show(Convert.ToString(MousePosition)+Convert.ToString(Form1.ActiveForm.Location));
            Button4.Enabled = true;
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 6; j++)
                {
                    if (buttons[i, j].Enabled == true)
                        Button4.Enabled = false;
                }
            }
            label1.Text = Convert.ToString(c2);
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            Button1.Visible = false;
            Button2.Visible = false;
            Button3.Visible = false;
            Button4 = new Button();
            Button4.Location = new Point(200, 20);
            Button4.Size = new Size(80, 30);
            Button4.Text = "檢測輸贏";
            Button4.BackColor = Color.White;
            this.Controls.Add(Button4);
            Button4.Click += new EventHandler(b_Click);
            Button5 = new Button();
            Button5.Location = new Point(200, 50);
            Button5.Size = new Size(80, 30);
            Button5.Text = "重新開始";
            Button5.BackColor = Color.White;
            this.Controls.Add(Button5);
            Button5.Click += new EventHandler(c_Click);
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 8; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(40 + 30 * (i - 1), 103 + 30 * (j - 1));
                    buttons[i, j].Size = new Size(30, 30);
                    buttons[i, j].Text = " ";
                    buttons[i, j].BackColor = Color.White;
                    this.Controls.Add(buttons[i, j]);
                    buttons[i, j].Click += new EventHandler(a3_Click);
                }
            }
            for (int j = 1; j < 8; j++)
            {
                buttons[1, j].Text = "O";
                buttons[13, j].Text = "X";
                buttons[1, j].Enabled = false;
                buttons[13, j].Enabled = false;
            }
            label2.Text = "7";
        }
        int c3 = 0;
        private void a3_Click(object sender, EventArgs e)
        {
            int x, y;
            x = Form1.ActiveForm.Location.X + 50;
            y = Form1.ActiveForm.Location.Y + 140;
            c3++;
            //MessageBox.Show(Convert.ToString(c));
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 8; j++)
                {
                    if (MousePosition.X >= x + (i - 1) * 30 && MousePosition.X < x + i * 30 && MousePosition.Y >= y + (j - 1) * 30 && MousePosition.Y < y + j * 30)
                    {
                        if (c3 % 2 == 1)
                        {
                            for (int a = 1; a <= i; a++)
                            {
                                buttons[a, j].Text = " ";
                                buttons[a, j].Enabled = false;
                            }
                            buttons[i, j].Text = "O";
                        }
                        if (c3 % 2 == 0)
                        {
                            for (int a = 13; a >= i; a--)
                            {
                                buttons[a, j].Text = " ";
                                buttons[a, j].Enabled = false;
                            }
                            buttons[i, j].Text = "X";
                        }
                    }
                }
            }
            //MessageBox.Show(Convert.ToString(MousePosition)+Convert.ToString(Form1.ActiveForm.Location));
            Button4.Enabled = true;
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < 8; j++)
                {
                    if (buttons[i, j].Enabled == true)
                        Button4.Enabled = false;
                }
            }
            label1.Text = Convert.ToString(c3);
        }

        private void b_Click(object sender, EventArgs e)
        {
            int d;
            d = Convert.ToInt32(label1.Text);
            if (d % 2 == 0)
                MessageBox.Show("X WIN");
            else
                MessageBox.Show("O WIN");
        }

        private void c_Click(object sender, EventArgs e)
        {
            button1.Visible = false;
            Button1 = new Button();
            Button1.Location = new Point(150, 60);
            Button1.Size = new Size(170, 50);
            Button1.Text = "EASY";
            Button1.BackColor = Color.White;
            this.Controls.Add(Button1);
            Button1.Click += new EventHandler(Button1_Click);
            Button2 = new Button();
            Button2.Location = new Point(150, 130);
            Button2.Size = new Size(170, 50);
            Button2.Text = "NORMAL";
            Button2.BackColor = Color.White;
            this.Controls.Add(Button2);
            Button2.Click += new EventHandler(Button2_Click);
            Button3 = new Button();
            Button3.Location = new Point(150, 200);
            Button3.Size = new Size(170, 50);
            Button3.Text = "HARD";
            Button3.BackColor = Color.White;
            this.Controls.Add(Button3);
            Button3.Click += new EventHandler(Button3_Click);
            int a;
            a = Convert.ToInt32(label2.Text);
            for (int i = 1; i < 14; i++)
            {
                for (int j = 1; j < a+1; j++)
                {
                    buttons[i, j].Visible = false;
                }
            }
            Button4.Visible = false;
            Button5.Visible = false;
        }
       
       
    }
}

2014年12月23日 星期二

猜數字遊戲

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public System.Windows.Forms.Button Button1;
        public System.Windows.Forms.Button Button2;
        Random rand = new Random();
        Button[] buttons = new Button[10];
        int a1, a2, a3, a4;
        double b1, b2, b3, b4;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int x, y;
            int[] m = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            for (int i = 9; i > 1; i--)
            {
                x = rand.Next(0, i);
                y = m[x];
                m[x] = m[i];
                m[i] = y;
            }
            a1 = m[1];
            a2 = m[2];
            a3 = m[3];
            a4 = m[4];
            //MessageBox.Show(Convert.ToString(a1) + Convert.ToString(a2) + Convert.ToString(a3) + Convert.ToString(a4));
            label1.Visible = true;
            label2.Visible = true;
            label3.Visible = true;
            label4.Visible = true;
            label1.Text = "   ";
            label2.Text = "   ";
            label3.Text = "   ";
            label4.Text = "   ";
            for(int i=0;i<10;i++)
            {
                buttons[i] = new Button();
                buttons[i].Location = new Point(10 + i * 30, 120 );
                buttons[i].Size = new Size(30, 30);
                buttons[i].Text = Convert.ToString(i);
                this.Controls.Add(buttons[i]);              
                buttons[i].Click += new EventHandler(a_Click);
            }
            Button1 = new System.Windows.Forms.Button();
            Button1.Location = new Point(165, 150);
            Button1.Size = new Size(50, 30);
            Button1.Click += new EventHandler(Button1_Click);
            Button1.Text = "取消";
            this.Controls.Add(Button1);
            Button2 = new System.Windows.Forms.Button();
            Button2.Location = new Point(105, 150);
            Button2.Size = new Size(50, 30);
            Button2.Click += new EventHandler(Button2_Click);
            Button2.Text = "確定";
            this.Controls.Add(Button2);
            label5.Text = " ";
            button1.Text = "開始新局";
        }
        int j = 0;
        private void a_Click(object sender, EventArgs e)
        {          
            j++;
            Button b = (Button)sender;
            double x = Convert.ToDouble(b.Text);
            for(int i=0;i<10;i++)
            {
                if(i==x)
                {
                    buttons[i].Visible = false;

                }
            }
            if(j%4==1)
            {
                label1.Text = b.Text;
            }
            if (j%4 == 2)
            {
                label2.Text = b.Text;
            }
            if (j%4 == 3)
            {
                label3.Text = b.Text;
            }
            if (j%4 == 0)
            {
                label4.Text = b.Text;
            }
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            label1.Visible = true;
            label1.Text = "   ";
            label2.Visible = true;
            label2.Text = "   ";
            label3.Visible = true;
            label3.Text = "   ";
            label4.Visible = true;
            label4.Text = "   ";
        }
        int p = 0;
        private void Button2_Click(object sender, EventArgs e)
        {
            p++;
            int a=0,b=0;
            b1 = Convert.ToDouble(label1.Text);
            b2 = Convert.ToDouble(label2.Text);
            b3 = Convert.ToDouble(label3.Text);
            b4 = Convert.ToDouble(label4.Text);
            if (a1 == b1 && a2 == b2 && a3 == b3 && a4 == b4)
                MessageBox.Show("贏了");
            if (a1 == b1)
                a++;
            if (a1 == b2 || a1 == b3 || a1 == b4)
                b++;
            if (a2 == b2)
                a++;
            if (a2 == b1 || a2 == b3 || a2 == b4)
                b++;
            if (a3 == b3)
                a++;
            if (a3 == b1 || a3 == b2 || a3 == b4)
                b++;
            if (a4 == b4)
                a++;
            if (a4 == b1 || a4 == b2 || a4 == b3)
                b++;
            label5.Text = label5.Text + Environment.NewLine+a + "a" + b + "b";
            label1.Text = "   ";
            label2.Text = "   ";
            label3.Text = "   ";
            label4.Text = "   ";
            for (int i = 0; i < 10; i++)
            {
                buttons[i].Visible = true;
            }
        }              
    }
}

2014年12月18日 星期四

2014/12/19

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 _123
{
    public partial class Form1 : Form
    {
        public System.Windows.Forms.Button Button1;
        Random rand = new Random();
        Button[,] buttons = new Button[10, 10];
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Button1 = new System.Windows.Forms.Button();
            Button1.Location = new Point(400, 400);
            Button1.Size = new Size(100, 30);
            Button1.Click += new EventHandler(Button1_Click);
            Button1.Text = "Rand";
            this.Controls.Add(Button1);

            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(80 + i * 50, 80 + j * 50);
                    buttons[i, j].Size = new Size(50, 50);
                    buttons[i, j].Text = Convert.ToString((i - 1) + 4 * (j - 1));
                    this.Controls.Add(buttons[i, j]);
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int x, y, a;
            int[] myarray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
            for (int i = 15; i > 1; i--)
            {

                x = rand.Next(0, i);
                y = myarray[x];
                myarray[x] = myarray[i];
                myarray[i] = y;

            }
            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    a = myarray[(j - 1) * 4 + (i - 1)];
                    buttons[i, j].Text = Convert.ToString(a);
                    buttons[i, j].Click += new EventHandler(a_Click);
                    this.Controls.Add(buttons[i, j]);
                }
            }

        }
        //int m, n;
        protected void a_Click(object sender, EventArgs e)
        {
           
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    if (Convert.ToDouble(buttons[i, j].Text) == 0)
                    {
                        buttons[i - 1, j].Click += new EventHandler(b_Click);
                        buttons[i + 1, j].Click += new EventHandler(b_Click);
                        buttons[i, j - 1].Click += new EventHandler(b_Click);
                        buttons[i, j + 1].Click += new EventHandler(b_Click);
                        //i = m;
                        //j = n;
                        //this.Controls.Add(buttons[i, j]);
                        //if (sender == buttons[i, j])
                        //MessageBox.Show("(" + Convert.ToString(i) + "," + Convert.ToString(j) + ")");

                    }
                }
            }
        }
        protected void b_Click(object sender, EventArgs e)
        {
            //buttons[m, n].Text = buttons[m - 1, n].Text;
            //buttons[m-1, n].Text = buttons[m , n].Text;
            MessageBox.Show("  ");
        }

    }
}
       
   

2014年12月4日 星期四

2014/12/05

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
           //System.Windows.Forms.Button Button1;
            //Button[,] Buttons;
            Button[,] buttons = new Button[4, 4];
           
     
        public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
               
         
            }
        private void button1_Click(object sender, EventArgs e)
        {
            int x, d1, a1;
         
            int width, height;
            int[] my = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
         
             Random irand = new Random();

             for (int k = 15; k >= 0; k--)
             {
                 d1 = irand.Next(0, k);
                 a1 = my[d1];
                 my[d1] = my[k];
                 my[k] = a1;
             }
                for (int j = 0; j < 4; j++)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        width = this.Size.Width;
                        height = this.Size.Height;
                        buttons[i, j] = new Button();
                        buttons[i, j].Location = new Point(i * 50, j * 50);
                        //x = (i + 1) + 4 * j;
                        x = my[j * 4 + i];
                        width = 50;
                        height = 50;
                        buttons[i, j].Size = new Size(width, height);
                        buttons[i, j].Text = x.ToString();
                        this.Controls.Add(buttons[i, j]);
                         MessageBox.Show("" + x.ToString());
               
                    }
                }
                   

            }
       
        }
    }

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.Threading.Tasks;
using System.Windows.Forms;

namespace 期中作業
{
   
    public partial class Form1 : Form
    {
        double t1;
        string t2="";
        bool t2_pressed = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
         
        }
     
        private void button_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0"||t2_pressed)
                textBox1.Clear();
            Button b = (Button)sender;
            textBox1.Text = textBox1.Text + b.Text;
        }

        private void a6_Click(object sender, EventArgs e)
        {
            textBox1.Text = "0";
        }
             
        private void buttona_Click(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            t2 = b.Text;
            t1 = Double.Parse(textBox1.Text);
            t2_pressed = true;
        }
         private void a7_Click(object sender, EventArgs e)
        {
            switch (t2)
            {
                case"+":
                    textBox1.Text = (t1 + Double.Parse(textBox1.Text)).ToString();
                    break;
                case "-":
                    textBox1.Text = (t1 - Double.Parse(textBox1.Text)).ToString();
                    break;
                case "*":
                    textBox1.Text = (t1 * Double.Parse(textBox1.Text)).ToString();
                    break;
                case "/":
                    textBox1.Text = (t1 / Double.Parse(textBox1.Text)).ToString();
                    break;
                default:
                    break;
            }
        }

         private void button1_Click(object sender, EventArgs e)
         {
             textBox1.Text =( Double.Parse(textBox1.Text)*100).ToString();
         }
       
    }
}

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9 = 0, sum;
        int b1,b2,b3,b4,b5,b6,b7,b8,b9;
        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)
        {
            a1++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button1.Text = "O";
                b1=1;
            }
            else
            {
                button1.Text = "X";
                b1=4;
            }
            button1.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button2_Click(object sender, EventArgs e)
        {
            a2++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button2.Text = "O";
                b2=1;
            }
            else
            {
                button2.Text = "X";
                b2=4;
            }
            button2.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button3_Click(object sender, EventArgs e)
        {
            a3++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button3.Text = "O";
                b3=1;
            }
            else
            {
                button3.Text = "X";
                b3=4;
            }
            button3.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button4_Click(object sender, EventArgs e)
        {
            a4++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button4.Text = "O";
                b4=1;
            }
            else
            {
                button4.Text = "X";
                b4=4;
            }
            button4.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button5_Click(object sender, EventArgs e)
        {
            a5++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button5.Text = "O";
                b5=1;
            }
            else
            {
                button5.Text = "X";
                b5=4;
            }
            button5.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button6_Click(object sender, EventArgs e)
        {
            a6++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button6.Text = "O";
                b6=1;
            }
            else
            {
                button6.Text = "X";
                b6=4;
            }
            button6.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button7_Click(object sender, EventArgs e)
        {
            a7++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button7.Text = "O";
                b7=1;
            }
            else
            {
                button7.Text = "X";
                b7=4;
            }
            button7.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button8_Click(object sender, EventArgs e)
        {
            a8++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button8.Text = "O";
                b8=1;
            }
            else
            {
                button8.Text = "X";
                b8=4;
            }
            button8.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }

        private void button9_Click(object sender, EventArgs e)
        {
            a9++;
            sum = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
            textBox1.Text = Convert.ToString(sum);
            if (sum % 2 == 0)
            {
                button9.Text = "O";
                b9=1;
            }
            else
            {
                button9.Text = "X";
                b9=4;
            }
            button9.Enabled = false;
            if ((b1 + b2 + b3 == 3) || (b4 + b5 + b6 == 3) || (b7 + b8 + b9 == 3) || (b1 + b4 + b7 == 3) || (b2 + b5 + b8 == 3) || (b3 + b6 + b9 == 3) || (b1 + b5 + b9 == 3) || (b3 + b5 + b7 == 3))
            {
                MessageBox.Show("O贏");
            }
            else if ((b1 + b2 + b3 == 12) || (b4 + b5 + b6 == 12) || (b7 + b8 + b9 == 12) || (b1 + b4 + b7 == 12) || (b2 + b5 + b8 == 12) || (b3 + b6 + b9 == 12) || (b1 + b5 + b9 == 12) || (b3 + b5 + b7 == 12))
            {
                MessageBox.Show("X贏");
            }    
        }
       
   
 
       
    }
 
}

2014年10月23日 星期四

擲骰子賽車程式
========================================================================

========================================================================
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;
using System.Threading;

namespace _1
{
    public partial class Form1 : Form
    {
        int ssum1 = 0, i = 0, ssum2 = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, d2,dsum1,dsum2;
            i++;                    
            if (i % 2 == 1)
            {
                Random ian = new Random();
                d1 = ian.Next(1, 7);
                d2 = ian.Next(1, 7);
                label1.Text = Convert.ToString(d1);
                label2.Text = Convert.ToString(d2);
                dsum1 = d1 + d2;
                textBox1.Text = Convert.ToString(dsum1);
                for (int k = 1; k <= dsum1; k++)
                {
                    Thread.Sleep(500);
                    Application.DoEvents();
                    button2.Left = (k+ssum1)*10;
                }
                ssum1 = ssum1 + dsum1;
               
            }
            else
            {
                Random ian = new Random();
                d1 = ian.Next(1, 7);
                d2 = ian.Next(1, 7);
                label1.Text = Convert.ToString(d1);
                label2.Text = Convert.ToString(d2);
                dsum2 = d1 + d2;
                textBox1.Text = Convert.ToString(dsum2);
                for (int h = 1; h <= dsum2; h++)
                {
                    Thread.Sleep(500);
                    Application.DoEvents();
                    button3.Left = (h+ssum2)*10;
                }
                ssum2 = ssum2 + dsum2;
               
            }
            if (button2.Left >= 250)
            {
                MessageBox.Show("甲車贏");
            }
            else if (button3.Left >= 250)
            {
                MessageBox.Show("乙車贏");
            }
        }
    }
}

2014年10月3日 星期五

物件導向 2014/10/03

要讓CAR於左右兩邊來回跑動

其程式:

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int a = 0,b,c;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            a++;
            b=a%130;
            if (b <= 65)
            {
                button1.Left = b * 10;
            }
            else
            {
                c = 130 - b;
                button1.Left = c * 10;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            a++;
            b = a % 130;
            if (b <= 65)
            {
                button1.Left = b * 10;
            }
            else
            {
                c = 130 - b;
                button1.Left = c * 10;
            }
        }
    }
}

2014年9月25日 星期四

物件導向 2014/09/26

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int a = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            a++;
            if (a % 3 == 1)
            {
                pictureBox1.BackColor = Color.Red;
                pictureBox2.BackColor = Color.Black;
                pictureBox3.BackColor = Color.Black;
            }
            else if (a % 3 == 2)
            {
                pictureBox1.BackColor = Color.Black;
                pictureBox2.BackColor = Color.Yellow;
                pictureBox3.BackColor = Color.Black;
            }
            else
            {
                pictureBox1.BackColor = Color.Black;
                pictureBox2.BackColor = Color.Black;
                pictureBox3.BackColor = Color.Green;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            a++;
            if (a % 3 == 1)
            {
                pictureBox1.BackColor = Color.Red;
                pictureBox2.BackColor = Color.Black;
                pictureBox3.BackColor = Color.Black;
            }
            else if (a % 3 == 2)
            {
                pictureBox1.BackColor = Color.Black;
                pictureBox2.BackColor = Color.Yellow;
                pictureBox3.BackColor = Color.Black;
            }
            else
            {
                pictureBox1.BackColor = Color.Black;
                pictureBox2.BackColor = Color.Black;
                pictureBox3.BackColor = Color.Green;
            }
        }
    }
}

2014年9月21日 星期日

物件導向 2014/09/19

一、button1 &button2


程式內容

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

namespace 上課習題
{
    public partial class Form1 : Form
    {
        int a = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("尚未完成");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            a+=1;
            if (a % 2 == 1)
            {
                button1.Location = new Point(250, 250);
            }
            else if(a%2==0)
            {
                button1.Location = new Point(47, 40);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


二、Cube 跑動

程式內容

using UnityEngine;
using System.Collections;

public class move : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
transform.Translate(Time.deltaTime, Time.deltaTime, 0);
}
}