
南开大学滨海学院
计算机科学系
课 程 设 计 报 告
课题名称:苹果风格 Java 网络
对战五子棋程序设计
系 别: 计算机科学系
专 业: 影视动画
年 级: 09 级
姓 名: 雷天音
学 号: 09990228
指导老师: 刘嘉欣
完成日期: 2012 年 1 月 4 日

南开大学滨海学院计算机科学系课程设计报告 - 1 -
1
设计论文诚信声明
本人郑重声明:所提交的论文内容,是本人在指导老师的指导下,独立进行研究工作
取得的结果,除本文中已经标注的引用内容外,本文不含有任何其他人以发表的作品成果。
本人完全了解本声明的法律责任由本人承担。
论文作者:雷天音
签名:
日期: 年 月 日

南开大学滨海学院计算机科学系课程设计报告 - 2 -
2
摘 要
五子棋是一种两人对弈的纯策略型棋类游戏,是起源于中国古代的传统黑白棋种之
一。发展于日本,流行于欧美。容易上手,老少皆宜,而且趣味横生,引人入胜;不仅能
增强思维能力,提高智力,而且富含哲理,有助于修身养性。在熟悉了五子棋的规则和特
点之后,决定用 Java 开发五子棋游戏。主要完成了在单机上两人对战和两个玩家之间联
网对战两个功能。程序采用 MVC+N+TG 框架(即 Model-View-Control + Net +
Thread Group)。 Control 负责程序的初始化及所有管理工作。网络连接部分(Net)为
Socket 编程应用,建立连接时分客户端和服务器端,一旦连接成功建立,网络两端程序
即处于平等状态,通过 TCP 协议传输字符串格式的事先定义好的协议,协议有很强扩展性。
同时在程序中有很多服务于主程序的线程,用来完成计时、播放音乐、回顾棋局等功能。
在游戏界面的美工上仿照了苹果风格,简洁大方,清晰明了。
关键词:五子棋, 游戏, 对战, 网络

南开大学滨海学院计算机科学系课程设计报告 - 3 -
3
Abstract
Gobang is a kind of chess game that needs two players with strategies. It was
formed in the ancient Chinese tradition of one of reversi. It was developed in
Japan, and is popular in Europe and the United states. It’s easy to use, suitable
for all ages, and interesting, fascinating; can not only enhance the thinking
ability, improve our intelligence, and rich in philosophy, contribute to
self-cultivation. Having been familiar with gobang rules and the characteristics,
I decided to use Java to develop Gobang game. Mainly completed in the single
two battle and two game player between networked battle of two functions.
The program using the MVC+N+TG framework (Model-View-Control + Net +
ThreadGroup). Control is responsible for the initialization procedure and
management work. Network connecting part ( Net ) for the Socket application
programming, establish the connection when the client and server side, once
the connection is established, the web ends procedure in equal status, through
the TCP protocol to transmit the string format of a pre-defined protocol,
protocol has high expansibility. At the same time in the program has many
services in the main thread, used to complete the time, playing music, game
reviewing function. The game interface design was modeled on the Apple style,
generous concise and clear.
Keywords : Gobang Online Game JAVA

南开大学滨海学院计算机科学系课程设计报告 - 4 -
4
目录
摘 要 .............................................................................................................................................. 2
Abstract ............................................................................................................................................. 3
第一章 概述...................................................................................................................................... 6
1.1 背景介绍.............................................................................................................................. 6
1.1.1 五子棋........................................................................................................................ 6
1.1.2 我与 JAVA .................................................................................................................. 7
1.2 本文的组织结构 .................................................................................................................... 7
第二章 主要技术及使用原因介绍 .................................................................................................... 8
2.1. Java...................................................................................................................................... 8
2.1.1 JAVA 的起源与发展 ..................................................................................................... 8
2.1.2 Java 的特性 ................................................................................................................. 9
2.1.3 JAVA 与 C++的差异 ....................................................................................................10
2.2 Eclipse............................................................................................................................... 11
2.3 MVC 程序构架 ..................................................................................................................... 11
第三章 设计 ...................................................................................................................................13
3.1 游戏整体功能设计................................................................................................................13
3.1.1 MVC-N-TG 结构.........................................................................................................13
3.2.游戏界面整体布局设计.........................................................................................................14
3.2.1 设计草图 ...................................................................................................................14
3.2.2 预加载窗口................................................................................................................14
第 四 章 具体实现方法................................................................................................................15
4.1 control 包............................................................................................................................15
4.1.1 Control 类 ...................................................................................................................15
4.1.2 GetTime 类 .................................................................................................................17
4.1.3 Reviewer 类 ................................................................................................................17
4.1.4 Timer 类 .....................................................................................................................17
4.2 model 包 ..............................................................................................................................18
4.2.1 ChessModel 类 ............................................................................................................18
4.3 view 包 ................................................................................................................................18
4.3.1 App 类........................................................................................................................19
4.3.2 MyPanel 类 .................................................................................................................19
4.3.3 Preview 类 ..................................................................................................................19
4.4 save 包 .................................................................................................................................20
4.4.1 SaveGame 类 ..............................................................................................................20