forked from lamapgame/lamap-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
132 lines (109 loc) · 3.86 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import logging
from datetime import datetime
from config import ADMIN_LIST, OPEN_LOBBY, MAX_PLAYERS, TIME_TO_PLAY, WAITING_TIME
from deck import Deck
class Game(object):
"""represents one game"""
waiting_time = WAITING_TIME
max_players = MAX_PLAYERS
open = OPEN_LOBBY
# mode = "DEFAULT_GAMEMODE"
def __init__(self, chat):
self.current_player = None
self.starter = None
self.started = False
self.control_card = None
self.control_player = None
self.player_won = None
self.first_player = None
self.play_round = 0 # game has 5 rounds: each player plays 5 times
self.game_round = 1
self.game_info = list()
self.game_players = list()
self.nkap = False
self.bet = 0
self.winnings = 0 # what the user wins
self.owner = ADMIN_LIST
self.chat = chat
self.last_card = None
self.owner = ADMIN_LIST
self.play_time = TIME_TO_PLAY
self.killer = None
# self.job = global_variables.LMjobQueue
self.deck = Deck()
self.logger = logging.getLogger(__name__)
@property
def players(self):
"""returns a list of all players in game"""
return self.game_players
@property
def current_player_index(self):
ref = list(filter(lambda n: n.id ==
self.current_player.id, self.players))
index = self.players.index(ref[0])
return index
@property
def control_player_index(self):
ref = list(filter(lambda n: n.id ==
self.control_player.id, self.players))
index = self.players.index(ref[0])
return index
@property
def next_player(self):
next = self.players[(self.current_player_index + 1) %
len(self.players)]
return next
@property
def get_players_except_current(self):
return [p for p in self.players if not (
self.current_player.id == p.user['id'])]
def turn(self):
""" Change a turn and change the player """
self.current_player = self.next_player
self.current_player.turn_started = datetime.now()
''' self.job.stop()
self.job.start() '''
self.play_round += 1
def turn_to_controler(self):
""" Change the turn to the game_controler """
self.current_player = self.players[self.control_player_index]
def play_card(self, card):
"""
Plays a card and triggers its effects.
Should be called only from Player.play
or on game start to play the first card
"""
if self.control_card is None:
self.control_player = self.current_player
self.control_card = card
elif takes_control(self.control_card, card):
self.control_player = self.current_player
self.control_card = card
self.last_card = card
self.turn()
def get_user_in_game(self, user):
ref = list(filter(lambda n: n.id == user.id, self.players))
return ref[0]
def start(self):
self.deck.fill_cards()
self.started = True
# self.job.run_once(self.end_turn_by_afk, WAITING_TIME)
def end(self):
self.started = False
def remove_player(self, player):
self.players.remove(player)
return
def end_turn_by_afk(self, context):
""" kill the turn and make the player afk """
return
def takes_control(previous, current):
""" Determine if a card takes control """
pv = int(previous.value)
cv = int(current.value)
if previous.suit is current.suit:
if cv > pv:
return True
else:
return False
else:
return False