| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2511 人关注过本帖
标题:自己写的五子棋游戏
只看楼主 加入收藏
moderndai
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2006-1-25
收藏
 问题点数:0 回复次数:17 
自己写的五子棋游戏

学C#一个月左右,写了个五子棋的游戏,还不能进行人机对战,过断时间再修改成IQ版本的
望大家帮我试试,看还有没有错误!谢了!

wGptazbN.rar (5.55 KB) 自己写的五子棋游戏


不好意思好久没上论坛来了,现在就发原码
// ***************************************************************
// Form1 version: 1.0 ? finished date: 03/28/2006
// -------------------------------------------------------------
// Email:espricle@hotmail.com or dai--yl@163.com
// -------------------------------------------------------------
// Copyright (C) 2006 - All Rights Reserved
// ***************************************************************
// made by moderndai
// ***************************************************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

namespace 五子棋
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
int count=0;

Pen bluepen=new Pen(Color.Blue);
SolidBrush brush=new SolidBrush(Color.BlanchedAlmond);
SolidBrush whitebrush=new SolidBrush(Color.White);
SolidBrush blackbrush=new SolidBrush(Color.Black);
private System.Windows.Forms.MenuItem menuItem6;
int[,]xy=new int[15,15];

public void F_QiPan()
{
Graphics g=CreateGraphics();
g.FillRectangle(brush,0,0,700,700);
for (int x_=30;x_<=450;x_+=30)
{
g.DrawLine(bluepen,x_,30,x_,450);
}
for (int y_=30;y_<=450;y_+=30)
{
g.DrawLine(bluepen,30,y_,450,y_);
}
}

public void QiPan()
{
Graphics g=CreateGraphics();
g.FillRectangle(brush,0,0,700,700);
for (int i=0;i<15;i++)
{
for (int j=0;j<15;j++)
{
xy[i,j]=0;
}
}
for (int x_=30;x_<=450;x_+=30)
{
g.DrawLine(bluepen,x_,30,x_,450);
}
for (int y_=30;y_<=450;y_+=30)
{
g.DrawLine(bluepen,30,y_,450,y_);
}
}

public static int XPosition(int x_position)
{
int xx;
if (x_position%30>15)
{
xx=(int)(x_position/30);
x_position=(x_position/30+1)*30;
}
else
{
xx=(int)(x_position/30);
x_position=xx*30;
}
return x_position;
}

public static int YPosition(int y_position)
{
int yy;
if (y_position%30>15)
{
yy=(int)(y_position/30);
y_position=(yy+1)*30;
}
else
{
yy=(int)(y_position/30);
y_position=yy*30;
}
return y_position;
}

public void X_QiZi(int x,int y)
{
Graphics g=CreateGraphics();
x=XPosition(x)/30-1;
y=YPosition(y)/30-1;
if (xy[x,y]==0)
{
if (count==0)
{
count=1;
xy[x,y]=1;
}
else if (count==1)
{
count=0;
xy[x,y]=-1;
}
}
else
return;
}

public void QiZi()
{
int x1,y1;
Graphics g=CreateGraphics();
for (int i=0;i<15;i++)
{
for (int j=0;j<15;j++)
{
x1=30*i+15;
y1=30*j+15;
if (xy[i,j]==1)
{
g.FillEllipse(blackbrush,x1,y1,30,30);
}
else if(xy[i,j]==-1)
{
g.FillEllipse(whitebrush,x1,y1,30,30);
}
}
}
}

public int H_Winner(int num1)
{
num1++;
if (num1>4)
{
MessageBox.Show("黑子获胜,按确定重新开始");
QiPan();
}
return num1;
}

public int B_Winner(int num2)
{
num2++;
if (num2>4)
{
MessageBox.Show("白子获胜,按确定重新开始");
QiPan();
}
return num2;
}

