c語言打字-九游会j9娱乐平台
1、感覺並沒有什麼技巧,靠的是多練。
大一有個《計算機導論》的課(感覺就是打字作ppt的課)硬生生的練會了盲打。然後c程序寫寫硬生生的靠肌肉記憶知道了"#""!""%"之類的地方。(記得用課上的標准打字姿勢)
2、就是用上面說的ide,想visual studio,devc ,c-free都支持自動對齊,聯想,括弧補充很方便
㈡ 打字游戲超細講解(c語言基礎小游戲)
深入探索:c語言基礎打字游戲開發指南
讓我們一起走進c語言的世界,親手打造一款簡單卻富有挑戰性的打字游戲。游戲的核心是提高打字速度與准確度,而實現過程分為幾個關鍵步驟:
- 環境搭建:在ubuntu系統雲環境中,藉助sublime text這樣的高效開發工具。
- 游戲框架構建:
- 主循環:一個永不停歇的while循環,確保游戲持續運行。
- 規則介紹:在游戲開始前,清晰地展示游戲規則,如首字母計時,錯誤字元用下劃線表示。
- 隨機元素:生成一組20個隨機小寫字母組成的字元串,模擬輸入挑戰。
- 用戶交互:用戶輸入字元,通過mygetch()函數接收,實時反饋正確與錯誤。
- 退出與暫停:按esc鍵退出遊戲,空格鍵則重新開始。
- 代碼實現要點:
- 在主函數中,生成隨機字元串並展示。
- 使用mygetch()函數,處理非回顯鍵盤輸入,增加游戲體驗。
在實踐中,你可以參考鑫哥b站的精彩教程,如「千鋒項目體驗課-自製ipod-2打字游戲框架」視頻,那裡有詳細的步驟和實例演示,助你快速上手。
通過這款基礎打字游戲,你不僅能提升打字速度,還能理解c語言中的循環、輸入處理和隨機數生成等核心概念,為編程之路打下堅實基礎。
㈢ 求c語言英文打字練習程序
比較簡單:
/*
練習訓練游戲
*/
#include
#include
#include
#include
#include
#include
#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,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,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))p0; /*獲取隨機數來指定下面指針的位*/
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
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
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是非標準的.
*/