## cube written by Yさ BEGIN{ # サイズ決定 MAXSIZE=10; printf("\nSize (3-%d) ?>", MAXSIZE); do{ max=""; getline max; }while(max<3 && MAXSIZE5)?5:max; sc=0; # 得点 bonus=20; do{ disp(); which(); }while(life>0 && nowPos!=way-1); if(sc>0) sc += 10*max; # ボーナス加算 if(life>0){ s="*** 脱出成功! おめでとう!! ***"; } else{ s="... あなたは しにました"; } printf("\n\n%s\n\n (SCORE:%05d0)\n", s, sc); }while( life==0 && tryAgain()=="y" ); exit; } END{ printf("\n\n## 部屋移動の履歴 ##"); pushEnter(); delete times; printf("[%03d](%d)\n", history[0], ++times[history[0]]); for(i=1; i [%03d](%d)\n", history[i], ++times[history[i]]); } function tryAgain( yn) { print "\n\nもう一度、同じ迷宮に挑戦しますか?"; printf("y:はい, n:もう止める >"); do{ yn=""; getline yn; yn=tolower(yn); }while(yn!="y" && yn!="n"); return yn; } function swap(tbl,p1,p2, t){ t=tbl[p1]; tbl[p1]=tbl[p2]; tbl[p2]=t; } function rndRange(size, i) { delete rndList; for(i=0; i=way-2) p+=3; # +3=スタートとゴールを繋がない if((cnt=startDetect(p))>0) ++ofs; }while(cnt>0); connect(0, p, d); setRoomType(p, 6); } # 残りを適当に繋ぐ m1=int((1 + way-2 +1)/2); m2=int((way + rooms-1 +1)/2); connectRange(1, m1-1, m2, rooms-1); connectRange(m1,way-2, way, m2-1); connectRange(1, way-3, way+1,rooms-1); for(i=1; i7)?0:(rnd(kind)); } function startDetect(p, d,c) { c=0; for(d=1; d<=6; ++d) if(room[p,d]==0) ++c; return c; } function connect(base, tgt, st, d) { d=st; while(room[base, d]>-1 || room[tgt, 7-d]>-1){ if(++d>6) d=1; if(d==st) return 0; } room[base, d]=tgt; room[tgt, 7-d]=base; return d; } function connectRange(b1_s, b1_e, b2_s, b2_e, i,n,c,p,x) { c=b1_e+1 - b1_s; n=b2_e+1 - b2_s +c; for(i=0; i=lv)?(t2-lv):t1)); } ## ## 扉指定 ## function which( p,tmp,x,y) { if(life==0 || nowPos==way-1) return; do{ printf("Which Door?>"); do{ tmp=""; getline tmp; }while(tmp<1 || 6=10000){ print "\nその扉はロックされています。"; } }while(p<0 || p>=10000); move(p); } function move(nextPos) { history[++walk]=roomNo[(nowPos=nextPos)]; if(++times[roomNo[nowPos]]==1) ++sc; print "\n移動しました。"; } ## ## 状況表示 ## function disp( n,d,type,cnt,visit,used) { type=room[nowPos, 0]; # 表示前に扉のロック/ロック解除を行う if(type==1){ doorUnlock(); if((cnt=unique()-1)>=1) event01(cnt); # 一部の扉をロック else type=(room[nowPos, 0]=2); # ロック対象外が作れないなら、全ロックに変更 } if(type==2) doorLock(); dispRoom(); print ""; if(type==1){ print " 扉がロックされました!"; print " 移動できる部屋が制限されました。"; }else if(type==2){ n=(rnd(10)>1)?2:3; d=rnd(6)+1; print " すべての扉がロックされました!"; printf(" %dが%d回連続して出るまで他の部屋へ移動できません。\n", d,n); event02(n,d,bonus); }else if(type==3){ if((n=makeVisit(visit,used))>0){ printf(" %d部屋強制的に移動させられます!\n", n); event03(n,visit,used); } }else if(type==4){ n=rnd(5)+1; print " サイコロが振られ、出た目が1つ記録されました。"; printf(" %d回以内に何の目か当てないとトラップが発動します。\n", n); event04(n); }else if(type==5){ n=rnd(5)+1; rndRange(6); print " センサーに引っ掛かりました!"; printf(" %sの目が出ないとトラップが発動します。\n", rndListToStr(n)); event05(n); }else if(type==6){ printf(" 部屋番号%03dへ飛ばされます!\n", roomNo[0]); pushEnter(); event06(); } } function safe() { print " トラップを回避できました。"; sc+=10; dispRoom(); } function dead() { print " 回避不能! トラップが発動しました!!"; if(--life>0) printf(" ダメージを受け、生命力が1つ減りました。(残り%d)\n", life); pushEnter(); if(life>0) dispRoom(); } function shootDice(unfair, e) { printf(" サイコロを振ります。"); pushEnter(); printf("%dが出ました。\n\n", e=(unfair>0)?unfair:(rnd(6)+1)); return e; } function rndListToStr(n, s,d,list,i,j) { delete list; for(d=0; dlist[j]) swap(list,i,j); s=sprintf("%d", list[0]); for(d=1; d>"); getline tmp; } function dispRoom( d,n,p) { n=times[(p=roomNo[nowPos])]; printf("\n現在位置:部屋番号%03d (%s)\n", p, (n>1)?(n+""):("初")); for(d=1; d<=6; ++d){ p=room[nowPos, d]; printf(" [%s]", (p==-1)?(" "):((p>=10000)?("x"):(d+""))); } print ""; for(d=1; d<=6; ++d){ if((p=room[nowPos, d])>=10000) p-=10000; if(p==-1) printf(" ***"); else printf(" %03d", roomNo[p]); } print ""; } function unique( c,d,list,p) { delete list; for(d=1; d<=6; ++d) if((p=room[nowPos, d])!=-1) ++list[p]; for(d in list) ++c; return c; } function doorLock( d) { for(d=1; d<=6; ++d) if(room[nowPos, d]!=-1) room[nowPos, d]+=10000; } function doorUnlock( d) { for(d=1; d<=6; ++d) if(room[nowPos, d]>=10000) room[nowPos, d]-=10000; } ## ## 移動制限 (type1) ## function event01(cnt, n,d,p,c,ofs) { rndRange((n=rnd(cnt)+1)); c=0; ofs=rnd(6)+1; do{ d=rndList[c]+ofs; if(room[nowPos, d]==-1){ if(++ofs>6) ofs=1; }else{ room[nowPos, d]+=10000; ++c; } }while(c=10000){ p-=10000; for(c=1; c<=6; ++c) if(c!=d && room[nowPos, c]==p) room[nowPos, c]+=10000; } } } ## ## 移動制限 (type2) ## function event02(n, d, bonus, c,e) { printf(" (%d回以内に解除できると、ボーナス点を獲得できます)\n\n", bonus); c=1; do{ printf(" %d/%d回目:", c,n); if(shootDice((bonus>0)?0:d)==d) ++c; else c=1; if(--bonus<0) bonus=0; }while(c<=n); print " 扉のロックが解除されました。"; if(bonus>0) printf(" (ボーナス点 %05d0)\n", bonus); sc+=bonus; doorUnlock(); dispRoom(); } ## ## 強制移動 (type3) ## function event03(cnt,visit,used, i,p,nx) { printf(" %3s%d: 扉[%d]\n", "", 1, used[0]); for(i=1; i<=cnt-1; ++i) printf(" -> %d: 扉[%d]\n", i+1, used[i]); pushEnter(); p=nowPos; for(i=0; i<=cnt-1; ++i){ nx=room[p, used[i]]; p=nx; if(i!=cnt-1){ print "\n移動しました。"; printf("\n現在位置:部屋番号%03d\n", roomNo[p]); } } move(p); disp(); } function makeVisit(visit,used, last,able,cnt,nx,p,same,h,d) { delete visit; delete used; last=rnd(3)+1; p=visit[0]=nowPos; cnt=1; do{ delete able; num=0; for(d=1; d<=6; ++d){ nx=room[p,d]; if(nx==-1 || nx==way-1) continue; same=0; for(h=0; h"); do{ tmp=""; getline tmp; }while(tmp<1 || 60); if(ans!=tmp){ printf(" (正解は%d)\n\n", ans); dead(); }else safe(); } ## ## トラップ (type5) ## function event05(n, e,d) { e=shootDice(0); for(d=0; d