C# 老虎机(赌博机)``源代码

name:5+x 更新原因: 人家技术含量俾我高滴程序都公开鸟源代码```,,,我不敢不公开鸟! 赌博机 目的就是让顾客输多赢少,抽不到老虎别骂我哦! 刚构思,就立刻编程了,代码自然会有点臃肿,请见谅!! name:5+x Hill@home namespace Gamble { public partial class FrmGamble : Form { public FrmGamble() { InitializeComponent(); } private int i = 0; private int j = 0; private int time = 20;//倒计时秒数 FrmGame game = new FrmGame(); ABout about = new ABout(); private void Backsound() { System.Media.SoundPlayer sndPlayer = new System.Media.SoundPlayer(Application.StartupPath + "./sound.wav"); sndPlayer.Play(); }//插入音乐 private void timer1_Tick(object sender, EventArgs e)//抽取颜色 { i++; Backsound(); switch (i) { case 1: gbRed.BackColor = System.Drawing.Color.Black; break; case 2: gbRed.BackColor = System.Drawing.Color.White; gbGreen.BackColor = System.Drawing.Color.Black; break; case 3: gbGreen.BackColor = System.Drawing.Color.White; gbYellow.BackColor = System.Drawing.Color.Black; break; default: gbYellow.BackColor = System.Drawing.Color.White; if (timer1.Interval == 100) { timer1.Enabled=false; CheckedColor(); } else { timer1.Interval -= 100;//加速 i = 0; } break; } } private void timer2_Tick(object sender, EventArgs e)//倒计时 { game.Show(); time--; lblTime.Text = time.ToString(); if (time == 0) { this.Activate(); game.Enabled = false; timer2.Enabled = false; timer1.Enabled = true; } } private void CheckedColor()//颜色随机 { int color=0; Random ro = new Random(); color = ro.Next(0,100); if (color <= 60) { gbYellow.BackColor = System.Drawing.Color.Black; result.Result[0] = "黄"; timer3.Enabled = true; } else if (color > 60&&color < 90) { gbGreen.BackColor = System.Drawing.Color.Black; result.Result[0] = "绿"; timer3.Enabled = true; } else if (color >= 90) { gbRed.BackColor = System.Drawing.Color.Black; result.Result[0] = "红"; timer3.Enabled = true; } } private void timer3_Tick(object sender, EventArgs e)//抽动物 { j++; Backsound(); switch (j) { case 1: gbr1.BackColor = System.Drawing.Color.Black; break; (- -!)新浪字符限制(重复代码省略) default: if (timer3.Interval == 100) { timer3.Enabled = false; CheckedAnimal(); } else { Animalclear(); timer3.Interval -= 100;//加速 j = 0; } break; } } private void Animalclear()//清屏 { gbr1.BackColor = System.Drawing.Color.White; (- -!)新浪字符限制(重复代码省略) } private void CheckedAnimal()//动物随机 { try { Animalclear(); int animal; Random ro = new Random(); animal = ro.Next(1, 100); if (animal <= 66) { result.Result[1] = "兔"; int r; r = ro.Next(1, 14); switch (r) { case 1: gbr1.BackColor = System.Drawing.Color.Black; break; (- -!)新浪字符限制(重复代码省略) default: break; } } else if (animal > 66 && animal < 80) { result.Result[1] = "羊"; int s; s = ro.Next(1, 6); switch (s) { case 1: gbs1.BackColor = System.Drawing.Color.Black; break; case 2: gbs2.BackColor = System.Drawing.Color.Black; break; case 3: gbs3.BackColor = System.Drawing.Color.Black; break; case 4: gbs4.BackColor = System.Drawing.Color.Black; break; case 5: gbs5.BackColor = System.Drawing.Color.Black; break; case 6: gbs6.BackColor = System.Drawing.Color.Black; break; default: break; } } else if (animal >= 80 && animal < 96) { result.Result[1] = "猴"; int m; m = ro.Next(1, 4); switch (m) { case 1: gbm1.BackColor = System.Drawing.Color.Black; break; case 2: gbm2.BackColor = System.Drawing.Color.Black; break; case 3: gbm3.BackColor = System.Drawing.Color.Black; break; case 4: gbm4.BackColor = System.Drawing.Color.Black; break; default: break; } } else if (animal >= 96) { result.Result[1] = "虎"; gbt.BackColor = System.Drawing.Color.Black; } } finally { //初始化配置 result.i = 1; game.Activate(); game.Enabled = true; timer2.Enabled = true; i = 0; j = 0; time = 26; timer1.Interval = 500; timer3.Interval = 300; } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//关于 { about.ShowDialog(); } private void FrmGamble_FormClosed(object sender, FormClosedEventArgs e) { about.ShowDialog(); } } } namespace Gamble { public partial class FrmGame : Form { public FrmGame() { InitializeComponent(); } private int score=100; private int r1 = 0, s1 = 0, m1 = 0, t1 = 0, r2 = 0, s2 = 0, m2 = 0, t2 = 0, r3 = 0, s3 = 0, m3 = 0, t3 = 0; private int time=5; #region 押分 private void btnr1_Click(object sender, EventArgs e) { if (score < 5) { MessageBox.Show("你的游戏分不足!"); } else { score -= 5; r1 += 5; lblScore.Text = score.ToString(); txtR1.Text = r1.ToString(); } } (- -!)新浪字符限制(重复代码省略) #endregion private void clear()//初始化 { result.Result[0] = ""; result.Result[1] = ""; gbYellow.BackColor = System.Drawing.Color.White; gbGreen.BackColor = System.Drawing.Color.White; gbRed.BackColor = System.Drawing.Color.White; gbr1.BackColor = System.Drawing.Color.White; gbs1.BackColor = System.Drawing.Color.White; gbm1.BackColor = System.Drawing.Color.White; gbt1.BackColor = System.Drawing.Color.White; (- -!)新浪字符限制(重复代码省略) txtR1.Text = "0"; txtS1.Text = "0"; txtM1.Text = "0"; txtT1.Text = "0"; txtR2.Text = "0"; txtS2.Text = "0"; txtM2.Text = "0"; txtT2.Text = "0"; txtR3.Text = "0"; txtS3.Text = "0"; txtM3.Text = "0"; txtT3.Text = "0"; r1 = 0; s1 = 0; m1 = 0; t1 = 0; r2 = 0; s2 = 0; m2 = 0; t2 = 0; r3 = 0; s3 = 0; m3 = 0; t3 = 0; } private void stop()//禁止押分 { btnr1.Enabled = false; btns1.Enabled = false; btnm1.Enabled = false; btnt1.Enabled = false; btnr2.Enabled = false; btns2.Enabled = false; btnm2.Enabled = false; btnt2.Enabled = false; btnr3.Enabled = false; btns3.Enabled = false; btnm3.Enabled = false; btnt3.Enabled = false; } private void start()//开启押分 { btnr1.Enabled = true; btns1.Enabled = true; btnm1.Enabled = true; btnt1.Enabled = true; btnr2.Enabled = true; btns2.Enabled = true; btnm2.Enabled = true; btnt2.Enabled = true; btnr3.Enabled = true; btns3.Enabled = true; btnm3.Enabled = true; btnt3.Enabled = true; } private void button1_Click(object sender, EventArgs e) { stop(); try { lblResult.Text = result.Result[0] + "+" + result.Result[1]; if (result.Result[0] == "黄" && result.Result[1] == "兔") { gbYellow.BackColor = System.Drawing.Color.Black; gbr1.BackColor = System.Drawing.Color.Black; score += Convert.ToInt32(txtR1.Text) * 2; lblScore.Text = score.ToString(); } (- -!)新浪字符限制(重复代码省略) } finally { time = 5; tmr.Enabled = true; } } private void btnAgain_Click(object sender, EventArgs e) { score = 100; lblScore.Text = score.ToString(); clear(); } private void FrmGame_Activated(object sender, EventArgs e) { while (result.i == 1) { button1_Click(sender, e); result.i=0; } } private void tmr_Tick(object sender, EventArgs e) { time--; if (time == 0) { clear(); start(); tmr.Enabled = false; } } } } namespace Gamble { public class result { public static string[] Result=new string[2];//保存中奖结果 public static int i = 0;//按键次数 } } 下载地址: http://www.vdisk.cn/down/index/6543746A3724 http://www.brsbox.com/filebox/down/fc/0ae4472d871922644539088ed2bde844 需要.net 2.0以上

你可能感兴趣的:(winform)