Hello everyone;
I am looking at making a Casino Slot maching type game. Has anyone attempted this? If so, would you be willing to share your idea's or workable code?
Any help in this would be greatly appreciated.
Hope to hear from you soon.
Bizi
BlueCat
10-11-2002, 08:03 PM
Can you give us a bit more detail about the game? I'm sure *someone* would be willing to share code :twisted: Sounds interesting, I'd like to see a 3D version :wink:
Alimonster
12-11-2002, 03:23 PM
Are you still interested in this, bizi?
The answer here depends on how complicated you want the machine to be. I'd be tempted to make a class for the reels themselves - with three objects of 'em in the main game itself.
Some things that the reels could do/store:
values: array for the values of each part in the wheel
spin: generates a random number for how long to spin, moves the reel
nudge: moves the reel forward one item
draw: display the reel.
count: returns amount of items in array
speed: (optional) - how quickly it updates
locked: whether this reel can update (handy if the user locks some reels as a bonus)
current_item: what item it's sitting at just now
First of all, do you know anything about random numbers? If you do then it's not a big deal to do the above. If not, here's a little info.
First of all, you have to call Randomize once when your program starts. This sets up the random number generator - but note that you don't have to call it several times. Once is enough.
Whenever you need a random number, you can use the Random function. IIRC (and I've not checked, so this may be incorrect), you have to pass in a value for the random number range. The number returned will be a value from 0..(number - 1). So, if you wanted a random number from 0 to 15, you'd use "MyNum := Random(16)" (note that 0..15 is 16 elements - don't forget about the zero there!). If you want a random number in a range, you can add a value to the result to alter the range - e.g. "MyNum := Random(6) + 1" will give you a result between 1 and 6 inclusive (since the call to random(6) gives 0..5, and you're adding one to it).
You can initialise the reels when they're created to random values (or deterministic ones if you want). This only needs to be done once, so it's an ideal job for a constructor.
Of course, drawing the reels is a whole other kettle of fish ;). You might want to skip the animation until you feel more confident.
When the user spins the reels, you want to do for loops over for a given number of times. Something like this:
procedure TReel.Spin;
var
i: Integer;
begin
for i := 0 to SpinCount - 1 do
begin
// spin based on speed (todo: animation)
Current_Item := Current_Item + Speed;
// if we've wrapped around then we have to
// keep the value within the correct range
while Current_Item >= Length(Reels)) do
dec(Current_Item, Length(Reels);
DisplayItem; // todo: show the current item somehow
end;
end;
You can also use mod to control the range if you're feeling brave, "Current_Item := (CurrentItem + Speed) mod Length(Reels));" ;) but I don't think you need to care about that yet.
The above should get you started. You might also want to keep track of how much money is in the machine (i.e., number of spins left) and how much money the player has. You would store each of the reels in an array, looping over each one. Remember to let the player win money! After spinning each of the reels, you'd check whether the values match a given pattern (three lemons, or whatever).
Of course, this is assuming you want a one-armed bandit machine, which I think you probably do.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.