当前位置:文档之家› c语言数独字谜游戏课程设计

c语言数独字谜游戏课程设计

学生课程设计报告
课程设计题目:
数独字谜游戏
专 业 名 称: 软件工程
2013 年 6 月 21 日
一、课程设计内容
数独字谜游戏:数独字谜游戏是在一个 9x9 的正方形内,给出一定的数字, 让玩家在剩余的空格之内填写数字,最终使每一行,每一列,每一个 3x3 的小 正方形都只有 1-9,并且不重复,这样玩家就算通关的一款游戏。
} else { setTextColor(3); cout<<"‖"; for(q=0,p=0;q<31,p<31;q++,p++) { if(i==b[q]&&j==c[p]) { setTextColor(14); cout<<a[i][j]; break; } if(q==30&&p==30) { setTextColor(12); cout<<a[i][j]; } } setTextColor(3); cout<<" "; } } setTextColor(3); cout<<"‖"<<endl; } setTextColor(3); cout<<" ‖==================================‖"<<endl; cout<<" ‖==================================‖"<<endl; for(i=6;i<9;i++) { setTextColor(15); cout<<" "<<(i+1)<<" "; for(j=0;j<9;j++) { if(j%3!=0) { setTextColor(3); cout<<"| "; for(q=0,p=0;q<31,p<31;q++,p++) { if(i==b[q]&&j==c[p]) { setTextColor(14);
break; } if(q==30&&p==30) { setTextColor(12); cout<<a[i][j]; } } setTextColor(3); cout<<" "; } } setTextColor(3); cout<<"‖"<<endl; } setTextColor(3); cout<<" ‖==================================‖"<<endl; cout<<" ‖==================================‖"<<endl; for(i=3;i<6;i++) { setTextColor(15); cout<<" "<<(i+1)<<" "; for(j=0;j<9;j++) { if(j%3!=0) { setTextColor(3); cout<<"| "; for(q=0,p=0;q<31,p<31;q++,p++) { if(i==b[q]&&j==c[p]) { setTextColor(14); cout<<a[i][j]; break; } if(q==30&&p==30) { setTextColor(12); cout<<a[i][j]; } } setTextColor(3); cout<<" ";
3.主函数int main() void main() { PlaySound((char*)"kanong.wav",NULL,SND_ASYNC|SND_LOOP); char a[9][10]={{"493761528"}, {"582943167"}, {"716528349"}, {"139674852"}, {"658219734"}, {"247835691"}, {"975382416"}, {"821456973"}, {"364197285"}}; int b[81],c[81],q=0,p=0; int k,x; do{ setTextColor(14); cout<<" *^0^*<<<<<欢迎进入数独游戏>>>>>*^0^*\n"; setTextColor(10); cout<<"请选择游戏的难易级别为?(3—高,2—中,1—低):"<<endl; cin>>k; switch(k) { int i,j,m,n,gs; case 1: srand((int)time(0)); for(gs=0;gs<30;gs++)//随机在已经布满的 9x9 宫格里,运用随机数,并且 以系统时间为参数,随机产生空白字符, { //低难度的数独,每次产生的空 白字符为 22 个左右, m=(int)(10*rand()/(RAND_MAX+1.0)); n=(int)(10*rand()/(RAND_MAX+1.0)); a[m][n]=' '; b[q]=m; //将随机产生的空白字符的坐标分别存在 b,c 两个数 组中. c[p]=n; q++; p++; } b[30]=10,c[30]=10; do {
setTextColor(15); cout<<" 1 2 3 4 5 6 7 8 9"<<endl; setTextColor(3); cout<<" __________________"<<endl; cout<<" ‖----------------------------------‖"<<endl; for(i=0;i<3;i++) { setTextColor(15); cout<<" "<<(i+1)<<" "; for(j=0;j<9;j++) //输出不同颜色的题目字符和空白字符. { if(j%3!=0) { setTextColor(3); cout<<"| "; for(q=0,p=0;q<31,p<31;q++,p++) // 将 随 机 的 空 白字符单独表示出来,并且以另一种颜色输出表示. { if(i==b[q]&&j==c[p]) { setTextColor(14); cout<<a[i][j]; break; } if(q==30&&p==30) //将 剩 下 的 题 目 字符用另一种颜色输出表示 { setTextColor(12); cout<<a[i][j]; } } setTextColor(3); cout<<" "; } else { setTextColor(3); cout<<"‖"; for(q=0,p=0;q<31,p<31;q++,p++) { if(i==b[q]&&j==c[p]) { setTextColor(14); cout<<a[i][j];
cout<<a[i][j]; break; } if(q==30&&p==30) { setTextColor(12); cout<<a[i][j]; } } setTextColor(3); cout<<" "; } else { setTextColor(3); cout<<"‖"; for(q=0,p=0;q<31,p<31;q++,p++) { if(i==b[q]&&j==c[p]) { setTextColor(14); cout<<a[i][j]; break; } if(q==30&&p==30) { setTextColor(12); cout<<a[i][j]; } } setTextColor(3); cout<<" "; } } setTextColor(3); cout<<"‖"<<endl; } setTextColor(3); cout<<" ‖----------------------------------‖"<<endl; cout<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄"<<endl; if(yz(a)==true) break; setTextColor(10); cout<<" 请 输 入 要 输 入 数 字 的 坐 标 , 以 及 要 填 入 的 数 字 ( 先 行 后 //输入每次要输入的数字.
相关主题