chess_rpg_backend/game/services/deck_handler.py

50 lines
1.3 KiB
Python
Raw Permalink Normal View History

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 = []
2022-07-30 00:00:59 +03:00
for x in range(1, 9):
for y in range(1, 3):
positions.append((x, y))
2022-07-30 00:00:59 +03:00
positions.remove((4, 1))
positions.remove((5, 1))
2022-07-27 01:24:47 +03:00
random.shuffle(positions)
2022-07-30 00:00:59 +03:00
types = ["KING", "WIZARD"] + ["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
for t in types:
hero = Hero()
hero.player = player
hero.type = t
# set random position on deck for heroes
if t == "KING":
2022-07-30 00:00:59 +03:00
pos_x = 5
pos_y = 1
elif t == "WIZARD":
2022-07-30 00:00:59 +03:00
pos_x = 4
pos_y = 1
else:
2022-07-27 01:24:47 +03:00
pos_x = positions[counter][0]
pos_y = positions[counter][1]
2022-07-27 01:24:47 +03:00
counter += 1
2022-08-01 18:23:36 +03:00
hero.health = random.randint(1, 10)
hero.attack = random.randint(1, 10)
hero.speed = random.randint(1, 10)
hero.save()
2022-07-30 00:00:59 +03:00
HeroInDeck.objects.create(deck=deck, hero=hero, x=pos_x, y=pos_y)