Last active
November 1, 2015 13:15
-
-
Save tedliou/fa462d266514d033e2c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
//宣告全域 | |
int allscore = 0; | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
int ch = 0; | |
int[] tbarray = new int[] { int.Parse(nu1.Text), int.Parse(nu2.Text), int.Parse(nu3.Text), int.Parse(nu4.Text), int.Parse(nu5.Text), int.Parse(sp1.Text) }; | |
//檢查數字範圍輸入錯誤 | |
if (tbarray[0] == tbarray[1] || tbarray[0] == tbarray[2] || tbarray[0] == tbarray[3] || tbarray[0] == tbarray[4] || tbarray[1] == tbarray[2] || tbarray[1] == tbarray[3] || tbarray[1] == tbarray[4] || tbarray[2] == tbarray[3] || tbarray[2] == tbarray[4] || tbarray[3] == tbarray[4]) | |
{ | |
label13.Text = "數值重複"; | |
ch -= 2; | |
} | |
if (tbarray[0] <= 0 || tbarray[0] > 20 || tbarray[1] <= 0 || tbarray[1] > 20 || tbarray[2] <= 0 || tbarray[2] > 20 || tbarray[3] <= 0 || tbarray[3] > 20 || tbarray[4] <= 0 || tbarray[4] > 20 || tbarray[5] <= 0 || tbarray[5] > 8) | |
{ | |
label13.Text = "範圍錯誤"; | |
ch -= 2; | |
} | |
if (ch == -4) | |
{ | |
label13.Text = "選號錯誤"; | |
} | |
if (ch==0) | |
{ | |
//開始抽獎 | |
nu1.Enabled = false; | |
nu2.Enabled = false; | |
nu3.Enabled = false; | |
nu4.Enabled = false; | |
nu5.Enabled = false; | |
sp1.Enabled = false; | |
op.Enabled = false; | |
op.Text = "選號完成"; | |
startapp.Enabled = true; | |
button3.Enabled = true; | |
startapp.Text = "抽獎!"; | |
button3.Text = "重新選號"; | |
label13.Text = "抽獎時間!"; | |
} | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
int[] randomize = new int[5]; | |
Random rnd = new Random(); | |
for (int i = 0; i < 5; i++) | |
{ | |
//將1~20亂數依序放進陣列randomize中 | |
randomize[i] = rnd.Next(1, 21); | |
for (int j = 0; j < i; j++) | |
{ | |
// 檢查是否有重複的亂數,如果有就重新產生 | |
while (randomize[j] == randomize[i]) | |
{ | |
j = 0; | |
randomize[i] = rnd.Next(1, 21); | |
} | |
} | |
//顯示中獎亂數號碼 | |
label1.Text = randomize[0].ToString("00"); | |
label2.Text = randomize[1].ToString("00"); | |
label3.Text = randomize[2].ToString("00"); | |
label4.Text = randomize[3].ToString("00"); | |
label5.Text = randomize[4].ToString("00"); | |
label11.Text = rnd.Next(1, 9).ToString("00"); | |
} | |
//比對號碼,計分 | |
string BRecord = ""; | |
if (nu1.Text.PadLeft(2, '0') == label1.Text) | |
{ | |
allscore += 3; | |
BRecord = nu1.Text.PadLeft(2, '0') + ","; | |
} | |
if (nu2.Text.PadLeft(2, '0') == label2.Text) | |
{ | |
allscore += 3; | |
BRecord = BRecord + nu2.Text.PadLeft(2, '0') + ","; | |
} | |
if (nu3.Text.PadLeft(2, '0') == label3.Text) | |
{ | |
allscore += 3; | |
BRecord = BRecord + nu3.Text.PadLeft(2, '0') + ","; | |
} | |
if (nu4.Text.PadLeft(2, '0') == label4.Text) | |
{ | |
allscore += 3; | |
BRecord = BRecord + nu4.Text.PadLeft(2, '0') + ","; | |
} | |
if (nu5.Text.PadLeft(2, '0') == label5.Text) | |
{ | |
allscore += 3; | |
BRecord = BRecord + nu5.Text.PadLeft(2, '0') + ","; | |
} | |
int cost = allscore * 500; | |
int spcost = 0; | |
if (sp1.Text == label11.Text) | |
{ | |
allscore += 1; | |
spcost = 500; | |
BRecord = BRecord + "特" + sp1.Text; | |
} | |
//最後統整 | |
string Record = nu1.Text.PadLeft(2, '0') + "," + nu2.Text.PadLeft(2, '0') + "," + nu3.Text.PadLeft(2, '0') + "," + nu4.Text.PadLeft(2, '0') + "," + nu5.Text.PadLeft(2, '0') + " 特" + sp1.Text; | |
string ARecord = label1.Text.PadLeft(2, '0') + "," + label2.Text.PadLeft(2, '0') + "," + label3.Text.PadLeft(2, '0') + "," + label4.Text.PadLeft(2, '0') + "," + label5.Text.PadLeft(2, '0') + " 特" + label11.Text; | |
//新增到紀錄中 | |
listView1.Items.Insert(0, Record); | |
listView1.Items[0].SubItems.Add(ARecord); | |
listView1.Items[0].SubItems.Add(BRecord); | |
listView1.Items[0].SubItems.Add(allscore.ToString()); | |
listView1.Items[0].SubItems.Add(Convert.ToString(cost + spcost)); | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
//重新選號 | |
startapp.Text = "請先選號"; | |
startapp.Enabled = false; | |
op.Enabled = true; | |
button3.Enabled = false; | |
button3.Text = "請先選號"; | |
nu1.Enabled = true; | |
nu2.Enabled = true; | |
nu3.Enabled = true; | |
nu4.Enabled = true; | |
nu5.Enabled = true; | |
sp1.Enabled = true; | |
} | |
private void button1_Click_1(object sender, EventArgs e) | |
{ | |
listView1.Items.Clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment