1.vb游戏代码大全vb小游戏源代码
2.全排列VB源代码
3.求VB源代码!源码!源码!源码
4.VB中国象棋源代码
vb游戏代码大全vb小游戏源代码
关于vb游戏代码大全,源码vb小游戏源代码这个很多人还不知道,源码今天来为大家解答以上的源码vc 连接ssh源码问题,现在让我们一起来看看吧!源码
1、源码Rem 窗体创建三个单选框按钮,源码OptionOption2、源码Option3 Private 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 "你输了!对方出的是石头哦!不好意思。
2、苹果给对方了哈!linux 源码添加中文" 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。
全排列VB源代码
文章标题:全排列VB源代码与C++实现,附非递归算法解答在编程世界中,全排列算法是一个常被提及的主题,尤其在解决组合数学问题时。本文将展示如何使用 Visual Basic (VB) 和 C++ 语言实现全排列,并提供一个非递归算法的解答,帮助读者理解和解决相关问题。企业源码wap web
首先,让我们聚焦于 VB 语言的实现。在 VB 中,我们可以通过编写一段代码来生成给定字符串的所有全排列。下面是一个典型的 VB 代码示例:
vb
Option Explicit
Private Sub Command1_Click()
Dim nt As Double: nt = Timer
List1.Visible = False: List1.Clear
Permutation("", Text1.Text)
List1.Visible = True
Debug.Print Timer - nt,
End Sub
Private Sub Permutation(pre As String, s As String)
Dim i As Long
If Len(s) = 1 Then List1.AddItem pre & s: Exit Sub
For i = 1 To Len(s)
Permutation(pre & Mid$(s, i, 1), Left$(s, i - 1) & Mid$(s, i + 1))
Next
End Sub
这段代码实现了一个递归过程来生成全排列。它首先检查字符串的长度,如果长度为1,则直接将字符串与前面的元素合并并添加到列表中。如果字符串长度大于1,则进行循环以取出待排列串的任意一位,并将该字符插入到已取出的字符串后,然后递归调用自身,同时更新待排列的字符串。这一过程一直持续到所有字符排列完成。
接下来,我们转向 C++ 实现,一种更广泛使用的编程语言。C++ 中的全排列实现通常使用模板类,以适应不同类型的元素。下面是一个简单的 C++ 全排列实现:
cpp
template class Type>
void Perm(Type list[], int k, int m) {
if (k == m) {
for (int i = 0; i <= m; i++) {
cout << list[i];
}
cout << endl;
} else {
for (int i = k; i <= m; i++) {
Swap(list[k], list[i]);
Perm(list, k + 1, m);
Swap(list[k], list[i]);
}
}
}
此模板函数 `Perm` 接受一个类型为 `Type` 的数组、起始索引 `k` 和结束索引 `m`,并递归地生成从 `k` 到 `m` 的数组的所有全排列。通过交换数组中的元素,我们逐步构建全排列并打印结果。
对于一个非递归的全排列算法,我们可以通过一个循环和条件判断来实现。下面是一个用 C++ 实现的非递归算法:
cpp
#include
int *n;
void arge(int *x, int size) {
int *t = new int[size];
int totoal = 0;
int pos = size - 2;
int just = 0;
for (int i = 0; i < size; i++) {
t[0] = 1;
}
while (1) {
for (int i = 0; i < size; i++) {
printf("%d ", x[i]);
}
printf("\n");
totoal++;
pos = size - 2;
while (x[pos] > x[pos + 1]) {
pos--;
t[x[pos + 1] - 1] = 0;
}
if (pos < 0) {
break;
}
t[x[pos] - 1] = 0;
t[x[pos + 1] - 1] = 0;
for (int i = pos + 1; i < size; i++) {
for (int j = 1; j <= size; j++) {
if (t[j - 1] == 0) {
x[i] = j;
t[j - 1] = 1;
break;
}
}
}
}
printf("totoal = %d\n", totoal);
delete[] t;
}
这个非递归算法通过使用一个辅助数组 `t` 来跟踪已排序的元素,从而避免了递归调用。通过循环和条件判断,该算法实现了从数组中生成全排列,并打印每个排列的结果。
通过以上三种不同的实现方式,我们可以看到全排列问题在不同编程语言中的解法,每种方法都有其优势和应用场景。理解这些不同的解决方案有助于提升编程技能,解决更多复杂问题。
扩展资料
从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。
求VB源代码!!!
用记事本把下面的代码保存到Form1.Frm文件中。然后用VB打开,试试吧。
===========
VERSION
5.
Begin
VB.Form
Form1
BorderStyle
=
1
'Fixed
Single
Caption
=
"打地鼠"
ClientHeight
=
ClientLeft
=
ClientTop
=
ClientWidth
=
LinkTopic
=
"Form1"
MaxButton
=
0
'False
MinButton
=
0
'False
ScaleHeight
=
ScaleWidth
=
StartUpPosition
=
3
'窗口缺省
Begin
VB.CommandButton
Command1
Caption
=
"开始"
Height
=
Left
=
0
TabIndex
=
9
Top
=
Width
=
End
Begin
VB.Timer
Timer1
Interval
=
Left
=
Top
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
8
Left
=
ScaleHeight
=
ScaleWidth
=
TabIndex
=
8
Top
=
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
7
Left
=
ScaleHeight
=
ScaleWidth
=
TabIndex
=
7
Top
=
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
6
Left
=
0
ScaleHeight
=
ScaleWidth
=
TabIndex
=
6
Top
=
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
5
Left
=
ScaleHeight
=
ScaleWidth
=
TabIndex
=
5
Top
=
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
4
Left
=
ScaleHeight
=
ScaleWidth
=
TabIndex
=
4
Top
=
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
3
Left
=
0
ScaleHeight
=
ScaleWidth
=
TabIndex
=
3
Top
=
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
2
Left
=
ScaleHeight
=
ScaleWidth
=
TabIndex
=
2
Top
=
0
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
1
Left
=
ScaleHeight
=
ScaleWidth
=
TabIndex
=
1
Top
=
0
Width
=
End
Begin
VB.PictureBox
Picture1
Height
=
Index
=
0
Left
=
0
ScaleHeight
=
ScaleWidth
=
TabIndex
=
0
Top
=
0
Width
=
End
Begin
VB.Label
Label1
AutoSize
=
-1
'True
Height
=
Left
=
TabIndex
=
Top
=
Width
=
End
End
Attribute
VB_Name
=
"Form1"
Attribute
VB_GlobalNameSpace
=
False
Attribute
VB_Creatable
=
False
Attribute
VB_PredeclaredId
=
True
Attribute
VB_Exposed
=
False
Dim
i
As
Integer,
t
As
Integer
Private
Sub
Command1_Click()
On
Error
GoTo
hErr
t
=
2
*
InputBox("请设置游戏时间,单位为秒:",
,
)
Caption
=
0
Timer1.Enabled
=
True
Command1.Enabled
=
False
hErr:
End
Sub
Private
Sub
Form_Load()
Timer1.Enabled
=
False
Randomize
For
Each
p
In
Picture1
p.FontName
=
"arial"
p.FontSize
=
Next
End
Sub
Private
Sub
Picture1_Click(Index
As
Integer)
If
Index
=
i
Then
Caption
=
Caption
+
1:
t
=
t
+
1:
Timer1_Timer
End
Sub
Private
Sub
Timer1_Timer()
For
Each
p
In
Picture1
p.Cls
Next
i
=
Int(Rnd
*
9)
Picture1(i).Print
i
+
1
t
=
t
-
1
Label1.Caption
=
"倒计时:"
&
Int(t
/
2)
If
t
=
0
Then
Timer1.Enabled
=
False:
MsgBox
"游戏结束,您共打到"
&
Caption
&
"次地鼠":
i
=
-1:
Command1.Enabled
=
True
End
Sub
VB中国象棋源代码
一、VB中国象棋源代码中国象棋程序一般是通过穷举法,列出人脑接下来可能走的棋,然后列出各种可能的应对方案,然后选择胜率较大的方案进行走棋,其实就是把策略的思考转化为了概率的计算。
当然,中国象棋软件也要具有一定的策略思考能力、棋局的分析能力。其次是要有效率,像人一样要“背”一些棋谱!
至于源码,不用我发了吧,以上已经讲得很清楚了,刚学编程的都会写了。
(仅供参考)
二、中国象棋的源代码
中国象棋源代码blackleft(){ int x,y,n; if(blackcurpos.y>0) { blackcurposition[blacktemppos.x][blacktemppos.y].x; y=position[blacktemppos.x][blacktemp if(board[b.x][blacktemppos.y]==0) drawbmp(xfile[blacblacktemppos.ylacktemppos.x==blackoldpos.x drawbmp(x); } if(blacktemppos.x==blackoldpos.x drawcursor(blackcurpos); blacktemppos.x=blackcuemppos.y=blackcurpos.y; }}blackright()lackcurpos.y<8) { blackcurpos.tion[blacktemppktemppos.ysition[blacktemppos.x][blacktemppos.y].y; if(board[blacktemppos.x][blacktemppos.y]==0) drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]); else if(.x==blackoldpos.x drawbhessfile[ncktemppos.x==blackoldpos.x drawcursor(blackcurpos); blacktemppos.x=blactemppos.ys.y; }}blackdon; if(blackstate==SELECT drawselecursor(blackcurpos); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; } } else if(blackstate==MOVE y=position[blackoldpos.x][blackoldpos.y].y; drawbmp(x,y,boardfile[blackoldpos.x][blackoldpos.y]); x=position[blackcurpos.x][blackcurpos.y].x; y=position[blackcurpos.x][blackcurpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); if(board[blackcurpos.x][blackcurpos.y]==RED_JIANG) { winner=BLACK; finish=1; return; } board[blackcurpos.x][blackcurpos.y]=n; board[blackoldpos.x][blackoldpos.y]=0; for(i=0;i<=2;i) for(j=3;j<=5;j) if(board[i][j]==BLACK_JIANG) { x=i;y=j;} for(i=x1,j=y,n=0;i<=9;i) { if(board[i][j]==RED_JIANGfinish=1;break;} else if(board[i][j]!=0) n; } turn=RED; redstate=SELECT; drawcursor(redcurpos); drawbmp(,,"bmp\.wfb"); /转交控制权给红方/ } }blackundo(){ int x,y,n; if(blackstate==MOVE) { x=position[blackoldpos.x][blackoldpos.y].x; y=position[blackoldpos.x][blackoldpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; drawcursor(blackcurpos); blackstate=SELECT; }}/----------------------------------------------------/start(){ drawcursor(blackcurpos); drawbmp(,,"bmp\.wfb"); while(!finish) { key=getkey(); switch(key){ case RED_UP: if(turn==RED) redup(); break; case RED_DOWN: if(turn==RED) reddown(); break; case RED_LEFT: if(turn==RED) redleft(); break; case RED_RIGHT: if(turn==RED) redright(); break; case RED_DO: if(turn==RED) reddo(); break; case RED_UNDO: if(turn==RED) redundo(); break; case BLACK_UP: if(turn==BLACK) blackup(); break; case BLACK_DOWN: if(turn==BLACK) blackdown(); break; case BLACK_LEFT: if(turn==BLACK) blackleft(); break; case BLACK_RIGHT: if(turn==BLACK) blackright(); break; case BLACK_DO: if(turn==BLACK) blackdo(); break; case BLACK_UNDO: if(turn==BLACK) blackundo(); break; case ESCAPE: finish=1;break; } }}main(){ init(); initpos(); initchesap(); drawbmp(0,0,"bmp\.wfb"); initdrawchess(); /初始化光标位置/ redcurpos.x=redoldpos.x=redtemppos.x=9; redcurpos.y=redoldpos.y=redtemppos.y=8; blackcurpos.x=blackoldpos.x=blacktemppos.x=0; blackcurpos.y=blackoldpos.y=blacktemppos.y=0;/开始/ start(); if(winner==RED) drawbmp(,,"bmp\.wfb"); else if(winner==BLACK) drawbmp(,,"bmp\.wfb"); else drawbmp(,,"bmp\.wfb"); getch(); end();}
三、中国象棋的源代码
中国象棋源代码blackleft(){ int x,y,n; if(blackcurpos.y>0) { blackcurpos.y--; x=position[blacktemppos.x][blacktemppos.y].x; y=position[blacktemppos.x][blacktemppos.y].y; if(board[blacktemppos.x][blacktemppos.y]==0) drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]); else if(!(blacktemppos.x==blackoldpos.x drawbmp(x,y,chessfile[n]); } if(blacktemppos.x==blackoldpos.x drawcursor(blackcurpos); blacktemppos.x=blackcurpos.x; blacktemppos.y=blackcurpos.y; }}blackright(){ int x,y,n; if(blackcurpos.y<8) { blackcurpos.y; x=position[blacktemppos.x][blacktemppos.y].x; y=position[blacktemppos.x][blacktemppos.y].y; if(board[blacktemppos.x][blacktemppos.y]==0) drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]); else if(!(blacktemppos.x==blackoldpos.x drawbmp(x,y,chessfile[n]); } if(blacktemppos.x==blackoldpos.x drawcursor(blackcurpos); blacktemppos.x=blackcurpos.x; blacktemppos.y=blackcurpos.y; }}blackdo(){ int i,j,x,y,n; if(blackstate==SELECT drawselecursor(blackcurpos); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; } } else if(blackstate==MOVE y=position[blackoldpos.x][blackoldpos.y].y; drawbmp(x,y,boardfile[blackoldpos.x][blackoldpos.y]); x=position[blackcurpos.x][blackcurpos.y].x; y=position[blackcurpos.x][blackcurpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); if(board[blackcurpos.x][blackcurpos.y]==RED_JIANG) { winner=BLACK; finish=1; return; } board[blackcurpos.x][blackcurpos.y]=n; board[blackoldpos.x][blackoldpos.y]=0; for(i=0;i<=2;i) for(j=3;j<=5;j) if(board[i][j]==BLACK_JIANG) { x=i;y=j;} for(i=x1,j=y,n=0;i<=9;i) { if(board[i][j]==RED_JIANGfinish=1;break;} else if(board[i][j]!=0) n; } turn=RED; redstate=SELECT; drawcursor(redcurpos); drawbmp(,,"bmp\\rzq.wfb"); /转交控制权给红方/ } }blackundo(){ int x,y,n; if(blackstate==MOVE) { x=position[blackoldpos.x][blackoldpos.y].x; y=position[blackoldpos.x][blackoldpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; drawcursor(blackcurpos); blackstate=SELECT; }}/----------------------------------------------------/start(){ drawcursor(blackcurpos); drawbmp(,,"bmp\\bzq.wfb"); while(!finish) { key=getkey(); switch(key){ case RED_UP: if(turn==RED) redup(); break; case RED_DOWN: if(turn==RED) reddown(); break; case RED_LEFT: if(turn==RED) redleft(); break; case RED_RIGHT: if(turn==RED) redright(); break; case RED_DO: if(turn==RED) reddo(); break; case RED_UNDO: if(turn==RED) redundo(); break; case BLACK_UP: if(turn==BLACK) blackup(); break; case BLACK_DOWN: if(turn==BLACK) blackdown(); break; case BLACK_LEFT: if(turn==BLACK) blackleft(); break; case BLACK_RIGHT: if(turn==BLACK) blackright(); break; case BLACK_DO: if(turn==BLACK) blackdo(); break; case BLACK_UNDO: if(turn==BLACK) blackundo(); break; case ESCAPE: finish=1;break; } }}main(){ init(); initpos(); initchesap(); drawbmp(0,0,"bmp\\board.wfb"); initdrawchess(); /初始化光标位置/ redcurpos.x=redoldpos.x=redtemppos.x=9; redcurpos.y=redoldpos.y=redtemppos.y=8; blackcurpos.x=blackoldpos.x=blacktemppos.x=0; blackcurpos.y=blackoldpos.y=blacktemppos.y=0;/开始/ start(); if(winner==RED) drawbmp(,,"bmp\\redwin.wfb"); else if(winner==BLACK) drawbmp(,,"bmp\\blackwin.wfb"); else drawbmp(,,"bmp\\exit.wfb"); getch(); end();}