
2、命令按钮command1~command13的caption属性分别为:“确定”,“退格”,“新一局”,“0”...“9”。
3、文本框Text1的FontSize为26;FontColor为250,250,0;BackColor为0,128,128;ContorlSource为ctet1(变量ctet1的值与text1的值相关联)。
4、文本框Text2的FontColor为250,250,0;ContorlSource为jlun;BackStyle为“0-透明”;BorderStyle为“0-无”。
5、文本框t1~t10,zq1~zq10,cw1~cw10(name=t1...,zq1...,cw1...cw10)
,(controlsource=t1...),FontColor为250,250,0;BackStyle为“0-透明”;BorderStyle为“0-无”。
6、标签Label1~Label3的caption属性分别为:“选择的数”,“位置正确”,“位置错误”。
7、标签Label4的caption属性为:="说明:选择4个数按确定键,在右侧显示这4位数有几位数与你要猜的数位置相同,"+chr(13)+"
有几位数包含在要猜的数中,但位置不同。根据以上提示猜出是哪4位数。",其中chr(13)是一个回车换行命令,“=”和英文引号(单、双都行)不能少;BackStyle为“0-透明”。
8、标签L1~L10的caption属性分别为:“第一次”...“第十次”;BackStyle为“0-透明”。
9、表面工作做完了,下面我们来输入一些命令(程序),双击表单出现表单过程编辑框,在Init过程中输入如下命令:
public
ctx1,ctx2,ctx3,ctx4,ctet1,ctet2,n,zq,cw,p
&&设置全局变量
zq=0
&&设置初始值
cw=0
ctet1=''
ctet2=''
n=0
thisform.command3.click()
&&执行命令按钮(command3)的click过程,相当于点击"新一局"按钮。
10、双击按钮“0”(command4),在其click过程中输入如下命令:
ctet2='0'
do
panduan
&&执行panduan.prg程序
thisform.refresh
11、按钮“1”~“9”的click过程中的命令与按钮“0”的click过程中的命令的不同之处就是ctet2的值,即ctet2='1'...ctet2='9'。
12、因为在按钮“0”~“9”的click过程中都执行一些相同的命令,所以我们把这些命令提出来,作为一个程序来调用(也可以在表单中创建一个方法程序,请参见第九课),可以简化程序的设计。选择“代码”——“程序”按“新建”按钮,新建程序panduan.prg:
if
len(allt(ctet1))<>4
&&判断text1的值的长度,如果不是4位,执行下面的命令.
if !ctet2$ctet1
&&判断按下的按钮的数值是否已被选过,若所选的数不包涵在已选的数值内.
ctet1=ctet1+ctet2 &&把选定的数加在后面.
endif
endif
13、双击按钮“确定”(command1),在其click过程中输入如下命令:
zq=0
&&正确值zq=0
cw=0 &&错误值cw=0
if
len(allt(ctet1))<>4 &&如果text1的值不是4 位
wait window
at 16,25 "数据不够4 位" &&提示
return
&&返回
endif
p=p+1
if ctx1$ctet1
&&判断cte1值是否在所选定的4位数中.(ctet1及ctet2、ctet3、ctet4的值是在表单运行时或点击了“新一局”按钮时机器随机产生的4位数值。)
if ctx1=substr(ctet1,1,1)
zq=zq+1
else
cw=cw+1
endif
endif
if
ctx2$ctet1
if ctx2=substr(ctet1,2,1)
zq=zq+1
else
cw=cw+1
endif
endif
if
ctx3$ctet1
if ctx3=substr(ctet1,3,1)
zq=zq+1
else
cw=cw+1
endif
endif
if
ctx4$ctet1
if ctx4=substr(ctet1,4,1)
zq=zq+1
else
cw=cw+1
endif
endif
do
case
case p=1
thisform.l1.visible=.t.
thisform.t1.visible=.t.
thisform.zq1.visible=.t.
thisform.cw1.visible=.t.
t1=ctet1
zq1=zq
cw1=cw
if zq=4
jlun="你真能蒙!"
endif
case p=2
thisform.l2.visible=.t.
thisform.t2.visible=.t.
thisform.zq2.visible=.t.
thisform.cw2.visible=.t.
t2=ctet1
zq2=zq
cw2=cw
if
zq=4
jlun="太棒了,你真能蒙!"
endif
case
p=3
thisform.l3.visible=.t.
thisform.t3.visible=.t.
thisform.zq3.visible=.t.
thisform.cw3.visible=.t.
t3=ctet1
zq3=zq
cw3=cw
if zq=4
jlun="太棒了,蒙的吧?!"
endif
case p=4
thisform.l4.visible=.t.
thisform.t4.visible=.t.
thisform.zq4.visible=.t.
thisform.cw4.visible=.t.
t4=ctet1
zq4=zq
cw4=cw
if
zq=4
jlun="太棒了,您是教授吗?"
endif
case
p=5
thisform.l5.visible=.t.
thisform.t5.visible=.t.
thisform.zq5.visible=.t.
thisform.cw5.visible=.t.
t5=ctet1
zq5=zq
cw5=cw
if zq=4
jlun="大学生水平,很可以!"
endif
case p=6
thisform.l6.visible=.t.
thisform.t6.visible=.t.
thisform.zq6.visible=.t.
thisform.cw6.visible=.t.
t6=ctet1
zq6=zq
cw6=cw
if
zq=4
jlun="智商不低吗!"
endif
case
p=7
thisform.l7.visible=.t.
thisform.t7.visible=.t.
thisform.zq7.visible=.t.
thisform.cw7.visible=.t.
t7=ctet1
zq7=zq
cw7=cw
if zq=4
jlun="还算可以,要努力呀!"
endif
case p=8
thisform.l8.visible=.t.
thisform.t8.visible=.t.
thisform.zq8.visible=.t.
thisform.cw8.visible=.t.
t8=ctet1
zq8=zq
cw8=cw
if
zq=4
jlun="一般人到这儿都能找到!"
endif
case p=9
thisform.l9.visible=.t.
thisform.t9.visible=.t.
thisform.zq9.visible=.t.
thisform.cw9.visible=.t.
t9=ctet1
zq9=zq
cw9=cw
if zq=4
jlun="太一般了!"
endif
case p=10
thisform.l10.visible=.t.
thisform.t10.visible=.t.
thisform.zq10.visible=.t.
thisform.cw10.visible=.t.
t10=ctet1
zq10=zq
cw10=cw
if
zq=4
jlun="到现在才早找出来?!智商有问题!"
else
jlun="智商太低了,再来一次?"
endif
endcase
ctet1=""
thisform.refresh
14、双击按钮“新一局”(command3),在其click过程中输入如下命令:
jlun=""
thisform.l1.visible=.f.
thisform.t1.visible=.f.
thisform.zq1.visible=.f.
thisform.cw1.visible=.f.
thisform.l10.visible=.f.
thisform.t10.visible=.f.
thisform.zq10.visible=.f.
thisform.cw10.visible=.f.
thisform.l2.visible=.f.
thisform.t2.visible=.f.
thisform.zq2.visible=.f.
thisform.cw2.visible=.f.
thisform.l3.visible=.f.
thisform.t3.visible=.f.
thisform.zq3.visible=.f.
thisform.cw3.visible=.f.
thisform.l4.visible=.f.
thisform.t4.visible=.f.
thisform.zq4.visible=.f.
thisform.cw4.visible=.f.
thisform.l5.visible=.f.
thisform.t5.visible=.f.
thisform.zq5.visible=.f.
thisform.cw5.visible=.f.
thisform.l6.visible=.f.
thisform.t6.visible=.f.
thisform.zq6.visible=.f.
thisform.cw6.visible=.f.
thisform.l7.visible=.f.
thisform.t7.visible=.f.
thisform.zq7.visible=.f.
thisform.cw7.visible=.f.
thisform.l8.visible=.f.
thisform.t8.visible=.f.
thisform.zq8.visible=.f.
thisform.cw8.visible=.f.
thisform.l9.visible=.f.
thisform.t9.visible=.f.
thisform.zq9.visible=.f.
thisform.cw9.visible=.f.
p=0
ctext='1234567890'
for
i=1 to 4
n=11-i
cn1=rand()
cn=int(cn1*n)+1
if
cn=0
cn=1
endif
txx='ctx'+allt(str(i))
&txx=substr(ctext,cn,1)
if
cn=1
ctext1=right(ctext,(10-i))
else
if
cn=11-i
ctext1=left(ctext,(10-i))
else
ctext1=left(ctext,cn-1)+right(ctext,(11-i-cn))
endif
endif
ctext=ctext1
endfor
thisform.text1.value=""
thisform.refresh
15、双击按钮“退格”(command2),在其click过程中输入如下命令:
if
len(allt(ctet1))<>0
&&长度不为0
ctet1=left(ctet1,len(allt(ctet1))-1)
&&删除后面的一为数
endif
thisform.refresh
16、修改主菜单,在“游戏”的猜数游戏后填加命令:do
form csyx,
别忘了生成程序文件。
17、因为表单和程序不在同一目录下,所以单独运行表单会出现找不到某程序的错误,我们需要运行主程序main.prg,来看看运行结果。