I’ll create a Ruby slot machine game with bonus features! Here’s a complete, playable slot machine game with multiple bonus features:

“`ruby
# Ruby Slot Machine with Bonus Features
class SlotMachine
SYMBOLS = {
‘馃崚’ => 2,
‘馃崑’ => 3,
‘馃崐’ => 4,
‘馃崏’ => 5,
‘7锔忊儯’ => 10,
‘馃拵’ => 20,
‘猸? => 50 # Bonus symbol
}

BONUS_SYMBOLS = [‘馃幇’, ‘馃挵’, ‘馃巵’, ‘馃弳’]

def initialize(balance = 100)
@balance = balance
@bet = 1
@bonus_round = false
@bonus_multiplier = 1
@free_spins = 0
@jackpot = 1000
@streak = 0
end

def play
puts “馃幇 Welcome to Ruby Slots! 馃幇”
puts “Balance: $#{@balance}”
puts “Jackpot: $#{@jackpot}”
puts “=” * 40

while @balance > 0
show_menu
choice = gets.chomp.downcase

case choice
when ‘s’
spin
when ‘b’
change_bet
when ‘r’
show_rules
when ‘q’
puts “Thanks for playing! Final balance: $#{@balance}”
break
else
puts “Invalid choice!”
end

if @balance <= 0 puts "馃捀 Game over! You're out of money!" break end end end private def show_menu puts "\nOptions:" puts "[S]pin (Bet: $#{@bet})" puts "[B]et amount" puts "[R]ules & Payouts" puts "[Q]uit" print "Your choice: " end def change_bet print "Enter new bet amount (1-10): " new_bet = gets.chomp.to_i if new_bet.between?(1, 10) @bet = new_bet puts "Bet changed to $#{@bet}" else puts "Invalid bet amount!" end end def show_rules puts "\n" + "=" * 40 puts "RULES & PAYOUTS:" puts "-" * 40 SYMBOLS.each do |symbol, multiplier| puts "#{symbol} x3 = #{multiplier * @bet}x bet" end puts "猸?x3 = BONUS ROUND!" puts "猸?x2 = 5x bet" puts "Any 2 matching = 2x bet" puts "-" * 40 puts "BONUS FEATURES:" puts "鈥?Win streak: Consecutive wins increase multiplier" puts "鈥?Free spins: Can be won in bonus round" puts "鈥?Progressive jackpot: Grows with each spin!" puts "=" * 40 end def spin if @free_spins > 0
@free_spins -= 1
puts “\n馃巵 FREE SPIN! (#{@free_spins} remaining) 馃巵”
@bet = 1 # Free spins are always minimum bet
else
@balance -= @bet
@jackpot += (@bet * 0.1) # 10% of bet goes to jackpot
end

reels = generate_reels
display_reels(reels)

winnings = calculate_winnings(reels)

if winnings > 0
handle_win(winnings)
else
handle_loss
end

show_status
end

def generate_reels
symbols = SYMBOLS.keys + BONUS_SYMBOLS
Array.new(3) { symbols.sample }
end

def display_reels(reels)
puts “\n” + “=” * 40
print “SPINNING: ”
3.times do |i|
sleep(0.3)
print “馃幇 ”
end
puts “\n” + “=” * 40
puts ” #{reels[0]} | #{reels[1]} | #{reels[2]}”
puts “=” * 40
end

def calculate_winnings(reels)
return 0 if @bonus_round

# Check for bonus symbol (star)
star_count = reels.count(‘猸?)

if star_count == 3
start_bonus_round
return 0
elsif star_count == 2
return @bet * 5 * @bonus_multiplier
end

# Check for regular wins
SYMBOLS.each do |symbol, multiplier|
if reels.count(symbol) == 3
return @bet * multiplier * @bonus_multiplier
end
end

# Check for any two matching
reels.each do |symbol|
if reels.count(symbol) == 2 && SYMBOLS.key?(symbol)
return @bet * 2 * @bonus_multiplier
end
end

0
end

def start_bonus_round
puts “\n” + “馃帀 BONUS ROUND! 馃帀”
puts “Pick one of the boxes below:”

boxes = [‘A’, ‘B’, ‘C’, ‘D’]
prizes = {
‘A’ => { type: :cash, value: @bet * 20 },
‘B’ => { type: :free_spins, value: 3 },
‘C’ => { type: :multiplier, value: 3 },
‘D’ => { type: :jackpot_chance, value: @jackpot }
}

boxes.shuffle!

boxes.each_with_index do |box, index|
puts “[#{box}] Box #{index + 1}”
end

print “Choose a box (A-D): ”
choice = gets.chomp.upcase

if boxes.include?(choice)
prize = prizes[choice]
award_bonus_prize(prize)
else
puts “Invalid choice! You get a consolation prize: $#{@bet * 5}”
@balance += @bet * 5
end
end

def award_bonus_prize(prize)
case prize[:type]
when :cash
amount = prize[:value]
@balance += amount
puts “馃挵 CASH PRIZE: $#{amount}!”

when :free_spins
@free_spins += prize[:value]
puts “馃巵 #{prize[:value]} FREE SPINS!”

when :multiplier
@bonus_multiplier = prize[:value]
puts “馃殌 #{prize[:value]}X MULTIPLIER FOR NEXT 5 SPINS!”

when :jackpot_chance
if rand(1..10) == 1 # 10% chance
puts “馃帄 JACKPOT! 馃帄”
puts “YOU WON $#{@jackpot}!”
@balance += @jackpot
@jackpot = 1000 # Reset jackpot
else
consolation = @bet * 10
puts “Almost! Consolation prize: $#{consolation}”
@balance += consolation
end
end
end

def handle_win(winnings)
@balance += winnings
@streak += 1

if @streak >= 3
@bonus_multiplier = [@bonus_multiplier, 2].max

code bonus ruby slots

puts “馃敟 WIN STREAK! #{@streak} in a row! (Multiplier: #{@bonus_multiplier}x)”
end

puts “馃帀 YOU WON $#{winnings}!”

# Check for jackpot trigger (rare)
if rand(1..1000) == 777 && winnings >= @bet * 10
puts “馃帄 MEGA JACKPOT! 馃帄”
mega_win = @jackpot * 2

code bonus ruby slots

@balance += mega_win
puts “BONUS: $#{mega_win} added to your balance!”
@jackpot = 1000
end
end

def handle_loss
@streak = 0
@bonus_multiplier = 1
puts “馃挃 No win this time…”
end

def show_status
puts “\n” + “-” * 40
puts “Balance: $#{@balance}”
puts “Jackpot: $#{@jackpot}”
puts “Win Streak: #{@streak}” if @streak > 0
puts “Multiplier: #{@bonus_multiplier}x” if @bonus_multiplier > 1
puts “Free Spins: #{@free_spins}” if @free_spins > 0
puts “-” * 40
end
end

# ASCII Art Title
def display_title
puts <<~TITLE 鈺斺晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺? 鈺? 馃幇 RUBY SLOT MACHINE 馃幇 鈺? 鈺? WITH BONUS FEATURES! 鈺? 鈺氣晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺? TITLE end # Start the game if __FILE__ == $0 display_title puts "\nPress Enter to start..." gets game = SlotMachine.new(100) game.play end ``` ## Features Included: 1. **Base Game**: - 7 different symbols with varying payouts - Bet adjustment (1-10) - Balance tracking 2. **Bonus Features**: - **Bonus Round**: Triggered by 3 star symbols - **Pick-a-Prize**: Choose from 4 mystery boxes in bonus round - **Free Spins**: Can be won in bonus round - **Win Streak Multiplier**: Consecutive wins increase payout multiplier - **Progressive Jackpot**: Grows with each spin - **Mega Jackpot**: Rare chance to win double the progressive jackpot 3. **Special Symbols**: - `猸恅 - Bonus symbol (triggers features) - `馃拵` - Highest paying regular symbol - `7锔忊儯` - Classic slot symbol 4. **Payout Types**: - 3 matching symbols: 2x to 50x bet - 2 matching symbols: 2x bet - 2 bonus symbols: 5x bet - 3 bonus symbols: Bonus round ## How to Play: 1. Save the code as `slot_machine.rb` 2. Run with: `ruby slot_machine.rb` 3. Use the menu options: - `S` to spin - `B` to change bet amount - `R` to see rules and payouts - `Q` to quit The game includes visual feedback with emojis, sound-effect-like delays, and clear status updates. The bonus features add excitement and variety beyond a basic slot machine! Would you like me to add any specific features like a high score system, different themes, or more complex bonus games?

Share this post

Related posts