PDA

View Full Version : [SOLVED] Creating simple games in Excel



Teknologist
07-28-2004, 12:09 PM
I am hoping someone could please give me some direction on getting started using rand, randbetween countif, vlookup and anything else to create a game. I am however familiar with the functions, well not too familiar http://www.mrexcel.com/board2/images/smiles/icon_redface.gif I just need to know how to get started, I have no clue for flipping coins, dice, or card games, I am at a total loss.

I just need to be pointed in the right direction to at least get started. Thanks in advance for any assistance anyone can provide.

http://www.mrexcel.com/board2/images/smiles/icon_bow.gif

Zack Barresse
07-28-2004, 01:30 PM
Hi, :006:

Did this link (http://www.mrexcel.com/board2/viewtopic.php?t=99011) not help any?

Do you have a sample file? Here you can upload a file to the board. It must be zipped, while in the reply page (hit Alt + X from here) scroll down to Manage Attachments and Browse.. and Upload file. An example may help anybody reading this.

Teknologist
07-28-2004, 02:30 PM
Hi,

I think that is my issue, I have no clue how to get started. I wished I had an example to post but I have nothing....I guess it's off to the book store to see what is available. This is definitely more programming than I would have expected in an intro Excel class.

Thanks again!


Hi, :006:

Did this link (http://www.mrexcel.com/board2/viewtopic.php?t=99011) not help any?

Do you have a sample file? Here you can upload a file to the board. It must be zipped, while in the reply page (hit Alt + X from here) scroll down to Manage Attachments and Browse.. and Upload file. An example may help anybody reading this.

Jacob Hilderbrand
07-28-2004, 04:30 PM
Dim Highest As Long
Dim Lowest As Long
Randomize
Choice = Int((Highest + 1 - Lowest) * Rnd + Lowest)


Just assign the values to "Highest" and "Lowest" as needed. 1 to 2 for coin, 1 to 6 for dice (six sided) etc.

Teknologist
07-29-2004, 06:14 PM
Excellent, this should get me started in the right direction. Thanks alot. I will keep you up on my progress.

Teko




Dim Highest As Long
Dim Lowest As Long
Randomize
Choice = Int((Highest + 1 - Lowest) * Rnd + Lowest)


Just assign the values to "Highest" and "Lowest" as needed. 1 to 2 for coin, 1 to 6 for dice (six sided) etc.

Jacob Hilderbrand
07-29-2004, 07:38 PM
You're Welcome

Take Care

Anne Troy
07-31-2004, 12:15 AM
Maybe we have a candidate here, DRJ?

Jacob Hilderbrand
07-31-2004, 12:59 AM
Definitely :)

parry
07-31-2004, 07:17 PM
Hi heres an example of single player Yahtzee I have built - run the PlayYahtzee macro. Its still work in progress but it gives you an idea. :)

Stromma from MrExcel board has recently built a nice multi-player Yahtzee one with Swedish rules which is well done with sounds etc and I believe he's looking for testers. Send him a PM on MrExcel and Im sure he wouldnt mind giving you a copy.

Anne Troy
07-31-2004, 07:59 PM
Stromma is also a member here. :)

http://www.vbaexpress.com/forum/member.php?u=81

Teknologist
08-05-2004, 12:07 PM
Ok, I was clowing around with a simple game and ran into a problem. Instead of either the "Heads or Tails" buttons actually perform calculations could I not instead have another button that performs the same as F9?

I know the game is ugly but hey, this is my first go at it. Any insight assistance, whatever would be nice.

Thanks all!

mdmackillop
08-05-2004, 03:30 PM
Hi Teknologist,
Here's somthing, not exacatly a game, but it may be of interest to try variations. The "ant" steps in a cell, if red, he turns it black and goes left, if Black, he turns it Red and goes left. Be patient until he "settles down".
MD

mdmackillop
08-05-2004, 04:28 PM
Hi,
I've had a play around and added some code to introduce you to some other possibilities, changing colours and fonts, keepng score, calling other routines etc. Sorry I've no time to Comment it properly, but if you step through, I'm sure you can follow what's happening.
MD


Sub Tails()
Range("B1").Formula = "T" 'Set the call
Flip ' Do the flip
End Sub

Sub Heads()
Range("B1").Formula = "H"
Flip
End Sub

Sub Flip()
Dim Success As Boolean
Dim MyFlip As Double

