### Thread: Help with game, just starting

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2010
Posts
1
Rep Power
0

#### Help with game, just starting

My boss told me to pick up a ruby book and start figuring, so he gave me this assignment to write a small game:

He sent me an email with:

> race.rb
> construct an array of cars,
> accept entry of two cars,
> race the two cars,
> determine and display a winner
>
> example:
>
> #each car is [name, horsepower, weight] cars = [
> ['mustang', 300, 3480 ],
> ['camaro', 400, 3780 ],
> ['s2000', 237, 2864 ],
> ['350z', 287, 3288 ]
> ]
>
> run it giving two car names on the command line, example:
> ruby race.rb mustang camaro
>
> Use ARGV[0] as the name of the first car, and ARGV[1] as the name of
> the second car, as follows:
> name1 = ARGV[0] || 'mustang'
> name2 = ARGV[1] || 'camaro'
>
> Locate both cars in the array, compare their performance numbers, and
> pick a winner.
>
>

So how on earth do i do this???? Please help!!
2. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Jan 2004
Location
Constant Limbo
Posts
989
Rep Power
366
The only thing not spelled out in that description is the equation of speed as it relates to weight and horsepower. What exactly have you tried?

I should warn you that as an employee you are expected to think - that is what a portion of your paycheck is intended to represent. If I had given you this problem to work out I would have a bank of questions intended to determine if you understood what you just did. I would want to know what roadblocks you ran into (however trivial) and how you overcame them. You farming an answer sets you up for a hard failure in that respect. Maybe your employer wont care how you got your answer - I wouldn't bank on that, however.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2010
Posts
7
Rep Power
0
He's already given you most of the code.

ruby Code:
```
# race.rb

#each car is [name, horsepower, weight]
cars = [
['mustang', 300, 3480 ],
['camaro', 400, 3780 ],
['s2000', 237, 2864 ],
['350z', 287, 3288 ]
]

name1 = ARGV[0] || 'mustang'
name2 = ARGV[1] || 'camaro'```

That's a pretty good start. The next step is to match the correct car with the name

ruby Code:
```car1 = *your code here*
...```

I'd recommend learning about accessing Array elements with [] and then look into the detect method on the Array class.

Once that's done, figure out how to compare the speed.

I was able to create a working version with just a few lines of code beyond what he gave you.