软著申请源代码.docx

上传人:b****4 文档编号:27238732 上传时间:2023-06-28 格式:DOCX 页数:109 大小:35.28KB
下载 相关 举报
软著申请源代码.docx_第1页
第1页 / 共109页
软著申请源代码.docx_第2页
第2页 / 共109页
软著申请源代码.docx_第3页
第3页 / 共109页
软著申请源代码.docx_第4页
第4页 / 共109页
软著申请源代码.docx_第5页
第5页 / 共109页
点击查看更多>>
下载资源
资源描述

软著申请源代码.docx

《软著申请源代码.docx》由会员分享,可在线阅读,更多相关《软著申请源代码.docx(109页珍藏版)》请在冰豆网上搜索。

软著申请源代码.docx

软著申请源代码

前言

围棋不仅能增强思维能力,提高智力,而且富含哲理,有助于修身养性。

同时它起源于中国,古称“弈”,是我国传统技艺之一。

本游戏软件提供了人机对弈,和棋手对弈(局域网对弈)两种模式,局域网模式可以保证多人同时进行游戏。

本软件使用C#语言编写,在windows7x64系统下采用VisualStudio2010开发和调试,附源码如下。

客户端程序:

//-------------------login.cs---------//

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

namespacego

{

publicpartialclassLogin:

Form

{

publicLogin()

{

InitializeComponent();

}

//人机对弈

privatevoidbutton1_Click(objectsender,EventArgse)

{

this.Hide();

Playingplaying=newPlaying();

playing.ShowDialog();

this.Show();

}

//局域网对弈

privatevoidbutton2_Click(objectsender,EventArgse)

{

this.Hide();

FormRoomformroom=newFormRoom();

formroom.ShowDialog();

this.Show();

}

privatevoidbutton3_Click(objectsender,EventArgse)

{

Application.Exit();

}

privatevoidbutton3_MouseEnter(objectsender,EventArgse)

{

Buttonbtn=(Button)sender;

btn.ForeColor=Color.Black;

btn.BackColor=Color.White;

}

privatevoidbutton3_MouseLeave(objectsender,EventArgse)

{

Buttonbtn=(Button)sender;

btn.ForeColor=Color.White;

btn.BackColor=Color.Black;

}

}

}

}

//-------------------Playing.cs---------//

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

namespacego

{

publicpartialclassPlaying:

Form

{

delegatevoidSetTextCallback(stringtext);

privateenumStatus

{

NotStarted=0,

InGame=1,

RemoveDead=2,

FillEmpty=3,

Ended=4

}

privateSystem.Threading.Threadpc_play;

privateBoardm_board=newBoard();

privateChess.ChessTypem_turn=Chess.ChessType.Black;

privateintm_secondsBlack=0;

privateintm_secondsWhite=0;

privateTimerm_timer=newTimer();

privateStatusm_status=Status.NotStarted;

publicChess.ChessTypeturn

{

get

{

returnm_turn;

}

set

{

m_turn=value;

this.SetTurn((m_turn.ToString()=="Black")?

"黑方":

"白方");

}

}

publicPlaying()

{

InitializeComponent();

floath=this.Size.Height-10;

floatw=this.Size.Width-140;

m_board.ReSize(0,0,w,h);

m_timer.Interval=1000;

m_timer.Tick+=newEventHandler(timer_Tick);

TimeSpantm=newTimeSpan(0,0,0);

labelTimeBlack.Text=tm.ToString();

labelTimeWhite.Text=tm.ToString();

labelTurn.Text="黑方";

}

privatevoidSetTurn(stringtext)

{

if(this.labelTurn.InvokeRequired)

{

SetTextCallbackd=newSetTextCallback(SetTurn);

this.Invoke(d,newobject[]{text});

}

else

{

this.labelTurn.Text=text;

}

}

//计时功能

privatevoidtimer_Tick(objectsender,EventArgse)

{

if(turn==Chess.ChessType.Black)

{

m_secondsBlack++;

TimeSpantm=newTimeSpan(0,0,m_secondsBlack);

labelTimeBlack.Text=tm.ToString();

}

elseif(turn==Chess.ChessType.White)

{

m_secondsWhite++;

TimeSpantm=newTimeSpan(0,0,m_secondsWhite);

labelTimeWhite.Text=tm.ToString();

}

if(pc_play!

=null&&!

pc_play.IsAlive)

{

pc_play.Abort();

pc_play.Join();

pc_play=null;

}

}

privatevoidOnFormClicked(objectsender,EventArgse)

{

//棋局结束

if(m_board.isGameOver)

{

this.buttonCalculate_Click(null,null);

m_board.isGameOver=false;

return;

}

//不是轮到黑子的时候禁止下棋

if(!

m_board.single||turn==Chess.ChessType.White)

{

return;

}

//备份棋局

this.m_board.BackupChess();

MouseEventArgsargs=easMouseEventArgs;

if(args!

=null)

{

if(args.Clicks==1&&args.Button==MouseButtons.Left)

{

//计算鼠标点击的坐标位置

Chess.POSpos=m_board.mapPointsToBoard(args.X,args.Y);

if(pos.isValid)

{

//游戏中

if(m_status==Status.NotStarted||m_status==Status.InGame)

{

if(m_board.addChess(pos,turn))

{

turn=(turn==Chess.ChessType.Black)?

Chess.ChessType.White:

Chess.ChessType.Black;

if(m_status==Status.NotStarted)

{

m_timer.Start();

m_status=Status.InGame;

}

Invalidate();

}

}

if(m_status==Status.RemoveDead)

{

m_board.toggleDead(pos);

Invalidate();

}

if(m_board.single)//人机对弈模式

{

pc_play=newSystem.Threading.Thread(newSystem.Threading.ThreadStart(ComputerPlay));

pc_play.Start();

}

}

}

}

}

delegatevoidButtonDelegate(Buttonbtn,boolflag);

privatevoidSetButton(Buttonbtn,boolflag)

{

if(btn.InvokeRequired)

{

ButtonDelegatebuttonDelegate=newButtonDelegate(SetButton);

this.Invoke(buttonDelegate,newobject[]{btn,flag});

}

else

{

btn.Enabled=flag;

}

}

privatevoidComputerPlay()

{

//计算下一步棋

Chess.POSpos=m_board.Play(2,turn);

if(m_board.addChess(pos,turn))

{

turn=(turn==Chess.ChessType.Black)?

Chess.ChessType.White:

Chess.ChessType.Black;

if(m_status==Status.NotStarted)

{

m_timer.Start();

m_status=Status.InGame;

}

Invalidate();

}

else

{

//计算棋局结果

m_status=Status.FillEmpty;

m_board.fillBoardWithChess();

stringstrResult=m_board.caclulateResult();

m_board.removeFilledChess();

MessageBox.Show(strResult,"结果");

m_board.single=false;

this.SetButton(this.btnCalc,false);

this.SetButton(this.btnLetOtherGo,false);

this.SetButton(this.btnAgain,false);

this.m_timer.Stop();

Invalidate();

}

}

//显示棋子序号

privatevoidcheckBoxShowNumber_CheckedChanged(objectsender,EventArgse)

{

m_board.showIndex=checkBoxShowNumber.Checked;

Invalidate();

}

//让子功能

privatevoidbuttonLetOtherGo_Click(objectsender,EventArgse)

{

if(this.turn==Chess.ChessType.Black)

{

turn=Chess.oppsiteType(turn);

if(m_board.single)

{

pc_play=newSystem.Threading.Thread(newSystem.Threading.ThreadStart(ComputerPlay));

pc_play.Start();

}

}

}

//求和功能

privatevoidbuttonCalculate_Click(objectsender,EventArgse)

{

m_status=Status.FillEmpty;

m_board.fillBoardWithChess();

stringstrResult=m_board.caclulateResult();

m_board.removeFilledChess();

MessageBox.Show(strResult,"结果");

m_board.single=false;

this.btnCalc.Enabled=false;

this.btnLetOtherGo.Enabled=false;

this.btnAgain.Enabled=false;

this.m_timer.Stop();

Invalidate();

}

//开始游戏

privatevoidbtnStart_Click(objectsender,EventArgse)

{

DialogResultresult=MessageBox.Show("确定要开始新游戏吗?

","新游戏",MessageBoxButtons.YesNo);

if(result==DialogResult.Yes)

{

m_board.newGame();

m_board.single=true;//人机对弈

m_secondsBlack=0;

m_secondsWhite=0;

TimeSpantm=newTimeSpan(0,0,0);

labelTimeBlack.Text=tm.ToString();

labelTimeWhite.Text=tm.ToString();

turn=Chess.ChessType.Black;

m_timer.Stop();

m_board.markAllChessAsLive();

m_status=Status.NotStarted;

this.btnCalc.Enabled=true;

this.btnLetOtherGo.Enabled=true;

this.btnAgain.Enabled=true;

Invalidate();

}

}

//退出功能

privatevoidMainForm_FormClosing(objectsender,FormClosingEventArgse)

{

DialogResultresult=MessageBox.Show("你确认要退出游戏吗?

","提示",MessageBoxButtons.YesNo);

if(result==DialogResult.No)

{

e.Cancel=true;

}

}

//主窗口大小

privatevoidMainForm_SizeChanged(objectsender,EventArgse)

{

floath=this.Size.Height-10;

floatw=this.Size.Width-140;

m_board.ReSize(0,0,w,h);

Invalidate();

}

//画棋盘

protectedoverridevoidOnPaint(PaintEventArgse)

{

Graphicsg=e.Graphics;

m_board.draw(g);

}

privatevoidbtnClose_Click(objectsender,EventArgse)

{

this.Close();

}

//悔棋功能

privatevoidbtnAgain_Click(objectsender,EventArgse)

{

if(this.m_board.MoveAgain())

{

Invalidate();

}

}

}

}

//------------------Board.cs---------//

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingSystem.Drawing;

usingSystem.IO;

usingChessBlock=System.Collections.ArrayList;

usingSystem.Collections;

namespacego

{

///

///棋盘

///

publicclassBoard

{

///

///单人模式

///

publicboolsingle=false;

///

///距离上方边缘的单位长度

///

privatestaticfloatmargin_top=10;

///

///距离左方边缘的单位长度

///

privatestaticfloatmargin_left=10;

///

///棋盘每条线之间的单位长度

///

privatestaticfloatgap=20;

///

///棋子大小

///

privatestaticfloatchessSize=8;

///

///数字字体大小

///

privatestaticfloatnumberSize=6;

///

///星位的大小

///

privatestaticfloatstarSize=3;

///

///棋盘的所有棋子

///

privateChess[,]m_Board=newChess[19,19];

///

///棋盘备份

///

privateChess[,]m_Board_backup=newChess[19,19];

///

///棋局记录对象

///

privateBoardRecorderm_recorder;

///

///最后一颗棋子

///

privateChessm_LastChess;

///

///最后一个棋子备份

///

privateChessm_LastChess_backup;

///

///最后一颗被吃的棋子

///

privateChessm_LastEatten;

///

///最后被吃棋子备份

///

privateChessm_LastEatten_backup;

///

///当前步数

///

privateintm_currentStep;

///

///是否显示棋子的编号

///

privateboolm_bShowIndex=false;

///

///模拟棋盘

///

privateChess[,]m_Sim_Board=newChess[19,19];

///

///模拟最后一颗棋子

///

privateChessm_Sim_LastChess;

///

///模拟最后一颗被吃的棋子

///

privateChessm_Sim_LastEatten;

///

///模拟当前步数

///

privateintm_Sim_currentStep;

///

///参数随机数,用于参数随机棋步

///

privateRandomr=newRandom();

///

///棋局结束

///

publicboolisGameOver=false;

///

///创建棋盘

///

publicBoard()

{

Clear();

}

///

///获取最后一颗

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 可爱清新

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1