find the pairs
来源:互联网 发布:软件质量管理部门职责 编辑:程序博客网 时间:2024/06/12 22:27
简版c语言“找你妹”(find the pairs)游戏
功能:
1.使用8个随机对(pairs)填充4x4矩阵(元素为ASCII字符);
2.短暂的显示随机矩阵;
3.允许玩家随机选择两个元素,并显示内容;
4.若玩家选择正确,则保持显示,否则隐藏;
5.玩家可以在任何时候按q退出游戏;
6.一旦8对find成功,结束游戏;
demo1:
#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>void printMatrix(int choose[],char c[]){ int i,j; char question = 63; for(i = 0;i<4;i++) { for(j = 0;j<4;j++) { if(choose[i*4+j] == 1) printf("%c ",c[i*4+j]); else printf("%c ",question); } printf("\n"); }}int main(){ int i,j; srand(time(0)); char c[16] = {0}; for(i = 0;i<8;i++) { c[i] = rand()%128; c[i+8] = c[i]; } for(i = 0;i<100;i++) { int j1 = rand()%16; int j2 = rand()%16; char tmp = c[j1]; c[j1] = c[j2]; c[j2] = tmp; } for(i = 0;i<4;i++) { for(j = 0;j<4;j++) { printf("%c ",c[i*4+j]); } printf("\n"); } Sleep(2000); int choose[16] = {0}; int k = 0; while(1) { system("cls"); printMatrix(choose,c); printf("please input your choose ? Row Column\n"); int row1,column1; scanf("%d %d",&row1,&column1); int num1 = row1*4+column1-5; choose[num1] = 1; system("cls"); printMatrix(choose,c); printf("please input your choose ? Row Column\n"); int row2,column2; scanf("%d %d",&row2,&column2); int num2 = row2*4+column2-5; choose[num2] = 1; system("cls"); printMatrix(choose,c); Sleep(2000); if(c[num1] != c[num2]) { choose[num1] = 0; choose[num2] = 0; } k++; int mark = 1; int q; for(q = 0;q<16;q++) { if(choose[q]==0) { mark = 0; break; } } if(mark == 1) break; } system("cls"); printMatrix(choose,c); printf("total steps:%d",k); return 0;}
demo2:
#include <iostream>#include <vector>#include <windows.h>#include <string>#include <conio.h>using namespace std;void main(){ char * a1 = new char[16];bool * a2 = new bool[16];memset(a2, false, 16);for(int i = 0; i < 16; i += 2){char temp = rand() % 256;do{temp = rand() % 256;}while(temp == '\r' || temp == ' ' || temp < 0); a1[i] = temp;a1[i + 1] = temp;}for(int i = 0; i < 16; i++){int buffer = rand() % 16;swap(a1[i], a1[buffer]);}for(int i = 0; i < 16; i++){cout<<a1[i];if((i + 1) % 4 == 0 && i > 0){cout<<endl;} else {cout<<" ";}}//Sleep(3000);//system("cls"); //产生随机数组完毕string str1 = "", str2 = "";int select1, select2;char isGoingOn ;while(true){cout<<"输入这次判断的结果:"<<endl;char ch = _getch();cout<<ch;while(isdigit(ch)){str1 += ch;ch = _getch();cout<<ch;}if(ch == 'q') exit(0); ch = _getch();cout<<ch; while(isdigit(ch)){str2 += ch;ch = _getch();cout<<ch;}if(ch == 'q') exit(0);int index1 = stoi(str1) - 1;int index2 = stoi(str2) - 1;if(a1[index1] == a1[index2] && index1 != index2){a2[index1] = a2[index2] = true;}str1 = "";str2 = "";cout<<"输出如下:"<<endl;for(int i = 0; i < 16; i++){if(a2[i])cout<<a1[i];else cout<<" ";if((i + 1) % 4 == 0 && i > 0){cout<<endl;} else {cout<<" ";}}}delete a1;delete a2;return 0;}
感谢bin童鞋和yu童鞋。
如有不对,欢迎指正!
0 0
- find the pairs
- Find zero pairs
- find palindrome pairs
- Find pairs equal zero -- Paypal
- hdoj4750 Count The Pairs
- Count The Pairs HDU
- Count The Pairs
- Count The Pairs
- HDU 4750(Count The Pairs)
- HDU 4750 Count The Pairs
- hdu 4750 Count The Pairs
- HDOJ 4750 Count The Pairs
- HDU 4750 Count The Pairs
- HDU-4750 Count The Pairs
- 【Leetcode】Find K Pairs with Smallest Sums
- Find K Pairs with Smallest Sums
- Find Closet Pairs -- To be continue
- Find K Pairs with Smallest Sums
- bee: command not found
- opencv:边缘特征
- HTML5中canvas的lineTo和moveTo的用法
- Service中onStartCommand方法返回值的探索
- java synchronized关键字的用法
- find the pairs
- Android版OpenGL游戏引擎的集成KeyMob管理库教程
- SVN(Subversion)
- NameNode运行原理浅析
- serialVersionUID的作用
- [原]8小时外实践系列之二——比Office Word更出色的印刷级文字工具: LaTex
- Spring的ApplicationEvent的使用
- struts2+spring+ibatis配置 学习笔记
- Spring MVC