Small Basic中文站-快乐编程

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1681|回复: 0

原创游戏【长方形】源码分享

[复制链接]
发表于 2013-2-6 15:58:12 | 显示全部楼层 |阅读模式
网址: http://smallbasic.com/program/?KZX293

(附有Textwindow的帮助(中英文))

  1. 'Set GraphicsWindow设置图形窗口
  2. GraphicsWindow.Title="Study_hard------Rectangle"
  3. GraphicsWindow.Width=900
  4. GraphicsWindow.Height=760
  5. GraphicsWindow.Top=0
  6. GraphicsWindow.Left=0
  7. GraphicsWindow.CanResize="No"
  8. GraphicsWindow.BackgroundColor="DeepSkyBlue"
  9. GraphicsWindow.KeyUp=key
  10. GraphicsWindow.MouseMove=usemouse
  11. Controls.ButtonClicked=button
  12. color[1]="Red"   'Color颜色
  13. color[2]="Yellow"   'Color颜色
  14. start=0   'If game start游戏是否开始
  15. colornum[1]=1   'The number of color颜色对应数字
  16. colornum[2]=1   'The number of color颜色对应数字
  17. next=0   
  18. '------------------------------------------------------------------------------------------------------------------
  19. GraphicsWindow.BrushColor="Cyan"
  20. GraphicsWindow.FontSize=74
  21. GraphicsWindow.FontItalic="Yes"
  22. title=Shapes.AddText("***Rectangle***")
  23. Shapes.Move(title,100,50)
  24. GraphicsWindow.FontSize=24
  25. GraphicsWindow.BrushColor="SteelBlue"
  26. space=Shapes.AddText("Press 'Space' to continue")
  27. Shapes.Move(space,300,500)
  28. While next=0   'boring...消遣。。。
  29.   boring=1
  30. EndWhile
  31. Shapes.HideShape(title)
  32. Shapes.HideShape(space)
  33. GraphicsWindow.BrushColor="Purple"
  34. GraphicsWindow.FillRectangle(0,0,500,500)
  35. GraphicsWindow.BackgroundColor="Snow"
  36. '------------------------------------------------------------------------------------------------------------------
  37. GraphicsWindow.FontSize=24   'For some reason and must be put on the top of it因为某些原因必须放在最上
  38. GraphicsWindow.BrushColor="Orange"
  39. GraphicsWindow.DrawText(500,350,"Player 1:")
  40. GraphicsWindow.BrushColor=color[1]
  41. circle[1]=Shapes.AddEllipse(30,30)
  42. Shapes.Move(circle[1],610,350)
  43. GraphicsWindow.BrushColor="Orange"
  44. GraphicsWindow.DrawText(500,410,"Player 2:")
  45. GraphicsWindow.BrushColor=color[2]
  46. circle[2]=Shapes.AddEllipse(30,30)
  47. Shapes.Move(circle[2],610,405)
  48. '--------------------------------------------------------------------------------------------------------------------
  49. GraphicsWindow.BrushColor="Red"
  50. model[1]=Shapes.AddRectangle(150,100)
  51. model[2]=Shapes.AddRectangle(100,150)
  52. Shapes.Move(model[1],750,0)
  53. Shapes.Move(model[2],800,0)
  54. Shapes.HideShape(model[2])
  55. '------------------------------------------------------------------------------------------------------------------------
  56. GraphicsWindow.FontSize=24
  57. GraphicsWindow.DrawText(520,20,"The shape is:")
  58. '-------------------------------------------------------------------------------------------------------------------
  59. GraphicsWindow.BrushColor="Orange"
  60. firstplayer=Math.GetRandomNumber(2)
  61. GraphicsWindow.DrawText(520,200,"Player"+firstplayer+" first.")
  62. turn=Shapes.AddText("It's player"+firstplayer+" turn.")
  63. Shapes.Move(turn,520,230)
  64. '-----------------------------------------------------------------------------------------------------------------------
  65. giveup=Controls.AddButton("Give up放弃",520,260)
  66. Sub button
  67.   If Controls.LastClickedButton=giveup Then
  68.     GraphicsWindow.ShowMessage("Player"+(3-firstplayer)+" won.","Win")
  69.     Program.End()
  70.   EndIf
  71. EndSub
  72. '-----------------------------------------------------------------------------------------------------------------------
  73. GraphicsWindow.BrushColor="Blue"
  74. GraphicsWindow.FontSize=100
  75. GraphicsWindow.FontItalic="Yes"
  76. GraphicsWindow.DrawText(20,530,"Small Basic")
  77. '------------------------------------------------------------------------------------------------------------------------
  78. 'The help of game帮助
  79. TextWindow.ForegroundColor="Red"
  80. TextWindow.WriteLine("******************************")
  81. TextWindow.WriteLine("        Play game!!")
  82. TextWindow.WriteLine("******************************")
  83. TextWindow.WriteLine("                           ")
  84. TextWindow.WriteLine("This a game of rectangle.")
  85. TextWindow.WriteLine("Put 2×3 rectangle on the purple vacant squares in turn.The computer will tell you who is the first.")
  86. TextWindow.WriteLine("Move the mouse and see it what the rectangle like and where.")
  87. TextWindow.WriteLine("Escape----Leave")
  88. TextWindow.WriteLine("Space----Turn the rectangle")
  89. TextWindow.WriteLine("Up----Start the game")
  90. TextWindow.WriteLine("A----Change the color of player1 before the game start.")
  91. TextWindow.WriteLine("L----Change the color of player2 before the game start.")
  92. TextWindow.WriteLine("Who can't put the rectangle in at the end,who lose,and the other won.")
  93. TextWindow.WriteLine("                           ")
  94. TextWindow.WriteLine("                           ")
  95. TextWindow.WriteLine("这是个关于放置长方形的游戏。")
  96. TextWindow.WriteLine("轮流在空的,紫的方格上放置2×3的长方形。电脑将告诉你谁先。")
  97. TextWindow.WriteLine("移动鼠标看到长方形的样子及位置。")
  98. TextWindow.WriteLine("Esc键----离开")
  99. TextWindow.WriteLine("空格----旋转长方形")
  100. TextWindow.WriteLine("↑键----游戏开始")
  101. TextWindow.WriteLine("A键----在游戏开始前换玩家1的颜色")
  102. TextWindow.WriteLine("L键----在游戏开始前换玩家2的颜色")
  103. TextWindow.WriteLine("谁最后不能放下长方形,谁就输了。")
  104. TextWindow.WriteLine("******************************")
  105. TextWindow.WriteLine("        Play game!!")
  106. TextWindow.WriteLine("******************************")
  107. TextWindow.Title="Help帮助"
  108. TextWindow.Show()
  109. cannot=0   'True or false to enter Sub aroud是否能不执行Sub around
  110. body=1   'Body of  the rectangle.长方形形状
  111. couldnot=0   'True or false to draw rectangle最终决定是否能画长方形
  112. boring=0
  113. '-----------------------------------------------------------------------------------------------------------
  114. While start=0
  115.   boring=1
  116. EndWhile
  117. '--------------------------------------------------------------------------------------------------------
  118. 'Draw 100 squares in the window.在窗口画100个正方形
  119. squarex=1
  120. squarey=1
  121. GraphicsWindow.BrushColor="Purple"
  122. For i=1 To 10
  123.   For j=1 To 10
  124.     bered[squarey*10+squarex]=0
  125.     square[squarey*10+squarex]=Shapes.AddRectangle(50,50)   'Use value principle用到位置原理
  126.     GraphicsWindow.BrushColor=color[1]
  127.     redsquare[squarey*10+squarex]=Shapes.AddRectangle(50,50)
  128.     GraphicsWindow.BrushColor=color[2]
  129.     yellowsquare[squarey*10+squarex]=Shapes.AddRectangle(50,50)
  130.     GraphicsWindow.BrushColor="Purple"
  131.     Shapes.Move(square[squarey*10+squarex],squarex*50-50,squarey*50-50)
  132.     Shapes.Move(redsquare[squarey*10+squarex],squarex*50-50,squarey*50-50)
  133.     Shapes.Move(yellowsquare[squarey*10+squarex],squarex*50-50,squarey*50-50)
  134.     Shapes.HideShape(redsquare[squarey*10+squarex])
  135.     Shapes.HideShape(yellowsquare[squarey*10+squarex])
  136.     squarex=squarex+1
  137.   EndFor
  138.   squarex=1
  139.   squarey=squarey+1
  140. EndFor
  141. '-----------------------------------------------------------------------------------------------------------
  142. GraphicsWindow.MouseDown=click
  143. Sub click
  144.   'Get where the mouse is.鼠标位置查询
  145.   cannot=0
  146.   GraphicsWindow.Top=0
  147.   GraphicsWindow.Left=0
  148.   mousex=GraphicsWindow.MouseX
  149.   mousey=GraphicsWindow.MouseY
  150.   numx=Math.Floor(mousex/50)+1   'Get where the square is求出鼠标所在的正方形
  151.   numy=Math.Floor(mousey/50)+1
  152.   'If any problems there.是否有错误
  153.   If mousex>=500 Or mousey>=500 Then
  154.     cannot=1
  155.     GraphicsWindow.ShowMessage("Don't click out of the big square!","Wrong")
  156.     Goto true
  157.   EndIf  
  158.   If (Math.Remainder(mousex,50)=0) Then
  159.     cannot=1
  160.     GraphicsWindow.ShowMessage("Don't click on the line!","Wrong")
  161.     Goto true
  162.   EndIf
  163.   If (Math.Remainder(mousey,50)=0) Then
  164.     cannot=1
  165.     GraphicsWindow.ShowMessage("Don't click on the line!","Wrong")
  166.     Goto true
  167.   EndIf
  168.   If bered[numy*10+numx]=1 Then
  169.     cannot=1
  170.     GraphicsWindow.ShowMessage("Don't put the rectangle over another.","Wrong")
  171.     Goto true
  172.   EndIf
  173.   '------------------------------------------------------------------------------------------------------------------------
  174.   'Above another or not in the square置于其它长方形上或出界
  175.   If body=1 Then
  176.     If numx=1 Or numx=10 Or numy=1 Then
  177.       GraphicsWindow.ShowMessage("Don't let any square out of the big square!","Wrong")
  178.       cannot=1
  179.       Goto true
  180.     EndIf  
  181.   EndIf
  182.   If body=2 Then
  183.     If numx=1 Or numy=1 Or numy=10 Then
  184.       GraphicsWindow.ShowMessage("Don't let any square out of the big square!","Wrong")
  185.       cannot=1
  186.       Goto true
  187.     EndIf  
  188.   EndIf
  189.   '---------------------------------------------------------------------------------------------------------------------------
  190.   true:
  191.   If cannot=0 Then   'Pass the conditions.通过条件
  192.     If firstplayer=1 Then
  193.       Shapes.ShowShape(redsquare[numy*10+numx])   'Draw first先画好第一个正方形
  194.     Else
  195.       Shapes.ShowShape(yellowsquare[numy*10+numx])
  196.     EndIf
  197.     bered[numy*10+numx]=1
  198.     around()
  199.   EndIf
  200. EndSub
  201. '-------------------------------------------------------------------------------------------------------------
  202. Sub around
  203.   couldnot=0   'More conditions更多条件·
  204.   If body=1 Then  'Put it over another放置重叠
  205.     If bered[numy*10+numx-11]=1 Or bered[numy*10+numx-10]=1 Or bered[numy*10+numx-9]=1 Or bered[numy*10+numx-1]=1 Or bered[numy*10+numx+1]=1 Then
  206.       If firstplayer=1 Then
  207.         Shapes.HideShape(redsquare[numy*10+numx])
  208.       Else
  209.         Shapes.HideShape(yellowsquare[numy*10+numx])
  210.       EndIf
  211.       couldnot=1
  212.       bered[numy*10+numx]=0
  213.       GraphicsWindow.ShowMessage("Don't put the rectangle over another.","Wrong")
  214.       Goto true2
  215.     EndIf
  216.     '----------------------------------------------------------------------------------------------------------------------
  217.     true2:
  218.     If couldnot=0 Then 'Pass the conditions 通过所有条件
  219.       If firstplayer=1 Then
  220.         Shapes.ShowShape(redsquare[numy*10+numx-11])
  221.         Shapes.ShowShape(redsquare[numy*10+numx-10])
  222.         Shapes.ShowShape(redsquare[numy*10+numx-9])
  223.         Shapes.ShowShape(redsquare[numy*10+numx-1])
  224.         Shapes.ShowShape(redsquare[numy*10+numx+1])
  225.       Else
  226.         Shapes.ShowShape(yellowsquare[numy*10+numx-11])
  227.         Shapes.ShowShape(yellowsquare[numy*10+numx-10])
  228.         Shapes.ShowShape(yellowsquare[numy*10+numx-9])
  229.         Shapes.ShowShape(yellowsquare[numy*10+numx-1])
  230.         Shapes.ShowShape(yellowsquare[numy*10+numx+1])
  231.       EndIf
  232.       bered[numy*10+numx-11]=1
  233.       bered[numy*10+numx-10]=1
  234.       bered[numy*10+numx-9]=1
  235.       bered[numy*10+numx-1]=1
  236.       bered[numy*10+numx+1]=1
  237.       firstplayer=3-firstplayer
  238.       Shapes.SetText(turn,"It's player"+firstplayer+" turn.")   'In turn轮流
  239.     EndIf
  240.   EndIf
  241.   '-------------------------------------------------------------------------------------------------------------------
  242.   If body=2 Then   'Put it over another放置重叠
  243.     If bered[numy*10+numx-11]=1 Or bered[numy*10+numx-10]=1 Or bered[numy*10+numx-1]=1 Or bered[numy*10+numx+9]=1 Or bered[numy*10+numx+10]=1 Then
  244.       If firstplayer=1 Then
  245.         Shapes.HideShape(redsquare[numy*10+numx])
  246.       Else
  247.         Shapes.HideShape(yellowsquare[numy*10+numx])
  248.       EndIf
  249.       couldnot=1
  250.       bered[numy*10+numx]=0
  251.       GraphicsWindow.ShowMessage("Don't put the rectangle over another.","Wrong")
  252.       Goto true3
  253.     EndIf
  254.     true3:
  255.     If couldnot=0 Then   'Pass the conditions 通过所有条件
  256.       If firstplayer=1 Then
  257.         Shapes.ShowShape(redsquare[numy*10+numx-11])
  258.         Shapes.ShowShape(redsquare[numy*10+numx-10])
  259.         Shapes.ShowShape(redsquare[numy*10+numx-1])
  260.         Shapes.ShowShape(redsquare[numy*10+numx+9])
  261.         Shapes.ShowShape(redsquare[numy*10+numx+10])
  262.       Else
  263.         Shapes.ShowShape(yellowsquare[numy*10+numx-11])
  264.         Shapes.ShowShape(yellowsquare[numy*10+numx-10])
  265.         Shapes.ShowShape(yellowsquare[numy*10+numx-1])
  266.         Shapes.ShowShape(yellowsquare[numy*10+numx+9])
  267.         Shapes.ShowShape(yellowsquare[numy*10+numx+10])
  268.       EndIf
  269.       bered[numy*10+numx-11]=1
  270.       bered[numy*10+numx-10]=1
  271.       bered[numy*10+numx-1]=1
  272.       bered[numy*10+numx+9]=1
  273.       bered[numy*10+numx+10]=1
  274.       firstplayer=3-firstplayer
  275.       Shapes.SetText(turn,"It's player"+firstplayer+" turn.")   'In turn轮流
  276.     EndIf
  277.   EndIf
  278. EndSub
  279. '--------------------------------------------------------------------------------------------------------------------
  280. Sub key
  281.   If GraphicsWindow.LastKey="Space" And start=0 Then
  282.     next=1
  283.   EndIf
  284.   If GraphicsWindow.LastKey="Space" And start=1 Then
  285.     body=3-body  'Change body改变形状
  286.     Shapes.HideShape(rectangle[3-body])
  287.     Shapes.HideShape(model[3-body])
  288.     Shapes.ShowShape(rectangle[body])
  289.     Shapes.ShowShape(model[body])
  290.     GraphicsWindow.Top=0
  291.     GraphicsWindow.Left=0
  292.     mousex=GraphicsWindow.MouseX
  293.     mousey=GraphicsWindow.MouseY
  294.     numx=Math.Floor(mousex/50)+1
  295.     numy=Math.Floor(mousey/50)+1
  296.     Shapes.Move(rectangle[body],numx*50-50,numy*50-100)
  297.   EndIf
  298.   If GraphicsWindow.LastKey="A" And start=0 Then
  299.     If colornum[1]=6 Then
  300.       colornum[1]=1
  301.     Else
  302.       colornum[1]=colornum[1]+1
  303.     EndIf
  304.     If colornum[1]=1 Then   'Set the color设置颜色
  305.       color[1]="Red"
  306.     ElseIf colornum[1]=2 Then
  307.       color[1]="Yellow"
  308.     ElseIf colornum[1]=3 Then
  309.       color[1]="Orange"
  310.     ElseIf colornum[1]=4 Then
  311.       color[1]="Green"
  312.     ElseIf colornum[1]=5 Then
  313.       color[1]="Blue"
  314.     ElseIf colornum[1]=6 Then
  315.       color[1]="Violet"
  316.     EndIf
  317.     Shapes.Remove(circle[1])
  318.     GraphicsWindow.BrushColor=color[1]
  319.     circle[1]=Shapes.AddEllipse(30,30)
  320.     Shapes.Move(circle[1],610,350)
  321.   EndIf
  322.   If GraphicsWindow.LastKey="L" And start=0 Then
  323.     If colornum[2]=6 Then
  324.       colornum[2]=1
  325.     Else
  326.       colornum[2]=colornum[2]+1
  327.     EndIf
  328.     If colornum[2]=1 Then
  329.       color[2]="Red"
  330.     ElseIf colornum[2]=2 Then
  331.       color[2]="Yellow"
  332.     ElseIf colornum[2]=3 Then
  333.       color[2]="Orange"
  334.     ElseIf colornum[2]=4 Then
  335.       color[2]="Green"
  336.     ElseIf colornum[2]=5 Then
  337.       color[2]="Blue"
  338.     ElseIf colornum[2]=6 Then
  339.       color[2]="Violet"
  340.     EndIf
  341.     Shapes.Remove(circle[2])
  342.     GraphicsWindow.BrushColor=color[2]
  343.     circle[2]=Shapes.AddEllipse(30,30)
  344.     Shapes.Move(circle[2],610,405)
  345.   EndIf
  346.   If GraphicsWindow.LastKey="Up" Then
  347.     If color[1]=color[2] Then
  348.       GraphicsWindow.ShowMessage("Don't make two color same!","Wrong")
  349.     Else
  350.       start=1
  351.     EndIf
  352.   EndIf
  353.   If GraphicsWindow.LastKey="Escape" Then
  354.     Program.End()
  355.   EndIf
  356. EndSub
  357. '-------------------------------------------------------------------------------------------------------------------
  358. 'Move shape when mouse move当鼠标移动时移动图形
  359. GraphicsWindow.BrushColor="Blue"
  360. rectangle[1]=Shapes.AddRectangle(150,100)
  361. rectangle[2]=Shapes.AddRectangle(100,150)
  362. Shapes.HideShape(rectangle[2])
  363. Shapes.SetOpacity(rectangle[1],80)
  364. Shapes.SetOpacity(rectangle[2],80)
  365. Sub usemouse
  366.   GraphicsWindow.Top=0
  367.   GraphicsWindow.Left=0
  368.   mousex=GraphicsWindow.MouseX
  369.   mousey=GraphicsWindow.MouseY
  370.   numx=Math.Floor(mousex/50)+1
  371.   numy=Math.Floor(mousey/50)+1
  372.   Shapes.Move(rectangle[body],numx*50-100,numy*50-100)
  373. EndSub
复制代码

study_hard  原创
***************
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2019-5-26 19:10 , Processed in 0.202027 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.3

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