enemyArray = [Ork, Goblin]
class Ork:
name = "Mountain Dweller"`
health = 10
armor = 1
damage = 5
class Goblin:
name = "Looter"
health = 5
armor = 0
damage = 5
Asked
Active
Viewed 43 times
0

Moses Koledoye
- 77,341
- 8
- 133
- 139

Justikun
- 33
- 1
- 6
-
I don't quite understand your question. – erip Jun 13 '17 at 21:29
-
2I think the answer is yes. Why don't you try it first and let us know where you have trouble? – Kind Stranger Jun 13 '17 at 21:31
-
1Why don't you just try it yourself, it's literally like 20 seconds. – Bubble Bubble Bubble Gut Jun 13 '17 at 21:33
-
You are not working with an array... you have a `list` – juanpa.arrivillaga Jun 13 '17 at 23:01
2 Answers
1
Sure, make sure you declare the classes first:
import random
class Ork:
name = "Mountain Dweller"
health = 10
armor = 1
damage = 5
class Goblin:
name = "Looter"
health = 5
armor = 0
damage = 5
enemyArray = [Ork, Goblin]
for _ in range(8):
print(random.choice(enemyArray))
Output:
<class '__main__.Ork'>
<class '__main__.Goblin'>
<class '__main__.Goblin'>
<class '__main__.Goblin'>
<class '__main__.Goblin'>
<class '__main__.Goblin'>
<class '__main__.Ork'>
<class '__main__.Ork'>

Mark Tolonen
- 166,664
- 26
- 169
- 251
-
Wish I had more reputation so I could up vote this. Thank you so much! – Justikun Jun 13 '17 at 21:36
-
@Justikun You're welcome. You can accept answers to your questions with the check near the answer. – Mark Tolonen Jun 14 '17 at 01:25
0
from random import choice
list_ = [Ork, Goblin]
rand_enemy = random.choice(list_)

syntaxError
- 896
- 8
- 15