Learn to Code via Tutorials on Repl.it!

← Back to all posts
Mining Simulator Section-1
DJWang (1130)

Hello everyone! I'm trying to start a small series on a Mining Simulator game. Throughout the series, we will design a game of Mining Simulator where you can mine blocks, sell them, and use the money to buy better equipment. Backpacks give you more storage and Tools help you mine faster.

Section-1 of Mining Simulator will teach you how to create the main structure of the game: Inside the mine. We will use hardcoded variables for our backpack and tool.

Let's get started!

Import the packs

Import the files/packs using this code.

from termcolor import cprint
from replit import clear
from time import sleep
  • cprint imports the text for colors.
  • Clear imports the function of deleting text
  • sleep imports the time in between print statements.

Your code should look like this:

Variables

To play this game, we need variables for our tools and backpacks. For our tools, we can make a variable called "ToolSpeed" so we know the time interval between mining blocks (We will measure ToolSpeed in seconds). For our backpack, we can have a variable called "PackLimit" to know our limit for the number of blocks we mine. Here is the code:

What this code really means is that every time you mine a block, it takes 3 seconds to be able to mine again, and once you've reached 10 blocks, you have to sell them.

Changing the Variables

Time to change the variables! Every time you mine a block, the tool needs a cooldown. The cooldown is the variable "Toolspeed." To mine a block, the output will need to be something that looks like this:

Press enter to mine a block. [0/10]

Then when you mine a block, it will say:

Regenerating... (Stay this text for three seconds)

Then it will clear the screen.

Then it will say:

Press enter to mine a block. [1/10]

You see the 0 changed to a 1. We can write the code as:

for i in range(PackLimit+1):
  print('Press enter to mine a block','[',(i),'/',PackLimit,']')
  input(">>> ")
  print("Regenerating...")
  sleep(Toolspeed)
  clear()

So far, you should see this in your screen:

Closing the Mine- Last chapter of this section

When you've mined to your backpack limit, it should say a screen that says, "You've reached your backpack limit! Visit the store to buy a better backpack or sell your mined blocks!"

We already have a "for" loop to take care of the backpack limit, so we don't need an if statement. We simply write a line of code on the next line:

print("You've reached your backpack limit! Visit the store to buy a better backpack or sell your mined blocks!")

THE END

Thank you for taking the time to read this! Please upvote and I hope you have fun making this game! Remember: Criticism IS ALLOWED. Please tell me if there is anything wrong.

Remember to upvote if you like this!

Peace for now!

-DJStudios Team

Commentshotnewtop
JoelMenezes (11)

@DJWang if you click enter while regenerating and then stop and don't do anything it keeps auto mining for you

IEDstudent (1)

Why do we need to import cprint?

mlawv25 (0)

it says there is no module named termcolor someone pls help i am new

DJWang (1130)

@mlawv25 are you using python?

mlawv25 (0)

@DJWang can you pls help i have put it on hold for now but i need an answer soon thanks

mlawv25 (0)

@DJWang pls i need an anwser soon

DJWang (1130)

@mlawv25 are you spelling it right?

DJWang (1130)

@mlawv25 Could you please send me a screenshot of your work?

Thanks

DJWang (1130)

@mlawv25 I don't see the error message.

DJWang (1130)

@mlawv25 This is so weird! It's happening for me now too. Maybe try typing this issue in a seperate post where it will get more attention.

victordfde (0)

Hello, how can I use the clear() function outside the replit compiler?
Is there a similar one or something to replace it

DJWang (1130)

@victordfde Yes there is another one but I'm not so sure on how to use it,

Haaruun (94)

sorry im late but you can do import os; os.sys("clear") @victordfde

DJWang (1130)

@Haaruun There is no problem to be late! :)