魔方游戏是个经典的游戏,在当前AI人工智能发展的大好形势下,机器人还原魔方成为一个很好的课题。由我对游戏和编程的兴趣爱好,设计编制了此魔方游戏程序。
魔方游戏程序设计几个方面的要点:
一、游戏界面设计
我是在手机上编制程序的,故游戏界面是手机界面。由于界面限制,只能将各个游戏功能紧凑在小界面上。
上部设置常用按钮:开始游戏,还原魔方,自动演示,退出程序,加 版本信息。
另加下拉菜单,可选六步解法,查看走步记录等。
中部设置魔方状态图,前右上三个面采用伪3D的图样,另加左后底三个面的平面图样。特别一点,图框下面加了六个面的一体图样。这样可使游戏者比较直观的看到魔方的状态。
下部设置操作按钮的功能块,设置了全部的12个操作按钮,和3个旋转翻转按钮。便于游戏的操作。
游戏的图形界面的是用简单的C语言编制的,全是用编译器绘图方法绘制的。一般的游戏图形都是方形和圆形为主,此魔方游戏图形是用伪3D的方法绘制的。此方法是用平面绘画方法画出许多菱形拼接成魔方的立体图像,给你的观感是立体的魔方。你可看到魔方的三个面,前面右面和上面。这样你能根据小方块的颜色来判断而操作魔方。一般人玩魔方都是左手拿魔方,右手做各种旋转动作。此设计就是左手拿手机,右手转魔方。游戏的视觉效果就这样。
二、游戏功能设置
游戏功能最主要的就是15个操作按钮的功能,我设计了一个比较直观的易于理解的算法。用一个数组存储六个面的54个小块的颜色值,一切的操作变换都是颜色的变换。我写了15个操作键的函数就能让魔方转起来。直接可以玩了,就这么简单。又写了判断完成的函数,这是游戏的基本的东西。
另外我做了隐藏按钮,在图框的右下角,可以查看4个重要的公式(助记),以及操作ABCD 公式。这些都是增加游戏可操控性。
算法解释:
int B[70] ; //存储颜色值,值为1-6,预设置为:蓝红绿 黄橙白
左面:基色蓝,编码B11- B19, 前面:基色红,编码 B21 - B29,
右面:基色绿,编码B31- B39, 上面:基色黄,编码 B41 - B49,
后面:基色橙,编码B51- B59, 下面:基色白,编码 B61 - B69,
(附图)
Frontright (){ //前右 F
sw[1]=B[47]; sw[2]=B[48]; sw[3]=B[49]; //sw = swap
B[47]=B[19]; B[48]=B[16]; B[49]=B[13];
B[19]=B[63]; B[16]=B[62]; B[13]=B[61];
B[63]=B[31]; B[62]=B[34]; B[61]=B[37];
B[31]=sw[1]; B[34]=sw[2]; B[37]=sw[3];
sw[1]=B[21]; B[21]=B[27]; B[27]=B[29]; B[29]=B[23]; B[23]=sw[1];
sw[2]=B[22]; B[22]=B[24]; B[24]=B[28]; B[28]=B[26]; B[26]=sw[2];
ts=ts+1; //走步计数
drawbox (); //画出
print "do> F Front right "; //打印走步记录
}//Frontright()
这算法很简单,没什么深奥的理论。就是按规则转换颜色值,画出魔方。
三、AI 智能解魔方
演示套用说明书经典公式,即六步公式:上层四棱,上层四角,翻转,二层四棱,上层十字,顶面同色,六面同色。同时还提供操作记录,查看操作复盘。自动演示的记录就套用六步公式以供学习和研究用。我感觉用手机玩魔方的手感有种别样的味道。
上层四棱按基本操作完成,上层四角有3个公式来完成,二层四棱有2个公式来完成。接下来有易于记忆的ABCD 4个公式,上层十字用A 公式,顶面同色用B C 公式,六面同色用D公式。公式简单易于理解,不作解释了。用公式时如何调整状态,代码里有解释。此方法公式量少,完成魔方要140-200步。演示解魔方用时也就70到100秒。
手机魔方游戏我见过国外编的仿3D动画式的游戏,用手指滑动旋转操作,蛮酷的。我这个游戏是很小巧的,它的优点是简单和有趣,希望大家喜欢。
四、魔方游戏设计前瞻
现在大家在玩用程序来解魔方,还有机器人解魔方。
输入打乱的魔方的颜色图,由程序来解,输出解法步骤。此程序扩展一下就行。
至于机器人解魔方,此程序就能输出解法步,开一个数组存储解法步,如:
String A[300] = ( R1, U, R, U, R, U, R1, U, ............),
传导给机器人程序,由它来解释操作。程序中打印记录抽出操作步就可以。
机器手设计,魔方翻转较难,那么就在第一步上层四棱和第二步上层四角操作倒着做,改为底层十字底层四角直接操作倒下面。后面的操作时底部白色中心和上面的黄色中心块是不变的。这样设计机器操作就简单了。
至于机器的速度,我手机操作用时70-100秒,大多时间是画出图样,我估计机器动作也就10秒吧。网上看到机器手解魔方视频,有兴趣的小伙伴可试验下。
本程序用的C语言是MySpringC v.2.7是目前的完善版本。
下面的游戏代码就是用它在安卓手机上编写的,可制作成安卓手机桌面app应用程序。此样例可复制黏贴到编译器直接使用,亦可用 VB6 ,C++ , java 改写。
以下是源码:
// 最简单的 C 语言编程
// myspringc v2.7 可编译安卓本机 app 应用
// 此样例可复制黏贴到 myspringc 编译
// 此文档可用 VB,VC , java 改写
//***********************
// 魔方 Magic Cube
// micelu@126.com
// 2024-07-15 修订
//***********************
Canvas cs ;
string sBarDes[10];
int nBarId[10];
string sMenu[50];
int nMenu[50];
float pi=3.1415926535;
float src[4]; //ClearDraw (cls) clear screen
string s,s1,s2,s3,s4,s5,s6,s7,s8,ss1,ss2,ss3;
float sx,sy,dx,dy;
float px,py;
FileInput filebox;
string fname; //filename
int i,j,n,t,k,ts; //t = times
int context,obj,id,event; //canvasProc
int bx,by; //button x y position
int bn; //button id number
int B[70]; //1 left 2 front 3 right 4 up 5 back 6 down
int cr1,cg1,cb1; //set color rgb
int scolor; // switch cube color
int sw[9]; //switch B color
int donum; //calculate do step number
int kn,cando;
double Rn; //random number
int tim[3]; //get Time
int hh,mm,ss;
int oldhh,oldmm,oldss;
int newhh,newmm,newss;
int mms; //show using time
string hhts,mmts,ssts, tim$;
string fs1,fs2,fs3,fs4,fs5,fs6; //show formula
string fma,fmb,fmc,fmd, fmd1; //formula
int ms, uf; //using formula
main(){
setDisplay(1);
cs.Active();
cs.SetProc (context, mycanvasProc); //getProc
sBarDes[0]="开始游戏";
nBarId[0]=100;
sBarDes[1]="还原魔方";
nBarId[1]=101;
sBarDes[2]="自动演示";
nBarId[2]=102;
sBarDes[3]="显示图板";
nBarId[3]=103;
sBarDes[4]="退出程序";
nBarId[4]=104;
sBarDes[5]="V.";
nBarId[5]=105;
setToolBarHeight(6);
setButtonTextSize(13);
setButtonColor(255,0,0,250);
setButtonTextColor(255,255,255,0);
setToolBar(100,myToolBarProc,sBarDes,nBarId,6);
sMenu[0]="开始游戏";
nMenu[0]=200;
sMenu[1]="第一步:上层四棱";
nMenu[1]=201;
sMenu[2]="第二步:上层四角";
nMenu[2]=202;
sMenu[3]="第三步:二层四棱";
nMenu[3]=203;
sMenu[4]="第四步:顶层十字";
nMenu[4]=204;
sMenu[5]="第五步:顶面同色";
nMenu[5]=205;
sMenu[6]="第六步:六面同色";
nMenu[6]=206;
sMenu[7]="自动演示";
nMenu[7]=207;
sMenu[8]="查看走步记录";
nMenu[8]=208;
sMenu[9]="显示游戏图板";
nMenu[9]=209;
sMenu[10]="退出";
nMenu[10]=210;
setMenu(200,myMenuProc,sMenu,nMenu,11);
setTitle("魔方 Magic Cube ");
//*****************************
getTime (tim);
oldhh=tim[0];
oldmm=tim[1];
oldss=tim[2];
kn=2;
drawcover ();
while (){}
}//main ()
mycanvasProc (int context,int obj,int id,int event,float x,float y){
bn=0; //init buttom
if (event==0||event==2||event==10){ //get touch
kn=kn+1;
if ((kn-kn/2*2)==0){ //触控防闪烁
cando=1; }else{cando=0; return; }
//设置界面操作按钮 12 cmd + 3 转向
if (x>20&&x<110){ //select button btn number
if (y>770&&y<840)bn=1;
if (y>840&&y<910)bn=2;
if (y>920&&y<980)bn=9; }
if (x>310&&x<400){ //select button btn number
if (y>760&&y<840)bn=3;
if (y>840&&y<920)bn=4;
if (y>920&&y<990)bn=10; }
if (x>120&&x<210&&y>750&&y<810)bn=5;
if (x>210&&x<300&&y>750&&y<810)bn=6;
if (x>120&&x<210&&y>815&&y<885)bn=7;
if (x>210&&x<300&&y>815&&y<885)bn=8;
if (x>120&&x<210&&y>890&&y<960)bn=11;
if (x>210&&x<300&&y>890&&y<960)bn=12;
//左旋转,右旋转,上翻转
if (x>430&&x<555&&y>750&&y<840)bn=13;
if (x>560&&x<690&&y>750&&y<840)bn=14;
if (x>490&&x<620&&y>850&&y<950)bn=15;
//** 设置操作标记
cs.SetFillMode (1);
cs.SetTextSize (20);
cs.SetColor(255,255,255,255);
//cs.DrawCircle (160,280,5); //L
// cs.DrawCircle (160,440,5);
if (x>120&&x<200&&y>240&&y<320)bn=1;
if (x>120&&x<200&&y>400&&y<480)bn=2;
cs.DrawText ("L1",150,290);
cs.DrawText ("L",150,450);
// cs.DrawCircle (320,370,2); //R
// cs.DrawCircle (320,520,2);
if (x>280&&x<360&&y>330&&y<410)bn=3;
if (x>280&&x<360&&y>480&&y<560)bn=4;
cs.DrawText ("R",310,370);
cs.DrawText ("R1",305,530);
// cs.DrawCircle (260,270,40); //U
//cs.DrawCircle (450,270,40);
if (x>220&&x<300&&y>230&&y<310)bn=5;
if (x>410&&x<490&&y>230&&y<310)bn=6;
cs.DrawText ("U",270,270);
cs.DrawText ("U1",430,270);
//cs.DrawCircle (400,370,2); //F
//cs.DrawCircle (400,520,2);
if (x>360&&x<440&&y>330&&y<410)bn=7;
if (x>360&&x<440&&y>480&&y<560)bn=8;
cs.DrawText ("F1",390,370);
cs.DrawText ("F",395,530);
//cs.DrawCircle (560,280,5); //B
//cs.DrawCircle (560,440,5);
if (x>520&&x<600&&y>240&&y<320)bn=10;
if (x>520&&x<600&&y>400&&y<480)bn=9;
cs.DrawText ("B",550,290);
cs.DrawText ("B1",550,450);
// cs.DrawCircle (230,490,4); //D
// cs.DrawCircle (480,490,4);
if (x>190&&x<270&&y>450&&y<530)bn=11;
if (x>440&&x<520&&y>450&&y<530)bn=12;
cs.DrawText ("D1",230,490);
cs.DrawText ("D",470,490);
cs.SetColor (255,0,0,250) ;
cs.DrawCircle (648,700, 21) ;
cs.DrawCircle (660,700, 21) ;
cs.SetColor (255,250,250,0) ;
cs.DrawText ("Fm", 640, 705 ) ;
//公式解法:
//顶层十字:至多三次即可
//公式 A:R1 U1 F1 U F R
// 顶面同色,顶面十字四角无色块,下角色块置左;
// 有一块,田置左下; 有二块,黄色置前左
//公式 B:R U R1 U R U U R1
//顶面同色:调整角块,两角块同色置前
//公式 C:R B1 R FF R1 B R FF RR
//六面同色:顶棱同色置后B,
//公式 D:R U1 R U R U R U1 R1 U1 RR
fma="A = R1 U1 F1 U F R ";
fmb="B = R U R1 U R U U R1 ";
fmc="C = R B1 R FF R1 B R FF RR ";
fmd="D = R U1 R U R U R U1 ";
fmd1=" R1 U1 RR";
if (x>640&&x<720&&y>650&&y<720){
uf=uf+1; }
if (uf>1) uf=0;
cs.SetColor (255,80,80,80) ; //clear text
cs.DrawRect (485, 525, 710, 625) ;
cs.DrawRect (667, 210, 685, 325) ;
cs.DrawRect (667, 380, 685, 520) ;
if (uf==1) {
cs.SetColor (255,250,250,250) ;
cs.SetTextSize (16);
cs.DrawText (fma,490,540);
cs.DrawText (fmb,490,560);
cs.DrawText (fmc,490,580);
cs.DrawText (fmd,490,600);
cs.DrawText (fmd1,490,620); }
cs.DrawCircle (675,220,5); //A
cs.DrawCircle (675,300,5); //B
cs.DrawCircle (675,400,5); //C
cs.DrawCircle (675,480,5); //D
cs.DrawText ("A",670,245);
cs.DrawText ("B",670,325);
cs.DrawText ("C",670,425);
cs.DrawText ("D",670,505);
if (x>660&&x<720&&y>180&&y<260){
ms=41; Formula (); } //A
if (x>660&&x<720&&y>260&&y<340){
ms=51; Formula (); } //B
if (x>660&&x<720&&y>380&&y<460){
ms=53; Formula (); } //C
if (x>660&&x<720&&y>460&&y<540){
ms=61; Formula (); } //D
cs.SetFillMode (1);
cs.Update ();
//********* get button position x y
bx=(int)(x);
by=(int)(y);
if (bn==1){
s3="走步: 左上 L ' ";
Leftup (); }
if (bn==2){
s3="走步: 左下 L ";
Leftdown (); }
if (bn==3){
s3="走步: 右上 R ";
Rightup (); }
if (bn==4){
s3="走步: 右下 R ' ";
Rightdown (); }
if (bn==5){
s3="走步: 上左 U ";
Upleft (); }
if (bn==6){
s3="走步: 上右 U ' ";
Upright (); }
if (bn==7){
s3="走步: 前左 F ' ";
Frontleft (); }
if (bn==8){
s3="走步: 前右 F ";
Frontright (); }
if (bn==9){
s3="走步: 后左 B ' ";
Backleft (); }
if (bn==10){
s3="走步: 后右 B ";
Backright (); }
if (bn==11){
s3="走步: 下左 D ' ";
Downleft (); }
if (bn==12){
s3="走步: 下右 D ";
Downright (); }
if (bn==13){
s3="走步: 左旋转 ";
Turnleft (); }
if (bn==14){
s3="走步: 右旋转 ";
Turnright (); }
if (bn==15){
s3="走步: 翻转 ";
Turnup (); }
} //screen touch and select button ********
cs.SetFillMode (1);
cs.SetColor(255,240,240,240);
cs.DrawRect (0,3,700,30); // clear print x y
s=intToString(bn);
s4="按钮(bn) > "+s;
s=intToString(bx);
s1="X= "+s;
s=intToString(by);
s2="Y= "+s;
cs.SetColor (255,50,20,120);
cs.SetTextSize (26);
// cs.DrawText (s1,25,25);
// cs.DrawText (s2,120,25);
// cs.DrawText (s4,220,25);
cs.DrawText (s3,445,25);
cs.Update ();
checkfinished ();
}//mycanvasProc ()
//***************************************
Autoplay (){
clearOutput ();
print "User select >>> 自动演示";
newgame ();
Astep1 (); //上层四棱
//sleep (1000);
Astep2 (); //上层四角
//sleep (1000);
Turnup (); Turnup ();
//sleep (1000);
Astep3 (); //二层四棱
//sleep (1000);
Astep4 (); //顶层十字
//sleep (1000);
Astep5 (); //顶面同色
//sleep (1000);
Astep6 (); //六面同色
}//Autoplay ()
Formula (){
//界面设置四公式操作,可直接使用公式
if (ms==41){ goto ms41; } //公式 A
if (ms==51){ goto ms51; } //公式 B
if (ms==53){ goto ms53; } //公式 C
if (ms==61){ goto ms61; } //公式 D
ms41: //顶层十字
//fma= A:R1 U1 F1 U F R
print "公式 A ";
Rightdown (); Upright (); Frontleft ();
Upleft (); Frontright (); Rightup ();
return; //************
ms51: //顶面同色:同色
//fmb= B:R U R1 U R U U R1
print "公式 B ";
Rightup (); Upleft (); Rightdown ();
Upleft (); Rightup ();
Upleft (); Upleft (); Rightdown ();
return; //************
ms53: //顶面同色:调整角块
//fmc= C:R B1 R FF R1 B R FF RR
print "公式 C";
Rightup (); Backleft (); //R B1
Rightup (); Frontright (); Frontright (); //R FF
Rightdown (); Backright (); //R1 B
Rightup (); Frontright (); Frontright (); //R FF
Rightup (); Rightup (); //RR
return; //顶面同色 *************
ms61: //六面同色:完成
//fmd= D:R U1 R U R U R U1 R1 U1 RR
print "公式 D ";
Rightup (); Upright (); //R U1
Rightup (); Upleft (); //R U
Rightup (); Upleft (); //R U
Rightup (); Upright (); //R U1
Rightdown (); Upright (); //R1 U1
Rightup (); Rightup (); //RR
return; // 公式 D
}//Formula ()
checkfinished (){
//**** check finished ************
for (i=1;i<10;i++){
if (B[10+i]==B[15]){ }else{ goto f60; }
if (B[20+i]==B[25]){ }else{ goto f60; }
if (B[30+i]==B[35]){ }else{ goto f60; }
if (B[40+i]==B[45]){ }else{ goto f60; }
if (B[50+i]==B[55]){ }else{ goto f60; }
if (B[60+i]==B[65]){ }else{ goto f60; }
} //check >>>>>>
goto f66; //if finished then show score
f60:
ms=80 ; return; //if not finished then retry
f66: // **** finished & show score *******
if (ms==99) return;
print "times = ", n ; //D 公式,次数
print "步数 steps = ", ts ; //使用步数
getTime (tim);
newhh=tim[0];
newmm=tim[1];
newss=tim[2];
hhts=intToString (tim[0]);
mmts=intToString (tim[1]);
ssts=intToString (tim[2]);
if (newhh<10)hhts="0"+hhts;
if (newmm<10)mmts="0"+mmts;
if (newss<10)ssts="0"+ssts;
mms=((newhh-oldhh)*3600)+
((newmm-oldmm)*60)+((newss-oldss));
if (mms<0) mms=mms+864000;
hh=mms/3600;
mm=(mms-hh*2600)/60;
ss=mms-hh*3600-mm*60;
s=intToString (ss);
if (ss<10) s="0"+s ; //** 若 sec<10 补 0
ss1=intToString (mm)+" 分 "+s+" 秒";
ss2=hhts+" : "+mmts+" : "+ssts;
s7="用时:"+ss1;
print "结束时间 "+ss2;
print s7;
oldhh=newhh;
oldmm=newmm;
oldss=newss;
//******************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《六面同色》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.DrawText (s7,100,25);
s="恭喜你完成了魔方游戏! ";
cs.SetTextSize (60);
cs.SetFillMode (1);
cs.SetStrokeWidth (2);
cs.SetColor (255,160,30,240);
cs.DrawText (s,63,313);
cs.SetColor (255,250,0,0);
cs.DrawText (s,60,310);
cs.SetFillMode (0);
cs.SetStrokeWidth (1);
cs.SetColor (255,250,250,0);
cs.DrawText (s,60,310);
cs.SetFillMode (1);
cs.SetTextSize (26);
cs.Update ();
ms=99; //if finished then cut
}//checkfinished ()
Astep6 (){ //六面同色 ************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(6)《六面同色》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
checkfinished (); // 可能 Astep5 () 已完成
if (ms==99) return; //已完成
s61:
//**** adjust status at first *********
if (B[12]==B[15]){ //same color edge to back
Turnleft (); }
if (B[22]==B[25]){ Turnleft (); Turnleft (); }
if (B[32]==B[35]){ Turnright (); }
//** new:using formula D to finished cube
ms=61; Formula ();
n=n+1;
checkfinished ();
if(ms<99){ goto s61 ; }
//已同色棱置后,逆一次,顺二次就可完成
}//Astep6 ()
Astep5 (){ //顶面同色 ************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(5)《顶面同色》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
//对齐前面同色棱,查看几块同色
if (B[12]==B[25]){ Upright (); }
if (B[32]==B[25]){ Upleft (); }
if (B[52]==B[25]){ Upleft (); Upleft (); }
s51:
k=0 ; n=n+1 ; //计算顶面有几角块同色
if (B[41]==B[45]) k=k+1 ;
if (B[43]==B[45]) k=k+1 ;
if (B[47]==B[45]) k=k+1 ;
if (B[49]==B[45]) k=k+1 ;
//state 1 > ** adjust status 顶面角块无同色
if (k==0){
if (B[23]==B[45]){ Turnleft (); }
if (B[33]==B[45]){ Turnleft (); Turnleft (); }
if (B[53]==B[45]){ Turnright (); }
if (B[13]==B[45]){ }
ms=51; Formula(); } //公式 B
//state 2 > ** adjust status
// 顶面一角块同色,小鱼置左
if (k==1) {
if (B[41]==B[45]){ Turnright (); }
if (B[43]==B[45]){ Turnleft (); Turnleft (); }
if (B[49]==B[45]){ Turnleft (); }
ms=51; Formula(); } //公式 B
//state 3 > ** adjust statue
// 顶面二以上角块同色,另角边色同顶色置前
if (k>1) {
if (B[11]==B[45]){ Turnright (); }
if (B[31]==B[45]){ Turnleft (); }
if (B[51]==B[45]){ Turnleft (); Turnleft (); }
ms=51; Formula(); //公式 B
} //若有2块以上同顶色,同色置前
//**** check finished ************
if (B[41]==B[45]&&B[42]==B[45]&&
B[43]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[47]==B[45]&&
B[48]==B[45]&&B[49]==B[45]) {
goto s53; } //to next execute
goto s51; //retry ******
return;
//*****************************
//**** sequence C *******
s53:
//**** state adjust
if (B[11]==B[25]){ Upright (); }
if (B[31]==B[25]){ Upleft (); }
if (B[51]==B[25]){ Upleft (); Upleft (); }
//**** 可能此步已完成
//**** check finished ************
if (B[41]==B[45]&&B[42]==B[45]&&
B[43]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[47]==B[45]&&
B[48]==B[45]&&B[49]==B[45]&&
B[11]==B[15]&&B[21]==B[25]&&
B[31]==B[35]&&B[51]==B[55]) {
goto s57; } //finished game
//完成顶面同色,再调整角块,二块同色置前
n=n+1 ;
if (B[11]==B[13]){ Turnright (); }
if (B[31]==B[33]){ Turnleft (); }
if (B[51]==B[53]){ Turnleft (); Turnleft (); }
ms=53; Formula(); //公式 C
//**** check finished ************
if (B[41]==B[45]&&B[42]==B[45]&&
B[43]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[47]==B[45]&&
B[48]==B[45]&&B[49]==B[45]&&
B[11]==B[15]&&B[21]==B[25]&&
B[31]==B[35]&&B[51]==B[55]) {
goto s57; } //finished game
else{ goto s53; } //if not finished then retry
return;
//**** finished ******
s57:
//**** check finished ************
if (B[11]==B[15]&&B[12]==B[15]&&B[13]==B[15]){
if (B[21]==B[25]&&B[22]==B[25]&&B[23]==B[25]){
if (B[31]==B[35]&&B[32]==B[35]&&B[33]==B[35]){
if (B[51]==B[55]&&B[52]==B[55]&&B[53]==B[55]){
goto s59; } } } } //六面同色已完成
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《顶面同色》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n;
print "steps = ",ts ;
return;
s59: //if finuished magic cube some times ****
checkfinished ();
print "Well done ! magic cube is finished. ";
ms=99 ;
}//Astep5 ()
Astep4 (){ //顶层十字 ************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(4)《顶层十字》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
goto s45; //check finished 可能此步已完成
s41: //run 4 times when finished *******
//adjust status ***********
if (B[44]==B[45]&&B[48]==B[45]){
Upleft (); }
if (B[46]==B[45]&&B[48]==B[45]){
Upleft (); Upleft (); }
if (B[42]==B[45]&&B[46]==B[45]){
Upright (); }
if (B[44]==B[45]&&B[46]==B[45]){
Upleft (); }
//use formula execute R' U' F' U F R *****
print "公式 A ";
Rightdown (); Upright (); Frontleft ();
Upleft (); Frontright (); Rightup ();
n=n+1;
// if (n>10) goto s46;
s45: //**** check finished ************
if (B[42]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[48]==B[45]){
goto s46; } else { goto s41; }
return;
s46:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《顶层十字》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n;
}//Astep4 ()
Astep3 (){ //二层四棱 *************
s30:
s3="Autoplay >> 二层四棱 ";
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(3)《二层四棱》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0 ; //计算次数
goto s35; //check finished
s31:
//****** adjust status ************
if (B[26]==B[35]||B[34]==B[25]){
if (B[26]==B[15]||B[34]==B[55]){
print "s3_31 "; // R' U' R' U' R' U R U R
Rightdown (); Upright (); Rightdown();
Upright (); Rightdown ();
Upleft (); Rightup (); Upleft ();
Rightup (); } } // s3_31
if (B[36]==B[25]||B[54]==B[35]){
if (B[36]==B[55]||B[54]==B[15]){
print "s3_32 "; //R U R U R U' R' U' R'
Rightup (); Upleft (); Rightup();
Upleft (); Rightup ();
Upright (); Rightdown (); Upright ();
Rightdown (); } } // s3_32
//**** adjust status *******************
if (B[44]==B[25]&&B[12]==B[35]){
Upright (); Upright (); }
if (B[44]==B[55]&&B[12]==B[35]){
Upright (); Upright (); }
if (B[42]==B[25]&&B[52]==B[35]){
Upleft (); }
if (B[42]==B[55]&&B[52]==B[35]){
Upleft (); }
if (B[48]==B[25]&&B[22]==B[35]){
Upright (); }
if (B[48]==B[55]&&B[22]==B[35]){
Upright (); }
s32: //do medium layer edges ******
if (B[46]==B[25]&&B[32]==B[35]){ //s3_31 left
print "s3_31 ";
Rightdown (); Upright (); Rightdown();
Upright (); Rightdown ();
Upleft (); Rightup (); Upleft ();
Rightup (); } //Turnleft (); }
if (B[46]==B[55]&&B[32]==B[35]){ //s3_32 right
print "s3_32 ";
Rightup (); Upleft (); Rightup();
Upleft (); Rightup ();
Upright (); Rightdown (); Upright ();
Rightdown (); }
Turnright (); // adjust status ******
n=n+1;
if (n>10) goto s30 ; //若没成,重做
s35: //**** check finished ************
if (B[24]==B[25]&&B[26]==B[25]&&
B[34]==B[35]&&B[36]==B[35]&&
B[14]==B[15]&&B[16]==B[15]&&
B[54]==B[55]&&B[56]==B[55]) {
goto s36; }
//else { Upright(); goto s31; }
else { goto s31; }
return;
s36:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《二层四棱》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n ;
}//Astep3 ()
Astep2 (){ //上层四角 *************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(2)《上层四角》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0; goto s25; //check finished
s21:
//**** under 4 corner to top layer ** state adjust
if (B[23]==B[45]||B[31]==B[45]||B[49]==B[45]){
Downleft (); Rightdown ();
Downright (); Rightup (); } //adjust
if (B[39]==B[45]||B[57]==B[45]||B[69]==B[45]){
if (B[39]==B[25]||B[57]==B[25]||B[69]==B[25]){
if (B[39]==B[35]||B[57]==B[35]||B[69]==B[35]){
Downleft (); } } }
if (B[19]==B[45]||B[27]==B[45]||B[61]==B[45]){
if (B[19]==B[25]||B[27]==B[25]||B[61]==B[25]){
if (B[19]==B[35]||B[27]==B[35]||B[61]==B[35]){
Downright (); } } }
if (B[59]==B[45]||B[17]==B[45]||B[67]==B[45]){
if (B[59]==B[25]||B[17]==B[25]||B[67]==B[25]){
if (B[59]==B[35]||B[17]==B[35]||B[67]==B[35]){
Downleft (); Downleft (); } } }
//**** under 4 corner to top layer ********
if (B[29]==B[45]&&B[37]==B[35]&&B[63]==B[25]){
print "s2_21";
Downleft (); Rightdown ();
Downright (); Rightup (); } //s2_21
if (B[37]==B[45]&&B[29]==B[25]&&B[63]==B[35]){
print " s2_22 ";
Rightdown (); Downleft ();
Rightup (); } //s2_22
if (B[63]==B[45]&&B[29]==B[35]&&B[37]==B[25]){
print "s2_23 ";
Rightdown (); Downleft (); Downleft ();
Rightup (); Downright (); Rightdown ();
Downleft (); Rightup (); } //s2_23
Turnleft ();
Downleft ();
n=n+1;
s25: //**** check finished ************
if (B[41]==B[45]&&B[43]==B[45]&&
B[47]==B[45]&&B[49]==B[45]){
goto s26; } else { goto s21; }
return;
s26:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《上层四角》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ", n ;
}//Astep2 ()
Astep1 (){ //上层四棱 ***********
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(1)《上层四棱》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
s11: //**** top 4 edge to under
if (B[12]==B[45]){
Leftdown(); Upright(); Frontleft(); }
if (B[22]==B[45]){
Frontleft() ; Upleft(); Leftdown(); }
if (B[32]==B[45]){
Rightdown(); Upleft(); Frontright(); }
if (B[52]==B[45]){
Backleft (); Upleft(); Rightup(); }
if (B[42]==B[45]){
Backleft (); Backleft (); }
if (B[44]==B[45]){
Leftdown (); Leftdown (); }
if (B[46]==B[45]){
Rightdown(); Rightdown (); }
if (B[48]==B[45]){
Frontleft(); Frontleft (); }
//return;
s12: //**** under layer 4 edges to top ****
if (B[66]==B[45]&&B[38]==B[35]){
Rightup(); Rightup (); }
if (B[68]==B[45]&&B[58]==B[55]){
Backleft(); Backleft (); }
if (B[64]==B[45]&&B[18]==B[15]){
Leftup (); Leftup (); }
if (B[62]==B[45]&&B[28]==B[25]){
Frontright (); Frontright (); }
s13:
if (B[66]==B[45]&&B[38]==B[35]){
Rightup(); Rightup (); }
if (B[66]==B[45]&&B[38]==B[25]){
Downleft (); Frontleft (); Frontleft (); }
if (B[66]==B[45]&&B[38]==B[15]){
Downleft (); Downleft (); Leftup (); Leftup (); }
if (B[66]==B[45]&&B[38]==B[55]){
Downright (); Backright (); Backright (); }
Downleft ();
s14: //**** 2 layer 4 edges to under ****
for (i=0;i<4;i++){
if (B[26]==B[45]){
Rightdown (); Downleft (); Rightup (); }
if (B[34]==B[45]){
Frontright (); Downright (); Frontleft (); }
Turnleft (); }
//*** under 4 edges b45 color ****
if (B[38]==B[45]){
Downleft (); Frontleft (); Rightdown ();
Frontright (); }
if (B[58]==B[45]){
Downleft (); Downleft ();
Frontleft (); Rightdown (); Frontright (); }
if (B[28]==B[45]){
Frontleft (); Rightdown (); Frontright (); }
if (B[18]==B[45]){
Downright (); Frontleft (); Rightdown ();
Frontright (); }
if (B[32]==B[45]){
Rightdown (); Frontright (); Downright ();
Frontleft (); }
n=n+1;
if (n>20) goto s16;
s15: //**** check finished ************
if (B[42]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[48]==B[45]){
goto s16; } else { goto s12; }
return;
s16:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《上层四棱》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n;
}//Astep1()
switchcolor (){
//颜色设置 set cube 1--6 color
//1. 中蓝 2. 深红 3. 中绿 4. 黄色 5. 橙色 6. 淡粉
if (scolor==1){cr1=0; cg1=120; cb1=250; }
if (scolor==2){cr1=200; cg1=0; cb1=0; }
if (scolor==3){cr1=0; cg1=220; cb1=0; }
if (scolor==4){cr1=250; cg1=220; cb1=0; }
if (scolor==5){cr1=250; cg1=150; cb1=0; }
if (scolor==6){cr1=250; cg1=230; cb1=250; }
}//switchcolor ()
drawbox (){ //draw out & show user cube ****
setDisplay (1);
cs.SetStrokeWidth(1);
cs.SetColor(255,80,80,80);
cs.DrawRect (10,30,710,730); // box backcolor
cs.SetColor(255,150,150,150); //cross line
cs.DrawLine(360,50,360,700); //center
cs.DrawLine(20,340,700,340); //center
cs.SetStrokeWidth(2);
for (j=0;j<80;j++){ //draw up cube ****
scolor=B[41];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u1
cs.DrawLine (280+j,140+j/2,360+j,100+j/2);
scolor=B[42];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u2
cs.DrawLine (360+j,180+j/2,440+j,140+j/2);
scolor=B[43];
switchcolor (); //界面块颜色设置
cs.SetColor(255,cr1,cg1,cb1); //u3
cs.DrawLine (440+j,220+j/2,520+j,180+j/2);
scolor=B[44];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u4
cs.DrawLine (200+j,180+j/2,280+j,140+j/2);
scolor=B[45];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u5
cs.DrawLine (280+j,220+j/2,360+j,180+j/2);
// cs.SetColor (255,250,250,0);
// cs.DrawOval (360,220,15,30,90);
scolor=B[46];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u6
cs.DrawLine (360+j,260+j/2,440+j,220+j/2);
scolor=B[47];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u7
cs.DrawLine (120+j,220+j/2,200+j,180+j/2);
scolor=B[48];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u8
cs.DrawLine (200+j,260+j/2,280+j,220+j/2);
scolor=B[49];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u9
cs.DrawLine (280+j,300+j/2,360+j,260+j/2);
}
//draw right cube ******
for (j=0;j<80;j++){ //draw right cube ****
scolor=B[31];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r1
cs.DrawLine (360+j,340-j/2,360+j,420-j/2);
scolor=B[32];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r2
cs.DrawLine (440+j,300-j/2,440+j,380-j/2);
scolor=B[33];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r3
cs.DrawLine (520+j,260-j/2,520+j,340-j/2);
scolor=B[34];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r4
cs.DrawLine (360+j,420-j/2,360+j,500-j/2);
scolor=B[35];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r5
cs.DrawLine (440+j,380-j/2,440+j,460-j/2);
scolor=B[36];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r6
cs.DrawLine (520+j,340-j/2,520+j,420-j/2);
scolor=B[37];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r7
cs.DrawLine (360+j,500-j/2,360+j,580-j/2);
scolor=B[38];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r8
cs.DrawLine (440+j,460-j/2,440+j,540-j/2);
scolor=B[39];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r9
cs.DrawLine (520+j,420-j/2,520+j,500-j/2);
}
//draw front cube ******
for (j=0;j<80;j++){ //draw front cube
scolor=B[21];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f1
cs.DrawLine (120+j,220+j/2,120+j,300+j/2);
scolor=B[22];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f2
cs.DrawLine (200+j,260+j/2,200+j,340+j/2);
scolor=B[23];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f3
cs.DrawLine (280+j,300+j/2,280+j,380+j/2);
scolor=B[24];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f4
cs.DrawLine (120+j,300+j/2,120+j,380+j/2);
scolor=B[25];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f5
cs.DrawLine (200+j,340+j/2,200+j,420+j/2);
scolor=B[26];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f6
cs.DrawLine (280+j,380+j/2,280+j,460+j/2);
scolor=B[27];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f7
cs.DrawLine (120+j,380+j/2,120+j,460+j/2);
scolor=B[28];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f8
cs.DrawLine (200+j,420+j/2,200+j,500+j/2);
scolor=B[29];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f9
cs.DrawLine (280+j,460+j/2,280+j,540+j/2);
}
cs.SetStrokeWidth (9);
//square divide lines *********
cs.SetColor(255,240,240,240);
for (i=0;i<4;i++){
cs.DrawLine(360+i*80,339-i*40,360+i*80,581-i*40);
cs.DrawLine(360-i*80,339-i*40,360-i*80,581-i*40);
cs.DrawLine(120+i*80,220+i*40,360+i*80,100+i*40);
cs.DrawLine(360-i*80,100+i*40,600-i*80,220+i*40);
cs.DrawLine(120,220+i*80,360,340+i*80);
cs.DrawLine(360,340+i*80,600,220+i*80);
}
cs.SetStrokeWidth (1);
//square divide lines *********
cs.SetColor(255,0,0,0);
for (i=1;i<3;i++){
cs.DrawLine(360+i*80,341-i*40,360+i*80,584-i*40);
cs.DrawLine(360-i*80,341-i*40,360-i*80,584-i*40);
cs.DrawLine(121+i*80,219+i*40,360+i*80,100+i*40);
cs.DrawLine(361-i*80,100+i*40,600-i*80,220+i*40);
cs.DrawLine(120,220+i*80,359,340+i*80);
cs.DrawLine(361,340+i*80,600,220+i*80);
}
cs.SetColor(255,240,240,240);
cs.DrawCircle (121,221,5);
cs.DrawCircle (121,460,5);
cs.DrawCircle (600,221,5);
cs.DrawCircle (600,459,5);
cs.DrawCircle (360,101,5);
cs.DrawCircle (360,579,5);
//draw left back down cube figuer ********
cs.SetTextSize (32);
cs.SetColor (255,250,250,20);
cs.DrawText ("Left ",185,150);
cs.DrawText ("Back ",470,150);
cs.DrawText ("Down ",175,555);
cs.DrawText ("Right ",612,350);
cs.DrawText ("Front ",30,350);
cs.DrawText ("Up ",340,80);
cs.SetColor (255,50,50,50); //left cube
cs.DrawRect (18,38,170,190);
scolor=B[11];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L1
cs.DrawRect (20,40,68,88);
cs.DrawRect (349,630,362,643);
scolor=B[12];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L2
cs.DrawRect (70,40,118,88);
cs.DrawRect (364,630,377,643);
scolor=B[13];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L3
cs.DrawRect (120,40,168,88);
cs.DrawRect (379,630,392,643);
scolor=B[14];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L4
cs.DrawRect (20,90,68,138);
cs.DrawRect (349,645,362,658);
scolor=B[15];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L5
cs.DrawRect (70,90,118,138);
cs.DrawRect (364,645,377,658);
scolor=B[16];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L6
cs.DrawRect (120,90,168,138);
cs.DrawRect (379,645,392,658);
scolor=B[17];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L7
cs.DrawRect (20,140,68,188);
cs.DrawRect (349,660,362,673);
scolor=B[18];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L8
cs.DrawRect (70,140,118,188);
cs.DrawRect (364,660,377,673);
scolor=B[19];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L9
cs.DrawRect (120,140,168,188);
cs.DrawRect (379,660,392,673);
scolor=B[31]; //right cube
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r1
cs.DrawRect (450,630,463,643);
scolor=B[32];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r2
cs.DrawRect (465,630,478,643);
scolor=B[33];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r3
cs.DrawRect (480,630,493,643);
scolor=B[34];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r4
cs.DrawRect (450,645,463,658);
scolor=B[35];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r5
cs.DrawRect (465,645,478,658);
scolor=B[36];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r6
cs.DrawRect (480,645,493,658);
scolor=B[37];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r7
cs.DrawRect (450,660,463,673);
scolor=B[38];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r8
cs.DrawRect (465,660,478,673);
scolor=B[39];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r9
cs.DrawRect (480,660,493,673);
cs.SetColor (255,50,50,50); //back cube
cs.DrawRect (548,38,700,190);
scolor=B[51];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b1
cs.DrawRect (550,40,598,88);
cs.DrawRect (500,630,513,643);
scolor=B[52];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b2
cs.DrawRect (600,40,648,88);
cs.DrawRect (515,630,528,643);
scolor=B[53];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b3
cs.DrawRect (650,40,698,88);
cs.DrawRect (530,630,543,643);
scolor=B[54];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b4
cs.DrawRect (550,90,598,138);
cs.DrawRect (500,645,513,658);
scolor=B[55];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b5
cs.DrawRect (600,90,648,138);
cs.DrawRect (515,645,528,658);
scolor=B[56];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b6
cs.DrawRect (650,90,698,138);
cs.DrawRect (530,645,543,658);
scolor=B[57];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b7
cs.DrawRect (550,140,598,188);
cs.DrawRect (500,660,513,673);
scolor=B[58];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b8
cs.DrawRect (600,140,648,188);
cs.DrawRect (515,660,528,673);
scolor=B[59];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b9
cs.DrawRect (650,140,698,188);
cs.DrawRect (530,660,543,673);
cs.SetColor (255,50,50,50); //down cube
cs.DrawRect (138,563,290,715);
scolor=B[61];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d1
cs.DrawRect (140,565,188,613);
cs.DrawRect (400,680,413,693);
scolor=B[62];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d2
cs.DrawRect (190,565,238,613);
cs.DrawRect (415,680,428,693);
scolor=B[63];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d3
cs.DrawRect (240,565,288,613);
cs.DrawRect (430,680,443,693);
scolor=B[64];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d4
cs.DrawRect (140,615,188,663);
cs.DrawRect (400,695,413,708);
scolor=B[65];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d5
cs.DrawRect (190,615,238,663);
cs.DrawRect (415,695,428,708);
scolor=B[66];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d6
cs.DrawRect (240,615,288,663);
cs.DrawRect (430,695,443,708);
scolor=B[67];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d7
cs.DrawRect (140,665,188,713);
cs.DrawRect (400,710,413,723);
scolor=B[68];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d8
cs.DrawRect (190,665,238,713);
cs.DrawRect (415,710,428,723);
scolor=B[69];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d9
cs.DrawRect (240,665,288,713);
cs.DrawRect (430,710,443,723);
scolor=B[21]; //**** front
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f1
cs.DrawRect (400,630,412,643);
scolor=B[22];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f2
cs.DrawRect (415,630,427,643);
scolor=B[23];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f3
cs.DrawRect (430,630,443,643);
scolor=B[24];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f4
cs.DrawRect (400,645,412,658);
scolor=B[25];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f5
cs.DrawRect (415,645,427,658);
scolor=B[26];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f6
cs.DrawRect (430,645,443,658);
scolor=B[27];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f7
cs.DrawRect (400,660,412,673);
scolor=B[28];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f8
cs.DrawRect (415,660,427,673);
scolor=B[29];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f9
cs.DrawRect (430,660,443,673);
scolor=B[41]; //**** up cube
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u1
cs.DrawRect (400,580,412,593);
scolor=B[42];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u2
cs.DrawRect (415,580,427,593);
scolor=B[43];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u3
cs.DrawRect (430,580,443,593);
scolor=B[44];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u4
cs.DrawRect (400,595,412,608);
scolor=B[45];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u5
cs.DrawRect (415,595,427,608);
scolor=B[46];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u6
cs.DrawRect (430,595,443,608);
scolor=B[47];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u7
cs.DrawRect (400,610,412,623);
scolor=B[48];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u8
cs.DrawRect (415,610,427,623);
scolor=B[49];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u9
cs.DrawRect (430,610,443,623);
//**********
s="S > "+intToString (ts);
cs.SetColor(255,250,250,250);
cs.DrawRect (3,3,80,30);
cs.SetColor(255,0,0,250);
cs.SetTextSize (20);
cs.DrawText (s, 10, 22);
cs.SetColor (255,250,250,250);
cs.SetTextSize (20);
cs.DrawText (tim$, 20, 710);
cs.Update ();
}//drawCube () //show cube box
drawButton (){
//setDisplay(1);
cs.SetStrokeWidth(2);
cs.SetFillMode (1);
cs.SetColor(255,250,250,250);
cs.DrawRect (0,2,720,30); // clear print x y
cs.SetColor(255,80,190,180);
cs.DrawRect (0,740,720,995); // btn backcolor
cs.SetColor(255,180,250,250);
cs.SetTextSize (28);
ss1="编译人:张纯叔 ( micelu@126.com ) ";
cs.DrawText (ss1,20,1020);
dy=800; //draw button bn1 - bn12
for (i=0;i<2;i++){
cs.SetColor(255,240,200,20); //big 2B
cs.DrawCircle (480+i*120,800,38);
cs.DrawCircle (518+i*120,800,38);
cs.SetColor(255,0,0,250);
cs.DrawCircle (482+i*120,800,35);
cs.DrawCircle (516+i*120,800,35); }
cs.SetColor(255,240,200,20); //big B
cs.DrawCircle (540,900,42);
cs.DrawCircle (574,900,42);
cs.SetColor(255,0,0,250);
cs.DrawCircle (542,900,38);
cs.DrawCircle (572,900,38);
dy=850;
cs.SetColor(255,240,200,20); //small B
cs.DrawCircle (50,dy-40,27);
cs.DrawRect (50,dy-68,105,dy-13);
cs.DrawCircle (50,dy+20,27);
cs.DrawRect (50,dy-7,105,dy+48);
cs.DrawCircle (370,dy-40,27);
cs.DrawRect (314,dy-68,370,dy-13);
cs.DrawCircle (370,dy+20,27);
cs.DrawRect (314,dy-7,370,dy+48);
cs.DrawCircle (50,dy+100,27);
cs.DrawRect (50,dy+73,105,dy+128);
cs.DrawCircle (370,dy+100,27);
cs.DrawRect (314,dy+73,370,dy+128); //
cs.SetColor(255,0,0,250); //small B center
cs.DrawCircle (50,dy-40,25);
cs.DrawRect (48,dy-66,101,dy-15);
cs.DrawCircle (50,dy+20,25);
cs.DrawRect (48,dy-5,101,dy+46);
cs.DrawCircle (370,dy-40,25);
cs.DrawRect (318,dy-66,368,dy-15);
cs.DrawCircle (370,dy+20,25);
cs.DrawRect (318,dy-5,368,dy+46);
cs.DrawCircle (50,dy+100,25);
cs.DrawRect (50,dy+75,101,dy+126);
cs.DrawCircle (370,dy+100,25);
cs.DrawRect (318,dy+75,368,dy+126);
for (i=0;i<3;i++){ //small 6B
cs.SetColor(255,240,200,20); //small B
cs.DrawCircle (150,dy-70+i*70,27);
cs.DrawRect (150,dy-97+i*70,205,dy-42+i*70);
cs.DrawCircle (270,dy-70+i*70,27);
cs.DrawRect (214,dy-97+i*70,270,dy-42+i*70);
cs.SetColor(255,0,0,250); //small B
cs.DrawCircle (150,dy-70+i*70,25);
cs.DrawRect (148,dy-95+i*70,201,dy-44+i*70);
cs.DrawCircle (270,dy-70+i*70,25);
cs.DrawRect (218,dy-95+i*70,268,dy-44+i*70);
}
cs.SetColor (255,255,255,20);
cs.SetTextSize (22);
cs.DrawText ("左上 L' ",32,816);
cs.DrawText ("左下 L ",32,877);
cs.DrawText ("后左 B' ",32,958);
cs.DrawText ("右上 R ",325,816);
cs.DrawText ("右下 R' ",325,877);
cs.DrawText ("后右 B ",325,958);
cs.DrawText ("上左 U ",132,788);
cs.DrawText ("上右 U' ",224,788);
cs.DrawText ("前左 F' ",132,858);
cs.DrawText ("前右 F ",224,858);
cs.DrawText ("下左 D' ",132,928);
cs.DrawText ("下右 D ",224,928);
cs.SetTextSize (26);
cs.DrawText ("左旋转 ",460,808);
cs.DrawText ("右旋转 ",582,808);
cs.DrawText ("翻 转 ",526,908);
cs.Update ();
}//drawButton ()
Turnup (){ //向上翻转
sw[1]=B[21]; //temp
sw[2]=B[22];
sw[3]=B[23];
sw[4]=B[24];
sw[5]=B[25];
sw[6]=B[26];
sw[7]=B[27];
sw[8]=B[28];
sw[9]=B[29];
B[21]=B[61];
B[22]=B[62];
B[23]=B[63];
B[24]=B[64];
B[25]=B[65];
B[26]=B[66];
B[27]=B[67];
B[28]=B[68];
B[29]=B[69];
B[61]=B[59];
B[62]=B[58];
B[63]=B[57];
B[64]=B[56];
B[65]=B[55];
B[66]=B[54];
B[67]=B[53];
B[68]=B[52];
B[69]=B[51];
B[59]=B[41];
B[58]=B[42];
B[57]=B[43];
B[56]=B[44];
B[55]=B[45];
B[54]=B[46];
B[53]=B[47];
B[52]=B[48];
B[51]=B[49];
B[41]=sw[1];
B[42]=sw[2];
B[43]=sw[3];
B[44]=sw[4];
B[45]=sw[5];
B[46]=sw[6];
B[47]=sw[7];
B[48]=sw[8];
B[49]=sw[9];
sw[1]=B[11];
B[11]=B[13];
B[13]=B[19];
B[19]=B[17];
B[17]=sw[1];
sw[2]=B[12];
B[12]=B[16];
B[16]=B[18];
B[18]=B[14];
B[14]=sw[2];
sw[1]=B[31];
B[31]=B[37];
B[37]=B[39];
B[39]=B[33];
B[33]=sw[1];
sw[2]=B[32];
B[32]=B[34];
B[34]=B[38];
B[38]=B[36];
B[36]=sw[2];
ts=ts+1;
drawbox ();
print "do> Turn Up ";
}//Turnup ()
Turnright (){ //右旋转
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
sw[4]=B[24];
sw[5]=B[25];
sw[6]=B[26];
sw[7]=B[27];
sw[8]=B[28];
sw[9]=B[29];
B[21]=B[11];
B[22]=B[12];
B[23]=B[13];
B[24]=B[14];
B[25]=B[15];
B[26]=B[16];
B[27]=B[17];
B[28]=B[18];
B[29]=B[19];
B[11]=B[51];
B[12]=B[52];
B[13]=B[53];
B[14]=B[54];
B[15]=B[55];
B[16]=B[56];
B[17]=B[57];
B[18]=B[58];
B[19]=B[59];
B[51]=B[31];
B[52]=B[32];
B[53]=B[33];
B[54]=B[34];
B[55]=B[35];
B[56]=B[36];
B[57]=B[37];
B[58]=B[38];
B[59]=B[39];
B[31]=sw[1];
B[32]=sw[2];
B[33]=sw[3];
B[34]=sw[4];
B[35]=sw[5];
B[36]=sw[6];
B[37]=sw[7];
B[38]=sw[8];
B[39]=sw[9];
sw[1]=B[41];
B[41]=B[43];
B[43]=B[49];
B[49]=B[47];
B[47]=sw[1];
sw[2]=B[42];
B[42]=B[46];
B[46]=B[48];
B[48]=B[44];
B[44]=sw[2];
sw[1]=B[61];
B[61]=B[67];
B[67]=B[69];
B[69]=B[63];
B[63]=sw[1];
sw[2]=B[62];
B[62]=B[64];
B[64]=B[68];
B[68]=B[66];
B[66]=sw[2];
ts=ts+1;
drawbox ();
print "do> Turn right ";
}//Turnright ()
Turnleft (){ //左旋转
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
sw[4]=B[24];
sw[5]=B[25];
sw[6]=B[26];
sw[7]=B[27];
sw[8]=B[28];
sw[9]=B[29];
B[21]=B[31];
B[22]=B[32];
B[23]=B[33];
B[24]=B[34];
B[25]=B[35];
B[26]=B[36];
B[27]=B[37];
B[28]=B[38];
B[29]=B[39];
B[31]=B[51];
B[32]=B[52];
B[33]=B[53];
B[34]=B[54];
B[35]=B[55];
B[36]=B[56];
B[37]=B[57];
B[38]=B[58];
B[39]=B[59];
B[51]=B[11];
B[52]=B[12];
B[53]=B[13];
B[54]=B[14];
B[55]=B[15];
B[56]=B[16];
B[57]=B[17];
B[58]=B[18];
B[59]=B[19];
B[11]=sw[1];
B[12]=sw[2];
B[13]=sw[3];
B[14]=sw[4];
B[15]=sw[5];
B[16]=sw[6];
B[17]=sw[7];
B[18]=sw[8];
B[19]=sw[9];
sw[1]=B[41];
B[41]=B[47];
B[47]=B[49];
B[49]=B[43];
B[43]=sw[1];
sw[2]=B[42];
B[42]=B[44];
B[44]=B[48];
B[48]=B[46];
B[46]=sw[2];
sw[1]=B[61];
B[61]=B[63];
B[63]=B[69];
B[69]=B[67];
B[67]=sw[1];
sw[2]=B[62];
B[62]=B[66];
B[66]=B[68];
B[68]=B[64];
B[64]=sw[2];
ts=ts+1;
drawbox ();
print "do> Turn left ";
}//Turnleft ()
Downleft (){ //下左 D1
sw[1]=B[27];
sw[2]=B[28];
sw[3]=B[29];
B[27]=B[37];
B[28]=B[38];
B[29]=B[39];
B[37]=B[57];
B[38]=B[58];
B[39]=B[59];
B[57]=B[17];
B[58]=B[18];
B[59]=B[19];
B[17]=sw[1];
B[18]=sw[2];
B[19]=sw[3];
sw[1]=B[61];
B[61]=B[63];
B[63]=B[69];
B[69]=B[67];
B[67]=sw[1];
sw[2]=B[62];
B[62]=B[66];
B[66]=B[68];
B[68]=B[64];
B[64]=sw[2];
ts=ts+1;
drawbox ();
print "do> D' Down left ";
}//Downleft()
Downright (){ //下右 D
sw[1]=B[27];
sw[2]=B[28];
sw[3]=B[29];
B[27]=B[17];
B[28]=B[18];
B[29]=B[19];
B[17]=B[57];
B[18]=B[58];
B[19]=B[59];
B[57]=B[37];
B[58]=B[38];
B[59]=B[39];
B[37]=sw[1];
B[38]=sw[2];
B[39]=sw[3];
sw[1]=B[61];
B[61]=B[67];
B[67]=B[69];
B[69]=B[63];
B[63]=sw[1];
sw[2]=B[62];
B[62]=B[64];
B[64]=B[68];
B[68]=B[66];
B[66]=sw[2];
ts=ts+1;
drawbox ();
print "do> D Down right ";
}//Downright()
Backleft (){ //后左 B1
sw[1]=B[41];
sw[2]=B[42];
sw[3]=B[43];
B[41]=B[17];
B[42]=B[14];
B[43]=B[11];
B[17]=B[69];
B[14]=B[68];
B[11]=B[67];
B[69]=B[33];
B[68]=B[36];
B[67]=B[39];
B[33]=sw[1];
B[36]=sw[2];
B[39]=sw[3];
sw[1]=B[51];
B[51]=B[53];
B[53]=B[59];
B[59]=B[57];
B[57]=sw[1];
sw[2]=B[52];
B[52]=B[56];
B[56]=B[58];
B[58]=B[54];
B[54]=sw[2];
ts=ts+1;
drawbox ();
print "do> B' Back left ";
}//Backleft()
Backright (){ //后右 B
sw[1]=B[41];
sw[2]=B[42];
sw[3]=B[43];
B[41]=B[33];
B[42]=B[36];
B[43]=B[39];
B[33]=B[69];
B[36]=B[68];
B[39]=B[67];
B[69]=B[17];
B[68]=B[14];
B[67]=B[11];
B[17]=sw[1];
B[14]=sw[2];
B[11]=sw[3];
sw[1]=B[51];
B[51]=B[57];
B[57]=B[59];
B[59]=B[53];
B[53]=sw[1];
sw[2]=B[52];
B[52]=B[54];
B[54]=B[58];
B[58]=B[56];
B[56]=sw[2];
ts=ts+1;
drawbox ();
print "do> B Back right ";
}//Backright()
Frontleft (){ //前左 F1
sw[1]=B[47];
sw[2]=B[48];
sw[3]=B[49];
B[47]=B[31];
B[48]=B[34];
B[49]=B[37];
B[31]=B[63];
B[34]=B[62];
B[37]=B[61];
B[63]=B[19];
B[62]=B[16];
B[61]=B[13];
B[19]=sw[1];
B[16]=sw[2];
B[13]=sw[3];
sw[1]=B[21];
B[21]=B[23];
B[23]=B[29];
B[29]=B[27];
B[27]=sw[1];
sw[2]=B[22];
B[22]=B[26];
B[26]=B[28];
B[28]=B[24];
B[24]=sw[2];
ts=ts+1;
drawbox ();
print "do> F' Front left ";
}//Frontleft()
Frontright (){ //前右 F
sw[1]=B[47];
sw[2]=B[48];
sw[3]=B[49];
B[47]=B[19];
B[48]=B[16];
B[49]=B[13];
B[19]=B[63];
B[16]=B[62];
B[13]=B[61];
B[63]=B[31];
B[62]=B[34];
B[61]=B[37];
B[31]=sw[1];
B[34]=sw[2];
B[37]=sw[3];
sw[1]=B[21];
B[21]=B[27];
B[27]=B[29];
B[29]=B[23];
B[23]=sw[1];
sw[2]=B[22];
B[22]=B[24];
B[24]=B[28];
B[28]=B[26];
B[26]=sw[2];
ts=ts+1;
drawbox ();
print "do> F Front right ";
}//Frontright()
Upleft (){ //上左 U
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
B[21]=B[31];
B[22]=B[32];
B[23]=B[33];
B[31]=B[51];
B[32]=B[52];
B[33]=B[53];
B[51]=B[11];
B[52]=B[12];
B[53]=B[13];
B[11]=sw[1];
B[12]=sw[2];
B[13]=sw[3];
sw[1]=B[41];
B[41]=B[47];
B[47]=B[49];
B[49]=B[43];
B[43]=sw[1];
sw[2]=B[42];
B[42]=B[44];
B[44]=B[48];
B[48]=B[46];
B[46]=sw[2];
ts=ts+1;
drawbox ();
print "do> U Up left ";
}//Upleft()
Upright (){ //上右 U1
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
B[21]=B[11];
B[22]=B[12];
B[23]=B[13];
B[11]=B[51];
B[12]=B[52];
B[13]=B[53];
B[51]=B[31];
B[52]=B[32];
B[53]=B[33];
B[31]=sw[1];
B[32]=sw[2];
B[33]=sw[3];
sw[1]=B[41];
B[41]=B[43];
B[43]=B[49];
B[49]=B[47];
B[47]=sw[1];
sw[2]=B[42];
B[42]=B[46];
B[46]=B[48];
B[48]=B[44];
B[44]=sw[2];
ts=ts+1;
drawbox ();
print "do> U' Up right ";
}//Upright ()
Rightdown (){ //右下 R1
sw[1]=B[23];
sw[2]=B[26];
sw[3]=B[29];
B[23]=B[43];
B[26]=B[46];
B[29]=B[49];
B[43]=B[57];
B[46]=B[54];
B[49]=B[51];
B[57]=B[63];
B[54]=B[66];
B[51]=B[69];
B[63]=sw[1];
B[66]=sw[2];
B[69]=sw[3];
sw[1]=B[31];
B[31]=B[33];
B[33]=B[39];
B[39]=B[37];
B[37]=sw[1];
sw[2]=B[32];
B[32]=B[36];
B[36]=B[38];
B[38]=B[34];
B[34]=sw[2];
ts=ts+1;
drawbox ();
print "do> R' Right down ";
}//Rightdown()
Rightup (){ //右上 R
sw[1]=B[23];
sw[2]=B[26];
sw[3]=B[29];
B[23]=B[63];
B[26]=B[66];
B[29]=B[69];
B[63]=B[57];
B[66]=B[54];
B[69]=B[51];
B[57]=B[43];
B[54]=B[46];
B[51]=B[49];
B[43]=sw[1];
B[46]=sw[2];
B[49]=sw[3];
sw[1]=B[31];
B[31]=B[37];
B[37]=B[39];
B[39]=B[33];
B[33]=sw[1];
sw[2]=B[32];
B[32]=B[34];
B[34]=B[38];
B[38]=B[36];
B[36]=sw[2];
ts=ts+1;
drawbox ();
print "do> R Right up ";
}//Rightup()
Leftdown (){ //左下 L
sw[1]=B[21];
sw[2]=B[24];
sw[3]=B[27];
B[21]=B[41];
B[24]=B[44];
B[27]=B[47];
B[41]=B[59];
B[44]=B[56];
B[47]=B[53];
B[59]=B[61];
B[56]=B[64];
B[53]=B[67];
B[61]=sw[1];
B[64]=sw[2];
B[67]=sw[3];
sw[1]=B[11];
B[11]=B[17];
B[17]=B[19];
B[19]=B[13];
B[13]=sw[1];
sw[2]=B[12];
B[12]=B[14];
B[14]=B[18];
B[18]=B[16];
B[16]=sw[2];
ts=ts+1;
drawbox ();
print "do> L Left down ";
}//Leftdown()
Leftup (){ //左上 L1
sw[1]=B[21];
sw[2]=B[24];
sw[3]=B[27];
B[21]=B[61];
B[24]=B[64];
B[27]=B[67];
B[61]=B[59];
B[64]=B[56];
B[67]=B[53];
B[59]=B[41];
B[56]=B[44];
B[53]=B[47];
B[41]=sw[1];
B[44]=sw[2];
B[47]=sw[3];
sw[1]=B[11];
B[11]=B[13];
B[13]=B[19];
B[19]=B[17];
B[17]=sw[1];
sw[2]=B[12];
B[12]=B[16];
B[16]=B[18];
B[18]=B[14];
B[14]=sw[2];
ts=ts+1;
drawbox ();
print "do> L' Left up ";
}//Leftup()
newgame (){
//打乱魔方,可依机器速度增加次数
Rn=(int)(random ()*5+1) ;
for (t=0; t<Rn+8; t++){
for (i=0; i<4; i++){
Rn=(int)(random()*11+1); //打乱 random bn
if (Rn==1){Leftup (); }
if (Rn==2){Leftdown (); }
if (Rn==3){Rightup (); }
if (Rn==4){Rightdown (); }
if (Rn==5){Upleft (); }
if (Rn==6){Upright (); }
if (Rn==7){Frontleft (); }
if (Rn==8){Frontright (); }
if (Rn==9){Backleft (); }
if (Rn==10){Backright (); }
if (Rn==11){Downleft (); }
if (Rn==12){Downright (); }
} }
Turnup (); //起首白色置上
Turnup ();
ts=0 ; //init step number
//********
s3="开始游戏 ";
getTime (tim);
newhh=tim[0];
newmm=tim[1];
newss=tim[2];
oldhh=newhh;
oldmm=newmm;
oldss=newss;
hhts=intToString (tim[0]);
mmts=intToString (tim[1]);
ssts=intToString (tim[2]);
if (newhh<10)hhts="0"+hhts;
if (newmm<10)mmts="0"+mmts;
if (newss<10)ssts="0"+ssts;
ss2=hhts+" : "+mmts+" : "+ssts;
print "开始时间 "+ss2;
tim$=ss2;
kn=2; //set canvasProc
ts=0 ; //init step number
}//newgame ()
restore (){ ///还原为 初始状态
//initlize cube color
for (i=1;i<10;i++){
B[10+i]=1;
B[20+i]=2;
B[30+i]=3;
B[40+i]=4;
B[50+i]=5;
B[60+i]=6; }
drawButton ();
ts=0 ; //init step number
drawbox ();
}//restore ()
drawcover (){
restore (); //initlize cube
cs.SetTextStyle (1); //正常 粗体 斜体字
cs.SetStrokeWidth (2);
cs.SetTextSize (78);
s="魔方 Magic Cube ";
cs.SetColor (255,250,20,20);
cs.DrawText (s,74,454);
cs.SetTextSize (76);
cs.SetColor (255,160,30,240);
cs.DrawText (s,80,450);
cs.SetFillMode (0);//0不填色,1填色
cs.SetColor (255,250,250,0);
cs.DrawText (s,80,450);
cs.SetTextSize (26);
cs.SetFillMode (1);//0不填色,1填色
cs.SetTextStyle (0); //正常 粗体 斜体字
s="@Copyright version 3.1.2 ";
cs.SetColor (255,250,50,50);
cs.DrawText (s,212,490);
cs.SetTextStyle (0);
cs.Update ();
}//drawcover()
myMenuProc(int nMen,int nContext){
if(nMen==200){
print "开始游戏";
// cs.ClearDraw (0,src);
clearOutput ();
newgame(); }
if(nMen==201){
print "上层四棱";
Astep1 (); }
if(nMen==202){
print "上层四角";
Astep2 (); }
if (nMen==203){//
print "二层四棱";
Astep3 (); }
if (nMen==204){//选项
print "顶层十字";
Astep4 (); }
if(nMen==205){//close canvas
print "顶面同色";
Astep5 (); }
if(nMen==206){//show canvas
print "六面同色";
Astep6 (); }
if (nMen==207){//
clearOutput ();
//print "自动演示";
Autoplay (); }
if (nMen==208){//show step data
setDisplay (0); }
if (nMen==209){//show canvas
setDisplay (1); }
if (nMen==210){//exit
clearOutput();
cs.ClearDraw (0,src);
setDisplay (0);
exit (0); }
}//myMenu()
myToolBarProc(int nBtn,int nContext){
if(nBtn==100){//Newgame
clearOutput ();
newgame(); }
if(nBtn==101){//restore cube box
clearOutput ();
restore (); }
if(nBtn==102){//AutoPlay
clearOutput ();
//print "自动演示";
Autoplay (); }
if(nBtn==103){//显示图板
setDisplay (1); }
if(nBtn==104){//退出程序
clearOutput();
cs.ClearDraw (0,src);
setDisplay (0);
exit (0); }
if(nBtn==105){//版本信息
setDisplay (1);
drawcover (); }
}//my toolbar()
savepic (){
filebox.SetTitle("保存图片(*.bmp;*.jpg;*.png)");
filebox.SetFilter(".bmp;.jpg;.png");
filebox.SetMode(1);
filebox.Show();
if(filebox.GetCount()==1){
fname=filebox.GetFileName(0);
cs.SaveBitmap(fname); }
} //savepic ()
//**** END ********