剪刀石頭布
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
{
Random rand = new Random();
int r;
string winner, time;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 這行程式碼會將資料載入 'testDataSet.data' 資料表。您可以視需要進行移動或移除。
this.dataTableAdapter.Fill(this.testDataSet.data);
}
private void button1_Click(object sender, EventArgs e)
{
r = rand.Next(1, 4);
if (r == 1)
{
winner = "Draw";
richTextBox1.Text += "Draw\n";
label6.Text = "剪刀";
}
if (r == 2)
{
winner = "Computer";
richTextBox1.Text += "Computer\n";
label6.Text = "石頭";
}
if (r == 3)
{
winner = "Player";
richTextBox1.Text += "Playler\n";
label6.Text = "布";
}
label5.Text = "剪刀";
time = DateTime.Now.ToLongTimeString();
richTextBox2.Text += DateTime.Now.ToLongTimeString()+"\n";
dataTableAdapter.Insert(winner, time);
}
private void button2_Click(object sender, EventArgs e)
{
r = rand.Next(1, 4);
if (r == 1)
{
winner = "Player";
richTextBox1.Text += "Player\n";
label6.Text = "剪刀";
}
if (r == 2)
{
winner = "Draw";
richTextBox1.Text += "Draw\n";
label6.Text = "石頭";
}
if (r == 3)
{
winner = "Computer";
richTextBox1.Text += "Computer\n";
label6.Text = "布";
}
label5.Text = "石頭";
time = DateTime.Now.ToLongTimeString();
richTextBox2.Text += DateTime.Now.ToLongTimeString() + "\n";
dataTableAdapter.Insert(winner, time);
}
private void button3_Click(object sender, EventArgs e)
{
r = rand.Next(1, 4);
if (r == 1)
{
winner = "Computer";
richTextBox1.Text += "Computer\n";
label6.Text = "剪刀";
}
if (r == 2)
{
winner = "Player";
richTextBox1.Text += "Player\n";
label6.Text = "石頭";
}
if (r == 3)
{
winner = "Draw";
richTextBox1.Text += "Draw\n";
label6.Text = "布";
}
label5.Text = "布";
time = DateTime.Now.ToLongTimeString();
richTextBox2.Text += DateTime.Now.ToLongTimeString() + "\n";
dataTableAdapter.Insert(winner, time);
}
}
}
沒有留言:
張貼留言