⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game1.aspx.cs

📁 ASP.NET构建的笑傲江湖社区(C#,全源码提供)
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace xajh.games
{
	/// <summary>
	/// 剪刀石头布。
	/// </summary>
	public class game1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button byts_submit;
		protected System.Web.UI.WebControls.Label gamemsg;
		protected System.Web.UI.WebControls.RadioButtonList gameselect;
		protected System.Web.UI.WebControls.Image gameimg;
		protected System.Web.UI.WebControls.TextBox gamemoney;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (this.Session["info"] == null)
			{
				this.Server.Transfer ("../error.aspx?v=relogin");
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.byts_submit.Click += new System.EventHandler(this.byts_submit_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void byts_submit_Click(object sender, System.EventArgs e)
		{
			x.UserInfo info = (x.UserInfo) this.Session["info"];
			int selectint = this.gameselect.SelectedIndex;
			string addmoney = this.gamemoney.Text.Trim();
			if (selectint == -1)
			{
				this.gamemsg.Text = "请作出选择!";
				this.gameimg.Visible = false;
			}
			else if (addmoney == "")
			{
				this.gamemsg.Text = "请输入下注金额!";
				this.gameimg.Visible = false;
			}
			else
			{
				for (int i = 0; i < addmoney.Length; i ++)
				{
					if (char.IsNumber(addmoney, i) != true)
					{
						this.gamemsg.Text = "下注金额必须为数字!";
						this.gameimg.Visible = false;
						return;
					}
				}
				int upv;
				try
				{
					upv = int.Parse(addmoney);
				}
				catch
				{
					this.gamemsg.Text = "输入数据溢出!(数据不允许超过21亿)";
					this.gameimg.Visible = false;
					return;
				}
				if (upv <= 0)
				{
					this.gamemsg.Text = "操作数额不能等于或者小于 0 !";
					this.gameimg.Visible = false;
					return;
				}
				x.CheckUse useinfo = var.public_bet;
				if (useinfo.MinGrade != -1 && info.Grade < useinfo.MinGrade)
				{
					this.gamemsg.Text = "等级小于 " + useinfo.MinGrade + " 不能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				if (useinfo.MaxGrade != -1 && info.Grade > useinfo.MaxGrade)
				{
					this.gamemsg.Text = "等级大于 " + useinfo.MaxGrade + " 不能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				if (useinfo.MinFGrade != -1 && info.FGrade < useinfo.MinFGrade)
				{
					this.gamemsg.Text = "战斗等级小于 " + useinfo.MinFGrade + " 不能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				if (useinfo.MaxFGrade != -1 && info.FGrade > useinfo.MaxFGrade)
				{
					this.gamemsg.Text = "战斗等级大于 " + useinfo.MaxFGrade + " 不能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				if (useinfo.MinGGrade != -1 && info.Gold < useinfo.MinGGrade)
				{
					this.gamemsg.Text = "会员等级小于 " + useinfo.MinGGrade + " 不能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				if (useinfo.MaxGGrade != -1 && info.Gold > useinfo.MaxGGrade)
				{
					this.gamemsg.Text = "会员等级大于 " + useinfo.MaxGGrade + " 不能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				if (useinfo.CheckSex == "boy" && info.Sex != "boy")
				{
					this.gamemsg.Text = "性别必须为 男 才能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				if (useinfo.CheckSex == "girl" && info.Sex != "girl")
				{
					this.gamemsg.Text = "性别必须为 女 才能赌博!";
					this.gameimg.Visible = false;
					return;
				}
				string sql = @"select [点券],[银两],[存款],[武功],[智力],[内力],[体力],[攻击],[防御],[生命],[魅力],[精确] from [注册用户] where [id]=" + info.DataID;
				if (useinfo.CheckIn != "(无)")
				{
					sql += " and " + useinfo.CheckIn;
				}
				OleDbConnection MyConn = new OleDbConnection(var.public_conn);
				MyConn.Open();
				OleDbCommand MyComm = new OleDbCommand(sql, MyConn);
				OleDbDataReader dr = MyComm.ExecuteReader();
				if (dr.Read())
				{
					if ((int)dr["银两"] < upv)
					{
						dr.Close();
						MyConn.Close();
						MyConn.Dispose();
						this.gamemsg.Text = "你的钱不够!";
						this.gameimg.Visible = false;
						return;
					}
					for (int i = 0; i < 3; i ++)
					{
						if (useinfo.Run_Name[i] != "(无)")
						{
							if ((int)dr[useinfo.Run_Name[i]] < useinfo.Run_Value[i])
							{
								dr.Close();
								MyConn.Close();
								MyConn.Dispose();
								this.gamemsg.Text = "赌博需要耗用" + useinfo.Run_Name[i] + "<font class=\"byts\">" + useinfo.Run_Value[i] + "</font>,<br />而你的" + useinfo.Run_Name[i] + "不够!";
								this.gameimg.Visible = false;
								return;
							}
						}
					}
					dr.Close();
					this.gameimg.Visible = true;
					System.Random MyRan = new System.Random();
					string dostr = "";
					switch (MyRan.Next(0,3))
					{
						case 0://机器剪刀
						switch (selectint)
						{
							case 0:
								this.gamemsg.Text = "你们想到一块了!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/4.gif";
								break;
							case 1://我石头
								this.gamemsg.Text = "你的石头砸了电脑的剪刀!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/3.gif";
								dostr = "+";
								break;
							default://我布
								this.gamemsg.Text = "电脑的剪刀剪了你的布!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/2.gif";
								dostr = "-";
								break;
						}
							break;
						case 1://机器石头
						switch (selectint)
						{
							case 0://我剪刀
								this.gamemsg.Text = "电脑的石头砸了你的剪刀!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/3.gif";
								dostr = "-";
								break;
							case 1:
								this.gamemsg.Text = "你们想到一块了!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/4.gif";
								break;
							default:
								this.gamemsg.Text = "你的布包住了电脑的石头!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/1.gif";
								dostr = "+";
								break;
						}
							break;
						default://机器布
						switch (selectint)
						{
							case 0:
								this.gamemsg.Text = "你的剪刀剪了电脑的布!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/2.gif";
								dostr = "+";
								break;
							case 1:
								this.gamemsg.Text = "电脑的布包住了你的石头!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/1.gif";
								dostr = "-";
								break;
							default:
								this.gamemsg.Text = "你们想到一块了!";
								this.gameimg.ImageUrl = "../xajhimg/bet/game1/4.gif";
								break;
						}
							break;
					}
					if (useinfo.sql != "")
					{
						if (dostr != "")
						{
							this.gamemsg.Text += "<br />(赢<font class=\"byts\">" + upv + "</font>两)";
							MyComm.CommandText = @"update [注册用户] set " + useinfo.sql + "[银两]=[银两]" + dostr + upv + " where [id]=" + info.DataID;
							MyComm.ExecuteNonQuery();
						}
						else
						{
							MyComm.CommandText = @"update [注册用户] set " + useinfo.sql.Substring(0, useinfo.sql.Length - 1) + " where [id]=" + info.DataID;
							MyComm.ExecuteNonQuery();
						}
					}
					else
					{
						if (dostr != "")
						{
							this.gamemsg.Text += "<br />(赢<font class=\"byts\">" + upv + "</font>两)";
							MyComm.CommandText = @"update [注册用户] set [银两]=[银两]" + dostr + upv + " where [id]=" + info.DataID;
							MyComm.ExecuteNonQuery();
						}
					}
					MyConn.Close();
					MyConn.Dispose();
				}
				else
				{
					dr.Close();
					MyConn.Close();
					MyConn.Dispose();
					this.gamemsg.Text = "必须符合 " + useinfo.CheckIn + " 才能赌博!";
					this.gameimg.Visible = false;
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -