软著申请源代码.doc

上传人:李医生 文档编号:7226642 上传时间:2020-11-07 格式:DOC 页数:99 大小:298.01KB
返回 下载 相关 举报
软著申请源代码.doc_第1页
第1页 / 共99页
软著申请源代码.doc_第2页
第2页 / 共99页
软著申请源代码.doc_第3页
第3页 / 共99页
软著申请源代码.doc_第4页
第4页 / 共99页
软著申请源代码.doc_第5页
第5页 / 共99页
点击查看更多>>
资源描述

《软著申请源代码.doc》由会员分享,可在线阅读,更多相关《软著申请源代码.doc(99页珍藏版)》请在三一文库上搜索。

1、前言 围棋不仅能增强思维能力,提高智力,而且富含哲理,有助于修身养性。同时它起源于中国,古称“弈”,是我国传统技艺之一。本游戏软件提供了人机对弈,和棋手对弈(局域网对弈)两种模式,局域网模式可以保证多人同时进行游戏。本软件使用C#语言编写,在windows 7 x64系统下采用Visual Studio 2010开发和调试,附源码如下。客户端程序:/-login.cs-/using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;

2、using System.Text;using System.Windows.Forms;namespace go public partial class Login : Form public Login() InitializeComponent(); /人机对弈 private void button1_Click(object sender, EventArgs e) this.Hide(); Playing playing = new Playing(); playing.ShowDialog(); this.Show(); /局域网对弈 private void button2_

3、Click(object sender,EventArgs e) this.Hide(); FormRoom formroom = new FormRoom(); formroom.ShowDialog(); this.Show(); private void button3_Click(object sender, EventArgs e) Application.Exit(); private void button3_MouseEnter(object sender, EventArgs e) Button btn = (Button)sender; btn.ForeColor = Co

4、lor.Black; btn.BackColor = Color.White; private void button3_MouseLeave(object sender, EventArgs e) Button btn = (Button)sender; btn.ForeColor = Color.White; btn.BackColor = Color.Black; /-Playing.cs-/using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using S

5、ystem.Drawing;using System.Text;using System.Windows.Forms;namespace go public partial class Playing : Form delegate void SetTextCallback(string text); private enum Status NotStarted = 0, InGame = 1, RemoveDead = 2, FillEmpty = 3, Ended = 4 private System.Threading.Thread pc_play; private Board m_bo

6、ard = new Board(); private Chess.ChessType m_turn = Chess.ChessType.Black; private int m_secondsBlack = 0; private int m_secondsWhite = 0; private Timer m_timer = new Timer(); private Status m_status = Status.NotStarted; public Chess.ChessType turn get return m_turn; set m_turn = value; this.SetTurn

7、(m_turn.ToString() = Black) ? 黑方 : 白方); public Playing() InitializeComponent(); float h = this.Size.Height - 10; float w = this.Size.Width - 140; m_board.ReSize(0, 0, w, h); m_timer.Interval = 1000; m_timer.Tick += new EventHandler(timer_Tick); TimeSpan tm = new TimeSpan(0, 0, 0); labelTimeBlack.Tex

8、t = tm.ToString(); labelTimeWhite.Text = tm.ToString(); labelTurn.Text = 黑方; private void SetTurn(string text) if (this.labelTurn.InvokeRequired) SetTextCallback d = new SetTextCallback(SetTurn); this.Invoke(d, new object text ); else this.labelTurn.Text = text; /计时功能 private void timer_Tick(object

9、sender, EventArgs e) if (turn = Chess.ChessType.Black) m_secondsBlack+; TimeSpan tm = new TimeSpan(0, 0, m_secondsBlack); labelTimeBlack.Text = tm.ToString(); else if (turn = Chess.ChessType.White) m_secondsWhite+; TimeSpan tm = new TimeSpan(0, 0, m_secondsWhite); labelTimeWhite.Text = tm.ToString()

10、; if (pc_play != null & !pc_play.IsAlive) pc_play.Abort(); pc_play.Join(); pc_play = null; private void OnFormClicked(object sender, EventArgs e) /棋局结束 if (m_board.isGameOver) this.buttonCalculate_Click(null, null); m_board.isGameOver = false; return; /不是轮到黑子的时候禁止下棋 if (!m_board.single | turn = Ches

11、s.ChessType.White) return; /备份棋局 this.m_board.BackupChess(); MouseEventArgs args = e as MouseEventArgs; if (args != null) if (args.Clicks = 1 & args.Button = MouseButtons.Left) / 计算鼠标点击的坐标位置 Chess.POS pos = m_board.mapPointsToBoard(args.X, args.Y); if (pos.isValid) / 游戏中 if (m_status = Status.NotSta

12、rted | 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)

