
用函数生成???晕
自己画吧,用现成的也可以,网上应该有,当然也可以用字符来组合;
补充一下,所谓的函数生成的意思可能是:通过ddraw,或者底层的win api来生成画图的基本元素
“五子棋”是大家都非常熟悉的一种益智类游戏,相关的游戏软件也非常多,在此我向大家隆重推出一款新的纯“网络版”的五子棋,它利用ASP做为开发环境,因此在Internet上对战的时候无需下载客户端软件,只要你有一个浏览器就可以了。你也可以在局域网上进行这个游戏。
对于ASP,我不想做过多的说明,在以前的文章中,我已经说过很多。
游戏的过程是这样的,我们首先登录,然后可以选择战场,有“金星”、“木星”、“水星”、“火星”、“土星”等五个战场,如果你自认为是一个高手,可以选择金星,否则可以依次选择其它几个星球做为战场。如果这个星球上没有擂主,你就应该以擂主的身份进入,然后别人就可以和你进行对战了。当然,如果所有的星球上都已经开始了战争,那么你就只能等一会儿了。
如果你是以擂主身份进入的,你可以等待别人来和你对战,如果你是以攻擂手的身份登录,你可以很快的和擂主展开战斗。开始战斗后,由擂主执黑先行,然后由攻擂手出招,如此这般。当最后决出胜负的时候,会有相应的提示。
该站点有几个主要的文件是:
Indexasp 登录文件:
Indesp中间文件:
Matchasp 比赛文件:
Back0jpg white0jpg black0jpg 中间用到的图形文件,分别指的棋盘,白子和黑子,
在程序的初始化的时候,将棋盘上分成若干的表格,将背景放入其中,形成一个棋盘,然后在放上一个棋子后,再将换上相应的白子或黑子就可以了。
先看看登录文件:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 60">
<title>星球大战之“五子连珠”大赛!</title>
</HEAD>
<BODY>
<font size=6>星球大战</font>
<tr><td>星球</td><td>擂主</td><td>大战</td><td>攻擂</td></tr>
<tr>
<td>金星</td>
<td>
<%
if application("first1")="" then
%>
<form action=indespflag=First1 method=post>
<INPUT id=text1 name=txtFirst1 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
responsewrite application("first1")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second1")="" then
%>
<form action=indespflag=second1 method=post>
<INPUT id=text1 name=txtSecond1 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
responsewrite application("Second1")
end if
%>
</td>
</tr>
<tr>
<td>木星</td>
<td>
<%
if application("first2")="" then
%>
<form action=indespflag=First2 method=post>
<INPUT id=text1 name=txtFirst2 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
responsewrite application("first2")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second2")="" then
%>
<form action=indespflag=second2 method=post>
<INPUT id=text1 name=txtSecond2 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
responsewrite application("Second2")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first3")="" then
%>
<form action=indespflag=First3 method=post>
<INPUT id=text1 name=txtFirst3 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
responsewrite application("first3")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second3")="" then
%>
<form action=indespflag=second3 method=post>
<INPUT id=text1 name=txtSecond3 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
responsewrite application("Second3")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first4")="" then
%>
<form action=indespflag=First4 method=post>
<INPUT id=text1 name=txtFirst4 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
responsewrite application("first4")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second4")="" then
%>
<form action=indespflag=second4 method=post>
<INPUT id=text1 name=txtSecond4 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
responsewrite application("Second4")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first5")="" then
%>
<form action=indespflag=First5 method=post>
<INPUT id=text1 name=txtFirst5 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
responsewrite application("first5")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second5")="" then
%>
<form action=indespflag=second5 method=post>
<INPUT id=text1 name=txtSecond5 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
responsewrite application("Second5")
end if
%>
</td>
</tr>
</BODY>
</HTML>
这个文件不用做过多的说明,就是一个大的表格,大家可以从那里进入,如果某个位置已经被使用,则它会变成该大 侠的名字,不允许重复登录。在登录后进入
indesp,这是一个中间交换文件,在里面进行一些变量的处理及赋值,然后再进入matchasp,进行正式的比赛。我们来看一下indesp的内容:
<%@ Language=VBScript %>
<%
if RequestForm("txt"
requestquerystring("flag"))<>"" then
'responsewrite "in!"
""
session("nice")=RequestForm("txt"
requestquerystring("flag"))
'responsewrite session("nice")
""
'responsewrite application(requestquerystring("flag"))
if application(requestquerystring("flag"))="" then
application(requestquerystring("flag"))=session("nice")
session("class")=right(requestquerystring("flag"),1)
if left(requestquerystring("flag"),1)="f" then
application(session("nice"))=false
elseif left(requestquerystring("flag"),1)="s" then
application(session("nice"))=false
application(application("first"
session("class")))=true
end if
ResponseRedirect "matchasp"
end if
end if
%>
<HTML>
</HTML>
该程序中,用session(“nice”)来记录您登录的大名,以后的处理中,很多都要用到它,用它来区分很多的用户。如果您是从擂主的位置进入,则您的权利是
first,否则是second,用session("class")来记录位于哪个战场场,“金”“木”
“水”“火”“土”分别表示为1、2、3、4、5,因为有多个战场可能同时开战,如果不能正确地区分开,则可能导致一片混乱。application(session("nice"))是一个逻辑型变量,用真假来表示您是否可以出棋,如果是假,您要等待一个,如果是真,您就可以下棋了。只有一个战场上的两个人都进入了以后,擂主方可以下棋,而且只有当擂主出子以后,攻擂手才可以下棋。准备好以后,下面就进入赛场,请看文件matchasp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 40">
<meta name="ProgId" content="FrontPageEditorDocument">
<META http-equiv=refresh content=3>
<title>连珠大赛</title>
</head>
<%
ResponseWrite "擂主:"
application("first"
session("class"))
" 攻擂:"
application("second"
session
("class"))
if RequestQueryString("pos")<>"" then
application("pos"
session("class")
RequestQueryString("pos"))
=true
end if
%>
<body>
<%
'ResponseWrite application("aaa")
if application("first"
session("class"))=session("nice") then
color="black"
if RequestQueryString("pos")<>"" then
if session("last")="" then session("last")="abc"
if session("last")<> RequestQueryString("pos") then
application(application("first"
session("class")))=false
if application("second"
session("class"))<>"" then application
(application("second"
session("class")))=true
session("last")=RequestQueryString("pos")
END IF
end if
else
if application("second"
session("class"))=session("nice") then
color="white"
if RequestQueryString("pos")<>"" then
'if session("last")="" then session("last")="abc"
if session("last")<> RequestQueryString("pos") then
application(application("first"
session("class")))=true
application(application("second"
session("class")))=false
session("last")=RequestQueryString("pos")
END IF
end if
else
if application("second"
session("class"))="" then
application("second"
session("class"))=session("nice")
color="white"
if RequestQueryString("pos")<>"" then
if session("last")="" then session("last")="abc"
if session("last")<> RequestQueryString("pos") then
application(application("first"
session("class")))=true
application(application("second"
session("class")))=false
session("last")=RequestQueryString("pos")
END IF
end if
else
color=""
end if
end if
end if
ResponseWrite "
cellpadding=0>"
for i=1 to 16
ResponseWrite "<tr>"
for j=1 to 16
if application("pos"
session("class")
cstr(i)
"_"
cstr(j))=""
then
application("color"
session("class")
"_"
RequestQueryString
("pos"))=color
ResponseWrite "<td width=25 height=25>"
'responsewrite application(application("first"
session("class")))
if application(session("nice"))=true then
responsewrite "<a href=matchasppos="
cstr(i)
"_"
cstr(j)
"><img border=0 src=back0jpg width=25 height=25></a>"
else
responsewrite "<img border=0 src=back0jpg width=25 height=25>"
end if
responsewrite "</td>"
else
ResponseWrite "<td width=25 height=25><img border=0 src="
application("color"
session("class")
"_"
cstr(i)
"_"
cstr
(j))
"0jpg width=25 height=25></td>"
chr(13)
end if
next
ResponseWrite "</tr>"
next
ResponseWrite "
"
'判断输赢
if application("first"
session("class"))=session("nice") then
m="black"
h="white"
else
h="black"
m="white"
end if
'横向判断"-"
for i=1 to 15
win=false
loss=false
five_me=0
five_he=0
for j=1 to 15
if application("color"
session("class")
"_"
cstr(i)
"_"
cstr
(j))=m then
five_me=five_me+1
five_he=0
elseif application("color"
session("class")
"_"
cstr(i)
"_"
cstr(j))=h then
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
end if
if five_me=5 then
win=true
loss=false
exit for
elseif five_he=5 then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
responsewrite "你赢了!"
application(application("first"
session("class")))=false
application(application("second"
session("class")))=false
end if
if loss then
responsewrite "对不起,你输了!"
application(application("first"
session("class")))=false
application(application("second"
session("class")))=false
end if
'列向判断"|"
for j=1 to 15
win=false
loss=false
five_me=0
five_he=0
for i=1 to 15
if application("color"
session("class")
"_"
cstr(i)
"_"
cstr
(j))=m then
five_me=five_me+1
five_he=0
elseif application("color"
session("class")
"_"
cstr(i)
"_"
cstr(j))=h then
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
end if
if five_me=5
针对当前错误提示,你需要两个调整:
在当前代码cpp文件(view类源代码)的头部,增加#include "mainfrmh" 这个包含(注意对比mainfrmcpp文件中的相对位置和文件名)。
修改一行代码如下:
//调用主框架里面的状态栏CMainFrame pFrm=(CMainFrame)AfxGetMainWnd();
1先独立完成数据结构,最简单的办法就用一个二维数组表来模拟五子棋的棋盘2用MFC做界面,或者是用OPENCV(个人推荐这个,这个比MFC简单)里面对于做界面有一些函数,必然绘制直线,绘制圆,绘制矩形~不过得先配置OPENCV的文件~3综合测试
我不要你的代码。
但我可以帮你解决。
你可以用CWnd类的两个定时器函数
分别是UINT SetTimer(UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORTlpfnTimer) (HWND, UINT, UINT, DWORD) );
还有一个
BOOL KillTimer( int nIDEvent );
具体用法:
SetTimer()
CWnd::SetTimer
UINT SetTimer(UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORTlpfnTimer) (HWND, UINT, UINT, DWORD) );
返回值:
如果函数成功,则返回新定时器的标识符。应用程序可以将这个值传递给KillTimer成员函数以销毁定时器。如果成功,则返回非零值;否则返回0。
参数: nIDEvent 指定了不为零的定时器标识符。
nElapse 指定了定时值;以毫秒为单位。
lpfnTimer 指定了应用程序提供的TimerProc回调函数的地址,该函数被用于处理WM_TIMER消息。如果这个参数为NULL,则WM_TIMER消息被放入应用程序的消息队列并由CWnd对象来处理。
说明:
这个函数设置一个系统定时器。指定了一个定时值,每当发生超时,则系统就向设置定时器的应用程序的消息队列发送一个WM_TIMER消息,或者将消息传递给应用程序定义的TimerProc回调函数。
lpfnTimer回调函数不需要被命名为TimerProc,但是它必须按照如下方式定义:
void CALLBACK EXPORT TimerProc(
HWND hWnd, // 调用SetTimer的CWnd的句柄
UINT nMsg, // WM_TIMER
UINT nIDEvent // 定时器标识
DWORD dwTime // 系统时间
);
定时器是有限的全局资源;因此对于应用程序来说,检查SetTimer返回的值以确定定时器是否可用是很重要的。
KillTimer()
CWnd::KillTimer
BOOL KillTimer( int nIDEvent );
返回值:
指定了函数的结果。如果事件已经被销毁,则返回值为非零值。如果KillTimer成员函数不能找到指定的定时器事件,则返回0。
参数: nIDEvent 传递给SetTimer的定时器事件值。
说明:
销毁以前调用SetTimer创建的用nIDEvent标识的定时器事件。任何与此定时器有关的未处理的WM_TIMER消息都从消息队列中清除。
你既然会用MFC写五子棋程序。
那么你也一定会添加消息映射吧
有了上面的知识,你应该知道在什么窗口中加WM_TIMER的消息映射了吧
哈哈,祝你写的愉快
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)