using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; using System.Threading; namespace pingguo ... { public partial class Form1 : Form ...{ private static int count = 1;//获取转盘停止的下标,然后调用 private Thread thrPlay;//转盘线程 private Thread thrBibei;//比倍线程 private Hashtable tblpic = new Hashtable();//转盘图片 private Hashtable tbllbl = new Hashtable();//压注显示 private Hashtable tblbtn = new Hashtable();//压注按钮 private Hashtable tblint = new Hashtable();//每个图片的数字 private int DB = 0,JN = 0,DL = 0,LW = 0, SD = 0,QW = 0,DG = 0,JQ = 0;//每个代表钱数 private int XYJQ = 0,YDJQ = 0;//现有和赢得金钱 private static int toubi = 0;//投币的控制,只能投币9次 private bool jia = true,jian = false,//用于加减轮盘转速 stop = false,//控制轮盘 zhuan = true;//用于开始一次线程后,禁止再开 private Point mouseOffset; private bool mouseDown = false; private Random Sudu = new Random();//随机数做sleep的参数 private float toumingdu = 1.0f;//透明度 //压注的代码 private void Yazhu(ref int x, Hashtable y, Hashtable z,int i) ...{ Label b = (Label)y[i]; Button c = (Button)z[i]; //压注的代码 if (XYJQ != 0) ...{ x += 1; b.Text = x.ToString(); if (x == 9) ...{ c.Enabled = false; } XYJQ--; lblXYQS.Text = XYJQ.ToString(); } } //构造函数 public Form1() ...{ InitializeComponent(); CheckForIllegalCrossThreadCalls = false; } //押注按钮显示的代码 private void xianshiYZAN() ...{ for (int i = 1; i <= 8; i++) ...{ Button b = (Button)tblbtn[i]; b.Enabled = true; } } //比倍的代码 private void bibei() ...{ Random N; N = new Random(DateTime.Now.Millisecond); Thread.Sleep(10); lblBiBei.Text = N.Next(0, 10).ToString(); bibei(); } //最后的消息和处理 private void xinxi() ...{ if (lblYDQS.Text != "0") ...{ lblXiaoXi.Text = "恭喜"; btnBiBei.Enabled = true; } else ...{ xianshiYZAN(); } DB = JN = DL = LW = SD = QW = DG = JQ = 0; for (int i = 1; i <= 8; i++) ...{ Label l = (Label)tbllbl[i]; l.Text = "0"; } btnStart.Enabled = true; zhuan = true; } //运行转盘代码 private void play() ...{ int cot = 0; int ooo = int.Parse(Sudu.Next(10, 300).ToString());//定一个随机数,转成int,以便进行+-运算 if (count == 20) ...{ count = 0; } for (int i = count + 1; i <= 20; i++) ...{ if (!stop) ...{ if (jian == true) ...{ ooo -= 5; if (ooo <= 10) ...{ cot++; if (cot >= 100) ...{ jian = true; jia = false; cot = 0; } } } if (ooo <= 0) ...{ ooo = 1; jia = true; } if (jia == true) ...{ ooo += 5; if (ooo >= 300) ...{ stop = true; } } } else //开始准备停止运行 ...{ ooo += 70; //首先把时间间隔加长 if (ooo >= 1000) //当时间间隔超过1000毫秒时停止线程运行. ...{ int current = 0; //现在已经点击了停止,当前标签的标记实际上是i,但是由于i的标签的颜色还没有被改变过来,所以必须选择i的上一个标签。 if (i == 1) ...{ current = 20; } else ...{ current = i - 1; } PictureBox currentL = (PictureBox)tblpic["pic"+current.ToString()]; if(current == 2 || current == 5 || current == 9 || current == 13 || current == 18) ...{ YDJQ = DB * 2; } else if (current == 3 || current == 8 || current == 12 || current == 19) ...{ YDJQ = JN * 5; } else if (current == 10 || current == 15) ...{ YDJQ = DL * 10; } else if (current == 1 || current == 6 || current == 11 || current == 16) ...{ YDJQ = LW * 15; } else if (current == 7 || current == 17) ...{ YDJQ = SD * 25; } else if (current == 20) ...{ YDJQ = QW * 30; } else if (current == 4) ...{ YDJQ = DG * 40; } else if (current == 14) ...{ YDJQ = JQ * 50; } lblYDQS.Text = YDJQ.ToString(); xinxi(); Thread.CurrentThread.Abort(); } } int j; if(i == 1) ...{ j = 20; } else ...{ j = i-1; } count = i; PictureBox P = (PictureBox)tblpic["pic"+i.ToString()]; PictureBox beforP = (PictureBox)tblpic["pic" + j.ToString()]; P.BackColor = Color.Red; beforP.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); //把当前标签的上一个标签背景色为浅蓝色. Thread.Sleep(ooo); if(i==20) ...{ i=0; } } } //压注的代码 private void btnDB_Click(object sender, EventArgs e) ...{ Yazhu(ref DB, tbllbl, tblbtn,1); } //压注的代码 private void btnJN_Click(object sender, EventArgs e) ...{ Yazhu(ref JN, tbllbl, tblbtn, 2); } //压注的代码 private void btnDL_Click(object sender, EventArgs e) ...{ Yazhu(ref DL, tbllbl, tblbtn, 3); } //压注的代码 private void btnLW_Click(object sender, EventArgs e) ...{ Yazhu(ref LW, tbllbl, tblbtn, 4); } //压注的代码 private void btnSD_Click(object sender, EventArgs e) ...{ Yazhu(ref SD, tbllbl, tblbtn, 5); } //压注的代码 private void btnQW_Click(object sender, EventArgs e) ...{ Yazhu(ref QW, tbllbl, tblbtn, 6); } //压注的代码 private void btnDG_Click(object sender, EventArgs e) ...{ Yazhu(ref DG, tbllbl, tblbtn, 7); } //压注的代码 private void btnJQ_Click(object sender, EventArgs e) ...{ Yazhu(ref JQ, tbllbl, tblbtn, 8); } //投币的代码 private void btnTouBi_Click(object sender, EventArgs e) ...{ toubi++; XYJQ += 10; lblXYQS.Text = XYJQ.ToString(); if (toubi == 10) ...{ btnTouBi.Enabled = false; } } //加载窗体时的代码加入hastable private void Form1_Load(object sender, EventArgs e) ...{ //将pic加入hastable中 tblpic.Add(pic1.Name, pic1); tblpic.Add(pic2.Name, pic2); tblpic.Add(pic3.Name, pic3); tblpic.Add(pic4.Name, pic4); tblpic.Add(pic5.Name, pic5); tblpic.Add(pic6.Name, pic6); tblpic.Add(pic7.Name, pic7); tblpic.Add(pic8.Name, pic8); tblpic.Add(pic9.Name, pic9); tblpic.Add(pic10.Name, pic10); tblpic.Add(pic11.Name, pic11); tblpic.Add(pic12.Name, pic12); tblpic.Add(pic13.Name, pic13); tblpic.Add(pic14.Name, pic14); tblpic.Add(pic15.Name, pic15); tblpic.Add(pic16.Name, pic16); tblpic.Add(pic17.Name, pic17); tblpic.Add(pic18.Name, pic18); tblpic.Add(pic19.Name, pic19); tblpic.Add(pic20.Name, pic20); tblbtn.Add(1, btnDB); tblbtn.Add(2, btnJN); tblbtn.Add(3, btnDL); tblbtn.Add(4, btnLW); tblbtn.Add(5, btnSD); tblbtn.Add(6, btnQW); tblbtn.Add(7, btnDG); tblbtn.Add(8, btnJQ); tbllbl.Add(1, lblDB); tbllbl.Add(2, lblJN); tbllbl.Add(3, lblDL); tbllbl.Add(4, lblLW); tbllbl.Add(5, lblSD); tbllbl.Add(6, lblQW); tbllbl.Add(7, lblDG); tbllbl.Add(8, lblJQ); btnD.Enabled = false; btnX.Enabled = false; btnBiBei.Enabled = false; } //开始转的代码 private void btnStart_Click(object sender, EventArgs e) ...{ if (zhuan) ...{ //如果没有压注,提示 if (lblDB.Text == "0" && lblJN.Text == "0" && lblDL.Text == "0" && lblLW.Text == "0" && lblSD.Text == "0" && lblQW.Text == "0" && lblDG.Text == "0" && lblJQ.Text == "0") ...{ MessageBox.Show("请压注!", "提示"); } else ...{ //恢复比倍和恭喜 lblBiBei.Text = ""; lblXiaoXi.Text = ""; for (int i = 1; i <= 8; i++) ...{ Button b = (Button)tblbtn[i]; b.Enabled = false; } //btnStart.Enabled = false; thrPlay = new Thread(new ThreadStart(play)); stop = false; thrPlay.Start(); zhuan = false; } } } //比倍的代码 private void btnBiBei_Click(object sender, EventArgs e) ...{ thrBibei = new Thread (new ThreadStart(bibei)); thrBibei.Start(); btnBiBei.Enabled = false; btnD.Enabled = true; btnX.Enabled = true; } //猜大的的代码 private void btnD_Click(object sender, EventArgs e) ...{ thrBibei.Abort(); if (int.Parse(lblBiBei.Text) >= 5) ...{ YDJQ *= 2; btnBiBei.Enabled = true; } else ...{ YDJQ = 0; btnBiBei.Enabled = false; xianshiYZAN(); } lblYDQS.Text = YDJQ.ToString(); btnD.Enabled = false; btnX.Enabled = false; } //猜小的代码 private void btnX_Click(object sender, EventArgs e) ...{ thrBibei.Abort(); if (int.Parse(lblBiBei.Text) >= 5) ...{ YDJQ *= 2; btnBiBei.Enabled = true; } else ...{ YDJQ = 0; btnBiBei.Enabled = false; xianshiYZAN(); } lblYDQS.Text = YDJQ.ToString(); btnD.Enabled = false; btnX.Enabled = false; } //退出的代码 private void btnTuiBi_Click(object sender, EventArgs e) ...{ Thread.CurrentThread.Abort(); MessageBox.Show("您的成绩是:" + lblXYQS.Text, "成绩"); Application.Exit(); } //得分的代码 private void btnDeFen_Click(object sender, EventArgs e) ...{ if (YDJQ != 0) ...{ xianshiYZAN(); } XYJQ += YDJQ; lblXYQS.Text = XYJQ.ToString(); YDJQ = 0; lblYDQS.Text = YDJQ.ToString(); btnBiBei.Enabled = false; } //鼠标在窗体按下的代码 private void Form1_MouseDown(object sender, MouseEventArgs e) ...{ if (e.Button == MouseButtons.Left) ...{ mouseDown = true; mouseOffset = new Point(-e.X, -e.Y); } } //鼠标移动的代码 private void Form1_MouseMove(object sender, MouseEventArgs e) ...{ if (mouseDown) ...{ Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } //鼠标弹起的代码 private void Form1_MouseUp(object sender, MouseEventArgs e) ...{ mouseDown = false; } //减少透明度的代码 private void label3_Click(object sender, EventArgs e) ...{ if (toumingdu < 1.0) ...{ toumingdu += 0.1f; } this.Opacity = toumingdu; } //增加透明度的代码 private void lblJIAN_Click(object sender, EventArgs e) ...{ if (toumingdu > 0.2f) ...{ toumingdu -= 0.1f; } this.Opacity = toumingdu; } }}