當前位置:首頁 » 編程語言 » c語言打字練習

c語言打字練習

發布時間: 2022-05-10 02:01:35

『壹』 用c語言編個英文打字練習程序要用到哪些知識

基本語言,GUI,少量的各種演算法
都是比較基礎的東西。
初學的話先看 譚浩強的C/C++程序設計吧。

『貳』 我寫了一個C語言的「練習打字程序」 ,出了些問題,求解答!

是字母下落的位置還是下落的字母?
我玩了5次等級1的沒出現提前結束啊

『叄』 用c語言編寫打字練習

#include <stdio.h>
#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 ration;
start=clock();
System();
finish=clock();
ration=(double)(finish-start)/CLOCKS_PER_SEC;
printf("用時:%.0f毫秒\n",ration*1000);
}
void System()
{
int i;
int number;
int n[4];
int w[4];
int j;
srand((unsigned)time(NULL));
for(i=0;i<4;i++)
{
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=0;i<4;i++)
{
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=0;i<4;i++)
{
if(w[i]!=n[i])
{
printf("\n未能過關\n");
return;
}
}
printf("\n恭喜過關\n");
}
int main()
{
Time();
}
/*原理是大差不差的自己研究一下*/

『肆』 C語言程序設計 (英文打字練習)

Option Explicit
Dim speed, right, wrong, keynum As Integer '定義速度,正確次數,錯誤次數,擊鍵次數
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Dim rtn As LongSub letterInit() '初始化每個字母
lbl_letter.Caption = Chr(Int(Rnd * 26) + 97) '隨機產生字母,如果要產生大寫字母只要把97改成65即可
speed = Int(Rnd * 100 + 200)
lbl_letter.Left = Int(Rnd * (Form1.Width - lbl_letter.Width)) '隨機產生字母出現的位置
lbl_letter.Top = lbl_score.Height
End SubPrivate Sub Command1_Click()
letterInit
lbl_score.Caption = "成績: " & 0 & " 分" & " 錯誤: " & 0 & " 個" & " 正確率: " & 0 & "%"
Timer1.Enabled = True '啟動定時器
Timer2.Enabled = True
Timer1.Interval = 100
Timer2.Interval = 1000
'隱藏命令按鈕
Command1.Visible = False
Command2.Visible = False
lbl_time.Caption = 120 & " 秒"
End SubPrivate Sub Command2_Click()
Unload Me
End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)
keynum = keynum + 1 If Chr(KeyAscii) = lbl_letter.Caption Then '判斷所按鍵位是否與產生的字母相符
letterInit
rtn = sndPlaySound(App.Path & "\right.wav", SND_ASYNC)
right = right + 1
Else
rtn = sndPlaySound(App.Path & "\wrong.wav", SND_ASYNC)
wrong = wrong + 1
End If
lbl_score.Caption = "成績: " & right & "分" & " 錯誤: " & wrong & " 個" & " 正確率: " & Int(right / keynum * 100) & "%" If KeyAscii = 27 Then
Timer1.Enabled = False
Timer2.Enabled = False
lbl_score.BackColor = vbYellow
lbl_score.Caption = "成績: " & right & "分" & " 錯誤: " & wrong & " 個" & " 正確率: " & Int(right / keynum * 100) & "%" & " 按任意鍵繼續"
Else
lbl_score.BackColor = vbGreen
Timer1.Enabled = True
Timer2.Enabled = True
End If
End SubPrivate Sub Form_Load()
Form1.Left = (Screen.Width - Form1.Width) / 2
Form1.Top = (Screen.Height - Form1.Height) / 2
Form1.BorderStyle = 1
Form1.BackColor = vbBlack
Form1.Caption = "英文打字練習程序"
Command1.Default = True
Command1.Caption = "開始"
Command2.Caption = "退出"
'設置lbl_letter中顯示的字元的字體、樣式、字型大小,請同時調整lbl_letter的大小與字元大小相等
With lbl_letter.Font
.Name = "宋體"
.Size = 20
.Bold = True
End With
lbl_letter.ForeColor = vbYellow
lbl_letter.BackColor = Form1.BackColor
lbl_score.BackColor = vbGreen
lbl_score.Alignment = 0
lbl_score.Caption = "敲回車鍵開始打字練習,按ESC鍵暫停"
lbl_time.BackColor = lbl_score.BackColor
lbl_time.Alignment = 2
lbl_time.Caption = "時間120秒"
Timer1.Enabled = False
Timer2.Enabled = False
Randomize '初始化
End SubPrivate Sub Timer1_Timer()
lbl_letter.Top = lbl_letter.Top + speed
If lbl_letter.Top >= Form1.Height Then
letterInit
End If
End Sub Private Sub Timer2_Timer()
lbl_time.Caption = Val(lbl_time.Caption) - 1 & " 秒"
If Val(lbl_time.Caption) <= 0 Then '判斷時間是否已經用完
Timer1.Enabled = False
Timer2.Enabled = False
lbl_letter.Caption = ""
Select Case (right * (right / keynum))
Case Is <= 80
MsgBox "成績: 不及格! 不過別灰心,請多多練習!", vbOKOnly, "練習結束!"
Case Is <= 100
MsgBox "成績: 及格! 還要繼續加油努力啊!", vbOKOnly, "練習結束!"
Case Is <= 120
MsgBox "成績: 良!再加加油你就可以成為高手了!", vbOKOnly, "練習結束!"
Case Is >= 150
MsgBox "成績: 優秀! 太棒了,恭喜你再也不會為打字發愁了!", vbOKOnly, "練習結束!"
End Select Command1.Visible = True '命令按鈕恢復為可見狀態
Command2.Visible = True
right = 0
wrong = 0
keynum = 0
End If
End Sub哥哥幫你,對你好吧!也不搞點分來啊

