Text Battle Royale

Medea - Mar 14 '22 - - Dev Community

Text Battle Royale


Introduction

In this post I'll show you the code for a text Battle Royale game in Python, which is completely based on luck.
You only need 1 file for this to work!


Code

import os
from time import sleep
from random import randint, choice
def clear():
    try:
        if os.name == 'posix':
            _ = os.system('clear')
        elif os.name == 'nt':
            _ = os.system('cls')
        return True
    except Exception as e:
        print(e)
        return False
print("WELCOME TO TEXT BATTLE ROYALE!!!")
start = input("Press enter to start.")
while start != "":
  start = input("Press enter to start.")
clear()
for i in range(5):
  print("Scanning island." + "." * i)
  sleep(1)
  clear()
areas_on_map = ["Cool Place", "Great Place", "Scary Place"]
landing_area = choice(areas_on_map)
input("Press enter to exit the battle bus.")
clear()
print("You are skydiving.")
input("Press enter to deploy your parachute.")
for i in range(5, 0, -1):
  clear()
  print(f"You have deployed your parachute. You are going to land in {i} seconds.")
  sleep(1)
clear()
print("You have landed on",landing_area)
sleep(3)
clear()
elimination = 0
players = 100
print("You have 1 sniper rifle with infinity ammo.")
while players>1:
  print("There are",players,"including you in the game.")
  risk = randint(1,50)
  if risk > 0 and risk < 16:
    print(f"Someone has shot you from behind. You were {players}th place.")
    exit()
  elif risk > 15 and risk < 24:
    print(f"Someone has shot you from the side. You were {players}th place.")
    exit()
  elif risk > 23 and risk < 51:
    shot = input("There is someone coming close to you. If you want to kill them, press enter.")
    if shot == "":
      print("You have killed someone.")
      players = players - 1
      elimination = elimination + 1
    else:
       print(f"Someone has shot you from behind. You were {players}th place.")
       exit()
  else:
    players = players - 1
    clear()
clear()
print("You have won!")
Enter fullscreen mode Exit fullscreen mode

Conclusion

After running the code, you will be able to play a text version of a Battle Royale game, fully based on luck!
Thanks to @dillonb07 for the clear function!
Thanks for reading! If you liked this, make sure you follow me on dev.to and GitHub

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .