當前位置:首頁 » 操作系統 » 打字源碼

打字源碼

發布時間: 2023-02-02 22:33:06

① 急求VB打字練習源代碼

Option Explicit
Dim score As Integer
Dim speed As Integer
Dim typetime As String

'初始化字元1
Sub innt1()
'產生隨機大寫字母、數字及其他符號
zi1.Caption = Chr(Int(Rnd * 43 + 48))
'起初位置
zi1.Left = Int(Rnd * (mm1.Width - zi1.Width))
zi1.Top = mm1.Top - zi1.Height
End Sub

'初始化字元2
Sub innt2()
'產生隨機小寫字母
zi2.Caption = Chr(Int(Rnd * 26) + 97)
'起初位置
zi2.Left = Int(Rnd * (mm1.Width - zi2.Width))
zi2.Top = mm1.Top - zi2.Height
End Sub

'開始
Private Sub Command1_Click()
'輸入時間
typetime = InputBox("請輸入打字時間(單位為秒):", "設置時間")
If IsNumeric(typetime) Then
Label5.Caption = typetime
Else
Exit Sub
End If
'調用子過程
innt1
innt2
'設置默認的下落速度
HScroll1.Value = 50
'開始下落
Timer1.Enabled = True
Timer2.Enabled = True
Command1.Enabled = False
Label3.Caption = 0
'設置時間為2分鍾
End Sub

'打字
Private Sub HScroll1_KeyPress(KeyAscii As Integer)
'若打中字元1
If Chr(KeyAscii) = zi1.Caption Then
'重新初始化
innt1
'分數累加
score = score + 1
'顯示分數
Label3.Caption = score
End If
'若打中字元2
If Chr(KeyAscii) = zi2.Caption Then
innt2
score = score + 1
Label3.Caption = score
End If
End Sub

'初始化設置
Private Sub Form_Load()
Randomize
Timer1.Enabled = False
Timer2.Enabled = False
zi1.AutoSize = True
zi2.AutoSize = True
HScroll1.Max = 300
HScroll1.Min = 10
End Sub

'改變速度
Private Sub HScroll1_Change()
speed = HScroll1.Value
End Sub

'字元下落
Private Sub Timer1_Timer()
'字元1下落
zi1.Top = zi1.Top + speed
If zi1.Top > mm1.Height Then
innt1
End If
'字元2下落
zi2.Top = zi2.Top + speed
If zi2.Top > mm1.Height Then
innt2
End If
End Sub

'控制打字時間
Private Sub Timer2_Timer()
'減時
Label5.Caption = Val(Label5.Caption) - 1
'若時間到
If Val(Label5.Caption) <= 0 Then
'停止字元下落
Timer1.Enabled = False
zi1.Caption = ""
zi2.Caption = ""
'分析分數
Select Case score
Case Is < 60
MsgBox vbCrLf + "你真菜!努力吧!"
Case Is >= 60
MsgBox vbCrLf + "恩~!還可以有進步!"
Case Is >= 100
MsgBox vbCrLf + "哈```滿分!"
Case Is > 150
MsgBox vbCrLf + "好厲害啊`!"
End Select
Command1.Enabled = True
Timer1.Enabled = False
Timer2.Enabled = False
End If
End Sub

② 求純C語言打字游戲源代碼及解析

# include "Typer.h"
# include <stdio.h>
# include <stdlib.h>
# include <graphics.h>
//download by http://www.codefans.net
void main()
{
BOOL bQuit=FALSE; /* 是否退出 */
BOOL bPause=FALSE; /* 是否暫停 */
int tm1,tm2;
BYTE Key;

randomize(); /* 初始化隨機數種子 */
SetGraphMode();
SelectLevel();
ShowBar();
tm1=CreateTimer(1,MoveLetter); /* 創建移動字元對象時鍾 */
tm2=CreateTimer(Interval,CreateLetter); /* 創建產生字元對象時鍾 */
CreateLetter();

Key=AscKey();
while (!bQuit)
{
TimerEvent();
switch (Key)
{
case NULL:
break;
case KEY_ESC:
bQuit=TRUE;
break;
case KEY_SPACE:
bPause=!bPause;
tmTM[tm1].Enable=!bPause;
tmTM[tm2].Enable=!bPause;
break;
default:
if (!bPause) Check(Key);
}
Key=AscKey();
}
CloseGraphMode();
}

