PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# this is my version of the famous goblin game used in python tutorials and not an exception our sololearn's python course in title a simple game . i took the liberty to change and modify a lot in it , which as a biginner took a lot of time ,the game exceeds 1k lines of code which make it too WET by the python standards , after a lot of tries i couldn't make it less lines without keeping the same functionality and readibility. this led to an idea of posting the game so i get answers to how do i get the code shorter keeping its functionality and readibility, and for the best answer i get i will upvote everysingle code or question or answer or comment for the person who post it in return .
#my post:
"""https://www.sololearn.com/Discuss/442186/?ref=app"""
# how to play : there are 5 characters in the game : you the main character which you can input your name for it , zainab the female heroin , the demon , the medusa , and of coarse the goblin . actions : hit , defend , sphit as specialhit ,and analyze chose any of the characters above you can first analyze each one at a time to make a wise choice remember that each character has its own different attributes, then chose an action from the actions above , now enter your name as the first line of input if you chose you or just leave it empty don't forget to press enter if you left it empty this way will stay as you .leave an empty line before your input if you chose other characters. now you should enter your input like this : you hit goblin and leave another empty line at the end of input when your done , you can enter multiple lines so at the end it will look like this : you or any name you input or just an empty line \n "you" analyze "you" \n "you" hit goblin \n "you" defend goblin \n ....\n as an empty line . with "you" and goblin as any characters you chose and hit as any action you chose and \n as pressing enter please report any bugs or errors in the comment section enjoy
from random import choice
class GameObject:
class_name = ""
desc = ""
objects = {}
inventory = []
health = int
xp = int
special_hit = ""
def __init__(self, name):
self.name = name
GameObject.objects[self.class_name] = self
def naming_you () :
name = input()
if len(name) != 0 :
return name
else :
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run