中国象棋(代码).doc_第1页
中国象棋(代码).doc_第2页
中国象棋(代码).doc_第3页
中国象棋(代码).doc_第4页
中国象棋(代码).doc_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

中国象棋(web版 源代码)程序:using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;namespace WebApplication1 public partial class WebForm1 : System.Web.UI.Page int tru = 20; int fals = 40; public ImageButton, _Image=new ImageButton11,10; /将上一次点击点的坐标保存到数据库中的lastx和lasty public void SaveToLast() if (Sessionuser.ToString() = red & _GetUserState(Sessionuser.ToString() = 20) int x, y, lastx, lasty; x = Getpointx(); y = Getpointy(); lastx = x; lasty = y; Updatalastx(lastx); Updatalasty(lasty); if (Sessionuser.ToString() = black & _GetUserState(Sessionuser.ToString() = 20) int x, y, lastx, lasty; x = Getpointx(); y = Getpointy(); lastx = x; lasty = y; Updatalastx(lastx); Updatalasty(lasty); /将棋盘上所有棋子图片显示到棋盘上 private void _Drawqizi() /_Init(); int i,j,k; if (_GetUserState(red) != 0 & _GetUserState(black) != 0) if (Sessionuser.ToString() = red) for (i = 1; i = 10; i+) for (j = 1; j = 9; j+) k = _GetDataQipan(i, j); _Imagei, j.ImageUrl = _GetImageAdd(k); if (Sessionuser.ToString() = black) for (i = 1; i = 10; i+) for (j = 1; j = 9; j+) k = _GetDataQipan(i, j); _Image11 - i, 10 - j.ImageUrl = _GetImageAdd(k); /初始化:对_Image,赋值,对ImageButton进行编号 private void _Init() _Image1, 1 = ImageButton1; _Image1, 2 = ImageButton2; _Image1, 3 = ImageButton3; _Image1, 4 = ImageButton4; _Image1, 5 = ImageButton5; _Image1, 6 = ImageButton6; _Image1, 7 = ImageButton7; _Image1, 8 = ImageButton8; _Image1, 9 = ImageButton9; _Image2, 1 = ImageButton11; _Image2, 2 = ImageButton12; _Image2, 3 = ImageButton13; _Image2, 4 = ImageButton14; _Image2, 5 = ImageButton15; _Image2, 6 = ImageButton16; _Image2, 7 = ImageButton17; _Image2, 8 = ImageButton18; _Image2, 9 = ImageButton19; _Image3, 1 = ImageButton21; _Image3, 2 = ImageButton22; _Image3, 3 = ImageButton23; _Image3, 4 = ImageButton24; _Image3, 5 = ImageButton25; _Image3, 6 = ImageButton26; _Image3, 7 = ImageButton27; _Image3, 8 = ImageButton28; _Image3, 9 = ImageButton29; _Image4, 1 = ImageButton31; _Image4, 2 = ImageButton32; _Image4, 3 = ImageButton33; _Image4, 4 = ImageButton34; _Image4, 5 = ImageButton35; _Image4, 6 = ImageButton36; _Image4, 7 = ImageButton37; _Image4, 8 = ImageButton38; _Image4, 9 = ImageButton39; _Image5, 1 = ImageButton41; _Image5, 2 = ImageButton42; _Image5, 3 = ImageButton43; _Image5, 4 = ImageButton44; _Image5, 5 = ImageButton45; _Image5, 6 = ImageButton46; _Image5, 7 = ImageButton47; _Image5, 8 = ImageButton48; _Image5, 9 = ImageButton49; _Image6, 1 = ImageButton51; _Image6, 2 = ImageButton52; _Image6, 3 = ImageButton53; _Image6, 4 = ImageButton54; _Image6, 5 = ImageButton55; _Image6, 6 = ImageButton56; _Image6, 7 = ImageButton57; _Image6, 8 = ImageButton58; _Image6, 9 = ImageButton59; _Image7, 1 = ImageButton61; _Image7, 2 = ImageButton62; _Image7, 3 = ImageButton63; _Image7, 4 = ImageButton64; _Image7, 5 = ImageButton65; _Image7, 6 = ImageButton66; _Image7, 7 = ImageButton67; _Image7, 8 = ImageButton68; _Image7, 9 = ImageButton69; _Image8, 1 = ImageButton71; _Image8, 2 = ImageButton72; _Image8, 3 = ImageButton73; _Image8, 4 = ImageButton74; _Image8, 5 = ImageButton75; _Image8, 6 = ImageButton76; _Image8, 7 = ImageButton77; _Image8, 8 = ImageButton78; _Image8, 9 = ImageButton79; _Image9, 1 = ImageButton81; _Image9, 2 = ImageButton82; _Image9, 3 = ImageButton83; _Image9, 4 = ImageButton84; _Image9, 5 = ImageButton85; _Image9, 6 = ImageButton86; _Image9, 7 = ImageButton87; _Image9, 8 = ImageButton88; _Image9, 9 = ImageButton89; _Image10, 1 = ImageButton91; _Image10, 2 = ImageButton92; _Image10, 3 = ImageButton93; _Image10, 4 = ImageButton94; _Image10, 5 = ImageButton95; _Image10, 6 = ImageButton96; _Image10, 7 = ImageButton97; _Image10, 8 = ImageButton98; _Image10, 9 = ImageButton99; int i, j; for (i = 1; i = 10; i+) for (j = 1; j = 9; j+) _Imagei, j.ImageUrl = /image/back.gif; /初始化棋盘,将两方棋子放好位 private void _InitQizi() int i = 0, j = 0, k = 0; int initqipandata = new int37; for (i = 1; i = 10; i+) for (j = 1; j = 9; j+) _UpdataQipan(i, j, k); for (i = 0; i = 36; i+) initqipandatai = i; _UpdataQipan(1, 1, initqipandata8); _UpdataQipan(1, 2, initqipandata6); _UpdataQipan(1, 3, initqipandata4); _UpdataQipan(1, 4, initqipandata2); _UpdataQipan(1, 5, initqipandata1); _UpdataQipan(1,6, initqipandata3); _UpdataQipan(1, 7, initqipandata5); _UpdataQipan(1, 8, initqipandata7); _UpdataQipan(1, 9, initqipandata9); _UpdataQipan(3, 2, initqipandata10); _UpdataQipan(3, 8, initqipandata11); _UpdataQipan(4, 1, initqipandata12); _UpdataQipan(4, 3, initqipandata13); _UpdataQipan(4, 5, initqipandata14); _UpdataQipan(4, 7, initqipandata15); _UpdataQipan(4, 9, initqipandata16); _UpdataQipan(10, 1, initqipandata28); _UpdataQipan(10, 2, initqipandata26); _UpdataQipan(10, 3, initqipandata24); _UpdataQipan(10, 4, initqipandata22); _UpdataQipan(10, 5, initqipandata21); _UpdataQipan(10, 6, initqipandata23); _UpdataQipan(10, 7, initqipandata25); _UpdataQipan(10, 8, initqipandata27); _UpdataQipan(10, 9, initqipandata29); _UpdataQipan(8, 2, initqipandata30); _UpdataQipan(8, 8, initqipandata31); _UpdataQipan(7, 1, initqipandata32); _UpdataQipan(7, 3, initqipandata33); _UpdataQipan(7, 5, initqipandata34); _UpdataQipan(7, 7, initqipandata35); _UpdataQipan(7, 9, initqipandata36); /获取棋子图片地址 private string _GetImageAdd(int xxx) string x= ; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select add_image from qizi where(no_qizi=+xxx+);, myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() x = sradd_image.ToString(); /Sessionadd_image = x; myconn.Close(); return x; /获取点击后的图片地址 private string _GetImageDownAdd(int xxx) string x =; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select add_image_down from qizi where(no_qizi= + xxx + ), myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() x = sradd_image_down.ToString(); myconn.Close(); return x; /读取鼠标点击点的坐标 private int Getpointx() int x = 0; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select x from zuobiao, myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() x = int.Parse(srx.ToString(); myconn.Close(); return x; private int Getpointy( ) int x = 0; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select y from zuobiao, myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() x = int.Parse(sry.ToString(); myconn.Close(); return x; private int Getpointlastx( ) int x = 0; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select lastx from zuobiao, myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() x = int.Parse(srlastx.ToString(); myconn.Close(); return x; private int Getpointlasty( ) int x = 0; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select lasty from zuobiao, myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() x = int.Parse(srlasty.ToString(); myconn.Close(); return x; /写入鼠标点击点的坐标 private void Updatax(int xxx) SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(update zuobiao set x= + xxx + , myconn); myconn.Open(); int aa = cmd.ExecuteNonQuery(); myconn.Close(); private void Updatay(int yyy) SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(update zuobiao set y= + yyy + , myconn); myconn.Open(); int aa = cmd.ExecuteNonQuery(); myconn.Close(); private void Updatalastx(int lastxxx) SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(update zuobiao set lastx= + lastxxx + , myconn); myconn.Open(); int aa = cmd.ExecuteNonQuery(); myconn.Close(); private void Updatalasty(int lastyyy) SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(update zuobiao set lasty= + lastyyy +, myconn); myconn.Open(); int aa = cmd.ExecuteNonQuery(); myconn.Close(); /以上四个函数的集合,达到一次写入四个坐标值的目的 private void _UpdataaZuobiao(int xxx, int yyy, int lastxxx, int lastyyy) Updatax(xxx); Updatay(yyy); Updatalastx(lastxxx); Updatalasty(lastyyy); /保存当前坐标值到x和y private void _UpdatZuobiaoXY(int xxx, int yyy) if (Sessionuser.ToString() = red & _GetUserState(Sessionuser.ToString() = 20) Updatax(xxx); Updatay(yyy); if (Sessionuser.ToString() = black & _GetUserState(Sessionuser.ToString() = 20) Updatax(xxx); Updatay(yyy); /读取棋盘上的棋子信息 private int _GetDataQipan(int xxx, int yyy) int i,data=0; i = (xxx - 1) * 9 + yyy; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select data_qipan from qipan where(position=+i+), myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() data = int.Parse(srdata_qipan.ToString(); myconn.Close(); return data; /将棋子信息写入棋盘 private void _UpdataQipan(int xxx, int yyy,int data) int i; i = (xxx - 1) * 9 + yyy; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(update qipan set data_qipan= + data + where (position=+i+), myconn); myconn.Open(); int aa = cmd.ExecuteNonQuery(); myconn.Close(); /读出用户此时状态 private int _GetUserState(string id) int data = 0; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select state from yonghu where(id= + id + ), myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() data = int.Parse(srstate.ToString(); myconn.Close(); return data; /读出用户输赢状态 0表示在进行游戏 20表示赢 40表示输 private int _GetUserWin(string id) int data = 0; SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(select winner from yonghu where(id= + id + ), myconn); myconn.Open(); SqlDataReader sr = cmd.ExecuteReader(); if (sr.Read() data = int.Parse(srwinner.ToString(); myconn.Close(); return data; /写入用户状态 private void _UpdataUserState(string id,int sta) SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(update yonghu set state= + sta + where (id= + id + ), myconn); myconn.Open(); int aa = cmd.ExecuteNonQuery(); myconn.Close(); /写入用户输赢状态 0表示在进行游戏 20表示赢 40表示输 private void _UpdataUserWin(string id, int sta) SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStringsSQLCONNECTIONSTRING.ConnectionString); SqlCommand cmd = new SqlCommand(update yonghu set winner= + sta + where (id= + id + ), myconn); myconn.Open(); int aa = cmd.ExecuteNonQuery(); myconn.Close(); protected void Page_Load(object sender, EventArgs e) _Init(); / _Test(); /测试程序函数 private void _Test() _UpdataUserState(red,tru); _UpdataUserState(black, tru); private bool _IsAbl

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论