vb小游戏源代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb小游戏源代码相关的知识,希望对你有一定的参考价值。
编写了石头剪刀布程序后,如果获胜则进行奖励,例如说奖励一只苹果
Rem 窗体创建三个单选框按钮,Option1、Option2、Option3。
小游戏是一个较模糊的概念,它是相对于体积庞大的单机游戏及网络游戏而言的,泛指所有体积较小、玩法简单的游戏,通常这类游戏以休闲益智类为主,有单机版有网页版,在网页上嵌入的多为FLASH格式。
当下小游戏主要是指在线玩的flash版本游戏,统称小游戏,其实小游戏还包含单机游戏,小型游戏机等。一般游戏大小小于10m的游戏都统称为小游戏,一些街机类小游戏。因其游戏安装简便,耐玩性强,无依赖性而广受白领及小朋友的喜爱。
小游戏”这个词的型含义其实很简单,它不是一些大的游戏,不必花费更多的时间和精力。
小游戏是原始的游戏娱乐方式,小游戏本身是为了叫人们在工作,学习后的一种娱乐、休闲的一种方式,不是为了叫玩家为之花费金钱、花费精力,更不是叫玩家为他痴迷。
小游戏也可以理解为“Flash游戏”,是以SWF为后缀的游戏的总称.这些游戏是通过Flash软件和 Flash 编程语言 Flash ActionScript 制作而成。
由于Flash是矢量软件,所以小游戏放大后几乎不影响画面效果。Flash小游戏是一种新兴起的游戏形式,以游戏简单,操作方便,绿色,无需安装,文件体积小等优点渐渐被广大网友喜爱。
参考技术A Rem 窗体创建三个单选框按钮,Option1、Option2、Option3Private Sub Form_Activate()
Option1.Caption = "石头"
Option2.Caption = "剪刀"
Option3.Caption = "布"
Option1.Value = False
Option2.Value = False
Option3.Value = False
End Sub
Private Sub Option1_Click()
Randomize
Select Case Int(3 * Rnd)
Case 0: MsgBox "对方也出石头!继续!"
Case 1: MsgBox "哈哈!你赢了!对方出的是剪刀!奖励你一个苹果!"
Case 2: MsgBox "你输了!对方出的是布哦!不好意思,苹果给对方了哈!"
End Select
Option1.Value = False
End Sub
Private Sub Option2_Click()
Randomize
Select Case Int(3 * Rnd)
Case 0: MsgBox "你输了!对方出的是石头哦!不好意思,苹果给对方了哈!"
Case 1: MsgBox "对方也出剪刀!继续!"
Case 2: MsgBox "哈哈!你赢了!对方出的是布!奖励你一个苹果!"
End Select
Option2.Value = False
End Sub
Private Sub Option3_Click()
Randomize
Select Case Int(3 * Rnd)
Case 0: MsgBox "哈哈!你赢了!对方出的是石头!奖励你一个苹果!"
Case 1: MsgBox "你输了!对方出的是剪刀哦!不好意思,苹果给对方了哈!"
Case 2: MsgBox "对方也出布!继续!"
End Select
Option3.Value = False
End Sub本回答被提问者采纳 参考技术B Dim pFist, cFist, cCount, pCount, dCount, tCount As Integer
Private Sub Form_Load()
cCount = 0
pCount = 0
dCount = 0
tCount = 1
lblPWinNum.Caption = ""
lblPWinNum.Caption = lblPWinNum.Caption & pCount
lblCWinNum.Caption = ""
lblCWinNum.Caption = lblCWinNum.Caption & cCount
lblDrawNum.Caption = ""
lblDrawNum.Caption = lblDrawNum.Caption & dCount
lblTotalNum.Caption = ""
lblTotalNum.Caption = lblTotalNum.Caption & tCount
End Sub
Private Sub imgCloth_Click()
pFist = 3
cFist = Int(Rnd * 3) + 1
txtPlayer.Text = ""
txtPlayer.Text = txtPlayer.Text & "布"
If cFist = 1 Then
txtComputer = ""
txtComputer = txtComputer & "石头"
Else
If cFist = 2 Then
txtComputer = ""
txtComputer = txtComputer & "剪刀"
Else
If cFist = 3 Then
txtComputer = ""
txtComputer = txtComputer & "布"
End If
End If
End If
If cFist = 1 Then
pCount = pCount + 1
lblPWinNum.Caption = ""
lblPWinNum.Caption = lblPWinNum.Caption & pCount
picSusess.Visible = True
MsgBox "恭喜你,你赢了!"
Else
If cFist = 2 Then
cCount = cCount + 1
lblCWinNum.Caption = ""
lblCWinNum.Caption = lblCWinNum.Caption & cCount
MsgBox "很遗憾,你输了!"
Else
dCount = dCount + 1
lblDrawNum.Caption = ""
lblDrawNum.Caption = lblDrawNum.Caption & dCount
MsgBox "打平了!"
End If
End If
tCount = tCount + 1
lblTotalNum.Caption = ""
lblTotalNum.Caption = lblTotalNum.Caption & tCount
End Sub
Private Sub imgScissors_Click()
pFist = 2
cFist = Int(Rnd * 3) + 1
txtPlayer.Text = ""
txtPlayer.Text = txtPlayer.Text & "剪刀"
If cFist = 1 Then
txtComputer = ""
txtComputer = txtComputer & "石头"
Else
If cFist = 2 Then
txtComputer = ""
txtComputer = txtComputer & "剪刀"
Else
If cFist = 3 Then
txtComputer = ""
txtComputer = txtComputer & "布"
End If
End If
End If
If cFist = 3 Then
pCount = pCount + 1
lblPWinNum.Caption = ""
lblPWinNum.Caption = lblPWinNum.Caption & pCount
picSusess.Visible = True
MsgBox "恭喜你,你赢了!"
Else
If cFist = 1 Then
cCount = cCount + 1
lblCWinNum.Caption = ""
lblCWinNum.Caption = lblCWinNum.Caption & cCount
MsgBox "很遗憾,你输了!"
Else
dCount = dCount + 1
lblDrawNum.Caption = ""
lblDrawNum.Caption = lblDrawNum.Caption & dCount
MsgBox "打平了!"
End If
End If
tCount = tCount + 1
lblTotalNum.Caption = ""
lblTotalNum.Caption = lblTotalNum.Caption & tCount
End Sub
Private Sub imgStone_Click()
pFist = 1
cFist = Int(Rnd * 3) + 1
txtPlayer.Text = ""
txtPlayer.Text = txtPlayer.Text & "石头"
If cFist = 1 Then
txtComputer = ""
txtComputer = txtComputer & "石头"
Else
If cFist = 2 Then
txtComputer = ""
txtComputer = txtComputer & "剪刀"
Else
If cFist = 3 Then
txtComputer = ""
txtComputer = txtComputer & "布"
End If
End If
End If
If cFist = 2 Then
pCount = pCount + 1
lblPWinNum.Caption = ""
lblPWinNum.Caption = lblPWinNum.Caption & pCount
picSusess.Visible = True
MsgBox "恭喜你,你赢了!"
Else
If cFist = 3 Then
cCount = cCount + 1
lblCWinNum.Caption = ""
lblCWinNum.Caption = lblCWinNum.Caption & cCount
MsgBox "很遗憾,你输了!"
Else
dCount = dCount + 1
lblDrawNum.Caption = ""
lblDrawNum.Caption = lblDrawNum.Caption & dCount
MsgBox "打平了!"
End If
End If
tCount = tCount + 1
lblTotalNum.Caption = ""
lblTotalNum.Caption = lblTotalNum.Caption & tCount
End Sub
Private Sub picSusess_Click()
picSusess.Visible = False
End Sub
我原来做的一个,按照你的提示加了一个图片,picSusess这个就是图片,里面放着一个苹果的图片,当你赢了就会出现,你点击一下,那个图片就消失,我这个里面除了你这个功能,还有战绩提示,统计你胜负平的局数和第多少局(计算公式是胜负平的局数+1,就是当前局数)
益智 | 用VB编程开发的围棋游戏!
VB编程易学实用、功能强大,非常有趣!
今天,我们就共同来领略用VB开发的象棋游戏如何实现。
象棋游戏实现第一步,首先是想办法用VB代码来实现上面的图形界面。
我们可以看到,棋盘界面上有方框、有图线、有文字。
这个如何来实现呢?
我们通过下面的代码来实现界面。
Option Explicit
Dim C As Byte '当前玩家
Dim cSel As Byte, osel As Byte '当前选中哪个棋子,目标哪个棋子
Dim DoCchess As Boolean '是否允许玩家选中棋子
Public a As Byte, b As Byte
Dim PubBestLocate As CHESSER '最后运算分数最高的结果
Const INITVALUE = -10000 '初始分数
Const KING = 5000
Dim ChessBoard(9, 10) As Chess '棋盘(横9列,竖10行)
Dim ChessBoardCopy(9, 10) As Chess '棋盘的复本
'Rem 根据ChessBoard数组显示棋子
Public Function DisplayImageCchess()
Dim i As Byte, j As Byte, k As Byte
k = 0
For j = 1 To 10
For i = 1 To 9
Cchess1(k).Value = ChessBoard(i, j).Value ''得知屏幕位置为何棋
If ChessBoard(i, j).Value = 0 Then
Cchess1(k).NoneCchess = True
Else
Cchess1(k).Visible = True
Cchess1(k).NoneCchess = False
Cchess1(k).Text = CchessWord(ChessBoard(i, j).Value)
If Int(ChessBoard(i, j).Value / 100) = 1 Then Cchess1(k).FillColor = vbBlue Else Cchess1(k).FillColor = vbRed ''颜色
End If
k = k + 1
Next i
Next j
End Function
单击新局按钮时,重置棋盘
Rem 重置棋盘
Private Sub SetCchess()
Call ClearChessBoard ''棋盘无子
ChessBoard(5, 1).Value = 107 ''黑帅
ChessBoard(4, 1).Value = 106 ''黑士
ChessBoard(6, 1).Value = 106 ''黑士
ChessBoard(3, 1).Value = 105 ''黑象
ChessBoard(7, 1).Value = 105 ''黑象
ChessBoard(2, 1).Value = 103 ''黑马
ChessBoard(8, 1).Value = 103 ''黑马
ChessBoard(1, 1).Value = 104 ''黑车
ChessBoard(9, 1).Value = 104 ''黑车
ChessBoard(2, 3).Value = 102 ''黑炮
ChessBoard(8, 3).Value = 102 ''黑炮
ChessBoard(1, 4).Value = 101 ''黑卒
ChessBoard(3, 4).Value = 101 ''黑卒
ChessBoard(5, 4).Value = 101 ''黑卒
ChessBoard(7, 4).Value = 101 ''黑卒
ChessBoard(9, 4).Value = 101 ''黑卒
ChessBoard(5, 10).Value = 207 ''红帅
ChessBoard(4, 10).Value = 206 ''红士
ChessBoard(6, 10).Value = 206 ''红士
ChessBoard(3, 10).Value = 205 ''红象
ChessBoard(7, 10).Value = 205 ''红象
ChessBoard(2, 10).Value = 203 ''红马
ChessBoard(8, 10).Value = 203 ''红马
ChessBoard(1, 10).Value = 204 ''红车
ChessBoard(9, 10).Value = 204 ''红车
ChessBoard(2, 8).Value = 202 ''红炮
ChessBoard(8, 8).Value = 202 ''红炮
ChessBoard(1, 7).Value = 201 ''红卒
ChessBoard(3, 7).Value = 201 ''红卒
ChessBoard(5, 7).Value = 201 ''红卒
ChessBoard(7, 7).Value = 201 ''红卒
ChessBoard(9, 7).Value = 201 ''红卒
End Sub
'开始下棋
Private Sub Command1_Click()
Dim CV As Integer
Command1.Enabled = False
PubBestLocate.Value = INITVALUE
'If C = 2 Then Call MsgBox("现在轮到红方(玩家)下棋!", vbOKOnly + 32, "提示:"): Exit Sub
C = 1
If C = 1 Or C = 2 Then
CV = Search(C, Val(Text1.Text) * 2, True, 10000) ''运算C方
''下棋
With PubBestLocate
Call MsgBox(Str(.Initx) & "," & Str(.Inity) & " 到 " & Str(.ObjX) & "," & Str(.ObjY), vbOKOnly)
Call MoveCchess(.Initx, .Inity, .ObjX, .ObjY)
End With
Text2.Text = Str(CV)
End If
Call DisplayImageCchess ''显示
Command1.Enabled = True
End Sub
往期回顾
●!
●
●
●
以上是关于vb小游戏源代码的主要内容,如果未能解决你的问题,请参考以下文章