Search⌘ K

Judgment Day Emulator

Explore how to apply Ruby operators, methods, loops, and conditionals by creating a Judgment Day emulator. Learn to simulate random events affecting humans and machines using boolean methods, random number generation, and control flow. This lesson helps you practice fundamental Ruby concepts by programming a survival scenario with event-driven logic.

Now, it’s time for us to practice and review everything we know about methods.

Judgment day

Machines have taken over the world. There is a struggle for survival. Who will survive: humanity or machines? It’s up to destiny to decide our future. Well, actually, it’s up to the random number generator. The program will show the stream of upcoming events happening in the world. It would be much more interesting if we could show these events with some graphics, but the observer’s imagination will have to suffice for now.

Note: This program can be written in a better way. However, we still only have a limited knowledge of how Ruby works, so our goal is to practice using it rather than deliver a piece of art.

Solution

First, let’s agree that there are only 10,000 ...