Small Basic中文站-快乐编程

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1335|回复: 3

用Small Basic做的打字游戏

[复制链接]
发表于 2015-8-23 19:47:01 | 显示全部楼层 |阅读模式
代码如下
  1. GraphicsWindow.BackgroundColor="black"
  2. j = 150
  3. name[1]="A"
  4. name[2]="B"
  5. name[3]="C"
  6. name[4]="D"
  7. name[5]="E"
  8. name[6]="F"
  9. name[7]="G"
  10. name[8]="H"
  11. name[9]="I"
  12. name[10]="J"
  13. name[11]="K"
  14. name[12]="L"
  15. name[13]="M"
  16. name[14]="N"
  17. name[15]="O"
  18. name[16]="P"
  19. name[17]="Q"
  20. name[18]="R"
  21. name[19]="S"
  22. name[20]="T"
  23. name[21]="U"
  24. name[22]="V"
  25. name[23]="W"
  26. name[24]="X"
  27. name[25]="Y"
  28. name[26]="Z"
  29. highscore = 0
  30. Sound.PlayChime()
  31. Program.Delay(900)
  32. start:
  33. score = 0
  34. health = 6
  35. While j > 100
  36.   x = Math.GetRandomNumber(GraphicsWindow.Width-35)
  37.   y = name[Math.GetRandomNumber(26)]
  38.   z = Math.GetRandomNumber(15)
  39.   a = Math.GetRandomNumber(255)
  40.   b = Math.GetRandomNumber(255)
  41.   c = Math.GetRandomNumber(255)
  42.   If a < 128 Then
  43.     a = a + 128
  44.   EndIf
  45.   If b < 128 Then
  46.     b = b + 128
  47.   EndIf
  48.   If c < 128 Then
  49.     c = c + 128
  50.   EndIf
  51.   i = 0
  52.   GraphicsWindow.BrushColor=GraphicsWindow.GetColorFromRGB(a,b,c)
  53.   GraphicsWindow.FillEllipse((GraphicsWindow.Width/2)-25,GraphicsWindow.Height-25,50,50)
  54.   GraphicsWindow.FontSize=16
  55.   text = Shapes.AddText(y)
  56.   While i < GraphicsWindow.Height+4
  57.     GraphicsWindow.BrushColor="lightblue"
  58.     GraphicsWindow.DrawBoundText(0,GraphicsWindow.Height-16,550,"highscore:"+highscore)
  59.     GraphicsWindow.DrawBoundText(0,0,350,"Health:"+(health-1))
  60.     GraphicsWindow.DrawBoundText(GraphicsWindow.Width-80,0,250,"Score:"+score)
  61.     GraphicsWindow.KeyDown = onkeydown
  62.     i = i+1
  63.     Program.Delay(z)
  64.     GraphicsWindow.BrushColor=GraphicsWindow.GetColorFromRGB(a,b,c)
  65.     Shapes.Move(text,x,i)
  66.     If (highscore < score) Then
  67.       highscore=score
  68.       GraphicsWindow.BrushColor="black"
  69.       GraphicsWindow.FillRectangle(0,GraphicsWindow.Height-35,550,35)
  70.       GraphicsWindow.BrushColor="lightblue"
  71.       GraphicsWindow.DrawBoundText(0,GraphicsWindow.Height-16,550,"highscore:"+highscore)
  72.     EndIf
  73.     If (i = GraphicsWindow.Height+4) Then
  74.       health = health - 1
  75.       Sound.PlayClick()
  76.       GraphicsWindow.BrushColor="black"
  77.       GraphicsWindow.FillRectangle(0,0,350,35)
  78.     EndIf
  79.     If (health < 2) Then
  80.       GraphicsWindow.ShowMessage("You Lose", "Sorry")
  81.       GraphicsWindow.Clear()
  82.       Goto start
  83.     EndIf
  84.   endwhile
  85.   GraphicsWindow.Clear()
  86. EndWhile



  87. Sub onkeydown
  88.   lastkey = GraphicsWindow.LastKey
  89.   If lastkey = y Then
  90.     Arrow()
  91.     GraphicsWindow.BrushColor="black"
  92.     GraphicsWindow.FillRectangle(x,i,40,40)
  93.     i = GraphicsWindow.Height + 5
  94.     score=score+1
  95.   ElseIf lastkey = "LeftShift" then
  96.     health=health
  97.   ElseIf lastkey = "RightShift" then
  98.     health=health
  99.   Else
  100.     health = health-1
  101.     Sound.PlayClick()
  102.     GraphicsWindow.BrushColor="black"
  103.     GraphicsWindow.FillRectangle(0,0,350,35)
  104.     GraphicsWindow.BrushColor="lightblue"
  105.     GraphicsWindow.DrawBoundText(0,GraphicsWindow.Height-16,550,"highscore:"+highscore)
  106.     GraphicsWindow.DrawBoundText(0,0,350,"Health:"+(health-1))
  107.     GraphicsWindow.DrawBoundText(GraphicsWindow.Width-80,0,250,"Score:"+score)
  108.   EndIf
  109. EndSub

  110. Sub Arrow
  111.   Sound.PlayChimes()
  112.   GraphicsWindow.PenColor=GraphicsWindow.GetColorFromRGB(a,b,c)
  113.   Program.Delay(50)
  114.   line = Shapes.AddLine(x+8,i+16,GraphicsWindow.Width/2,GraphicsWindow.Height)
  115.   Shapes.ShowShape(line)
  116. EndSub[b][/b]
复制代码
回复

使用道具 举报

 楼主| 发表于 2015-8-23 19:47:53 | 显示全部楼层
以后可能会更简短?
回复 支持 反对

使用道具 举报

发表于 2016-1-6 20:11:03 | 显示全部楼层
不错,可以同时掉落多个字母增加难度
回复 支持 反对

使用道具 举报

发表于 2017-11-25 13:16:37 | 显示全部楼层
多谢多谢!
可以提高打字速度,还可以自己改一改.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|Small Basic中文站-快乐编程 ( 闽ICP备09051788号 |

GMT+8, 2017-12-13 09:39 , Processed in 0.140008 second(s), 8 queries , File On.

Powered by Discuz! X3.3

快速回复 返回顶部 返回列表