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():
def __init__(self, score):
self.score = score
def __repr__(self):
return type(self).__name__ + "(%d)"%self.score
@ -31,39 +31,39 @@ class Pearl(Card):
def __init__(self, score):
Card.__init__(self, score)
class Witch(Card):
def __init__(self, score):
Card.__init__(self, score)
class DragonPetrified(Card):
def __init__(self, score):
Card.__init__(self, score)
class Golem(Card):
def __init__(self, score):
Card.__init__(self, score)
class Guardian(Card):
def __init__(self, score):
Card.__init__(self, score)
class Horser(Card):
def __init__(self, score):
Card.__init__(self, score)
class City(Card):
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
"""
from board import Board
from player import Player
from opale.carte import *
from opale.board import Board
from opale.player import Player
class Game():
def __init__(self):
def __init__(self, player1_name, player2_name):
self.board = Board()
self.player1 = Player()
self.player2 = Player()
self.player1 = Player(player1_name)
self.player2 = Player(player2_name)
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)
c2 = Pearl(1)
@property
def current_partner(self):
if self.round % 2:
return self.player1
else:
return self.player2
game = Game()
print(game.board.play_card(c1, c2))
def isFinished(self):
return self.board.isFinished() or self.player1.cantpioche or self.player2.cantpioche
c3 = DragonCorail(2)
print(game.board.play_card(c3))
def play_round(self, *cards):
self.current_player.play_card(*cards)
c4 = City()
print(game.board.play_card(c4, c4, c4))
print(game.board.play_card(c4, c4, c4))
print(game.board.play_card(c4, c4, c4))
print(game.board.isFinished())
ret = self.board.play_card(*cards)
for c in ret:
if type(c) == DragonPetrified:
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
from carte import *
from opale.carte import *
class Player():
def __init__(self):
def __init__(self, name):
self.name = name
self.pioche = []
self.cantpioche = False
self.défausse = []
self.main = []
self.hand = []
self.dragonPetrified = False
# we are creating the deck
@ -32,16 +34,21 @@ class Player():
self.pioche += [Guardian(3) for i in range(1)]
random.shuffle(self.pioche)
self.pick()
def pick(self):
for i in range((6 if self.dragonPetrified else 5) - len(self.main)):
self.main.append(self.pioche.pop())
for i in range((6 if self.dragonPetrified else 5) - len(self.hand)):
if len(self.pioche) > 0:
self.hand.append(self.pioche.pop())
else:
self.cantpioche = True
def lose_dragon(self):
self.dragonPetrified = False
random.shuffle(self.main)
for i in range(len(self.main)):
self.pioche.append(self.main.pop())
random.shuffle(self.hand)
for i in range(len(self.hand)):
self.pioche.append(self.hand.pop())
self.pick()
@ -52,5 +59,23 @@ class Player():
self.défausse += cards
def play_card(self, *cards):
ret = []
kind = None
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