I'im thinking of building a text-based browser game. A racing game.like F1 or rally. users can set-up a car. thinks like tyres, fuel, driver,brakes. every attribute gets a value.

the part where i am stuck is the race.

i think a race exist out of corners, straight parts, hills,...

i have no idea how i can come to a solution who wins the race and what the lap times would be.

idea i have: a race has for all attributes of a car the best value. the car with the best values of that race, normally wins.

anyone with some idea's?

  • 3
    \$\begingroup\$ race_position = random(1,10); \$\endgroup\$ – thedaian Oct 4 '11 at 16:53
  • \$\begingroup\$ On a procedural note: You might want to spend some more time in the pre-development phase when you create games. How the determine the winner of a race given the cars' setup, the drivers' stats, etc., is a core mechanic of your game, and by the time you write actual code, you should have a pretty good idea of how these things are supposed to work -- even if you're only implementing a prototype. That way, you will not have to re-code entire modules of your code. Chances are that your game's design will also improve, since you don't just make up mechanics as you go. \$\endgroup\$ – BerndBrot Aug 21 '12 at 20:17

When you watch a race, it unfolds sequentially, until by the end there is a history of that race that you could tell someone as a story. Some research like watching races with your buddies might show off what the most exciting parts are, or how the story tends to divide itself up.

In the "race" part of the game, you could randomise a story like this, having the story unfold as the player passively watches, periodically spitting out sentences describing the major events in the race (), with a dramatic pause between each (picture moving ellipsis .....) and use those events as the build up to who wins or who doesn't. You'd need to use a stack to track the positions of the various drivers as you make each statement.

So for example

  • "They're at the line up. Mansell has pole position...."
  • "And they're away! Senna's moving quickly, he outskirts Prost..."
  • "Berger..."
  • "and Patrese!..."
  • "Oh! Patrese swerves out of the way and Häkkinen is into the boundary! What a start we're off to!..."

You could break this up into early race, mid race, and end race, keeping each section brief (maybe 10-15 lines?) so that things don't get too boring. This way, you are rewarding the player with a suspenseful race after all the effort they've put in setting up their car and driver. Also cool to see the name of your driver mixing it up with the other drivers when the commentator focuses on him/her. You could even have simple sound effects for many of the events as they happen, like tyres screeching, revving hard, or gearing down... just to add some life to the text output.

All these events are templates of course, which you will probably create and store in a long text file that you load at runtime, and you can then mix and match them in different ways to create the race experience as commentated. Some events rely on others, such as where one of the drivers crashes due to another one's reckless action.

Of course, kitting out the cars in the first place would be part of who wins and who loses on which tracks, meaning it has an effect on what story events are generated as the race proceeds. Crappy tyres? Expect a blowout on a hard corner. Ferrari engine? Expect superb acceleration. Cars with good traction and suspension win on curvy tracks, cars with best top speed win on long-straight tracks. Or you could do it by track section if you wanted more detail, i.e. straights, long bends, and esses.

PS. You could even do a sci-fi or fantasy themed race. Perhaps more fun? Just my two cents.

  • 1
    \$\begingroup\$ I like this, also adding some risk vs reward input might work as well. "type t to attempt to pass" and you would compare your car to the car you are attempting to pass. \$\endgroup\$ – Johnny Quest Oct 4 '11 at 18:20
  • 2
    \$\begingroup\$ I like the ideas, however, and this might just be me knit-picking, but a stack probably isn't the best data structure. Stacks typically only support a few operations (pop, push, peek) a linked list would be a better option so you could move the cars positions around freely. \$\endgroup\$ – Shaded Oct 4 '11 at 19:23
  • \$\begingroup\$ You're right of course, however it's been so long since I used linked lists that I tend to forget about them; in the languages I use these days, it's common to just use some sort of array or stack structure for almost everything. I really don't think it's going to impact performance much in a game like this ;) \$\endgroup\$ – Engineer Oct 4 '11 at 19:50
  • \$\begingroup\$ Remember to exempt the player's car from 'random' disaster events like blowouts, brake failures, crashes, and the like. These are fine, even exciting, for the other racers to experience, but would just ruin the sense of control for the player. *Unless, of course, the player is given the chance to make a recovery somehow, such as a minigame. \$\endgroup\$ – DampeS8N Oct 5 '11 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.