I have a class called Unit which is a generic unit in a game. An instance of this Unit can be Cavalry, Infantry etc. and each unit has coordinates which indicate its initial position on a grid. I want to create many instances of this Unit class so as to populate the map.
Here is what I have:
#create units for team 1
#(self, name, x, y, char, color, move_range, atk_range, unit_size, morale, power, fatigue, team)
team_1_cavalry =[(Unit('Cavalry', i+20, 10, 'A', libtcod.yellow, 6, 1, 1000, 100, 1.5, 500, 1)) for i in range(11) ]
team_1_infantry = [(Unit('Heavy Infantry', i+20, 9, '=', libtcod.yellow, 3, 1, 2000, 100, 1.0, 200, 1)) for i in range(11)]
team_1_elephants = [(Unit('War Elephants', 20, 8, 'R', libtcod.yellow, 5, 1, 37, 100, 100, 800, 1)) for i in range(2)]
#create units for team 2
team_2_cavalry = [(Unit('Cavalry', 20+i, 15, 'A', libtcod.green, 6, 1, 500, 1000, 1.5, 500, 2)) for i in range (5)]
team_2_infantry = [(Unit('Roman Infantry', 20+i, 16, '=', libtcod.green, 3, 1, 2000, 100, 1.0, 200, 2)) for i in range(20)]
#the list of objects with those two
team1 = []
team2 = []
for unit in team_1_cavalry, team_1_infantry, team_1_elephants:
    team1.append(unit)
for unit in team_2_cavalry, team_2_infantry:
    team2.append(unit)
teams = [team1, team2]
What I'm trying to do is populate two lists with generated instances of the class. Then iterate over those lists to do various things to the instances therein. However, whenever I try to do anything I get an error saying List object has no attribute [attribute]
I am well aware that I should make each category of unit into a class which inherits from the unit class, I'm just wondering if that is absolutely necessary to make this work and why the way I'm doing it is not working.
