一个ASP作的剪包锤游戏(转)

本文介绍了一个简单的石头剪刀布游戏脚本,详细展示了如何使用随机数生成计算机选择,并通过一系列条件判断来确定游戏胜负。游戏提供多种交互选项,包括开始游戏、再次游戏和结束游戏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

'*********************************************
' THIS IS A SIMPLE GAME OF ROCK SCISSORS PAPER
' FEEL FREE TO DO WHATEVER YOU LIKE WITH THIS
' SCRIPT! -IAN S. CARROLL
'*********************************************



'*********************************************
' THIS FUNCTION GENERATES A RANDOM NUMBER
'*********************************************
Function computerChooses()
Dim randomNum
Dim choice
randomize
randomNum = int(rnd*15)+1

If randomNum = 1 OR randomNum = 3 OR randomNum = 7 OR randomNum = 8 OR randomNum = 15 OR randomNum = 12 Then
choice = "R"
ElseIf randomNum = 2 OR randomNum = 6 OR randomNum = 11 OR randomNum = 13 Then
choice = "S"
Else
choice = "P"
End If

computerChooses = choice
End Function



'*********************************************
' THIS FUNCTION SIMPLY DETERMINES THE WINNER
' OF THE GAME
'*********************************************
Sub determineWinner(playerChoice, computerChoice)
Const Rock = "R"
Const Scissor = "S"
Const Paper = "P"
Dim tempPlayer, tempComputer

If playerChoice = Rock Then

If computerChoice = Scissor Then
%>


rock_beats_scissors.gif%22

Your ROCK crushed the computer's SCISSORS!"

End If

ElseIf playerChoice = Scissor Then

If computerChoice = Paper Then
%>


scissors_beats_paper.gif%22

Your SCISSORS cut up the computer's PAPER!

End If

ElseIf playerChoice = Paper Then

If computerChoice = Rock Then
%>


paper_beats_rock.gif%22

Your PAPER stumped the computer's ROCK!

End If

ElseIf playerChoice = computerChoice Then
%>


tie.gif%22

We seem to have a tie!

End If


If computerChoice = Rock Then

If playerChoice = Scissor Then
%>


rock_beats_scissors.gif%22

The computer's ROCK crushed your SCISSORS!

ElseIf playerChoice = computerChoice Then
%>


tie.gif%22

We seem to have a tie!

End If

ElseIf computerChoice = Scissor Then

If playerChoice = Paper Then
%>


scissors_beats_paper.gif%22

The computer's SCISSOR cut up your PAPER!

ElseIf playerChoice = computerChoice Then
%>


tie.gif%22

We seem to have a tie!

End If

ElseIf computerChoice = Paper Then

If playerChoice = Rock Then
%>


paper_beats_rock.gif%22

The computer's PAPER stumped your ROCK!


ElseIf playerChoice = computerChoice Then
%>


tie.gif%22

We seem to have a tie!

End If
ElseIf computerChoice = playerChoice Then
%>


tie.gif%22

We seem to have a tie!

End If


End Sub


'*********************************************
' THIS FUNCTION WILL CAUSE THE GAME TO
' EXECUTE UNLESS A DIFFERENT ACTION WAS CHOSEN
'*********************************************
Sub playGame()
%>

Welcome to the famous game: ROCK, SCISSORS, PAPER!

Good Luck!




Please choose your weapon:




ROCK
SCISSOR
PAPER



End Sub



'********************************************
' THIS FUNCTION WILL BE RUN IF THE GAME IS
' PLAYED
'********************************************
Sub playAgain()
%>
Would you like to play this game again?



YES
NO

End Sub



'*********************************************
' THIS FUNCTION WILL BE DISPLAYED WILL THE
' PERSON CHOOSES TO END THE GAME
'*********************************************
Sub endGame()
Response.Buffer = true

Response.Redirect "http://www.luckybbs.com"


End Sub


'*********************************************
' THE BASIC RUN-TIME SCRIPT
'*********************************************
Dim player, computer
Dim gameAction
gameAction = Request.QueryString("action")

Select Case gameAction
Case "winner"
player = Request.Form("playerSelect")
computer = computerChooses

determineWinner player, computer
Response.Write "

"
playAgain

Case "again"
playAgain

Case "gameover"
endGame

Case Else
playGame

End Select
%>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7178747/viewspace-161982/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7178747/viewspace-161982/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值