Randomize
MyFlip = Rnd 'Random number between 0 & 1
If MyFlip > 0.5 Then
Range("B2").Formula = "Tails"
Else
Range("B2").Formula = "Heads"
End If
'Compare first letter of Result weith Guess
If Left(Range("B2"), 1) = Range("B1") Then 'Win
With Range("B3:C3")
.Interior.ColorIndex = 6
.Font.Name = "Arial"
.Font.FontStyle = "Bold Italic"
.Font.Size = 14
End With
With Range("B3")
.Formula = "You win !!!"
End With

Success = True 'for keeping score
Else 'Lose
With Range("B3:C3")
.Interior.ColorIndex = 8
.Font.Name = "Arial"
.Font.FontStyle = "Bold"
.Font.Size = 12
End With
With Range("B3")
.Formula = "Sorry, you lose."
End With
Success = False
End If
' Call another routine to keep score
CountScore Success
End Sub

Sub CountScore(Success)
'Set up the cell format
Range("B8").NumberFormat = "0 ""wins"""
Range("B9").NumberFormat = "0 "" losses"""
'Make sure there's a numeric value
If Range("B8") = "" Then Range("B8").Formula = 0
If Range("B9") = "" Then Range("B9").Formula = 0
'Change the score by the result "passed" by the Success parameter
If Success = True Then
Range("B8").Formula = Range("B8") + 1
Else
Range("B9").Formula = Range("B9") + 1
End If
End Sub

Teknologist
08-05-2004, 04:36 PM
Whew, yup, definitely gottah have patience. I will attempt playing with it after class tonight, if not too late...

Thanks for sharing.

Did you get the chance to look at mine?


Hi,
I've had a play around and added some code to introduce you to some other possibilities, changing colours and fonts, keepng score, calling other routines etc. Sorry I've no time to Comment it properly, but if you step through, I'm sure you can follow what's happening.
MD


Sub Tails()
Range("B1").Formula = "T" 'Set the call
Flip ' Do the flip
End Sub

Sub Heads()
Range("B1").Formula = "H"
Flip
End Sub

Sub Flip()
Dim Success As Boolean
Dim MyFlip As Double

Randomize
MyFlip = Rnd 'Random number between 0 & 1
If MyFlip > 0.5 Then
Range("B2").Formula = "Tails"
Else
Range("B2").Formula = "Heads"
End If
'Compare first letter of Result weith Guess
If Left(Range("B2"), 1) = Range("B1") Then 'Win
With Range("B3:C3")
.Interior.ColorIndex = 6
.Font.Name = "Arial"
.Font.FontStyle = "Bold Italic"
.Font.Size = 14
End With
With Range("B3")
.Formula = "You win !!!"
End With

Success = True 'for keeping score
Else 'Lose
With Range("B3:C3")
.Interior.ColorIndex = 8
.Font.Name = "Arial"
.Font.FontStyle = "Bold"
.Font.Size = 12
End With
With Range("B3")
.Formula = "Sorry, you lose."
End With
Success = False
End If
' Call another routine to keep score
CountScore Success
End Sub

Sub CountScore(Success)
'Set up the cell format
Range("B8").NumberFormat = "0 ""wins"""
Range("B9").NumberFormat = "0 "" losses"""
'Make sure there's a numeric value
If Range("B8") = "" Then Range("B8").Formula = 0
If Range("B9") = "" Then Range("B9").Formula = 0
'Change the score by the result "passed" by the Success parameter
If Success = True Then
Range("B8").Formula = Range("B8") + 1
Else
Range("B9").Formula = Range("B9") + 1
End If
End Sub

roos01
08-08-2004, 12:37 AM
here another link with some simple examples:
http://www.erlandsendata.no/english/index.php?d=endownloadgames

Jacob Hilderbrand
08-08-2004, 01:16 AM
Some of those are pretty good. I really like the Calculate Your Bonus joke User Form. :)

mdmackillop
08-12-2004, 07:42 AM
Hi.
You could try making up a two player verion of Reversi for an excel spreadsheet;
challenging, but not too "heavy" on ther coding front
MD

Ken Wright
08-14-2004, 02:29 AM
Tekno, if you are looking for a very very simple example for your intro class, then the attached modification of your file may help. Uses VBA to give a Heads/Tails result, and then Conditional formatting and a formula to display whether they have won or not.

Regards
Ken.............