『伍』 C語言打字練習游戲中循環體里用sleep()函數和system("cls")有什麼作用

sleep是延時函數
可以使程序暫停運行
cls是清屏函數
可以清除當前屏幕所有輸出 也就是全黑。

『陸』 一個打字練習的小程序(C語言)

不知道這個合不合你意 哈哈#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=0;i<100;i++)
{
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=0;i<100;i++)
printf("%c",ch[i]);
}
else
{
printf("等級為2\n");
for(i=0;i<100;i++)
printf("%c",ch[i]);
}
printf("\n");
for(i =0;i<100;i++)
{
scanf("%c",&data[i]);
}
for(i=0;i<100;i++)
{
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;
}數字可以自己改的!

『柒』 請問如何用C語言編寫打字模擬練習程序呢

定議鍵碼,
用一個數組來定義
key13=key[13] 是一個數組
在FORM上面的keyperss
上加入
if key=#13 and key=true then //如果你按了回車和當前回車鍵出現則。。。。。。。
key=false
這樣簡單可以實現它的原理,基礎。。。見笑了

『捌』 C語言打字練習游戲中怎樣實現字母掉落,不用換行和隨機坐標還有別的方法嗎

可以指定游標位置進行printf輸出字元,多字元同時出現,最好使用多線程,下面是個簡單的例子,希望對你有幫助

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>

voidsetxy(intx,inty)
{
COORDcoord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}

intmain()
{
CONSOLE_CURSOR_INFOcci;
cci.bVisible=FALSE;
cci.dwSize=sizeof(cci);
HANDLEhandle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle,&cci);
srand((unsigned)time(0));
intx,y;
intc;
while(1)
{
c=rand()%26;
c+='A';
x=rand()%40;
y=0;
while(1)
{
setxy(x,y);
printf("%c",c);
sleep(1);
setxy(x,y);
printf("");
y++;
if(y>5)
{
break;
}
}
}
return0;
}

『玖』 求c語言英文打字練習程序

比較簡單:
/*
練習訓練游戲
*/
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>
#include <time.h>
#define MAXCHAR 100
#define ESC 0x011b /* 退出程序鍵,調用quitgame()函數*/
#define F1 0x3b00 /* 查看幫助信息,調用Help()函數 */
#define F2 0x3c00 /* 查看關於...信息,調用About()函數 */
#define F3 0x3d00 /* 以下功能鍵暫時保留,如果增加功能可使用 */
#define F4 0x3e00
#define F5 0x3f00
#define F6 0x4000
#define F7 0x4100
#define F8 0x4200
#define F9 0x4300
#define F10 0x4400
#define KEY1 0x0231
#define KEY2 0x0332
#define KEY3 0x0433
#define KEY4 0x0534
#define KEY01 0x4f31
#define KEY02 0x5032
#define KEY03 0x5133
#define KEY04 0x4b34

char string[MAXCHAR+1];
int LittleWin(int WinType/*=1, quitgame; =2, Help;=3, About; =4, others;*/);/*when WinType=1, return 0, quit, return 1, not quit*/
void quitgame();
void Welcome();
void drawframe();
void Frame();
void GetCharacter();
void Typing();