public void Win(int x2,int y2)//嬴的条件
{
x2=XPosition(x2)/30-1;
y2=YPosition(y2)/30-1;
int number1=1,number2=1,number3=1,number4=1;
for (int i=x2,j=y2-4;j<y2+5;j++)//判断所下的子的列有没有5个是一样的
{
if (j<=-1)
{
j=-1;
}
else if (j<15)
{
if (j<14)
{
if(xy[i,j]==xy[i,j+1]&&xy[i,j]!=0)
{
if (xy[i,j]==1)
{
number1=H_Winner(number1);
}
else
{
number1=B_Winner(number1);
}
}
else
number1=1;
}
else
number1=1;
}
else
number1=1;
}

for (int i=x2-5,j=y2;i<x2+4;i++)//判断所下的子的行的有没有5个子连着是一样的
{
if (i<0)
{
i=-1;
}
else if (i<15)
{
if (i<14)
{
if (xy[i,j]==xy[i+1,j]&&xy[i,j]!=0)
{
if (xy[i,j]==1)
{
number2=H_Winner(number2);
}
else
{
number2=B_Winner(number2);
}
}
else
number2=1;
}
else
number2=1;
}
else
number2=1;
}

for (int j=y2-4,i=x2-4;i<x2+5;j++,i++)//判断所下的子斜着的有没有5个连续一样的
{
if (i<=-1||j<=-1)
{
while(i!=-1||j!=-1)
{
i++;
j++;
if (i>=-1&&j>=-1)
{
break;
}
}
}
else if (i>14||j>14)
{
number3=1;
break;
}
else
{
if (i<14&&j<14)
{
if(xy[i,j]==xy[i+1,j+1]&&xy[i,j]!=0)
{
if (xy[i,j]==1)
{
number3=H_Winner(number3);
}
else
{
number3=B_Winner(number3);
}
}
}
else
{
number3=1;
break;
}
}
}

for (int j=y2+4,i=x2-4;i<x2+5;j--,i++)
{
if (i<=-1||j>=15)
{
while (i!=-1||j!=15)
{
i++;
j--;
if(i>=-1&&j<=15)
{
break;
}
}
}
else if(i>14||j<0)
{
number4=1;
break;
}
else
{
if (i<14&&j>0)
{
if(xy[i,j]==xy[i+1,j-1]&&xy[i,j]!=0)
{
if (xy[i,j]==1)
{
number4=H_Winner(number4);
}
else
{
number4=B_Winner(number4);
}
}
else
number4=1;
}
else
{
number4=1;
break;
}
}
}
}

private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2,
this.menuItem6});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem4});
this.menuItem1.Text = "菜单";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "重新开始";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.Text = "退出";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5});
this.menuItem2.Text = "帮助";
//
// menuItem5
//
this.menuItem5.Index = 0;
this.menuItem5.Text = "游戏说明";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem6
//
this.menuItem6.Index = 2;
this.menuItem6.Text = "联系方式";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(692, 645);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void menuItem3_Click(object sender, System.EventArgs e)
{
QiPan();
}

private void Form1_MouseEnter(object sender, System.EventArgs e)
{
F_QiPan();
QiZi();
}

private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.X<15||e.X>465||e.Y<15||e.Y>465)
{
return;
}
else
{
X_QiZi(e.X,e.Y);
QiZi();
Win(e.X,e.Y);
}
}

private void menuItem4_Click(object sender, System.EventArgs e)
{
Application.Exit();
}

private void menuItem5_Click(object sender, System.EventArgs e)
{
MessageBox.Show("\n谁先将自己手中颜色的棋子先连成5个就算嬴\n","游戏说明",MessageBoxButtons.OK,MessageBoxIcon.Information);
}

private void menuItem6_Click(object sender, System.EventArgs e)
{
MessageBox.Show("dai--yl@163.com或者espricle@hotmail.com","联系方式",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}

[此贴子已经被作者于2006-12-13 17:21:12编辑过]

搜索更多相关主题的帖子: 五子棋 游戏 dai target 
2006-03-29 13:14
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
期待你的IQ版本

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2006-03-29 14:10
htzz
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-3-10
收藏
得分:0 
我玩了一会
发现了个漏洞,如果在玩的过程中把鼠标移出窗体再移进去,棋盘上的棋子就会消失。

2006-03-29 17:40
moderndai
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2006-1-25
收藏
得分:0 
以下是引用htzz在2006-3-29 17:40:00的发言:
我玩了一会

发现了个漏洞,如果在玩的过程中把鼠标移出窗体再移进去,棋盘上的棋子就会消失。

谢谢了
我这就去改!


ROCK AND ROCK PROGRAMING dai--yl@&&espricle@
2006-03-29 18:33
moderndai
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2006-1-25
收藏
得分:0 
以下是引用htzz在2006-3-29 17:40:00的发言:
我玩了一会

发现了个漏洞,如果在玩的过程中把鼠标移出窗体再移进去,棋盘上的棋子就会消失。

兄弟改好了这就传上去

UcmrX7rq.rar (5.6 KB) 自己写的五子棋游戏



ROCK AND ROCK PROGRAMING dai--yl@&&espricle@
2006-03-29 18:38
liusername
Rank: 2
等 级:论坛游民
帖 子:17
专家分:20
注 册:2006-3-24
收藏
得分:0 
没有源码贴出来作什么。
2006-03-30 16:51
heaton527
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-9
收藏
得分:0 
真是没有源码放出来作什么
2006-05-09 10:05
lzhgigi
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-5-9
收藏
得分:0 
精神值得学习!!!努力中...
2006-05-09 16:14
文盲
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-2-24
收藏
得分:0 

楼主把代码贴出来吧
或者就发到我邮箱里好吗?
谢谢楼主!
jzjz05@163.com


熟悉的地方没有风景!
2006-05-09 21:29
Smiling
Rank: 1
等 级:新手上路
帖 子:111
专家分:0
注 册:2005-9-7
收藏
得分:0 
就是,要上传就应该把原代码一起传上来撒,拿个运行文件出来Show干吗呢?是希望我们赞扬呢还是什么呢?
2006-05-11 09:20
快速回复:自己写的五子棋游戏
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019067 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved