#include <conio.h>
#include <windows.h>
#include <time.h>
#include <stdlib.h>
int funcA(int n)
{
n=getch()
if(n==0x50)
{
return 2
}
else if(n==0x4b)
{
return 3
}
else if(n==0x4d)
{
return 4
}
else if(n==0x48)
{
return 1
}
}
void Time()
{
clock_t start,finish
double duration
start=clock()
System()
finish=clock()
duration=(double)(finish-start)/CLOCKS_PER_SEC
printf("用时:%.0f毫秒\n",duration*1000)
}
void System()
{
int i
int number
int n[4]
int w[4]
int j
srand((unsigned)time(NULL))
for(i=0i<4i++)
{
number=rand()%4+1
w[i]=number
switch(number)
{
case 1:
printf("↑ ")
break
case 2:
printf("↓ ")
break
case 3:
printf("← ")
break
case 4:
printf("→ ")
break
}
}
printf("\n")
for(i=0i<4i++)
{
j=getch()
n[i]=funcA(j)
switch(n[i])
{
case 1:
printf("↑ ")
break
case 2:
printf("↓ ")
break
case 3:
printf("← ")
break
case 4:
printf("→ ")
break
}
}
for(i=0i<4i++)
{
if(w[i]!=n[i])
{
printf("\n未能过关\n")
return
}
}
printf("\n恭喜过关\n")
}
int main()
{
Time()
}
/*原理是大差不差的自己研究一下*/
不知道这个合不合你意 哈哈#include<stdio.h>#include<time.h>
#include<stdlib.h>int main()
{
int i,j,count1=0,count2=0,c=1
char ch[100],data[100]
srand(time(NULL))
for(i=0i<100i++)
{
j = rand()%52 + 0
if(j<26)
{
c = 2
ch[i] = j + 'A'
}
else
ch[i] = j + 'A' + 6
}
if(c == 1)
{
printf("等级为1\n")
for(i=0i<100i++)
printf("%c",ch[i])
}
else
{
printf("等级为2\n")
for(i=0i<100i++)
printf("%c",ch[i])
}
printf("\n")
for(i =0i<100i++)
{
scanf("%c",&data[i])
}
for(i=0i<100i++)
{
if(data[i] == ch[i])
{
printf("%c",data[i])
count1++
}
else
{
printf("*")
count2++
}
}
printf("\n")
printf("对了%d个\n",count1)
printf("错了%d个\n",count2)
return 1
}数字可以自己改的!
#include "stdio.h"#include "time.h"
#include "stdlib.h"
#include "conio.h"
#include "dos.h"
#define xLine 70
#define yLine 20
#define full 100
#define true 1
#define false 0
/*---------------------------------------------------------------------*/
void printScreen(int level,int right,int sum,char p[yLine][xLine])/* 刷新屏幕的输出图像 */
{
int i,j
clrscr()
printf("level:%d Press 0 to exit1 to pause score:%d/%d\n",level,right,sum)/* 输出现在的等级,击中数和现在已下落总数 */
printf ("----------------------------------------------------------------------\n")
for (i=0i<yLinei++)
{
for(j=0j<xLinej++)
printf ("%c",p[i][j])
printf("\n")
}/* for (i) */
printf ("----------------------------------------------------------------------\n")
}/* printScreen */
/*---------------------------------------------------------------------*/
void leave()/* 离开程序时,调用该函数结束程序。 */
{
clrscr()
printf ("\n\n\n\nThank you for playing.")
delay (2500)
exit (0)
}
/*----------------------------------------------------------------------*/
int levelChoice(int level)/* 进入游戏时选择游戏等级 */
{
while (true)/* void */
{
clrscr ()
printf("please input 1-9 to choice level.choice 0 to return.\n")
level=getch()
level=level-48
if (level>0&&level<10) return (level)
else if (level==0)
leave ()
else
printf ("Please input a correct number!\n")
}/* while (true) */
}/* levelChoice */
/*---------------------------------------------------------------------*/
int newWord(int sum,char p[yLine][xLine])/* 随生成一个新的字符并将其加入数组的首行 */
{
int j,w
if (sum!=full)
{
j=(rand()%(xLine-2))+1
w=(rand()%26)+65
p[0][j]=w
return (++sum)
}/* if */
return (sum)
}/* newWord */
/*---------------------------------------------------------------------*/
int moving(int miss,char p[yLine][xLine])/* 将最后一行置空,并使所有在数组中其他行的字符下降一行 */
{
int i,j
char w
for (j=1,i=yLine-1j<xLine-1j++)/* 遍历最后一行的所有字符,如果该字符非空则将其置空并使miss加一 */
{
if (p[i][j]!=' ')
{
miss++
p[i][j]=' '
}
}
for (i=yLine-2i>=0i--)/* 从倒数第二行的最后一个字符开始开始向前遍历该数组内的元素,如果该位置非空则将该字符移动至下一行 */
{
for (j=xLine-2j>0j--)
{
if (p[i][j]!=' ')
{
w=p[i][j]
p[i][j]=' '
p[i+1][j]=w
}/* if */
}/* for(j) */
}/* for(i) */
return (miss)
}/* moving */
/*---------------------------------------------------------------------*/
int wordHit(char p[yLine][xLine])
/*判断是否有字符从键盘键入。
如果有,则从最后一行的最后一个元素开始遍历该数组,找出该字符,并把对应位置置空,且返回1。
如果有输入,但屏幕上无对应项,或无输入则返回0*/
{
int i,j
char key
if(kbhit())/* 判断用户是否从键盘键入字符。如果kbhit返回值为 */
key=getch()
if(key)
{
if (key=='0') leave()
if (key=='1')
{
clrscr()
printf ("Press any key to continue.")
getch()
}
for (i=yLinei>0i--)
{
for (j=xLinej>0j--)
{
if (key-32==p[i-1][j-1])
{
p[i-1][j-1]=' '
return (true)
}/* if */
}/* for (j) */
}/* for (i) */
sound(300)
}/* if (key) */
return (false)
}/* wordHit */
/*---------------------------------------------------------------------*/
int result(int right)
/*判断该次的成绩并输出对应的结果,询问用户是否继续,若继续,判断是否可以进入下一级别。*/
{
int score
char yn
score=right*100/full
nosound()
clrscr()
if (score==100)
printf("perfect!\n")
else if (score>=85)
printf("good!\n")
else if (score>=70)
printf("That's OK!\n")
else
printf("you need to play again.\n")
printf("do you want to continue? Y/N\n")
for ()/* void */
{
yn=getch()
switch (yn)
{
case 'y' :
{
if (score>=70) return(true)
else return(false)
}/* case */
case 'n' : leave ()
default : printf("Please input a correct choice:")
}/* switch */
}/* for */
}/* result */
/*---------------------------------------------------------------------*/
int start()/* 进入程序时调用该函数,提示其操作。 */
{
char c
while (true)
{
clrscr ()
printf ("\n\n\n\n\n Welcome to type game!\n\n\n 1.start\n 2.How to play\n 0.Exit")
c=getch()
switch (c)
{
case '0' : leave()/* 用户选择退出,退出主程序 */
case '2' :
{
clrscr()
printf ("\n\n\n\n\n Hit the type when you see it on the screen.\n Press 0 to exit.\n Press 1 to pause\n 1.start\n 0.exit")
while (true)
{
c=getch ()
if (c=='0') leave()
if (c=='1') return (true)
}
}
case '1' : return (true)
}
}
}
/*----------------------------------------------------------------------*/
void main()
{
/*---------------------------------------------------------------------*/
/*函数声明*/
void printScreen(int level,int right,int sum,char p[yLine][xLine])
void leave()
int levelChoice(int level)
int newWord(int sum,char p[yLine][xLine])
int moving(int miss,char p[yLine][xLine])
int wordHit(char p[yLine][xLine])
int result(int right)
int start()
/*---------------------------------------------------------------------*/
char p[yLine][xLine]
int i,j,level,right,sum,n,m,miss
srand(time(NULL))
start()
for (i=0i<yLinei++)/* 初始化屏显数组 */
{
for (j=0j<xLinej++)
if (j==0||j==xLine-1)
p[i][j]=140
else
p[i][j]=' '
}/* for (i) */
level=levelChoice(level)
for ()/* 开始运行主程序 */
{ sum=0
right=0
miss=0
printf("Press any key to start!")
m=getch()
printScreen(level,right,sum,p)
for (n=0,m=4n++)
{
delay(20)/* 延迟 */
nosound()
if(m%4==0)/* 当m为4的整数倍,即上一个字母下落3行时生成一个新的字母在首行并刷新屏幕 */
{
sum=newWord(sum,p)
m=5
printScreen(level,right,sum,p)
}/*if(newWord)*/
if (wordHit(p)==true)/* 如果用户输入了字符并且正确,则使答对的数加一,并刷新屏幕 */
{
right++
sound (1500)
printScreen(level,right,sum,p)
}/* if(wordHit) */
if(n==(37-4*level))/* 当n=37-4*level时,屏幕上的字母下落一行,并刷新屏幕,若最后一行有字母,则使错过数加一 */
{
n=0
m++
miss=moving(miss,p)
printScreen(level,right,sum,p)
}/* if (moving)*/
if(right+miss==full) break/* 当正确数加错误数等于预置的总字母个数时跳出该循环 */
}
if (result (right)==true&&level<9)/* 当用户成绩在70以上,并且等级小于9时,等级加一,即进入下一级别 */
level++
}/* for(sum,right) */
}
//在tc3.0下编译通过