2022-07-07 23:54:03 +03:00
|
|
|
import random
|
|
|
|
|
|
|
|
from game.models import Deck, Player, HeroTypes, Hero, HeroInDeck
|
|
|
|
|
|
|
|
|
|
|
|
def create_first_deck(player: Player):
|
|
|
|
deck = Deck.objects.create(player=player)
|
2022-07-27 01:24:47 +03:00
|
|
|
positions = []
|
|
|
|
|
|
|
|
for x in range(8):
|
|
|
|
for y in range(2):
|
2022-07-28 16:50:17 +03:00
|
|
|
positions.append((x, y))
|
|
|
|
positions.remove((3, 0))
|
|
|
|
positions.remove((4, 0))
|
2022-07-27 01:24:47 +03:00
|
|
|
random.shuffle(positions)
|
|
|
|
|
2022-07-07 23:54:03 +03:00
|
|
|
types = (
|
2022-07-09 14:12:29 +03:00
|
|
|
["KING", "WIZARD"]
|
2022-07-07 23:54:03 +03:00
|
|
|
+ ["ARCHER" for _ in range(4)]
|
|
|
|
+ ["WARRIOR" for _ in range(6)]
|
|
|
|
)
|
2022-07-27 01:24:47 +03:00
|
|
|
for _ in range(4):
|
|
|
|
t = random.choice(HeroTypes.choices[:3])[0]
|
|
|
|
if t == "WIZARD" and types.count("WIZARD") > 1:
|
|
|
|
t = random.choice(HeroTypes.choices[:2])[0]
|
|
|
|
types.append(t)
|
|
|
|
|
|
|
|
counter = 0
|
2022-07-07 23:54:03 +03:00
|
|
|
for t in types:
|
|
|
|
hero = Hero()
|
|
|
|
hero.player = player
|
|
|
|
hero.type = t
|
|
|
|
|
|
|
|
# set random position on deck for heroes
|
|
|
|
if t == "KING":
|
|
|
|
pos_x = 4
|
|
|
|
pos_y = 0
|
2022-07-09 14:12:29 +03:00
|
|
|
elif t == "WIZARD":
|
|
|
|
pos_x = 3
|
|
|
|
pos_y = 0
|
2022-07-07 23:54:03 +03:00
|
|
|
else:
|
2022-07-27 01:24:47 +03:00
|
|
|
pos_x = positions[counter][0]
|
|
|
|
pos_y = positions[counter][1]
|
2022-07-07 23:54:03 +03:00
|
|
|
|
2022-07-27 01:24:47 +03:00
|
|
|
counter += 1
|
2022-07-07 23:54:03 +03:00
|
|
|
|
|
|
|
hero.health = random.randint(0, 10)
|
|
|
|
hero.attack = random.randint(0, 10)
|
|
|
|
hero.speed = random.randint(0, 10)
|
|
|
|
|
|
|
|
hero.save()
|
|
|
|
HeroInDeck.objects.create(deck=deck, hero=hero, x=pos_x + 1, y=pos_y + 1)
|