2015年10月30日 星期五

圖片拉霸未完成。

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 WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        int i,j,p1 = -70, p2 = 70, p3 = 210, max =280, min = -140,v1=30,v2=30,v3=30,x1=0,x2=300,x3=600,qq=0,pp;
        int[,] ea = new int[3, 3] { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }};
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            qq++;
            pp = qq % 2;
            if (pp == 1)
            {
                timer1.Enabled = true;
                timer2.Enabled = true;
                timer3.Enabled = true;
            }
            else if(pp==0)
            {
                timer1.Enabled = false;
                timer2.Enabled = false;
                timer3.Enabled = false;
            }
         
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
         
         
            if (min - p1<= ea[0,0] && ea[0,0] <= max-p1) ea[0,0]+=v1;
            else ea[0,0] = min - p1;
            pictureBox1.Location = new Point(x1,p1+ea[0,0]);
            if (min - p2 <= ea[0,1] && ea[0,1] <= max-p2) ea[0,1]+=v1;
            else ea[0,1] = min - p2;
            pictureBox2.Location = new Point(x1, p2+ea[0,1]);
            if (min - p3 <= ea[0,2] && ea[0,2] <= max - p3) ea[0,2] += v1;
            else ea[0,2] = min - p3;
            pictureBox3.Location = new Point(x1, p3+ea[0,2]);
        }


        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
           if (min - p1 <= ea[1,0] && ea[1,0] <= max - p1) ea[1,0] += v2;
            else ea[1,0] = min - p1;
            pictureBox4.Location = new Point(x2, p1 + ea[1,0]);
            if (min - p2 <= ea[1,1] && ea[1,1] <= max - p2) ea[1,1] += v2;
            else ea[1,1] = min - p2;
            pictureBox5.Location = new Point(x2, p2 + ea[1,1]);
            if (min - p3 <= ea[1,2] && ea[1,2] <= max - p3) ea[1,2] += v2;
            else ea[1,2] = min - p3;
            pictureBox6.Location = new Point(x2, p3 + ea[1,2]);
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            if (min - p1 <= ea[2, 0] && ea[2, 0] <= max - p1) ea[2, 0] += v3;
            else ea[2, 0] = min - p1;
            pictureBox7.Location = new Point(x3, p1 + ea[2, 0]);
            if (min - p2 <= ea[2, 1] && ea[2, 1] <= max - p2) ea[2, 1] += v3;
            else ea[2, 1] = min - p2;
            pictureBox8.Location = new Point(x3, p2 + ea[2, 1]);
            if (min - p3 <= ea[2, 2] && ea[2, 2] <= max - p3) ea[2, 2] += v3;
            else ea[2, 2] = min - p3;
            pictureBox9.Location = new Point(x3, p3 + ea[2, 2]);
        }

     
    }
}

隨機變數nxn

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 ggwp
{
    public partial class Form1 : Form
    {
        const int n = 4,s=300;
        Button[,] buttons = new Button[n, n];
        int i, j,d;
        int width = s/n, height = s/n;
        int[,] matrix = new int[1, n*n];
        Random rnd = new Random();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (i = 0; i < n; i++)
            {
                for (j = 0; j < n; j++)
                {
                 
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point((i + 1) * s/n, (j + 1) * s/n);
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i, j].Text = (i * n + j+1).ToString();
                 
                    this.Controls.Add(buttons[i, j]);
                }
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
         
            for (i = 0; i < n * n; i++)
            {
                matrix[0, i] = i+1;    
            }
            for (i = 0; i < n * n; i++)
            {
                int a = rnd.Next(1, n * n);
                int b = rnd.Next(1, n * n);
                int temp;
                temp = matrix[0, a];
                matrix[0, a] = matrix[0, b];
                matrix[0, b] = temp;
            }
            for (i = 0; i < n; i++)
            {
                for (j = 0; j < n; j++)
                {
                     buttons[i, j].Text = matrix[0, i * n + j].ToString();
                }
            }
        }
    }
}

2015年10月26日 星期一

