DEV Community

Cover image for LUCID: a text-based game about lucid dreams

Posted on • Updated on

LUCID: a text-based game about lucid dreams

Lucid dreaming has been a passion of mine for many years, now you might be wondering... "Lucid dreams? What's that?". According to Wikipedia: "A lucid dream is a type of dream in which the dreamer becomes aware that they are dreaming. During a lucid dream, the dreamer may gain some amount of control over the dream characters, narrative, or environment; however, this is not actually necessary for a dream to be described as lucid". This means that you can do whatever you want with no limits, and it'll feel totally real. However, like all skills, it takes a lot of patience and practice before you can get to that level of conscious dreaming.

For my final project in the Computer Science path on Codecademy, I decided to code a game about something I'm passionate about since it's my first ever project off-platform. What better way to practice a new skill than to integrate something you already love into it? To make things more exciting, the dreams you'll encounter in the game are inspired by the ones from my personal dream journal, my friend's dream, and a song I listened to on loop while programming called "Jackie Onassis" by ELIO (ft. Nolie).


How does the game work?

On a typical night, a person goes through 4 sleep cycles. For each sleep cycle, both the players can either have a lucid dream with a possibility of slipping into another one, a dream which makes you lose your awareness, a mutual dream in which both players are sharing and experiencing the same dream, or a normal dream.

The maximum number of lucidity points (LP) a player can have is 100, it represents the probability that a player will not have a normal dream. LP can be collected by having lucid dreams, mutual dreams, communicating in them, or performing a technique. 20 LP will be awarded at the end of each cycle by default, the reason behind this is that the rapid eye movement (REM) stage, the dream-stage of sleep, lengthens for every subsequent sleep cycle.

Types of Dreams

  • If a player experiences a lucid dream, they will be given the option to perform a technique which will help them tune their focus back to the dream, gaining more LP, although success isn't guaranteed. Afterwards, the player will be given another chance to dream.

  • All mutual dreams are lucid dreams, and both players will be rewarded with LP. They will have the opportunity to communicate with each other depending on who talks first in the dream, if taken, both players will gain 30 LP each.

  • Dreams that make a player lose their awareness will knock down their score.

  • Normal dreams neither award nor revoke a player's LP.

Bonus Features

  • If you enter "qis" as your dreamer name, you'll receive a greeting and start the game with 30 LP, no questions asked!

  • If your lucidity score plunges below 0, you'll experience sleep paralysis and wake up due to the pure terror your sleep paralysis demon has invoked on you. This will strip the other player's chances of having a mutual dream for the rest of the game. Despite that, the chances of this happening are mathematically proven to be very low! So there shouldn't be any reason to worry... plus, what's the worst a sleep paralysis demon that lives in your computer's terminal can do anyway?

About the Code

The program is written in Python 3. Its classes and respective instance variables are:

class Dream:
  def __init__(self, effect, descrip):
    self.effect = effect
    self.descrip = descrip
class Technique:
  def __init__(self, name, effect, rate): = name
    self.effect = effect
    self.rate = rate
class Player:
  def __init__(self, name): = name
    self.minutes = td(hours = 0, minutes = 0)
    self.score = 0
    self.counter = 0
    self.lucid = False
    self.experience = False
    self.log = False
    self.awake = False
Enter fullscreen mode Exit fullscreen mode

All the dreams are stored in a list and randomly selected by the random module, it is then removed from the list to avoid dream repetition. One of the issues I ran into was awarding both players in a mutual dream, the solution I came up with was to define a separate function for them in the Player class and store the dreams along with their respective scores within it. This gave me the option to allow for communication between the players which wouldn't have otherwise been possible had they been instances of the Dream class. An edge case I struggled to handle was removing the possibility of mutual dreaming if a player wakes up before the end of a game, but I figured that by declaring an instance variable awake, I could make sure that both players are asleep before allowing the option to have a mutual dream. The variable also proved to be useful in marking the end of the game.

I had to go on the internet as I encountered many bugs and errors that I couldn't solve on the spot. There were also things that I wanted my code to do but weren't taught to me in my course, after searching through the internet, I found the modules pytz, which I used to change the time zone, and rich, which could colourize the terminal output and make it look more appealing since I felt like it was too basic. Although pytz wasn't necessary for this project and was removed, I enjoyed venturing out of Codecademy to learn more.

If you are interested in playing the game, you can find it here:

GitHub logo farah-qistina / LUCID

A text-based game about lucid dreams



A text-based game about lucid dreams

Read the blog post to learn more, such as what lucid dreams are and other things about the game, like bonus features!

How to Play

  • Install the Python library 'rich' (optional)
  • Start the game on a terminal
  • Enter the players' names
  • Answer according to the options given
  • Press proceed to enter



Coding this game was the perfect chance to practice the new concepts I learned in "CS101: Introduction to Programming" on Codecademy. The main idea was to polish my understanding of Object-Oriented Programming, but I ended up learning much more beyond that. In the middle of the project, I sidetracked and picked up the GitHub course on Codecademy so I could create a repository on GitHub for LUCID, and practice version control by setting up Git Tracking in my directory and committing changes as I make them. The whole process helped me get my foot in the door to the world of Git and GitHub. Finally, making the README file and writing this blog post greatly helped me get used to markdown, which was also introduced to me in the GitHub course.

Coding this game took much longer than I expected, but I believe that it was worth every bit of effort.

Top comments (2)

seif_sekalala_81e09fe6b9e profile image
Seif Sekalala

Good job! πŸ€˜πŸ‘πŸ‘

farahqistina profile image

Thx mann πŸͺ„