Jump to content

Let's code some python!


Tux1
 Share

Recommended Posts

Pretty self explanatory, but there are some rules.

Rules:

  • Your submission must be valid Python3, that is, if I put it into repl.it, it should not return an error.
  • You may not end the program unless I say so.
  • When I end the program, I will run it and see what I get.
  • Have fun, I guess.

I'll start off simple:

print("Hello Program!")

Link to comment
Share on other sites

  • 1 month later...
On 2/4/2018 at 3:48 PM, IncongruousGoat said:

# Welp, we've already got a crash. @TheMadKraken2297 forgot a colon.

#Aww crap! I was wondering why My #email spambot wasn't working...

for I in range(9001):

    print(JEBEDIAH)

#WOOOOOP! 100 rep!

print(I'mma start talking in python functions now)

Edited by TheMadKraken2297
Hashtags. And the dang colon. I just learned python, ok?!
Link to comment
Share on other sites

  • 5 months later...

This ought to be a good start:

Spoiler

class entity():
    def __init__(self, type, name, alignment, symbol):
        self.type = type
        self.name = name
        self.alignment = alignment
        self.symbol = symbol
    def move(self, player, cur_room, index):#, events, entities, index
        #honestly I forgot how this function works
        move = random.randint(0, 9)
        if move == 4:
            move = random.randint(0, 3) #what direction to move?
            if move == 0 and cur_room.thing_at_coord(x + 1, y) == (False, 0, 0):
                cur_room.entities[index][1] += 1
            if move == 1 and cur_room.thing_at_coord(x - 1, y) == (False, 0, 0):
                cur_room.entities[index][1] -= 1
            if move == 2 and cur_room.thing_at_coord(x, y + 1) == (False, 0, 0):
                cur_room.entities[index][2] += 1
            if move == 3 and cur_room.thing_at_coord(x, y - 1) == (False, 0, 0):
                cur_room.entities[index][2] -= 1

class player():
    def __init__(self, name, gold, x, y, alignment, species):
        self.name = name
        self.gold = gold
        self.fight_exp = 0
        self.magic_exp = 0
        self.species = species
        self.alignment = alignment
        self.resourcefulness = 0
        self.work_ethic = 0
        self.common_sense = 0
        self.smartness = 0
        self.cuteness = 0
        self.trickiness = 0
        self.happiness = 0
        self.boldness = 0
        self.sadness = 0
        self.calmness = 0
        self.x = x
        self.y = y
        self.inventory = []
        
class room():
    def __init__(self, width, height, openings, events, entities, id):#, big_things):
        self.width = width
        self.height = height
        self.openings = openings
        self.events = events
        self.entities = entities
        self.id = id
    def thing_at_coord(self, x, y):
        for i in self.openings:
            if i[1] == x and i[2] == y: #opening x and y is at index 1 and 2, the info is at 3
                return(True, "opn", i[3])
        for i in self.entities:
            if i[1] == x and i[2] == y: #event and entity x and y is at index 1 and 2
                return(True, "ent", i[0]) #the event or entity itself is at index 0, but is returned as index 2 because 0 is taken
        for i in self.events:
            if i[1] == x and i[2] == y:
                return(True, "evn", i[0])
        if x == self.width - 1 or x == 0: return(True, "wal", 0)
        if y == self.height - 1 or y == 0: return(True, "wal", 0)
        return(False, 0, 0)
    def update_entities(self, player):
        for i in self.entities:
            i[0].move(player, self, self.entities.index(i)) #self.events, self.entities, self.entities.index(i))

def draw_room(passed_room, player_char):
    global quest_stage
    w = passed_room.width
    h = passed_room.height
    openings = passed_room.openings
    events = passed_room.events
    entities = passed_room.entities
    room_map = {} #just to init the dict
    for x in range(w): #fill it with blanks
        for y in range(h):
            room_map[(x, y)] = "."
    for x in range(w): #outline the horizontal walls
        room_map[(x, 0)] = "#"
        room_map[(x,(h-1))] = "#"
    for y in range(h): #outline the vertical walls
        room_map[(0, y)] = "#"
        room_map[((w-1),y)] = "#"
    for get_coords in openings:
        room_map[(get_coords[1], get_coords[2])] = ']' #openings marked by brackets for visibility (clever)
    for get_coords in events:
        room_map[(get_coords[1], get_coords[2])] = get_coords[0].symbol
        print(end="")
    for get_coords in entities:
        room_map[(get_coords[1], get_coords[2])] = get_coords[0].symbol
        print(end="")
    room_map[(player_char.x, player_char.y)] = "@"
    for y in range(h): #cycle through each row
        for x in range(w): #in each row, print each column
            print(room_map[(x, y)], end="")
            if x == (w-1): #when at the end, print a \n
                print("")
    print(("Name: " + player_char.name).ljust(20) + "Alignment: " + player_char.alignment)
    print(("GP: " + str(player_char.gold)).ljust(20) + "Species: " + player_char.species)

#entity format: (type, name, alignment, symbol)
yuyuko = entity("ghost", "Yuyuko Saigyouji", "probably evil", "Y")
sanae = entity("shrine maiden", "Sanae Kochiya", "100% good girl", "S")
suiseiseki = entity("doll", "Suiseiseki", "meh", "Q")
lain = entity("actual deity", "Lain Iwakura", "beyond good and evil", "%")

player1 = player("Jebediah", 50, 4, 4, "BadS", "Kerbal")

#here's how rooms work:
#first two values: width and height
#third value is a list of openings.
#    each opening has this format: (ID#, x, y, (ID# of connecting room, ID# of connecting opening))
#fourth/fifth values are list of events (I didn't include the class for events) and entities
#    the format is: [event/entity, x, y]
#the sixth value is the room ID
BigS_room = room(25, 25, [[0, 5, 15, (1, 4)]], [], [[yuyuko, 4, 7], [suiseiseki, 12, 18], [sanae, 16, 2], [lain, 10, 10]], 0)
draw_room(BigS_room, player1)

This is part of a larger game, but I won't do all the work for you (you don't want to see the rest of the code anyway, I promise ;))

Edited by MDZhB
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...