Opale module

This commit is contained in:
nemunaire 2020-03-12 20:05:39 +01:00
parent 920f9c9ab2
commit 1abb0e0755
4 changed files with 83 additions and 41 deletions

0
opale/__init__.py Normal file
View File

View File

@ -7,10 +7,10 @@ Created on Wed Mar 4 22:33:46 2020
""" """
class Card(): class Card():
def __init__(self, score): def __init__(self, score):
self.score = score self.score = score
def __repr__(self): def __repr__(self):
return type(self).__name__ + "(%d)"%self.score return type(self).__name__ + "(%d)"%self.score
@ -31,39 +31,39 @@ class Pearl(Card):
def __init__(self, score): def __init__(self, score):
Card.__init__(self, score) Card.__init__(self, score)
class Witch(Card): class Witch(Card):
def __init__(self, score): def __init__(self, score):
Card.__init__(self, score) Card.__init__(self, score)
class DragonPetrified(Card): class DragonPetrified(Card):
def __init__(self, score): def __init__(self, score):
Card.__init__(self, score) Card.__init__(self, score)
class Golem(Card): class Golem(Card):
def __init__(self, score): def __init__(self, score):
Card.__init__(self, score) Card.__init__(self, score)
class Guardian(Card): class Guardian(Card):
def __init__(self, score): def __init__(self, score):
Card.__init__(self, score) Card.__init__(self, score)
class Horser(Card): class Horser(Card):
def __init__(self, score): def __init__(self, score):
Card.__init__(self, score) Card.__init__(self, score)
class City(Card): class City(Card):
def __init__(self): def __init__(self):
Card.__init__(self, 0) Card.__init__(self, 0)

View File

@ -6,30 +6,47 @@ Created on Wed Mar 4 22:20:15 2020
@author: AlexandreMouchel @author: AlexandreMouchel
""" """
from board import Board from opale.carte import *
from player import Player from opale.board import Board
from opale.player import Player
class Game(): class Game():
def __init__(self): def __init__(self, player1_name, player2_name):
self.board = Board() self.board = Board()
self.player1 = Player() self.player1 = Player(player1_name)
self.player2 = Player() self.player2 = Player(player2_name)
self.round = 0 self.round = 0
from carte import * @property
def current_player(self):
if self.round % 2:
return self.player2
else:
return self.player1
c1 = Pearl(2) @property
c2 = Pearl(1) def current_partner(self):
if self.round % 2:
return self.player1
else:
return self.player2
game = Game() def isFinished(self):
print(game.board.play_card(c1, c2)) return self.board.isFinished() or self.player1.cantpioche or self.player2.cantpioche
c3 = DragonCorail(2) def play_round(self, *cards):
print(game.board.play_card(c3)) self.current_player.play_card(*cards)
c4 = City() ret = self.board.play_card(*cards)
print(game.board.play_card(c4, c4, c4))
print(game.board.play_card(c4, c4, c4)) for c in ret:
print(game.board.play_card(c4, c4, c4)) if type(c) == DragonPetrified:
print(game.board.isFinished()) self.current_partner.lose_dragon()
self.current_player.take_dragon()
break
self.current_player.push_défausse(*ret)
self.current_player.pick()
self.round += 1

View File

@ -7,15 +7,17 @@ Created on Wed Mar 4 22:32:32 2020
""" """
import random import random
from carte import * from opale.carte import *
class Player(): class Player():
def __init__(self): def __init__(self, name):
self.name = name
self.pioche = [] self.pioche = []
self.cantpioche = False
self.défausse = [] self.défausse = []
self.main = [] self.hand = []
self.dragonPetrified = False self.dragonPetrified = False
# we are creating the deck # we are creating the deck
@ -32,16 +34,21 @@ class Player():
self.pioche += [Guardian(3) for i in range(1)] self.pioche += [Guardian(3) for i in range(1)]
random.shuffle(self.pioche) random.shuffle(self.pioche)
self.pick()
def pick(self): def pick(self):
for i in range((6 if self.dragonPetrified else 5) - len(self.main)): for i in range((6 if self.dragonPetrified else 5) - len(self.hand)):
self.main.append(self.pioche.pop()) if len(self.pioche) > 0:
self.hand.append(self.pioche.pop())
else:
self.cantpioche = True
def lose_dragon(self): def lose_dragon(self):
self.dragonPetrified = False self.dragonPetrified = False
random.shuffle(self.main) random.shuffle(self.hand)
for i in range(len(self.main)): for i in range(len(self.hand)):
self.pioche.append(self.main.pop()) self.pioche.append(self.hand.pop())
self.pick() self.pick()
@ -52,5 +59,23 @@ class Player():
self.défausse += cards self.défausse += cards
def play_card(self, *cards): def play_card(self, *cards):
ret = []
kind = None
for card in cards: for card in cards:
self.main.remove(card) if kind is None:
kind = type(card)
elif kind != type(card):
self.hand += ret
raise Exception("You select multiple card types, this is not allowed. At least: %s and %s." % (kind.__name__, type(card).__name__))
elif self.hand.count(card) <= 0:
self.hand += ret
raise Exception("You select too much cards %s than you have in your hand." % (kind.__name__))
ret.append(card)
self.hand.remove(card)
return ret
def get_score(self):
score = 3 if self.dragonPetrified else 0
for c in self.défausse:
score += c.score
return score