Small Basic中文站-快乐编程

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 7782|回复: 3

SmallBasic棋牌类游戏的源代码

[复制链接]
发表于 2010-6-14 15:12:36 | 显示全部楼层 |阅读模式
5金钱
谁有SmallBasic棋类游戏的源代码 象棋 围棋 跳棋 各类扑克牌游戏都行

回复

使用道具 举报

发表于 2012-8-28 15:28:03 | 显示全部楼层
由于技术有限,所以只能编一个“井字棋”的游戏,希望你能喜欢。
帮助:3个同色的棋子摆成一行、一列、或一对角线,就算赢了,很简单的规则~~
以下是代码(原创)
————————————————————————————————————————
GraphicsWindow.Width=840
GraphicsWindow.Clear()
GraphicsWindow.Height=750
GraphicsWindow.MouseDown = MouseDown
player=Math.GetRandomNumber(2)
GraphicsWindow.FontSize="24"
GraphicsWindow.BrushColor="Purple"
GraphicsWindow.DrawText(610,200,"Player"+player+"first")
start:
W=200
H=200
color=1
GraphicsWindow.BrushColor="Blue"
viewtext()
For i=1 TO 9 step 1
  place[i]=0
  win[i]=1000
  GraphicsWindow.BrushColor="MediumSlateBlue"
  square[i]=Shapes.AddRectangle(W,H)
  Shapes.Move(square[i],Math.Remainder(i-1,3)*W,(math.Ceiling(i/3)-1)*H)
endfor
GraphicsWindow.BrushColor="Black"
next=Shapes.AddEllipse(100,100)
Shapes.Move(next,610,35)
GraphicsWindow.BrushColor="White"
next2=Shapes.AddEllipse(100,100)
GraphicsWindow.BrushColor="Blue"
Shapes.Move(next2,610,35)
Shapes.HideShape(next2)
GraphicsWindow.BrushColor="Blue"
GraphicsWindow.DrawText(610,10,"Next color is:")
While "true"
  If color=0 Then
    Shapes.HideShape(next)
    Shapes.ShowShape(next2)
  EndIf
  If color=1 Then
    Shapes.HideShape(next2)
    Shapes.ShowShape(next)
  EndIf
  Program.Delay(200)