void SetGraphMode()
{
int Device=VGA,Mode=VGAHI;
initgraph(&Device,&Mode,"");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
setfillstyle(SOLID_FILL,0);
setcolor(7);
}

void CloseGraphMode()
{
restorecrtmode();
}

/* 從鍵盤緩沖區內直接讀出ASC碼 */
BYTE AscKey(void)
{
int start,end;
WORD key=0;
start=peek(0,0x41a);
end=peek(0,0x41c);
if (start==end) return(0);
else
{
key=peek(0x40,start);
start+=2;
if (start==0x3e) start=0x1e;
poke(0x40,0x1a,start);
return(key&0xff);
}
}

void MoveLetter(void)
{
int i;

for (i=0;i<MAX_LETTER;i++)
{
if (Letter[i].Used)
{
HideLetter(i);
Letter[i].y+=Step;
ShowLetter(i);
/* 字元對象下落到最底部 */
if (Letter[i].y>MAX_HEIGHT) KillLetter(i);
}
}
}

void KillLetter(int LetterID)
{
if (Letter[LetterID].Used)
{
Letter[LetterID].Used=FALSE;
LetterUsed--;
HideLetter(LetterID);
}
/* 刪除字元對象後馬上再創建一個 */
CreateLetter();
}

void CreateLetter()
{
int i=0;
int x;
BYTE val;

if (LetterUsed==MAX_LETTER) return; /* 無字元對象可用則返回 */
while (Letter[++i].Used); /* 找到第一個空閑的字元對象,產生一個字元對象 */
x=i;
Letter[i].x=x*640/MAX_LETTER;
Letter[i].y=0;
Letter[i].val=random(26)+'A';
Letter[i].Used=TRUE;
LetterUsed++;
}

void HideLetter(int ID)
{
/* 用填充矩形來消隱字元 */
bar(Letter[ID].x,Letter[ID].y,Letter[ID].x+16,Letter[ID].y+20);
}

void ShowLetter(int ID)
{
char str[2]={0,0};
str[0]=Letter[ID].val;
outtextxy(Letter[ID].x,Letter[ID].y,str);
}

void Check(BYTE Key)
{
int i;
char str[6];

Hits++;
for (i=0;i<MAX_LETTER;i++)
/* 擊中 */
if (Letter[i].Used&&Letter[i].val==toupper(Key))
{
sound(1000);
delay(10);
KillLetter(i);
Right++;
nosound();
}
/* 顯示狀態 */
setfillstyle(SOLID_FILL,5);
bar(260,430,320,450);
bar(410,430,470,450);
setcolor(2);
sprintf(str," %4ld",Hits);
outtextxy(260,430,str);
sprintf(str," %4ld",Right);
outtextxy(410,430,str);
setcolor(7);
setfillstyle(SOLID_FILL,0);
}

void ShowBar()
{
FILE *bmp;
BYTE r,g,b,t;
int i,x,y;

bmp=fopen("bar.bmp","rb");
fseek(bmp,54,SEEK_SET);
for (i=0;i<16;i++)
{
setpalette(i,i);
b=fgetc(bmp)>>2;
g=fgetc(bmp)>>2;
r=fgetc(bmp)>>2;
t=fgetc(bmp)>>2;
setrgbpalette(i,r,g,b);
}
for (y=0;y<80;y++)
for (x=0;x<320;x++)
{
t=fgetc(bmp);
putpixel(x*2,479-y,t>>4);
putpixel(x*2+1,479-y,t&15);
}
fclose(bmp);
}

void SelectLevel()
{
int Steps[3]={1,2,4};
int Intervals[3]={18,9,5};
int Sel=0;
FILE *bmp;
BYTE r,g,b,t,Key;
int i,x,y;

bmp=fopen("sel.bmp","rb");
fseek(bmp,54,SEEK_SET);
for (i=0;i<16;i++)
{
setpalette(i,i);
b=fgetc(bmp)>>2;
g=fgetc(bmp)>>2;
r=fgetc(bmp)>>2;
t=fgetc(bmp)>>2;
setrgbpalette(i,r,g,b);
}
for (y=0;y<200;y++)
for (x=0;x<160;x++)
{
t=fgetc(bmp);
putpixel(x*2+160,339-y,t>>4);
putpixel(x*2+161,339-y,t&15);
}
fclose(bmp);
while (TRUE)
{
Key=toupper(AscKey());
if (Key=='A') Sel=1;
if (Key=='B') Sel=2;
if (Key=='C') Sel=3;
if (Sel) break;
}
Step=Steps[Sel-1];
Interval=Intervals[Sel-1];
cleardevice();
}

/*********************************************************/
/* 文件:TIMER.H */
/*********************************************************/
/*********************************************************/

/* 系統可用計時器的最大數目 */
# define MAXTIMER 10
# ifndef NULL
# define NULL 0
# endif

/* 計時器結構 */
struct TM
{
DWORD Interval; /* 間隔 */
DWORD LastTimer; /* 上次事件發生時間*/
BOOL Enable; /* 活動 */
BOOL Used; /* 可用 */
void (*Pointer)(); /* 事件遠指針 */
};

struct TM tmTM[MAXTIMER+1];
int TimerUsed=0;

/* 獲取BIOS計數器數值 */
DWORD BiosTimer(void)
{
DWORD BIOSTIMER=0;
BIOSTIMER=peek(0x0,0x46e);
BIOSTIMER<<=8;
BIOSTIMER+=peek(0x0,0x46c);
return (BIOSTIMER);
}

/* 時間事件(時鍾系統核心) */
void TimerEvent()
{
int i;
DWORD TimerDiff;

for (i=1;i<=MAXTIMER;i++)
{
if (tmTM[i].Used&&tmTM[i].Enable)
{
TimerDiff=BiosTimer()-tmTM[i].LastTimer;
if (tmTM[i].Interval<=TimerDiff)
{
tmTM[i].Pointer();
tmTM[i].LastTimer=BiosTimer();
}
}
}
}

/* 創建一個時鍾(成功返回時鍾的句柄,否則返回NULL) */
int CreateTimer(DWORD Interval,void (*Pointer)())
{
int i=0;
if (TimerUsed==MAXTIMER) return NULL;

while (tmTM[++i].Used);

tmTM[i].Pointer=Pointer;
tmTM[i].Interval=Interval;
tmTM[i].Enable=TRUE;
tmTM[i].Used=TRUE;
tmTM[i].LastTimer=BiosTimer();

TimerUsed++;
return i;
}

/* 刪除一個時鍾 */
void KillTimer(int *TimerID)
{
if (tmTM[*TimerID].Used)
{
TimerUsed--;
tmTM[*TimerID].Used=FALSE;
}
*TimerID=0;
}

/* 刪除所有時鍾 */
void KillAllTimer()
{
int i;
for (i=0;i<=MAXTIMER;i++) tmTM[i].Used=FALSE;
TimerUsed=0;
}

③ 求一個簡易英文打字平台的源代碼

■ 初學者英文打字練習程序

————————————————以下為程序代碼—————————————

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 Long

Sub 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 Sub

Private 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 Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private 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 Sub

Private 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 Sub

Private 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

④ 有沒有vb編寫打字游戲的源代碼啊

Dim score As Integer
Dim speed As Integer
Dim typetime As Integer

Private Sub init()
Randomize

lblletter1.Caption = Chr(Int(Rnd * 42) + 48)
lblletter1.Left = Int(Rnd * 2800) + 1
lblletter1.Top = 0

End Sub

Private Sub init1()
Randomize
lblletter2.Caption = Chr(Int(Rnd * 25) + 97)
lblletter2.Left = Int(Rnd * 2800) + 1
lblletter2.Top = 0

End Sub

Private Sub Command1_Click()
score = Int(lblscore.Text)
init
init1
Timer1 = True
Timer2 = True
HScroll1.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
HScroll1.Enabled = False

If lbltime.Text <= 0 Then
Timer1 = False
Timer2 = False
lblletter1.Caption = ""
lblletter2.Caption = ""
End If

End Sub

Private Sub Command2_Click()
typetime = InputBox("請輸入打字時間。", "時間設置")
If typetime <= 0 Then
lbltime.Text = 60
End If
lbltime.Text = typetime
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = lblletter1.Caption Then

score = score + 1
lblscore.Text = score
init
End If
If Chr(KeyAscii) = lblletter2.Caption Then
score = score + 1
lblscore.Text = score
init1
End If
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
lblletter1.AutoSize = True
lblletter2.AutoSize = True
lblletter1.Caption = ""
lblletter2.Caption = ""
lblscore.Text = 0
lblspeed.Caption = 100
lbltime.Text = 60
HScroll1.Max = 200
HScroll1.Min = 20
HScroll1.SmallChange = 5
HScroll1.LargeChange = 20
HScroll1.Value = 100
End Sub

