Small Basic中文站-快乐编程

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 346|回复: 0

Small Basic保龄球游戏源码

[复制链接]
发表于 2017-7-14 19:00:28 | 显示全部楼层 |阅读模式
作者:Nonki Takahashi
代码导入的ID是  : GRT732-3
效果图:


sb121.png
sb122.png
sb123.png

源码:
  1. ' Bowling Game
  2. ' Version 0.5b
  3. ' Copyright © 2017 Nonki Takahashi. The MIT License.
  4. ' Last update 2017-03-12
  5. ' Program ID GRT732-3

  6. title = "Bowling Game 0.5b"
  7. GraphicsWindow.Title = title + " - Hit arrow key."
  8. Init()
  9. Form()
  10. GraphicsWindow.KeyDown = OnKeyDown
  11. While "True"
  12.   subtotal = ""
  13.   For frame = 1 To 10
  14.     InitPins()
  15.     InitBall()
  16.     Position()      ' for the first throwing
  17.     ThrowBall()
  18.     SelectPins()    ' to blow
  19.     BlowPins()
  20.     throw = 1
  21.     DrawScore()
  22.     If Array.ContainsValue(fell, "False") Then
  23.       InitBall()
  24.       Position()    ' for the second throwing
  25.       ThrowBall()
  26.       prevPoint = point
  27.       SelectPins()  ' to blow
  28.       BlowPins()
  29.       throw = 2
  30.       point = point - prevPoint
  31.       DrawScore()
  32.     EndIf
  33.     If (frame = 10) And (subtotal[iPerson][frame] = 10) Then
  34.       InitPins()
  35.       InitBall()
  36.       Position()    ' for the third throwing
  37.       ThrowBall()
  38.       SelectPins()  ' to blow
  39.       BlowPins()
  40.       throw = 3
  41.       DrawScore()
  42.     EndIf
  43.     If frame = 10 Then
  44.       DrawTotal()
  45.     EndIf
  46.   EndFor
  47.   DrawTotal()
  48.   KeyInput()
  49.   ClearScore()
  50. EndWhile

  51. Sub BlowPins
  52.   For t = 0 To 1000 Step delay
  53.     For i = 1 To 10
  54.       If fell[i] Then
  55.         x[i] = x[i] + dx[i]
  56.         y[i] = y[i] - 5
  57.         a[i] = a[i] + da[i]
  58.         Shapes.Move(pin[i], x[i], y[i])
  59.         Shapes.Rotate(pin[i], a[i])
  60.       EndIf
  61.     EndFor
  62.     If ye <= yb Then
  63.       MoveBall()
  64.       yb = yb - 2
  65.     EndIf
  66.     Program.Delay(delay)
  67.   EndFor
  68.   Shapes.HideShape(ball)
  69.   For i = 1 To 10
  70.     If fell[i] Then
  71.       Shapes.HideShape(pin[i])
  72.     EndIf
  73.   EndFor
  74. EndSub

  75. Sub ClearScore
  76.   For i = 1 To nObj
  77.     Shapes.Remove(obj[i])
  78.   EndFor
  79.   nObj = 0
  80. EndSub

  81. Sub DrawBall
  82.   ' param xb, yb - ball position
  83.   ' param ab - ball angle
  84.   scale = yb / 212
  85.   If shadow = "" Then
  86.     GraphicsWindow.BrushColor = "Black"
  87.     shadow = Shapes.AddEllipse(78, 20)
  88.     Shapes.SetOpacity(shadow, 50)
  89.   EndIf
  90.   Shapes.Move(shadow, xb - 39, yb - 10)
  91.   Shapes.Zoom(shadow, scale, scale)
  92.   If ball = "" Then
  93.     path = "http://www.nonkit.com/smallbasic.files/Ball.png"
  94.     ball = Shapes.AddImage(path)
  95.   EndIf
  96.   Shapes.Move(ball, xb - 39, yb - 33 * scale - 39)
  97.   Shapes.Zoom(ball, scale, scale)
  98.   Shapes.Rotate(ball, ab)
  99. EndSub

  100. Sub DrawPoint
  101.   ' param x, y - left top of the cursor
  102.   ' param point - point
  103.   ' param throw
  104.   ' param frame
  105.   ' param prevPoint
  106.   ' return nObj
  107.   nObj = nObj + 1
  108.   GraphicsWindow.BrushColor = "Black"
  109.   If 0 < point Then
  110.     obj[nObj] = Shapes.AddText(point)
  111.   Else
  112.     If frame < 10 Then
  113.       If throw = 1 Then
  114.         obj[nObj] = Shapes.AddText("G")
  115.       Else
  116.         obj[nObj] = Shapes.AddText("-")
  117.       EndIf
  118.     Else
  119.       If (prevPoint = 0) Or (prevPoint = 10) Then
  120.         obj[nObj] = Shapes.AddText("G")
  121.       Else
  122.         obj[nObj] = Shapes.AddText("-")
  123.       EndIf
  124.     EndIf
  125.   EndIf
  126.   Shapes.Move(obj[nObj], x + 2, y)
  127. EndSub

  128. Sub DrawScore
  129.   ' param point - point
  130.   ' param throw
  131.   ' param frame
  132.   ' param prevPoint
  133.   ' return nObj
  134.   If frame < 10 Then
  135.     x = xo + pw + (frame - 1) * fw + (throw - 1) * fw / 2
  136.   Else
  137.     x = xo + pw + (frame - 1) * fw + (throw - 1) * fw / 3
  138.   EndIf
  139.   y = yo + hh + (iPerson - 1) * fh
  140.     If frame < 10 Then
  141.       If 10 < point + subtotal[iPerson][frame] Then
  142.         point = 10 - subtotal[iPerson][frame]
  143.       EndIf
  144.     Else
  145.       If (1 < throw) And (prevPoint < 10) Then
  146.         If 10 < point + prevPoint Then
  147.           point = 10 - prevPoint
  148.         EndIf
  149.       EndIf
  150.     EndIf
  151.     subtotal[iPerson][frame] = subtotal[iPerson][frame] + point
  152.     If (1 < frame) And (0 < spare[iPerson][frame - 1]) Then
  153.       subtotal[iPerson][frame - 1] = subtotal[iPerson][frame - 1] + point
  154.       spare[iPerson][frame - 1] = spare[iPerson][frame - 1] - 1
  155.       If spare[iPerson][frame - 1] = 0 Then
  156.         frame = frame - 1
  157.         DrawTotal()
  158.         frame = frame + 1
  159.       EndIf
  160.     EndIf
  161.     If (2 < frame) And (0 < spare[iPerson][frame - 2]) Then
  162.       subtotal[iPerson][frame - 2] = subtotal[iPerson][frame - 2] + point
  163.       spare[iPerson][frame - 2] = spare[iPerson][frame - 2] - 1
  164.       If spare[iPerson][frame - 2] = 0 Then
  165.         frame = frame - 2
  166.         DrawTotal()
  167.         frame = frame + 2
  168.       EndIf
  169.     EndIf
  170.     isSpare = "False"
  171.     If (frame < 10) And (subtotal[iPerson][frame] = 10) Then
  172.       isSpare = "True"
  173.     ElseIf (frame = 10) And (point <> 10) And (1 < throw) And (spare[iPerson][frame][throw - 1] = 0) And (prevPoint + point = 10) Then
  174.       isSpare = "True"
  175.     EndIf
  176.     If point = 10 Then  ' strike
  177.       If frame < 10 Then
  178.         spare[iPerson][frame] = 2
  179.       Else
  180.         spare[iPerson][frame][throw] = 2
  181.       EndIf
  182.       DrawStrike()
  183.     ElseIf isSpare Then
  184.       If frame < 10 Then
  185.         spare[iPerson][frame] = 1
  186.       Else
  187.         spare[iPerson][frame][throw] = 1
  188.       EndIf
  189.       DrawSpare()
  190.     Else
  191.       DrawPoint()
  192.       If throw = 2 And frame < 10 Then
  193.         DrawTotal()
  194.       EndIf
  195.     EndIf
  196. EndSub

  197. Sub DrawSpare
  198.   ' param x, y - left top of the cursor
  199.   If frame < 10 Then
  200.     sw = fw / 2
  201.   Else
  202.     sw = fw / 3
  203.   EndIf
  204.   GraphicsWindow.PenWidth = 0
  205.   GraphicsWindow.BrushColor = "Black"
  206.   nObj = nObj + 1
  207.   obj[nObj] = Shapes.AddTriangle(x, y + fh / 2, x + sw, y, x + sw, y + fh / 2)
  208. EndSub

  209. Sub DrawStrike
  210.   ' param x, y - left top of the cursor
  211.   If frame < 10 Then
  212.     dx = fw / 2
  213.     sw = fw / 2
  214.   Else
  215.     dx = 0
  216.     sw = fw / 3
  217.   EndIf
  218.   GraphicsWindow.PenWidth = 0
  219.   GraphicsWindow.BrushColor = "Black"
  220.   nObj = nObj + 1
  221.   obj[nObj] = Shapes.AddTriangle(x + dx, y, x + dx, y + fh / 2, x + dx + sw / 2,  y + fh / 4)
  222.   nObj = nObj + 1
  223.   obj[nObj] = Shapes.AddTriangle(x + dx + sw / 2,  y + fh / 4, x + dx + sw, y, x + dx + sw, y + fh / 2)
  224. EndSub

  225. Sub DrawTotal
  226.   ' param frame
  227.   ' param iPerson
  228.   GraphicsWindow.BrushColor = "Black"
  229.   _x = xo + pw + (frame - 1) * fw
  230.   _y = yo + hh + (iPerson - 0.5) * fh
  231.   total = 0
  232.   For _i = 1 To frame
  233.     total = total + subtotal[iPerson][_i]
  234.   EndFor
  235.   nObj = nObj + 1
  236.   obj[nObj] = Shapes.AddText(total)
  237.   Shapes.Move(obj[nObj], _x + 2, _y)
  238.   If frame = 10 Then
  239.     _x = xo + pw + frame * fw
  240.     _y = yo + hh + (iPerson - 1) * fh
  241.     nObj = nObj + 1
  242.     obj[nObj] = Shapes.AddText(total)
  243.     Shapes.Move(obj[nObj], _x + 2, _y)
  244.   EndIf
  245. EndSub

  246. Sub Form
  247.   GraphicsWindow.PenWidth = 2
  248.   GraphicsWindow.PenColor = "GreenYellow"
  249.   maxPerson = 1
  250.   hh = 22
  251.   pw = 100
  252.   fw = 44
  253.   fh = 44
  254.   bh = 26
  255.   xo = (gw - pw - fw * 11) / 2
  256.   yo = 8
  257.   GraphicsWindow.PenWidth = 0
  258.   GraphicsWindow.BrushColor = "White"
  259.   rect = Shapes.AddRectangle(pw - 2, hh - 2)
  260.   Shapes.Move(rect, xo + 1, yo + 1)
  261.   GraphicsWindow.BrushColor = "Black"
  262.   txt = Shapes.AddText("NAME")
  263.   Shapes.Move(txt, xo + 2, yo)
  264.   For iFrame = 1 To 11
  265.     x = xo + pw + (iFrame - 1) * fw
  266.     GraphicsWindow.BrushColor = "White"
  267.     rect = Shapes.AddRectangle(fw - 2, hh - 2)
  268.     Shapes.Move(rect, x + 1, yo + 1)
  269.     GraphicsWindow.BrushColor = "Black"
  270.     If iFrame = 11 Then
  271.       txt = Shapes.AddText("TOTAL")
  272.     Else
  273.       txt = Shapes.AddText(iFrame)
  274.     EndIf
  275.     Shapes.Move(txt, x + 2, yo)
  276.   EndFor
  277.   For iPerson = 1 To maxPerson
  278.     y = yo + hh + (iPerson - 1) * fh
  279.     GraphicsWindow.BrushColor = "White"
  280.     rect = Shapes.AddRectangle(pw - 2, fh - 2)
  281.     Shapes.Move(rect, xo + 1, y + 1)
  282.     GraphicsWindow.BrushColor = "Black"
  283.     txt = Shapes.AddText("PLAYER")
  284.     Shapes.Move(txt, xo + 2, y)
  285.     For iFrame = 1 To 11
  286.       x = xo + pw + (iFrame - 1) * fw
  287.       GraphicsWindow.BrushColor = "White"
  288.       rect = Shapes.AddRectangle(fw - 2, fh - 2)
  289.       Shapes.Move(rect, x + 1, y + 1)
  290.       GraphicsWindow.PenWidth = 2
  291.       GraphicsWindow.BrushColor = "Transparent"
  292.       If iFrame < 10 Then
  293.         rect = Shapes.AddRectangle(fw / 2, fh / 2)
  294.         Shapes.Move(rect, x + fw / 2, y)
  295.         spare[iPerson][iFrame] = 0
  296.       ElseIf iFrame = 10 Then
  297.         rect = Shapes.AddRectangle(fw / 3, fh / 2)
  298.         Shapes.Move(rect, x, y)
  299.         rect = Shapes.AddRectangle(fw / 3, fh / 2)
  300.         Shapes.Move(rect, x + fw / 3, y)
  301.         rect = Shapes.AddRectangle(fw / 3, fh / 2)
  302.         Shapes.Move(rect, x + fw * 2 / 3, y)
  303.         spare[iPerson][iFrame][1] = 0
  304.         spare[iPerson][iFrame][2] = 0
  305.         spare[iPerson][iFrame][3] = 0
  306.       EndIf
  307.       GraphicsWindow.PenWidth = 0
  308.     EndFor
  309.   EndFor
  310.   y = yo + hh + maxPerson * fh + 4
  311.   iPerson = 1
  312. EndSub

  313. Sub Init
  314.   Not = "False=True;True=False;"
  315.   gw = 598
  316.   gh = 428
  317.   GraphicsWindow.Width = gw
  318.   GraphicsWindow.Height = gh
  319.   range = "1=7;2=47;3=2478;4=12458;5=123589;6=13569;7=369A;8=6A;9=A;"
  320.   beyond = "1=23;2=45;3=56;4=78;5=89;6=9A;"
  321.   da = "1=-10;2=-8;3=8;4=-6;5=-6;6=6;7=-4;8=-4;9=4;10=4;"
  322.   dx = "1=-3;2=-4;3=4;4=-5;5=-3;6=5;7=-5;8=-4;9=4;10=5;"
  323.   GraphicsWindow.BackgroundColor = "LightGray"
  324.   ' draw gutter
  325.   GraphicsWindow.BrushColor = "SaddleBrown"
  326.   color = GraphicsWindow.BrushColor
  327.   rate = 0.5
  328.   Colors_Init()
  329.   Color_Blacken()
  330.   GraphicsWindow.BrushColor = color
  331.   GraphicsWindow.FillTriangle(gw / 2, 60, -70, gh, gw + 70, gh)
  332.   ' draw lane
  333.   ye = 200
  334.   GraphicsWindow.BrushColor = "SaddleBrown"
  335.   GraphicsWindow.FillTriangle(gw / 2, 60, 0, gh, gw, gh)
  336.   GraphicsWindow.BrushColor = "LightGray"
  337.   GraphicsWindow.FillRectangle(0, 0, gw, ye)
  338.   GraphicsWindow.BrushColor = "Black"
  339.   path = "http://www.nonkit.com/smallbasic.files/Pin.png"
  340.   i = 6
  341.   d = 3
  342.   For row = 4 To 1 Step -1
  343.     y = 130 - row * 10
  344.     For col = 1 To row
  345.       i = i + 1
  346.       pin[i] = Shapes.AddImage(path)
  347.       x = 249 + col * 60 - row * 30
  348.       Shapes.Move(pin[i], x, y)
  349.       x0[i] = x
  350.       y0[i] = y
  351.     EndFor
  352.     i = i - row - d
  353.     d = d - 1
  354.     shadow = Shapes.AddRectangle(366, 160)
  355.     Shapes.SetOpacity(shadow, 15)
  356.     Shapes.Move(shadow, 116, 82)
  357.   EndFor
  358.   shadow = ""
  359.   ' draw wall
  360.   GraphicsWindow.PenWidth = 0
  361.   GraphicsWindow.BrushColor = "GreenYellow"
  362.   wall = Shapes.AddRectangle(gw, 82)
  363.   Shapes.Move(wall, 0, 0)
  364.   wall = Shapes.AddRectangle(116,160)
  365.   Shapes.Move(wall, 0, 82)
  366.   wall = Shapes.AddRectangle(149, 160)
  367.   Shapes.Move(wall, gw - 116, 82)
  368.   delay = 10  ' [ms]
  369. EndSub

  370. Sub InitBall
  371.   xb = gw / 2     ' ball position
  372.   yb = gh + 120
  373.   ab = 120        ' ball angle
  374.   DrawBall()
  375. EndSub

  376. Sub InitPins
  377.   For i = 1 To 10
  378.     Shapes.Move(pin[i], x0[i], y0[i])
  379.     Shapes.Rotate(pin[i], 0)
  380.     Shapes.ShowShape(pin[i])
  381.     fell[i] = "False"
  382.   EndFor
  383. EndSub

  384. Sub KeyInput
  385.   GraphicsWindow.Title = title + " - Hit any key."
  386.   While Not[keyDown]
  387.     Program.Delay(500)
  388.   EndWhile
  389.   keyDown = "False"
  390.   GraphicsWindow.Title = title + " - Hit arrow key."
  391. EndSub

  392. Sub MoveBall
  393.   ' param xs - ball start x position
  394.   xb = (gw / 2) * (1 - yb / gh) + xs * yb / gh
  395.   ab = ab - 4
  396.   DrawBall()
  397.   Program.Delay(delay)
  398. EndSub

  399. Sub OnKeyDown
  400.   keyDown = "True"
  401. EndSub

  402. Sub Position
  403.   Shapes.ShowShape(ball)
  404.   positioning = "True"
  405.   While positioning
  406.     If keyDown Then
  407.       If GraphicsWindow.LastKey = "Up" Then
  408.         positioning = "False"
  409.       ElseIf GraphicsWindow.LastKey = "Left" Then
  410.         If 0 <= xb - 10 Then
  411.           xb = xb - 10
  412.           DrawBall()
  413.         EndIf
  414.       ElseIf GraphicsWindow.LastKey = "Right" Then
  415.         If xb + 10 <= gw Then
  416.           xb = xb + 10
  417.           DrawBall()
  418.         EndIf
  419.       EndIf
  420.       keyDown = "False"
  421.     EndIf
  422.   EndWhile
  423. EndSub

  424. Sub SelectPins
  425.   ' param xb - ball position
  426.   ' return point
  427.   point = 0
  428.   r = Math.Floor(xb / (gw / 9)) + 1
  429.   For i = 1 To 10
  430.     c = i
  431.     If c = 10 Then
  432.       c = "A"
  433.     EndIf
  434.     If Text.IsSubText(range[r], c) Then
  435.       fell[i] = "True"
  436.       n = i
  437.       While n <> ""
  438.         l = Text.GetLength(beyond[n])
  439.         If 0 < l Then
  440.           n = Text.GetSubText(beyond[n], Math.GetRandomNumber(l), 1)
  441.           If n = "A" Then
  442.             n = 10
  443.           EndIf
  444.           fell[n] = "True"
  445.         Else
  446.           n = ""
  447.         EndIf
  448.       EndWhile
  449.     EndIf
  450.     If fell[i] Then
  451.       point = point + 1
  452.     EndIf
  453.     x[i] = x0[i]
  454.     y[i] = y0[i]
  455.     a[i] = 0
  456.   EndFor
  457. EndSub

  458. Sub ThrowBall
  459.   Shapes.ShowShape(shadow)
  460.   xs = xb
  461.   For yb = gh - 1 To 208 Step -2
  462.     MoveBall()
  463.   EndFor
  464.   Shapes.HideShape(shadow)
  465. EndSub

  466. Sub Color_Blacken
  467.   ' Color | Blacken given color
  468.   ' param color - given color
  469.   ' param rate - 0..1
  470.   ' return color - color blackened
  471.   Color_NameToColor()
  472.   Color_ColorToRGB()
  473.   r = Math.Floor(r * (1 - rate))
  474.   g = Math.Floor(g * (1 - rate))
  475.   b = Math.Floor(b * (1 - rate))
  476.   color = GraphicsWindow.GetColorFromRGB(r, g, b)
  477. EndSub

  478. Sub Color_ColorToRGB
  479.   ' Color | Convert color to RGB values
  480.   ' param color - "#rrggbb" (hexadecimal values)
  481.   ' return r, g, b - RGB values 0..255
  482.   sR = Text.GetSubText(color, 2, 2)
  483.   sG = Text.GetSubText(color, 4, 2)
  484.   sB = Text.GetSubText(color, 6, 2)
  485.   hex = sR
  486.   Math_Hex2Dec()
  487.   r = dec
  488.   hex = sG
  489.   Math_Hex2Dec()
  490.   g = dec
  491.   hex = sB
  492.   Math_Hex2Dec()
  493.   b = dec
  494. EndSub

  495. Sub Color_NameToColor
  496.   ' Color | Convert color name to color
  497.   ' param color - color name
  498.   ' return color -"#rrggbb"
  499.   If Text.StartsWith(color, "#") Then
  500.     color = Text.ConvertToUpperCase(color)
  501.   Else
  502.     color = Text.ConvertToLowerCase(color)
  503.     color = colors[color]
  504.   EndIf
  505. EndSub

  506. Sub Colors_Init
  507.   ' Colors | Initialize 140 colors array
  508.   txt = "aliceblue,antiquewhite,aqua,aquamarine,"
  509.   txt = txt + "azure,beige,bisque,black,blanchedalmond,"
  510.   txt = txt + "blue,blueviolet,brown,burlywood,"
  511.   txt = txt + "cadetblue,chartreuse,chocolate,coral,"
  512.   txt = txt + "cornflowerblue,cornsilk,crimson,"
  513.   txt = txt + "cyan,darkblue,darkcyan,darkgoldenrod,"
  514.   txt = txt + "darkgray,darkgreen,darkkhaki,"
  515.   txt = txt + "darkmagenta,darkolivegreen,darkorange,"
  516.   txt = txt + "darkorchid,darkred,darksalmon,darkseagreen,"
  517.   txt = txt + "darkslateblue,darkslategray,"
  518.   txt = txt + "darkturquoise,darkviolet,deeppink,"
  519.   txt = txt + "deepskyblue,dimgray,dodgerblue,"
  520.   txt = txt + "firebrick,floralwhite,forestgreen,"
  521.   txt = txt + "fuchsia,gainsboro,ghostwhite,gold,"
  522.   txt = txt + "goldenrod,gray,green,greenyellow,"
  523.   txt = txt + "honeydew,hotpink,indianred,indigo,"
  524.   txt = txt + "ivory,khaki,lavender,lavenderblush,"
  525.   txt = txt + "lawngreen,lemonchiffon,lightblue,"
  526.   txt = txt + "lightcoral,lightcyan,lightgoldenrodyellow,"
  527.   txt = txt + "lightgray,lightgreen,lightpink,"
  528.   txt = txt + "lightsalmon,lightseagreen,lightskyblue,"
  529.   txt = txt + "lightslategray,lightsteelblue,"
  530.   txt = txt + "lightyellow,lime,limegreen,linen,"
  531.   txt = txt + "magenta,maroon,mediumaquamarine,mediumblue,"
  532.   txt = txt + "mediumorchid,mediumpurple,mediumseagreen,"
  533.   txt = txt + "mediumslateblue,mediumspringgreen,"
  534.   txt = txt + "mediumturquoise,mediumvioletred,midnightblue,"
  535.   txt = txt + "mintcream,mistyrose,moccasin,navajowhite,"
  536.   txt = txt + "navy,oldlace,olive,olivedrab,orange,"
  537.   txt = txt + "orangered,orchid,palegoldenrod,palegreen,"
  538.   txt = txt + "paleturquoise,palevioletred,papayawhip,"
  539.   txt = txt + "peachpuff,peru,pink,plum,powderblue,"
  540.   txt = txt + "purple,red,rosybrown,royalblue,saddlebrown,"
  541.   txt = txt + "salmon,sandybrown,seagreen,seashell,"
  542.   txt = txt + "sienna,silver,skyblue,slateblue,slategray,"
  543.   txt = txt + "snow,springgreen,steelblue,"
  544.   txt = txt + "tan,teal,thistle,tomato,turquoise,violet,"
  545.   txt = txt + "wheat,white,whitesmoke,yellow,yellowgreen"
  546.   delim = ","
  547.   Text_Split()
  548.   saved = GraphicsWindow.PenColor
  549.   n = Array.GetItemCount(arry)
  550.   For i = 1 To n
  551.     GraphicsWindow.PenColor = arry[i]
  552.     c = GraphicsWindow.PenColor
  553.     colors[arry[i]] = c
  554.   EndFor
  555.   GraphicsWindow.PenColor = saved
  556. EndSub

  557. Sub Math_Hex2Dec
  558.   ' Math | Convert hexadecimal to decimal
  559.   ' param hex
  560.   ' return dec
  561.   dec = 0
  562.   len = Text.GetLength(hex)
  563.   For ptr = 1 To len
  564.     dec = dec * 16 + Text.GetIndexOf("123456789ABCDEF", Text.GetSubText(hex, ptr, 1))
  565.   EndFor
  566. EndSub

  567. Sub Text_Split
  568.   ' Text | Split text to array by delimiter
  569.   ' param txt - to split
  570.   ' param delim - delimiter
  571.   ' return arry - splitted
  572.   len = Text.GetLength(txt)
  573.   p = 1
  574.   n = 0
  575.   d = Text.GetIndexOf(Text.GetSubTextToEnd(txt, p), delim)
  576.   While (0 < d) And (p <= len)
  577.     n = n + 1
  578.     arry[n] = Text.GetSubText(txt, p, d - 1)
  579.     p = p + d
  580.     d = Text.GetIndexOf(Text.GetSubTextToEnd(txt, p), delim)
  581.   EndWhile
  582.   n = n + 1
  583.   arry[n] = Text.GetSubTextToEnd(txt, p)
  584. EndSub
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2017-11-18 16:03 , Processed in 0.242287 second(s), 11 queries , File On.

Powered by Discuz! X3.3

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