This blog no longer exists.
You will be redirected to something cool.

Tuesday, November 30, 2010

First to 100 Game Program

This one was monumentally more comfortable to write than the lottery program although it uses similar elements. I have a few questions that I will ask about things I can do to make the program smaller, but I am still proud of this program despite its size.

The url:

The Lottery Program

So you may have noticed I haven't posted for a while. Why? The lottery program. Yeah. It was a dreaded horrible beast. I saw there for weeks, really, staring at the lines of code I'd spewed forth, stressing, rewriting, throwing things (okay, not really.) And then I was told to take a break. I did... a long one. It would be just fine if I could just write every program in the book just not this one. It was impossible and a stupid task.

But alas, I could not excuse myself from the project so I sat down to it. Ever have one of those moments when you feel like one synapsis fires, and then thus another one, and then it's just a cascade of just everything working... it puts you on quite a roll. That's what happened. I HATED this program for the longest time, but as I was finishing the program, I just felt so on top of everything. It felt really good, empowering or something.
I created a new GitHub... actually I just changed my sn over there.

This is because I'm going now... this is what I've always wanted to do growing up and no matter how many walls I face how many tall, towering lottery programs I face, I will cower like a big baby, cry about it, and then face my problem head on. Below is the link to my completed lottery program. Yeah, there are better ways to write it, but as I learn those ways, I will come back and improve upon the program. I think showing these changes would be better viewed on github than here, but I will continue to document my journey here.

The program:

Tuesday, November 2, 2010

Dice Game: Ifs & Loops

I had a little fun with some 'ifs' and 'while loops' with this program. When I first started the program I became somewhat frustrated. I stopped and slept on it. When I came back to the code, it was sooo easy to piece together. The break was a really good idea. The code:
count = 0
count2 = 3
guess = 0

while guess <2 || guess >12
  puts( 'Pick a number 2-12: ')
  guess = gets.chomp.to_i

dieTotal = 0

while dieTotal != guess && count != 3
  count = count + 1
  count2 = count2 - 1
  die1 = rand(6)
  die1 = die1 + 1
  die2 = rand(6)
  die2 = die2 + 1
  dieTotal = die1 + die2
  input = ''
  puts( 'Type roll to roll the dice: ')
  input = gets.chomp

  while input != 'roll'
    puts( 'Type roll to roll the dice: ')
    input = gets.chomp
    puts( 'I don\'t understand. ')
  puts( "Your guess is #{guess}.")
  puts( "You rolled #{die1} and #{die2}. For a total of #{dieTotal}.")

  if dieTotal != guess && count2 > 1
  puts( "You have #{count2} rolls left.") 
  elsif dieTotal != guess && count2 == 1
  puts( "You have #{count2} roll left.")
  elsif dieTotal != guess && count2 == 0
  puts( "You have no rolls left.")
  puts( "Sorry, you lose.")
  puts( "Congrats! You win!")