Private Sub HScroll1_Change()
lblspeed.Caption = HScroll1.Value
End Sub

Private Sub Timer1_Timer()
lblletter1.Top = lblletter1.Top + lblspeed.Caption
If lblletter1.Top >= 4335 Then
Call init
End If
lblletter2.Top = lblletter2.Top + lblspeed.Caption
If lblletter2.Top >= 4335 Then
Call init1
End If
End Sub

Private Sub Timer2_Timer()
If lbltime.Text > 0 Then
lbltime.Text = lbltime.Text - 1

Else: Select Case score / (typetime / 60)
Case Is <= 40
MsgBox ("不要放棄再試一次!")
Case 40 To 80
MsgBox ("太棒了,繼續努力!")
Case 80 To 120
MsgBox ("堅持下去,你將成為一個打字高手!")
Case Is > 120
MsgBox ("祝賀你!你已經是一個打字高手!")
End Select
Timer1 = False
Timer2 = False
HScroll1.Enabled = True
Command1.Enabled = True
Command2.Enabled = True
HScroll1.Enabled = True
init
init1
End If

End Sub

⑤ 求:機器貓打字游戲源代碼

776

⑥ 求:c++ 打字游戲源代碼

暈死了,這個代碼很長的,以前同學還編出來,可惜自己沒記。回去問問看

⑦ jQuery打字效果實現方法(附demo源碼下載)