int LittleWin(int WinType/*=1, quitgame; =2, Help;=3, About; =4, others;*/)
/*when WinType=1, return 0, quit, return 1, not quit*/
{
int i;
char ch;
window(18,6,62,20);
textbackground(LIGHTGRAY);
textcolor(BLACK);
clrscr();
gotoxy(1,1);
cprintf("%c",201);
for(i=0;i<43;i++)
cprintf("%c",205);
cprintf("%c",187);
for(i=0;i<13;i++)
{
gotoxy(1,i+2);
cprintf("%c",186);
gotoxy(45,i+2);
cprintf("%c",186);
}
gotoxy(1,14);
cprintf("%c",200);
for(i=0;i<43;i++)
cprintf("%c",205);
cprintf("%c",188);
gotoxy(20,1);
switch(WinType)
{
case 1:
cprintf(" Exit ");
textcolor(LIGHTRED);
gotoxy(18,3);
cprintf("Warning!");
textcolor(LIGHTBLUE);
gotoxy(5,5);
cprintf("This operation will exit the program!");
gotoxy(10,7);
cprintf("Do you really want to quit?");
textcolor(LIGHTGREEN);
gotoxy(18,9);
cprintf("OK? [Y/N]");
/*window(18,20,62,20);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();*/
window(19,18,61,18);
textbackground(LIGHTBLUE);
textcolor(WHITE);
clrscr();
gotoxy(5,1);
cprintf("Press Y to quit, press N to return.");
while(1)
{
ch=getch();
if(ch=='Y'||ch=='y')
return 0;
else if(ch=='N'||ch=='n')
return 1;
}
break;
case 2:
cprintf(" Help ");
break;
case 3:
cprintf(" About ");
break;
case 4:
cprintf(" Info ");
break;
default:
break;

}

}

