I've been doing some self-imposed exercises to get accustomed to Python and below is my code.
import random from random import randint from random import randrange from mainlist import legendaryitems from mainlist import waystodie from mainlist import powerup from mainlist import mood from mainlist import ponder import time class Player(object): def __init__(self, name): self.name = name self.lifecondition = True self.hitpoints = 100 self.items =  self.waystodie =  self.mood = "" def death(self): self.lifecondition = False def ways_to_die(self, death): self.waystodie.append(death) def add_items(self, item): self.items.append(item) def change_hp(self, hp): self.hitpoints = hp def change_mood(self, mood): self.mood = mood def __repr__(self): return repr(self.name) def addplayers(alist): players =  for item in alist: item = Player("%s" % item) players.append(item) print "%s enters the game with %s HP of life and feels pretty much alive" % (item.name, item.hitpoints, ) return players def player_mood(playerlist, moodlist): for item in playerlist: mood = random.choice(moodlist) item.change_mood(mood) playerlist = ["Player1", "Player2", "Player3", "Player4", "Player5", "Player6", "Player7", "Player8", "Player9", "Player10"] players = addplayers(playerlist) player_mood(players, mood) print players.mood print players.mood player_mood(players, mood) print players.mood print players.mood
My intention is to create actions depending on the mood of characters. Basically it's gonna be a "There can be only one!" game. The reason of my post is not so that someone else can write the code for me but for feedback on how to write more clean, efficient code following Python's philosophy at the same time.
I am calling the instances through the players list but is there any other way I should be using to recall them from the class?
I'm able to convey what I want to do into code but is it ok to interact with standalone functions with my class? Or should I be building methods within another Class (utilize inheritance as well) to interact with