用vb編寫人與電腦玩剪刀布錘的遊戲

2022-01-13 10:40:33 字數 5154 閱讀 4289

1樓:萬慕山

srand(time(0));

這個只需要執行一次就行了,放在迴圈體前邊就行了

2樓:匿名使用者

'在窗體上新增3個按鈕,分別代表石頭剪子布,加一個label,新增**就好了

'1為石頭,2為剪刀,3為布

private sub command1_click()randomize

dim computer as long

computer = int(rnd() * 3) + 1if computer = 1 then

label1.caption = "deuce"

elseif computer = 2 thenlabel1.caption = "win"

elseif computer = 3 thenlabel1.caption = "lose"

end if

end sub

private sub command2_click()randomize

dim computer as long

computer = int(rnd() * 3) + 1if computer = 1 then

label1.caption = "lose"

elseif computer = 2 thenlabel1.caption = "deuce"

elseif computer = 3 thenlabel1.caption = "win"

end if

end sub

private sub command3_click()randomize

dim computer as long

computer = int(rnd() * 3) + 1if computer = 1 then

label1.caption = "win"

elseif computer = 2 thenlabel1.caption = "lose"

elseif computer = 3 thenlabel1.caption = "deuce"

end if

end sub

private sub form_load()command1.caption = "石頭"

command2.caption = "剪刀"

command3.caption = "布"

label1.caption = "猜拳"

end sub

3樓:匿名使用者

private sub form_load()label1.fontsize = 18

label1.fontbold = trueend sub

private sub text1_keypress(keyascii as integer)

dim jiqi as integer

label1.caption = ""

if keyascii = 13 thenif text1.text = "剪刀" or text1.text = "石頭" or text1.text = "布" then

randomize

jiqi = int(rnd * 3 + 1)label2.caption = (jiqi)if (jiqi) = 1 then

if text1.text = "剪刀" thenlabel1.caption = "deuce"

elseif text1.text = "布" thenlabel1.caption = "lose"

elseif text1.text = "石頭" thenlabel1.caption = "win"

end if

elseif (jiqi) = 2 thenif text1.text = "剪刀" thenlabel1.caption = "lose"

elseif text1.text = "布" thenlabel1.caption = "win"

elseif text1.text = "石頭" thenlabel1.caption = "deuce"

end if

elseif (jiqi) = 3 thenif text1.text = "剪刀" thenlabel1.caption = "win"

elseif text1.text = "布" thenlabel1.caption = "deuce"

elseif text1.text = "石頭" thenlabel1.caption = "lose"

end if

end if

end if

end if

end sub

用vb編一個與電腦玩石頭剪刀布的遊戲

4樓:

窗體上畫控制元件:單選框coption(0)、coption(1)、coption(2),按鈕command1,標籤label1。

加**:

dim selectnumber as integer

private sub command1_click()

dim computernumber as integer

randomize

computernumber = int(rnd * 3)

select case computernumber

case 0: label1.caption = "計算機出剪刀"

case 1: label1.caption = "計算機出石頭"

case 2: label1.caption = "計算機出布"

end select

if selectnumber = computernumber then

label1.caption = label1.caption & vbcrlf & "平局"

else

select case selectnumber

case 0

if computernumber = 1 then

label1.caption = label1.caption & vbcrlf & "計算機贏"

else

label1.caption = label1.caption & vbcrlf & "你贏"

end if

case 1

if computernumber = 2 then

label1.caption = label1.caption & vbcrlf & "計算機贏"

else

label1.caption = label1.caption & vbcrlf & "你贏"

end if

case 2

if computernumber = 0 then

label1.caption = label1.caption & vbcrlf & "計算機贏"

else

label1.caption = label1.caption & vbcrlf & "你贏"

end if

end select

end if

end sub

private sub form_load()

coption(0).caption = "剪刀"

coption(1).caption = "石頭"

coption(2).caption = "布"

command1.caption = "開始"

label1.caption = ""

end sub

private sub coption_click(index as integer)

selectnumber = index

end sub

幫忙用vb語言編一個與電腦玩剪刀石頭布遊戲。(控制檯程式)這是我的**。請高手們幫我看下。

5樓:受芃

請問你的**有什麼問題嗎?這個程式很簡單啊,就用1、2、3代表石頭、剪子、布就行了,兩邊相等時再重複一次,直到不相等為止。

6樓:匿名使用者

兩個vlabel 三e個fcommand 複製**,就可以4了t '-2石頭 '0剪刀u '3布 private sub command3_click() dim a, b as integer randomize a = -6 b = int(rnd * (-3) + 7) label0。caption = "石頭" select case a - b case -7: label8。

caption = "布": msgbox "電腦勝" case 0: label2。

caption = "石頭": msgbox "平" case -1: label3。

caption = "剪刀a": msgbox "玩家勝" end select end sub private sub command8_click() dim a, b as integer randomize a = 0 b = int(rnd * (-2) + 4) label5。caption = "剪刀l" select case a - b case 7:

label3。caption = "布": msgbox "玩家勝" case 0:

label7。caption = "剪刀n": msgbox "平" case -6:

label7。caption = "石頭": msgbox "電腦勝" end select end sub private sub command7_click() dim a, b as integer randomize a = 7 b = int(rnd * (-1) + 2) label5。

caption = "布" select case a - b case 3: label5。caption = "石頭":

msgbox "玩家勝" case 0: label6。caption = "布":

msgbox "平" case 2: label5。caption = "剪刀l":

msgbox "電腦勝" end select end sub private sub form_load() command1。caption = "石頭" command1。caption = "剪刀r" command1。

caption = "布" end sub

z猢たgp¨紜rjxtd』hq摔a十

用vb編寫程式for迴圈,讓使用者輸入字串,輸出這個字串中字母a和b出現

dim in str as string dim s1 as integer,s2 as integerin str inputbox 請輸入字串 for i 1 to len in str t mid in str,i,1 if t a or t b thenprint t if t a then...

編寫求1到100之間奇數的和用vb語言

private sub command1 click dim i,sum1,sum2 as integersum1 0 sum2 0 for i 1 to 100 if i mod 2 1 then sum1 sum1 i else sum2 sum2 i end if next i print 奇...

高手請教,怎樣用vb編寫簡單的計算器?謝謝

加上一個按鈕 按鈕單擊事件內 dim a,b a 100 b 100 a b a b a b a b 明白了嗎?靠自己想想啦 直接給你原始碼 你寫不寫沒必要了就 自己慢慢連 增加知識 這個還是給你推薦本書吧 visual basic 程式設計 孫志輝編著。裡面有一章就是講簡單計算器的設計,如果能看到...