void quitgame()
{
if(LittleWin(1))
{
Frame();
return;
}
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
void Welcome()
{
int driver=VGA,mode=VGAHI; /*定義變數*/
int x1=20,y1=20,r=10,num,i;
int x2=20,y2=450;
int color1=10,color2=10; /*在此設置顏色,一改全改*/
static char ch1[28][2]={"W","e","l","c","o","m","e"," ","t","o"," ","t","h","e"," ","T","y","p","i","n","g"," ","W","o","r","l","d","!"};
initgraph(&driver,&mode,"C:\\tc "); /*初始化圖形模式*/
setbkcolor(LIGHTBLUE);
setcolor(color1); /*步驟一、設置當前顏色用於繪圖*/
for(num=0;num<30;num++)
{
circle(x1,y1,r); /*步驟二、使用當前顏色繪制一個閉合圖形*/
setfillstyle(num%12,color1); /*步驟三、設置填充方式*/
floodfill(x1,y1,color1); /*步驟四、對閉合圖形進行填充*/
x1+=20;
sound(300); /*輸出聲音*/
delay(3000);
nosound();
}
setcolor(color2);
for(num=0;num<30;num++)
{
circle(x2,y2,r);
setfillstyle(num%12,color2);
floodfill(x2,y2,color2);
x2+=20;
sound(300); /*輸出聲音*/
delay(3000);
nosound();
}

settextstyle(0,0,2);
setcolor(LIGHTRED);
sound(300); /*輸出聲音*/
delay(3000);
nosound();
outtextxy(180,90,"^o^ Hello! ^o^");
sound(300); /*輸出聲音*/
delay(3000);
nosound();
setcolor(YELLOW);
gotoxy(50,150);
for(i=0;i<28;i++)
{
outtextxy(50+i*16,150,ch1[i]);
sound(300); /*輸出聲音*/
delay(3000);
nosound();
}
/*outtextxy(50,150,"Welcome to the Typing World!");*/
setcolor(WHITE);
outtextxy(50,200,"This is a little");
sound(300); /*輸出聲音*/
delay(6000);
nosound();
outtextxy(100,250,"Typing Training");
sound(300); /*輸出聲音*/
delay(6000);
nosound();
outtextxy(150,300,"Software ... ^_^");
sound(300); /*輸出聲音*/
delay(6000);
nosound();
setcolor(LIGHTMAGENTA);
outtextxy(100,350,"Ver. 2004-04-30");
sound(300); /*輸出聲音*/
delay(6000);
nosound();
setcolor(LIGHTGREEN);
outtextxy(100,400,"Press any key to start...");
sound(300); /*輸出聲音*/
delay(6000);
nosound();
getch();
closegraph(); /*關閉圖形*/

}
void drawframe()
{
int i;
window(1,1,80,1);
textbackground(LIGHTGRAY);
textcolor(BLACK);
clrscr();
gotoxy(7,1);
cprintf("File Edit Run Compile Project Options Debug Help");
textcolor(RED);
gotoxy(7,1);
cprintf("F");
gotoxy(14,1);
cprintf("E");
gotoxy(21,1);
cprintf("R");
gotoxy(27,1);
cprintf("C");
gotoxy(37,1);
cprintf("P");
gotoxy(47,1);
cprintf("O");
gotoxy(57,1);
cprintf("D");
gotoxy(65,1);
cprintf("H");
window(1,25,80,25);
textbackground(LIGHTGRAY);
textcolor(BLACK);
clrscr();
gotoxy(7,1);
printf("F1-Help F2-About F3-Open F4-Restart Ctrl+F9-Run ESC-Quit");
textcolor(RED);
gotoxy(7,1);
cprintf("F1");
gotoxy(17,1);
cprintf("F2");
gotoxy(28,1);
cprintf("F3");
gotoxy(37,1);
cprintf("F4");
gotoxy(50,1);
cprintf("Ctrl+F9");
gotoxy(64,1);
cprintf("ESC");
window(1,2,80,24);
textbackground(LIGHTBLUE);
textcolor(LIGHTGRAY);
clrscr();
gotoxy(1,2);
cprintf("%c",213);
for(i=0;i<78;i++)
cprintf("%c",205);
cprintf("%c",184);
for(i=0;i<21;i++)
{
gotoxy(1,i+3);
cprintf("%c",179);
gotoxy(80,i+3);
cprintf("%c",179);
}
gotoxy(1,22);
cprintf("%c",192);
for(i=0;i<78;i++)
cprintf("%c",196);
cprintf("%c",217);
textcolor(WHITE);
gotoxy(37,1);
cprintf(" Type ");
}
void Frame() /*設置菜單函數*/
{
drawframe();
window(2,3,79,22);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(25,2);
cprintf("The Typing World Menu\n");
gotoxy(12,4);
cprintf("1:Practice Only ENGLISH Characters.");
gotoxy(12,6);
cprintf("2:Practice Other Charcters.");
gotoxy(12,8);
cprintf("3:Practice All Charcters.");
gotoxy(12,10);
cprintf("4:Quit at once!");
GetCharacter();

}
void GetCharacter(void) /*設置得到字元函數*/
{
void Typing(); /*聲明typing()函數*/
FILE *in;
int i,t,choice;
char ch;
t=abs(time(0))%700; /*獲取隨機數來指定下面指針的位*/
gotoxy(12,12);
cprintf("Please input your choice: ");
while(1)
{
gotoxy(38,12);
choice=bioskey(0);
if(choice==ESC||choice==KEY4||choice==KEY04)
{
quitgame();
break;
}
else if(choice==KEY1||choice==KEY01)
{
in=fopen("english.dat","r");
break;
}
else if(choice==KEY2||choice==KEY02)
{
in=fopen("others.dat","r");
break;
}
else if(choice==KEY3||choice==KEY03)
{
in=fopen("typeall.dat","r");
break;
}
}
clrscr(); /*清屏*/
fseek(in,t*1l,0);
fgets(string,MAXCHAR+1,in);
textcolor(WHITE);
gotoxy(1,2);
cprintf("******************************************************************************");
textcolor(YELLOW);
for(i=0;i<MAXCHAR;i++)
cprintf("%c",string[i]);
gotoxy(1,5);
textcolor(WHITE);
cprintf("******************************************************************************");
fclose(in);
gotoxy(1,6);
cprintf("Let's begin typing,OK?[Y/N]");
while(1)
{
gotoxy(28,6);
ch=getch();
if(ch=='n'||ch=='N') /*判斷是否練習打字*/
{
quitgame();
break;
}
else if(ch=='y'||ch=='Y')
{
Typing();
break;
}
}
}
void Typing(void) /*設置打字(包括計算其他結果)函數*/
{
int i,j,Right_char=0,Wrong_char=0,Sum_char=0;
float Speed,Timeused,Right_rate;
char absorb_char,ch_1,ch_2,ch_3;
time_t star,stop; /*定義time變數,獲取系統時間並顯示在屏幕上*/
time(&star);
textcolor(WHITE);
gotoxy(1,6);
cprintf("time begin:%s",ctime(&star));
gotoxy(1,7);
i=0;
textcolor(YELLOW);
absorb_char=getch(); /*接受鍵盤輸入的字元並在下面的while語句判斷正錯和計算結果*/
while(i<MAXCHAR)
{
if(absorb_char=='\n')
continue;
else
cprintf("%c",absorb_char);
if(absorb_char==string[i])
{
Right_char++;
Sum_char++;
}
else
{
Wrong_char++;
Sum_char++;
}
i++;
absorb_char=getch();
}
time(&stop);
Timeused=difftime(stop,star); /*利用difftime()函數輸出所用時間*/
Right_rate=(float)Right_char/(float)Sum_char*100;
Speed=(Sum_char/Timeused)*60;
textcolor(WHITE);
gotoxy(1,11);
cprintf("time end:%s",ctime(&stop)); /*下面顯示分數*/
textcolor(LIGHTGREEN);
gotoxy(1,12);
cprintf("********************Your Score!*************************");
gotoxy(7,13);
textcolor(WHITE);
cprintf(" 1: TOTAL TIME USED:%.3f",Timeused);
gotoxy(7,14);
cprintf(" 2: YOU HAVE TYPED:%d",Sum_char);
gotoxy(7,15);
cprintf(" 3: Typing Right_Characters are:%d",Right_char);
gotoxy(7,16);
cprintf(" 4: Typing Wrong_Characters are:%d\n",Wrong_char);
gotoxy(7,17);
cprintf(" 5: YOUR TYPING SPEED IS :%.2f\\min\n",Speed);
gotoxy(7,18);
cprintf(" 6: YOUR TYPING RIGHT_RATE IS :%.2f%%\n",Right_rate);
textcolor(LIGHTGREEN);
gotoxy(1,19);
cprintf("********************Your Score!*************************");
gotoxy(1,20);
textcolor(WHITE);
if(Speed<=50||Right_rate<=80) /*詢問用戶是否重來一遍*/
{
cprintf("Not Very Good! Try it Again,OK?[Y/N]");
while(1)
{
gotoxy(39,20);
ch_2=getch();
if(ch_2=='n'||ch_2=='N')
{
quitgame();
break;
}
else if(ch_2=='y'||ch_2=='Y')
{
Frame();
break;
}
}
}
else
{
cprintf("Well Done!! One More Time?[Y/N]"); /*詢問用戶是否重來一遍*/
while(1)
{
gotoxy(35,20);
ch_3=getch();
if(ch_3=='n'||ch_3=='N')
{
quitgame();
break;
}
else if(ch_3=='y'||ch_3=='Y')
{
Frame();
break;
}
}
}
}
main(void) /*主函數包含兩個要調用的函數*/
{
/*Welcome();*/
Frame();
}
/*註:cprintf與printf的區別如下:
1.cprintf函數用於向當前窗口輸出數據,比如你用window函數定義一個窗口
window(20,10,60,20),那麼當你調用cprintf函數時,cprintf的輸出就是相對於20,10,
60,20這個窗口,當輸出的字元串長度大於當前窗口長度時,會在當前窗口自動換行。
默認方式下,當前窗口為整個屏幕,即:0,0,79,25
2.cprintf函數可以配合setcolor,setbkcolor等函數使用,而調用printf函數時會忽略這些
函數執行的結果。
比如執行:setcolor(RED);
cprintf( "Hello world ");
printf( "Hello ");
將會在屏幕上顯示紅色字元串:Hello world
和白色字元串(因為setcolor函數對printf函數比起作用:Hello
在原來的C語言中,cprintf中的c代表console,就是控制台.(conio.h中的con也是這個意思)到了windows也繼承了這個淵源.
按照設計者本來的意圖,printf是標准輸出,就是指可以完全不知道你輸出的對象,只是以標準的文本流方式輸出.cprintf是與終端相關的,要用到一些系統平台,硬體設備相關的特性,所以可以有顏色等很多東西可供選擇,同時也削弱了移植性所以cprintf是非標準的.

*/


熱點內容
寫shell腳本 發布:2025-05-11 04:37:41 瀏覽:934
電腦伺服器打開有什麼用 發布:2025-05-11 04:36:49 瀏覽:98
sqlserver2008查詢時間 發布:2025-05-11 04:15:28 瀏覽:386
安卓孤膽車神被封號怎麼解封 發布:2025-05-11 04:05:22 瀏覽:940
高壓洗車泡沫怎麼配置 發布:2025-05-11 04:00:47 瀏覽:547
騰訊輕量伺服器怎麼使用 發布:2025-05-11 03:52:46 瀏覽:174
4位密碼組合有多少種至少有一個0 發布:2025-05-11 03:44:03 瀏覽:338
八卦手指演算法 發布:2025-05-11 03:23:32 瀏覽:281
編譯成exe是什麼意思 發布:2025-05-11 03:23:28 瀏覽:470
javaweb技術內幕 發布:2025-05-11 03:20:14 瀏覽:803