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 = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button1.Text = "O";
}
else
{
button1.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button1.Enabled = false;
judge();
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button2.Text = "O";
}
else
{
button2.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button2.Enabled = false;
judge();
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button3.Text = "O";
}
else
{
button3.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button3.Enabled = false;
judge();
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button4.Text = "O";
}
else
{
button4.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button4.Enabled = false;
judge();
}
private void button5_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button5.Text = "O";
}
else
{
button5.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button5.Enabled = false;
judge();
}
private void button6_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button6.Text = "O";
}
else
{
button6.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button6.Enabled = false;
judge();
}
private void button7_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button7.Text = "O";
}
else
{
button7.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button7.Enabled = false;
judge();
}
private void button8_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button8.Text = "O";
}
else
{
button8.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button8.Enabled = false;
judge();
}
private void button9_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button9.Text = "O";
}
else
{
button9.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button9.Enabled = false;
judge();
}
private void judge()
{
if(button1.Text==("x") && button2.Text==("x") && button3.Text==("x"))
{
MessageBox.Show("X好棒棒!");
}
if(button4.Text==("x") && button5.Text==("x") && button6.Text==("x"))
{
MessageBox.Show("X好棒棒!");
}
if(button7.Text==("x") && button8.Text==("x") && button9.Text==("x"))
{
MessageBox.Show("X好棒棒!");
}
if(button1.Text==("x") && button4.Text==("x") && button7.Text==("x"))
{
MessageBox.Show("X好棒棒!");
}
if(button2.Text==("x") && button5.Text==("x") && button8.Text==("x"))
{
MessageBox.Show("X好棒棒!");
}
if(button3.Text==("x") && button6.Text==("x") && button9.Text==("x"))
{
MessageBox.Show("X好棒棒!");
}
if(button1.Text==("x") && button5.Text==("x") && button9.Text==("x"))
{
MessageBox.Show("X好棒棒!");
}
if (button3.Text == ("x") && button5.Text == ("x") && button7.Text == ("x"))
{
MessageBox.Show("X好棒棒!");
}
}
}
2014年10月31日 星期五
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
int c = 0;宣告一個變數C
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
int r; 設一個變數r
r = c % 2; 設r為變數c除以2的餘數
if (r == 0)假設r=0
{
button3.Text = "O";則按鈕顯示為"O"
}
else否則為"X"
{
button3.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button3.Enabled = false;
}
private void button1_Click(object sender, EventArgs e)
{
c = c + 1;
int r ;
r = c % 2;
if (r == 0)
{
button1.Text="O";
}
else
{
button1.Text="x";
}
textBox1.Text=Convert.ToString(r);
button1.Enabled = false;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button2.Text = "O";
}
else
{
button2.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button2.Enabled = false;
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button4.Text = "O";
}
else
{
button4.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button4.Enabled = false;
}
private void button5_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button5.Text = "O";
}
else
{
button5.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button5.Enabled = false;
}
private void button6_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button6.Text = "O";
}
else
{
button6.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button6.Enabled = false;
}
private void button7_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button7.Text = "O";
}
else
{
button7.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button7.Enabled = false;
}
private void button8_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button8.Text = "O";
}
else
{
button8.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button8.Enabled = false;
}
private void button9_Click(object sender, EventArgs e)
{
c = c + 1;
int r;
r = c % 2;
if (r == 0)
{
button9.Text = "O";
}
else
{
button9.Text = "x";
}
textBox1.Text = Convert.ToString(r);
button9.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
int ssum1 = 0;
int ssum2 = 0;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2, dsum;
Random ir = new Random();
d1 = ir.Next(1, 7);
d2 = ir.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();
}
textBox1.Text = Convert.ToString(ssum1);
ssum1 = ssum1 + dsum;
if (button2.Left >= 100)
{
MessageBox.Show ("馬1獲勝");
}
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
int d1, d2, dsum;
Random ir = new Random();
d1 = ir.Next(1, 7);
d2 = ir.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();
}
textBox1.Text = Convert.ToString(ssum2);
ssum2 = ssum2 + dsum;
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
2014年10月3日 星期五
訂閱:
文章 (Atom)