Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions lesson-1/huyong/fanpai.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include<stdio.h>
#include <stdlib.h>
#include <windows.h>
#include<time.h>
void shuchuint(char a[4][4])
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++) {printf("%2c",a[i][j]);}
printf("\n");
}
}
int panduan(char a[4][4])
{
int i,j,s=1;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(a[i][j]=='*')
s=0;
break;
}

}
return s;
}
int main()
{
int i,j,x1,y1,x2,y2,k=0,m,n,s;
char a[4][4]={'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'};
char c[16]={'2','8','7','1','1','6','7','8','4','2','3','6','4','3','5','5'};
char b[4][4];
printf("这是一个锻炼记忆力的翻牌游戏!\n一开始有10s的时间观察随机产生的4x4矩阵。其后输入坐标进行翻牌,数字相同则翻牌成功.\nHave a try!\n");
printf("******************************************************************\n");
printf("按下回车,游戏开始!");
while(getchar()==10)
{
srand((unsigned)time(NULL));
for(i=0;i<1000;i++)
{
m=rand()%16;
n=rand()%16;
s=c[m];
c[m]=c[n];
c[n]=s;
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
b[i][j]=c[k];
k++;
}
}
shuchuint(b);
Sleep(5000);
system("cls");
shuchuint(a);
while(panduan(a)==0)
{
lab1:
printf("x1= ,y1= (1~4)\t");scanf("%d%d",&x1,&y1);
if(!(x1>=1&&x1<=4)||!(y1>=1&&y1<=4)) {printf("请正确输入!"); goto lab1;}
printf("\nx2= ,y2= (1~4)\t");scanf("%d%d",&x2,&y2);
lab2:
if(!(x2>=1&&x2<=4)||!(y2>=1&&y2<=4)) {printf("请正确输入!"); goto lab2;}
if(b[x1-1][y1-1]==b[x2-1][y2-1])
{
a[x1-1][y1-1]=b[x1-1][y1-1];
a[x2-1][y2-1]=b[x2-1][y2-1];
shuchuint(a);
printf("正确,Go on!\n");
}
else
{
a[x1-1][y1-1]=b[x1-1][y1-1];
a[x2-1][y2-1]=b[x2-1][y2-1];
shuchuint(a);
printf("不正确哟!");
Sleep(2000);
system("cls");
a[x1-1][y1-1]='*';
a[x2-1][y2-1]='*';
shuchuint(a);
}
}
printf("U Win!!");
}
}
37 changes: 37 additions & 0 deletions lesson-1/huyong/fanpai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
翻牌游戏
===========



翻牌
===
---

问题描述
------

- 游戏初始:
现在有一个4*4的矩阵,存储两组1~8数字。起始时,会有两秒的时间观察数字在矩阵的位置,之后每个点则处于未翻开状态


- 游戏过程:
每次翻开两个点,如果相同,则成功翻开(图1),输出翻开后的矩阵;如果不同,则翻开失败(图2),等待1s后输出保持翻开前的矩阵。直到全部翻开为成功(图片3).
![alt 图片1](C:\Users\acer\Desktop\fanpai\图片1)
![alt 图片2](C:\Users\acer\Desktop\fanpai\图片2)
![alt 图片3](C:\Users\acer\Desktop\fanpai\图片3)


- 游戏操作:
输入:每次输入四个1~8的整数,作为(x1,y1)(x2,y2)即翻开的两个点的坐标


游戏编程:
----
-见: http://1013975672.qzone.qq.com


编程难点
----
- 将一个二维数组乱序
- 清屏函数
-屏幕暂停函数
Binary file added lesson-1/huyong/图片1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lesson-1/huyong/图片2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lesson-1/huyong/图片3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lesson-1/huyong/无标题.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.