本文實例講述了jQuery打字效果實現方法。分享給大家供大家參考,具體如下:
運行效果截圖如下:
點擊此處查看在線演示效果。
1.前台頁面代碼:
<!DOCTYPE
html
PUBLIC
"-//W3C//DTD
XHTML
1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>無標題頁</title>
<script
type="text/javascript"
src="jquery-1.4.2.min.js"></script>
<script
type="text/javascript"
src="jticker_split.js"></script>
<script
type="text/javascript">
$(function(){
$("#ticker").ticker({
cursorList:
"
",
rate:
100,
delay:
4000
}).trigger("play").trigger("stop");
});
</script>
</head>
<body>
<div
id="ticker"
style="height:
200px;
width:
500px;
border:
solid
1px
#cccccc;">
<div>
<h3>
1.1
RIA與Flex</h3>
<p>
當下非常流行一個名詞叫RIA,RIA全稱是Rich
Internet
Application,翻譯成中文為豐富互聯網應用程序。RIA
是集桌面應用程序的最佳用戶界面功能與Web應用程序的普遍採用和快速、低成本布署以及互動多媒體通信的實時快捷於一體的新一代網路應用程序。目前WEB領域和桌面軟體領域正逐步向RIA靠攏,預計3、5年後RIA的時代將會完全到來。</p>
</div>
</div>
</body>
</html>
2.jticker_split.js腳本代碼:
復制代碼
代碼如下:eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return
d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new
RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return
p}('(3(m){5
b="Z";3
h(n,o){2(n>=o)?h(n-o,o):((n<0)?h(n+o,o):n)}3
k(p){5
q=p.u(b);5
o;17(5
n=0;n<1b;n++){4(!q.F[n]){o=n;16}}q.v=h((q.v||0),o);q.10=q.v;q.y=[q.10];q.D=0;q.v++}3
l(o){5
p={Q:o.1k().G()};5
n=o.N();4(n.7){n.R(3(q){p[q]=l(m(L))});2
p}6{p.x=o.x();2
p}}3
e(p,n){5
o;4(p[n[0]]){4(p[n[0]].x){2
p[n[0]]}6{4(n.7==1){2
K}6{o=m.T(n);2
e(p[o[0]],o.1e(1,o.7))}}}6{2
8}}3
d(n){4(n.7>1){n[n.7-1]++;2
n}6{2
8}}3
g(o,n){4(n===8){2
8}5
p=e(o,n);4(p===8){2
g(o,d(n.X(0,n.7-1)))}6{4(p===K){n[n.7]=0;2
g(o,n)}6{2
n}}}3
c(r,q,n,s){5
p,o;5
t=r.N().1c(n[0]);4(!n.7){2{P:r,x:q.x}}6{4(t.7){o=t}6{o=q[n[0]].Q.1h(r)}}p=m.T(n).X(1,n.7);2
c(o,q[n[0]],p,s)}3
i(n){5
o=n.u(b);m("*",n).G();n.G();o.H=0;o.E=0;4(o.w){w=0}}3
a(n){5
o=n.u(b);o.H=o.E}3
j(q,n,r){5
o,p;4(r.w!==8){r.w=h(r.w+1,r.z.7);r.9.U(r.z[r.w])}6{r.9.U(r.z)}o=r.D-r.H;p=r.x.18(o-1);r.9.19(p);4(r.D>=r.E){r.9.S();r.y=d(r.y);2
f(q,n)}6{2
V(3(){4(r.B==n){r.D++;j(q,n,r)}n=W},r.A)}}3
f(o,n){5
p=o.u(b);4(p.B==n){p.y=g(p.F,p.y);4(p.y===8){2
V(3(){4(p.I&&(p.B==n)){k(o);2
f(o,n)}n=W},p.C)}6{4(!p.D){i(o)}6{a(o)}}m.O(p,c(o,p.F,p.y));p.E=p.E+p.x.7;p.P.1l(p.9);2
j(o,n,p)}}m.M[b]=3(n){5
p=m.O({},m.M.Z.Y,n);2
L.R(3(){5
o=m(L);o.u(b,{A:p.A,C:p.C,F:l(o),9:p.9,z:p.z,w:(1f(p.z)=="1m")?0:8,v:0,B:0}).J("1j",3(r){5
q=o.u(b);q.I=8}).J("13",3(r){5
q=o.u(b);q.B++;q.I=K;q.v=(r.11||q.v);k(o);f(o,q.B)}).J("15",3(r){5
q=o.u(b);m().O(q,{v:r.11,A:r.A,C:r.C})}).N().S()})};m.M[b].Y={A:1d,C:12,z:"14",9:m(\'<1i
1a="9"
/>\')}})(1g);',62,85,'||return|function|if|var|else|length|false|cursor|||||||||||||||||||||data|nextItem|cursorIndex|text|elemIndex|cursorList|rate|eventIndex|delay|charIndex|sum|content|empty|start|running|bind|true|this|fn|children|extend|readout|elem|each|remove|makeArray|html|setTimeout|null|slice|defaults|ticker|currentItem|item|2000|play|_|control|break|for|charAt|before|class|200|eq|40|splice|typeof|jQuery|appendTo|span|stop|clone|append|object'.split('|'),0,{}))
完整實例代碼點擊此處本站下載。
希望本文所述對大家jQuery程序設計有所幫助。

⑧ flash 仿「金山打字通之打地鼠」(打字游戲) 源碼

個簡單的Flash打字游戲
上一篇 / 下一篇 2007-09-25 16:42:03

查看( 142 ) / 評論( 3 ) / 評分( 5 / 0 )
代碼:

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
打字游戲 ——V1.0
日期:2007-9-24
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
定義變數
----------------------------------------------------------------------------------------------
*/
fscommand("fullscreen", true);
var Bring_num:Number = 0;
var Bring_maxnum:Number = 20;
var Grade_num:Number = 1;
var Grade_bring:Number = 100;
var Move_speed:Number = 2;
var Bring_speed:Number = 0;
var Press_num:Number = 0;
var Right_num:Number = 0;
var Loss_num:Number = 0;
var Grade_boolean:Boolean = false;
var Interval_num:Number = 0;
var Listener:Object = new Object();
var Addsound:Sound = new Sound();
var Addblast_mc:Object = new Object();
var Time_m:Number = 0;
var Time_s:Number = 1;
var Hide_id:Number;
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Bring_word函數功能:隨機產生字元
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
function Bring_word() {
var color_array:Array = new Array(0xffffff, 0x9B4A8B, 0xE0C0DB, 0xAC285E, 0x235CB1, 0x379D37, 0xB1A323);
var txtstyle:TextFormat = new TextFormat();
txtstyle.bold = true;
txtstyle.font = "宋體";
txtstyle.size = 20;
txtstyle.color = color_array[random(7)];
_root.Bring_num++;
if (_root.Bring_num>=Bring_maxnum) {
_root.Bring_num = 0;
}
switch (random(2)) {
case 0 :
txt = random(26)+97;
break;
case 1 :
txt = random(10)+48;
break;
}
_root.createTextField("txt"+_root.Bring_num, _root.Bring_num, random(Stage.width), -(random(200)+10), 25, 25);
this["txt"+_root.Bring_num].text = chr(txt);
this["txt"+_root.Bring_num].setTextFormat(txtstyle);
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Interval_event();初始化時產生的字元個數
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
function Interval_event() {
Bring_word();
Interval_num++;
if (Interval_num>=3) {
clearInterval(Interval_id);
}
}
var Interval_id:Number = setInterval(Interval_event, 1000);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cyc_event下落函數
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
function cyc_event() {
function _event() {
for (var i = 0; i<=Bring_maxnum; i++) {
var n:Number = random(2) ? -Math.random()*9 : Math.random()*9;
_root["txt"+i]._y += Move_speed;
_root["txt"+i]._x += n;
if (_root["txt"+i]._y>Stage.height) {
_root["txt"+i].removeTextField();
Bring_word();
Loss_num++;
loss_txt.text = Loss_num;
}
}
}
var cyc_id:Number = setInterval(_event, 50);
}
cyc_event();
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
監聽鍵盤
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
Key.addListener(Listener);
Listener.onKeyDown = function() {
Press_num++;
//trace(Press_num);
if (Grade_boolean) {
Grade_num++;
Grade_boolean = false;
grade_txt.text = "第"+Grade_num+"關";
Move_speed += 2;
for (var i = 0; i<3; i++) {
Bring_word();
}
}
//trace("Press_num="+Press_num);
for (i=0; i<=Bring_maxnum; i++) {
if (_root["txt"+i].text == chr(Key.getAscii())) {
Right_num++;
Addsound.attachSound("Sound_mc");
Addsound.start();
//_root.attachMovie("Blast_mc", "Addblast_mc", _root.getNextHighestDepth(), {_x:_root["txt"+i]._x, _y:_root["txt"+i]._y});
Blast_mc.play();
Blast_mc._x = _root["txt"+i]._x;
Blast_mc._y = _root["txt"+i]._y;
_root["txt"+i].removeTextField();
Bring_word();
if (Right_num>=Grade_bring and Right_num%Grade_bring == 0) {
Grade_boolean = true;
} else {
Grade_boolean = false;
}
}
}
right_txt.text = String(Right_num);
if (Press_num-Right_num>0) {
wrong_txt.text = String(Press_num-Right_num);
} else {
Press_num += Math.abs(Press_num-Right_num);
}
};
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
時間函數
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
*/
function Time_event() {
Time_s++;
if (Time_s/60>1) {
Time_m++;
Time_s = 1;
}
time_txt.text = Time_m+":"+Time_s%60;
}
setInterval(Time_event, 1000);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
簡介函數
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
var newmenu:ContextMenu = new ContextMenu();
newmenu.hideBuiltInItems();
this.menu = newmenu;
newmenu.customItems.push(new ContextMenuItem("作者:Edward.yang", by_event));
newmenu.customItems.push(new ContextMenuItem("QQ:77839683", getqq));
newmenu.customItems.push(new ContextMenuItem("退出", exit_event, true));
function exit_event() {
fscommand("quit", "");
}
function by_event() {
Hide_id = setInterval(hide_by, 5000);
by_mc.gotoAndStop(2);
by_mc._alpha = 0;
by_mc.onEnterFrame = function() {
this._alpha += (100-this._alpha)/8;
this._x += (Stage.width/2-this._x)/8;
this._y += (Stage.height/2-this._y)/8;
//trace(this._alpha);
if (this._alpha>=100) {
delete by_mc.onEnterFrame;
}
};
}
function hide_by() {
by_mc.onEnterFrame = function() {
this._alpha -= 8;
//trace(this._alpha);
if (this._alpha<=0) {
this.gotoAndStop(1);
clearInterval(Hide_id);
delete by_mc.onEnterFrame;
}
};
}
function getqq() {
getURL("tencent://message/?uin=77839683");

熱點內容
api開發php 發布:2025-09-16 22:06:15 瀏覽:594
mysql自動備份linux 發布:2025-09-16 21:58:33 瀏覽:942
怎麼用自己的伺服器ip做域名 發布:2025-09-16 21:49:57 瀏覽:915
vc為什麼能編譯不能用 發布:2025-09-16 21:48:03 瀏覽:742
編譯原理沖突圖的定義 發布:2025-09-16 21:26:45 瀏覽:808
安卓手機芯哪個牌子好 發布:2025-09-16 21:26:33 瀏覽:206
centos編譯安裝git 發布:2025-09-16 21:19:55 瀏覽:975
安卓系統如何使用手機優盤 發布:2025-09-16 21:14:01 瀏覽:331
在手機上注冊公積金如何設置密碼 發布:2025-09-16 21:07:01 瀏覽:824
無控制器存儲 發布:2025-09-16 21:02:44 瀏覽:718