O'Reilly logo

Wicked Cool Ruby Scripts by Steve Pugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pig

Pig

pig.rb

Pig is one of the lesser-known games of our time, but nonetheless, a fun one to play. All it requires is a six-sided die. The goal of the game is to reach 100 points by adding the totals of your throws. You can throw the die as many times as you want during your turn, but if you roll a 1, you lose all of the points gained during that turn and then your opponent gets a chance to rack up points. Pig is a simple game, but it is deceptively difficult to win.

The Code

 puts "\n\n\n\n\n\n\nWelcome to the game PIG!" puts "\n----INSTRUCTIONS----" puts "The object of the game is to reach 100 points." puts "*** Be careful, if you roll a 1 you lose ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required