數字拉霸

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 WindowsFormsApplication4
{  
    public partial class Form1 : Form
    {
        int c = 0, d=1,f,qq =0,qaq=0;
        public Form1()
        {
            InitializeComponent();
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (qaq == 0)
            {
                qq = 0;
                button10.Text = "按我開死";
                button11.Text = "勝負";
            }
        }
        private void button10_Click(object sender, EventArgs e)
        {

            qaq = 1;
            d++;
            f = d % 2;
            if (f == 0&& qq==0)
            {
                timer1.Enabled = true;
                button10.Text = "stop me";
            }
            else if (f ==1&qq== 0)
            {
                timer1.Enabled = false;
                button10.Text = "繼續開死";
                button11.Text = "勝負";
            }
            if (qq==3)
            {
                timer1.Enabled = true;
               // qaq = 0;//
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Random rnd = new Random();
            int s = rnd.Next(1, 11);
            int t = rnd.Next(1,11);
            int u = rnd.Next(1, 11);

            if (qq == 0)
            {
                button1.Text = s.ToString();
                button4.Text = t.ToString();
                button7.Text = u.ToString();
            }

            qq = qq + 1;
            if (qq == 1)
            {
                s = s - 1;
                t = t - 1;
                u = u - 1;
                button2.Text = s.ToString();
                button5.Text = t.ToString();
                button8.Text = u.ToString();
            }
            qq = qq + 1;
            if (qq == 2)
            {
                s = s + 2;
                t = t + 2;
                u = u + 2;
                button3.Text = s.ToString();
                button6.Text = t.ToString();
                button9.Text = u.ToString();
                qq = qq - 2;
            }
            if (s == t && t == u)
            {
                button10.Text = "reset";
                button11.Text = "ㄋ營ㄌ";
                timer1.Enabled = false;
            }
        }
             
                }
            }

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Random rnd = new Random();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button10_Click(object sender, EventArgs e)
        {
            int a = rnd.Next(1, 10);
            int b = rnd.Next(1, 10);
            int c = rnd.Next(1, 10);
            int d = rnd.Next(1, 10);
            int f = rnd.Next(1, 10);
            int g = rnd.Next(1, 10);
            int h = rnd.Next(1, 10);
            int i = rnd.Next(1, 10);
            int j = rnd.Next(1, 10);
            button1.Text = a.ToString();
            button2.Text = b.ToString();
            button3.Text = c.ToString();
            button4.Text = d.ToString();
            button5.Text = f.ToString();
            button6.Text = g.ToString();
            button7.Text = h.ToString();
            button8.Text = i.ToString();
            button9.Text = j.ToString();
            while (button1.Text == button2.Text || button1.Text == button3.Text || button2.Text == button3.Text)
            {
                MessageBox.Show("他們一樣ㄌ。。。。");
                button1.Text = rnd.Next(1, 10).ToString();
                button2.Text = rnd.Next(1, 10).ToString();
                button3.Text = rnd.Next(1, 10).ToString();
             
            }
             
             
     
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

        }
    }
}

2015年10月2日 星期五

程式設計工藝大師

應數三甲D0250521盧宥銨

























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 c=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {  

        }

        private void button1_Click(object sender, EventArgs e)
        {
            c++;
            button1.Text = c.ToString();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            c++;
            button1.Text = c.ToString();
            button2.Text = c.ToString();
            button3.Text = c.ToString();

            if (c % 3 == 0)
            {
                button2.BackColor = System.Drawing.Color.White;
                button1.BackColor = System.Drawing.Color.Red;
                button3.BackColor = System.Drawing.Color.White;
            }
            else if (c % 3 == 1)
            {
                button2.BackColor = System.Drawing.Color.Yellow;
                button1.BackColor = System.Drawing.Color.White;
                button3.BackColor = System.Drawing.Color.White;
            }
            else if (c % 3 == 2)
            {
                button2.BackColor = System.Drawing.Color.White;
                button1.BackColor = System.Drawing.Color.White;
                button3.BackColor = System.Drawing.Color.Green;
            }
           
        }

        private void timer2_Tick(object sender, EventArgs e)
        {

        }

        private void button2_Click_1(object sender, EventArgs e)
        {

        }
    }
}