EndWhile
Sub Mousedown
  For i=1 TO 9 step 1
    If Mouse.IsLeftButtonDown And place[i]=0 And GraphicsWindow.MouseX>=Shapes.GetLeft(square[i]) And  (GraphicsWindow.MouseX<=Shapes.GetLeft(square[i])+W) Then
      If  GraphicsWindow.MouseY> Shapes.GetTop(square[i]) And (GraphicsWindow.MouseY< Shapes.GetTop(square[i])+H) then
        place[i]=1
        If color=1 then
          color=0
          GraphicsWindow.BrushColor="Black"
          mm[i]=Shapes.AddEllipse(200,200)
          Shapes.Move(mm[i],Math.Remainder(i-1,3)*W,(math.Ceiling(i/3)-1)*H)
          win[i]=10
        Else
          color=1
          GraphicsWindow.BrushColor="White"
          mm[i]=Shapes.AddEllipse(200,200)
          Shapes.Move(mm[i],Math.Remainder(i-1,3)*W,(math.Ceiling(i/3)-1)*H)
          win[i]=100
        EndIf
        If win[1]+win[2]+win[3]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[4]+win[5]+win[6]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[7]+win[8]+win[9]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        EndIf
        If win[1]+win[4]+win[7]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[2]+win[5]+win[8]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[3]+win[6]+win[9]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[1]+win[5]+win[9]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[3]+win[5]+win[7]=30 then
          GraphicsWindow.ShowMessage("Black win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[1]+win[2]+win[3]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[4]+win[5]+win[6]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[7]+win[8]+win[9]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        EndIf
        If win[1]+win[4]+win[7]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[2]+win[5]+win[8]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[3]+win[6]+win[9]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[1]+win[5]+win[9]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
        If win[3]+win[5]+win[7]=300 then
          GraphicsWindow.ShowMessage("White win.","win")
          Sound.PlayChimeAndWait()
          Program.End()
        Endif
      Endif
    EndIf  
  Endfor
EndSub
Sub viewtext
  GraphicsWindow.BrushColor="Green"
  GraphicsWindow.FontSize="20"
  GraphicsWindow.BrushColor="Green"
  help=Shapes.AddText("If there're three same stones in a line(across,upright and diagonal),the player wins.")
  Shapes.Move(help,0,700)
EndSub
Sub reset
  For i=1 To 9
    Shapes.Remove(mm[i])
    Shapes.Remove(square[i])
  EndFor
Goto start
EndSub
回复

使用道具 举报

发表于 2012-9-15 11:55:02 | 显示全部楼层
上面这断井字棋代码复制来运行了一下,没有运行问题,只是只能自己和自己下,不能人机对战。不过study_hard已经很厉害了,我才刚开始学,要向你学习啊。
回复

使用道具 举报

发表于 2015-6-18 21:37:39 | 显示全部楼层
'Set windows
GraphicsWindow.Width=840
GraphicsWindow.Height=750
GraphicsWindow.FontSize="24"
GraphicsWindow.MouseDown = MouseDown
GraphicsWindow.Left=20
GraphicsWindow.Top=20
color=Math.GetRandomNumber(2)
W=40
H=40
end=0

'Draw squares
For i=1 To 225 Step 1
  place[i]=0
  win[i]=1000
  GraphicsWindow.BrushColor="MediumSlateBlue"
  square[i]=Shapes.AddRectangle(W,H)
  Shapes.Move(square[i],Math.Remainder(i-1,15)*W+20,(math.Ceiling(i/15)-1)*H+20)
Endfor

'Creat more texts
GraphicsWindow.BrushColor="Black"
next=Shapes.AddEllipse(80,80)
GraphicsWindow.BrushColor="White"
next2=Shapes.AddEllipse(80,80)
GraphicsWindow.BrushColor="Blue"
GraphicsWindow.DrawText(630,10,"Next color is:")
Shapes.Move(next,650,35)
Shapes.Move(next2,650,35)
Shapes.HideShape(next2)

'Hide/Show texts
While "true"
  If color=1 Then
    Shapes.HideShape(next)
    Shapes.ShowShape(next2)
  EndIf
  If color=2 Then
    Shapes.HideShape(next2)
    Shapes.ShowShape(next)
  EndIf
  Program.Delay(200)
EndWhile

'Draw circle
Sub Mousedown
  If end=0 Then
    For i=1 To 225 Step 1
      If Mouse.IsLeftButtonDown And place[i]=0 And GraphicsWindow.MouseX>=Shapes.GetLeft(square[i]) And  (GraphicsWindow.MouseX<=Shapes.GetLeft(square[i])+W) Then
        If  GraphicsWindow.MouseY> Shapes.GetTop(square[i]) And (GraphicsWindow.MouseY< Shapes.GetTop(square[i])+H) Then
          place[i]=1
          If color=2 Then
            color=1
            GraphicsWindow.BrushColor="Black"
            mm[i]=Shapes.AddEllipse(40,40)
            Shapes.Move(mm[i],Math.Remainder(i-1,15)*W+20,(math.Ceiling(i/15)-1)*H+20)
            win[i]=10
          Else
            color=2
            GraphicsWindow.BrushColor="White"
            mm[i]=Shapes.AddEllipse(40,40)
            Shapes.Move(mm[i],Math.Remainder(i-1,15)*W+20,(math.Ceiling(i/15)-1)*H+20)
            win[i]=100
          EndIf
        EndIf
      EndIf
    EndFor
    For i=1 To 225 Step 1
      fromx=Math.Remainder(i-1,15)*W+20+W/2
      fromy=Math.Ceiling((i/15)-1)*H+20+H/2
      tox=Math.Remainder(i+3,15)*W+20+W/2
      toy=Math.Ceiling(((i+4)/15)-1)*H+20+H/2
      If win[i]+win[i+1]+win[i+2]+win[i+3]+win[i+4]=50 And Math.Floor((i+4)/15)=Math.Floor(i/15) Then
        GraphicsWindow.ShowMessage("Black wins.","WIN")
        Goto wins
      EndIf
      If win[i]+win[i+1]+win[i+2]+win[i+3]+win[i+4]=500 And Math.Floor((i+4)/15)=Math.Floor(i/15) Then
        GraphicsWindow.ShowMessage("White wins.","WIN")
        Goto wins
      EndIf
      tox=Math.Remainder(i+59,15)*W+20+W/2
      toy=Math.Ceiling(((i+60)/15)-1)*H+20+H/2
      If win[i]+win[i+15]+win[i+30]+win[i+45]+win[i+60]=50 And Math.Remainder(i,10)=Math.Remainder(i+60,10) Then
        GraphicsWindow.ShowMessage("Black wins.","WIN")
        Goto wins
      EndIf
      If win[i]+win[i+15]+win[i+30]+win[i+45]+win[i+60]=500 And Math.Remainder(i,10)=Math.Remainder(i+60,10) Then
        GraphicsWindow.ShowMessage("White wins.","WIN")
        Goto wins
      EndIf
      tox=Math.Remainder(i+63,15)*W+20+W/2
      toy=Math.Ceiling(((i+64)/15)-1)*H+20+H/2
      If win[i]+win[i+16]+win[i+32]+win[i+48]+win[i+64]=50 And Math.Floor((i+4)/15)=Math.Floor(i/15) And Math.Remainder(i,10)=Math.Remainder(i+60,10) Then
        GraphicsWindow.ShowMessage("Black wins.","WIN")
        Goto wins
      EndIf
      If win[i]+win[i+16]+win[i+32]+win[i+48]+win[i+64]=500 And Math.Floor((i+4)/15)=Math.Floor(i/15) And Math.Remainder(i,10)=Math.Remainder(i+60,10) Then
        GraphicsWindow.ShowMessage("White wins.","WIN")
        Goto wins
      EndIf
      tox=Math.Remainder(i+55,15)*W+20+W/2
      toy=Math.Ceiling(((i+56)/15)-1)*H+20+H/2
      If win[i]+win[i+14]+win[i+28]+win[i+42]+win[i+56]=50 And Math.Floor((i+4)/15)=Math.Floor(i/15) And Math.Remainder(i,10)=Math.Remainder(i+50,10) Then
        GraphicsWindow.ShowMessage("Black wins.","WIN")
        Goto wins
      EndIf
      If win[i]+win[i+14]+win[i+28]+win[i+42]+win[i+56]=500 And Math.Floor((i+4)/15)=Math.Floor(i/15) And Math.Remainder(i,10)=Math.Remainder(i+50,10) Then
        GraphicsWindow.ShowMessage("White wins.","WIN")
        Goto wins
      EndIf
    EndFor
    Goto jump
    wins:
    end=1
    GraphicsWindow.PenColor="Red"
    Shapes.AddLine(fromx,fromy,tox,toy)
    jump:
  EndIf
EndSub
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2017-10-21 05:31 , Processed in 0.242696 second(s), 6 queries , File On.

Powered by Discuz! X3.3

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