Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with a type of 'Select Case' statement 1

Status
Not open for further replies.

Aycee

Programmer
May 16, 2002
2
0
0
AU
I was wondering if anyone at all could help me with some coding.

My program is wanting to perform a function which is like the game 'SCISSORS, PAPER, ROCK'. I'm having problem making it so that if rock = rock a msgbox pops up and says it's a draw or if rock = paper paper wins and so forth. If anyone could help me out it could be greatly appreciated.

Thanks
 
Select Case play1
Case "rock"
Select Case play2
Case "rock"
"tie"
Case "paper"
"lose"
Case Else
"win"
End select
Case "paper"
Select Case Play2
Case "rock"
"win"
Case "papper"
'tie"
etc Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Could you try this:

Public Function GetResult(Play1 As String, Play2 As String) As String
Dim P1 As Integer, P2 As Integer, ResultA As Integer
GetResult = "Not a game."
If Play1 <> &quot;rock&quot; And Play1 <> &quot;paper&quot; And Play1 <> &quot;scissors&quot; Then
MsgBox &quot;Please check your spelling for &quot; & Play1
Exit Function
End If
If Play2 <> &quot;rock&quot; And Play2 <> &quot;paper&quot; And Play2 <> &quot;scissors&quot; Then
MsgBox &quot;Please check your spelling for &quot; & Play2
Exit Function
End If
Select Case Play1
Case &quot;rock&quot;
P1 = 1
Case &quot;paper&quot;
P1 = 2
Case &quot;scissors&quot;
P1 = 3
End Select
Select Case Play2
Case &quot;rock&quot;
P2 = 1
Case &quot;paper&quot;
P2 = 2
Case &quot;scissors&quot;
P2 = 3
End Select
ResultA = P1 - P2
If Abs(ResultA) > 1 Then
ResultA = ResultA * (-1)
End If
Select Case ResultA
Case Is = 0
GetResult = &quot; tie!&quot;
Case Is > 0
GetResult = Play1 & &quot; win!&quot;
Case Is < 0
GetResult = Play2 & &quot; win!&quot;
End Select
End Function
 
Assign the value of
1 to paper,
2 to scissors,
3 to rock.

Then get the absolute value of the difference between the two.

Diff = abs(Value1 - Value2)
Select Case Diff
Case 0
Its a Tie
Case 1
Won by Max(Value1, Value2)
Case 2
Won by Min(Value1, Value2)
End Select
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
I'm in a silly mood today, so here's a silly solution (I don't advise you actually use it...):
[tt]
Option Explicit
Enum Thing
rock = 0
paper = 1
scissors = 2
End Enum

Private Sub Command1_Click()
Dim Objects(3) As String
Objects(0) = &quot;Rock&quot;
Objects(1) = &quot;Paper&quot;
Objects(2) = &quot;Scissors&quot;
Objects(3) = &quot;Tie&quot;

MsgBox Objects(Winner(scissors, scissors))
End Sub

Public Function Winner(Player1 As Thing, Player2 As Thing) As Long
If Player1 = Player2 Then
Winner = 3
Else
Winner = (3 - (2 ^ Player1 - 2 ^ Player2)) Mod 3
End If
End Function
 
CajunCentirian's answer seems the most direct (and
easiest).
 

Try this one:

Enum eBids
ePaper = -2
eScissors = 0
eRock = 1
End Enum
Enum eWinner
eTie = 0
ePlayer1 = 1
ePlayer2 = 2
End Enum

Public Function Winner(PlayerOneBid As eBids, PlayerTwoBid As eBids) As eWinner

If PlayerOneBid <> eScissors And PlayerTwoBid <> eScissors Then
PlayerOneBid = Abs(PlayerOneBid)
PlayerTwoBid = Abs(PlayerTwoBid)
End If

If PlayerOneBid > PlayerTwoBid Then
Winner = ePlayer1

ElseIf PlayerOneBid < PlayerTwoBid Then
Winner = ePlayer2

Else
Winner = eTie
End If

End Function
 
I used:

Dim Diff as Long

Select Case Diff
Case 0
MsgBox &quot;It's a tie, play again&quot;
Case 1
MsgBox &quot;You win&quot;
Case 2
MsgBox &quot;You lose&quot;
End Select

Cajun, I don't get this part of your coding. It works, except everytime It comes up with &quot;It's a tie, play again&quot;. How can u make it so that when for example it's

imgPlayer = rock and imgComp = paper

the computer wins?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top