13、; Invalidate(); if (m_board.single)/人机对弈模式 pc_play = new System.Threading.Thread(new System.Threading.ThreadStart(ComputerPlay); pc_play.Start(); delegate void ButtonDelegate(Button btn, bool flag); private void SetButton(Button btn, bool flag) if (btn.InvokeRequired) ButtonDelegate buttonDelegate =

14、 new ButtonDelegate(SetButton); this.Invoke(buttonDelegate, new object btn, flag ); else btn.Enabled = flag; private void ComputerPlay() /计算下一步棋 Chess.POS pos = m_board.Play(2, turn); if (m_board.addChess(pos, turn) turn = (turn = Chess.ChessType.Black) ? Chess.ChessType.White : Chess.ChessType.Blac

15、k; if (m_status = Status.NotStarted) m_timer.Start(); m_status = Status.InGame; Invalidate(); else /计算棋局结果 m_status = Status.FillEmpty; m_board.fillBoardWithChess(); string strResult = m_board.caclulateResult(); m_board.removeFilledChess(); MessageBox.Show(strResult, 结果); m_board.single = false; thi

16、s.SetButton (this.btnCalc, false); this.SetButton (this.btnLetOtherGo, false); this.SetButton (this.btnAgain, false); this.m_timer.Stop(); Invalidate(); /显示棋子序号 private void checkBoxShowNumber_CheckedChanged(object sender, EventArgs e) m_board.showIndex = checkBoxShowNumber.Checked; Invalidate(); /让

17、子功能 private void buttonLetOtherGo_Click(object sender, EventArgs e) if (this.turn = Chess.ChessType.Black) turn = Chess.oppsiteType(turn); if (m_board.single) pc_play = new System.Threading.Thread(new System.Threading.ThreadStart(ComputerPlay); pc_play.Start(); /求和功能 private void buttonCalculate_Cli

18、ck(object sender, EventArgs e) m_status = Status.FillEmpty; m_board.fillBoardWithChess(); string strResult = m_board.caclulateResult(); m_board.removeFilledChess(); MessageBox.Show(strResult, 结果); m_board.single = false; this.btnCalc.Enabled = false; this.btnLetOtherGo.Enabled = false; this.btnAgain

19、.Enabled = false; this.m_timer.Stop(); Invalidate(); /开始游戏 private void btnStart_Click(object sender, EventArgs e) DialogResult result = MessageBox.Show(确定要开始新游戏吗?, 新游戏, MessageBoxButtons.YesNo); if (result = DialogResult.Yes) m_board.newGame(); m_board.single = true;/人机对弈 m_secondsBlack = 0; m_seco

20、ndsWhite = 0; TimeSpan tm = new TimeSpan(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.

21、btnAgain.Enabled = true; Invalidate(); /退出功能 private void MainForm_FormClosing(object sender, FormClosingEventArgs e) DialogResult result = MessageBox.Show(你确认要退出游戏吗?, 提示, MessageBoxButtons.YesNo); if (result = DialogResult.No) e.Cancel = true; /主窗口大小 private void MainForm_SizeChanged(object sender,

22、 EventArgs e) float h = this.Size.Height - 10; float w = this.Size.Width - 140; m_board.ReSize(0, 0, w, h); Invalidate(); /画棋盘 protected override void OnPaint(PaintEventArgs e) Graphics g = e.Graphics; m_board.draw(g); private void btnClose_Click(object sender, EventArgs e) this.Close(); /悔棋功能 priva

23、te void btnAgain_Click(object sender, EventArgs e) if (this.m_board.MoveAgain() Invalidate(); /-Board.cs-/using System;using System.Collections.Generic;using System.Text;using System.Drawing;using System.IO;using ChessBlock = System.Collections.ArrayList;using System.Collections;namespace go / / 棋盘

24、/ public class Board / / 单人模式 / public bool single = false; / / 距离上方边缘的单位长度 / private static float margin_top = 10; / / 距离左方边缘的单位长度 / private static float margin_left = 10; / / 棋盘每条线之间的单位长度 / private static float gap = 20; / / 棋子大小 / private static float chessSize = 8; / / 数字字体大小 / private static fl

25、oat numberSize = 6; / / 星位的大小 / private static float starSize = 3; / / 棋盘的所有棋子 / private Chess, m_Board = new Chess19, 19; / / 棋盘备份 / private Chess, m_Board_backup = new Chess19, 19; / / 棋局记录对象 / private BoardRecorder m_recorder; / / 最后一颗棋子 / private Chess m_LastChess; / / 最后一个棋子备份 / private Chess m

26、_LastChess_backup; / / 最后一颗被吃的棋子 / private Chess m_LastEatten; / / 最后被吃棋子备份 / private Chess m_LastEatten_backup; / / 当前步数 / private int m_currentStep; / / 是否显示棋子的编号 / private bool m_bShowIndex = false; / / 模拟棋盘 / private Chess, m_Sim_Board = new Chess19, 19; / / 模拟最后一颗棋子 / private Chess m_Sim_LastCh

27、ess; / / 模拟最后一颗被吃的棋子 / private Chess m_Sim_LastEatten; / / 模拟当前步数 / private int m_Sim_currentStep; / / 参数随机数,用于参数随机棋步 / private Random r = new Random(); / / 棋局结束 / public bool isGameOver = false; / / 创建棋盘 / public Board() Clear(); / / 获取最后一颗棋子 / public Chess lastChess get return m_LastChess; / / 获取或设置是否显示棋子的编号 / public bool showIndex get return m_bShowIndex; set m_bShowIndex = value; / / 调整棋子在棋盘中的位置,并返回棋子的位置 / / / / public Chess.POS mapPointsToBoard(float pointX, floa

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

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1