ono_sendai - wip
This commit is contained in:
parent
ca982b07a7
commit
e7d1f0ea03
3 changed files with 50 additions and 13 deletions
|
@ -59,20 +59,25 @@ class FrameFactory:
|
|||
def newHandFrame(self, cards):
|
||||
assert type(cards) is list, type(cards)
|
||||
h = 27 # height ?
|
||||
self.d.add(1, 1, WColoredFrame(12, h, 'HAND', red))
|
||||
w = WCardRadioButton([f'{Fore.RED}'+cards[0]] + cards[1:-1] + [cards[-1]+f'{Style.RESET_ALL}'], isHand=True)
|
||||
self.d.add(1, 1, WColoredFrame(12, h, 'HAND', blue))
|
||||
w = WCardRadioButton([f'{Fore.BLUE}'+cards[0]] + cards[1:-1] + [cards[-1]+f'{Style.RESET_ALL}'], isHand=True)
|
||||
self.d.add(2, 2, w)
|
||||
self.hand = w
|
||||
|
||||
def getChoices(self):
|
||||
src = -1; dst = -1
|
||||
src = (None, None); dst = None
|
||||
|
||||
if self.widgets[0].choice == 0:
|
||||
dst = 'Empty'
|
||||
if self.hand.choice > 1:
|
||||
src = 'Hand', self.hand.choice-2
|
||||
|
||||
for i, w in enumerate(self.widgets[1:]):
|
||||
if w.choice == 0:
|
||||
assert dst != 'Empty'
|
||||
dst = i
|
||||
elif w.choice > 1:
|
||||
assert src[0] != 'Hand'
|
||||
src = i, w.choice-2
|
||||
return src, dst
|
||||
|
||||
|
@ -82,6 +87,7 @@ c = ['asd', 'asd']
|
|||
|
||||
import state
|
||||
table = state.table
|
||||
hand = state.hand
|
||||
|
||||
exit = False
|
||||
while not exit:
|
||||
|
@ -118,7 +124,7 @@ while not exit:
|
|||
f.emptyFrame()
|
||||
for cards in table.widget_repr():
|
||||
f.newFrame(cards)
|
||||
# f.newHandFrame()
|
||||
f.newHandFrame(hand.widget_repr())
|
||||
|
||||
tableDialog.redraw()
|
||||
res = tableDialog.loop()
|
||||
|
@ -127,7 +133,7 @@ while not exit:
|
|||
else:
|
||||
print(*f.getChoices())
|
||||
sleep(2)
|
||||
table = state.update_table(table, *f.getChoices())
|
||||
table, hand = state.update_table(table, hand, *f.getChoices())
|
||||
|
||||
|
||||
print('TODO: massimo due scelte')
|
||||
print('TODO: sempre due scelte')
|
||||
|
|
|
@ -36,15 +36,45 @@ table = Table([
|
|||
Card("Tiles", 1)]),
|
||||
])
|
||||
|
||||
|
||||
class Hand:
|
||||
def __init__(self, cards):
|
||||
self.cards = cards
|
||||
|
||||
def widget_repr(self):
|
||||
yi = [sym.big['hat']]
|
||||
seed = self.cards[0][0].lower()
|
||||
yi.append(sym.big[seed])
|
||||
yi.append(sym.big[self.cards[0][1]])
|
||||
for card in self.cards[1:]:
|
||||
seed = card[0].lower()
|
||||
yi.append(sym.sym[seed][card[1]])
|
||||
return yi
|
||||
|
||||
hand = Hand([
|
||||
Card("Pikes", 12),
|
||||
Card("Clovers", 12),
|
||||
Card("Tiles", 12),
|
||||
Card("Hearts", 12),
|
||||
Card("Hearts", 13),
|
||||
Card("Clovers", 13),
|
||||
Card("Pikes", 13),
|
||||
Card("Tiles", 13)
|
||||
])
|
||||
|
||||
# TODO: refactor language
|
||||
def gioca(tavolo, src, dst):
|
||||
def gioca(tavolo, hand, src, dst):
|
||||
giocata = [] if dst == 'Empty' else tavolo.cards[dst]
|
||||
da_muovere = tavolo.cards[src[0]].cards[src[1]]
|
||||
assert type(dst) is int or dst == 'Empty' or dst == 'Hand'
|
||||
da_muovere = hand.cards[src[1]] if src[0] == 'Hand' else tavolo.cards[src[0]].cards[src[1]]
|
||||
hcards = hand.cards[:src[1]] + hand.cards[src[1]+1:] if src[0] == 'Hand' else hand.cards
|
||||
|
||||
assert type(dst) is int or dst == 'Empty'
|
||||
assert type(src[0]) is int or src[0] == 'Hand'
|
||||
assert type(da_muovere) is Card
|
||||
assert type(giocata) is TaggedCards or giocata == []
|
||||
|
||||
idx = -1 if dst == 'Empty' else tavolo.cards.index(giocata)
|
||||
news = [TaggedCards([da_muovere])] if giocata == [] else []
|
||||
news = [TaggedCards([da_muovere])] if type(giocata) is list else []
|
||||
rimpiazzata = False
|
||||
for i, t in enumerate(tavolo.cards):
|
||||
if i == idx:
|
||||
|
@ -57,7 +87,7 @@ def gioca(tavolo, src, dst):
|
|||
rimpiazzata = True
|
||||
else:
|
||||
news.append(t)
|
||||
return Table(news)
|
||||
return Table(news), Hand(hcards)
|
||||
|
||||
def update_table(table, src, dst):
|
||||
return gioca(table, src, dst)
|
||||
def update_table(table, hand, src, dst):
|
||||
return gioca(table, hand, src, dst)
|
||||
|
|
|
@ -3,6 +3,7 @@ from picotui.defs import *
|
|||
from colorama import Style, Fore
|
||||
|
||||
red = f'{Fore.RED}'.encode('utf-8')
|
||||
blue = f'{Fore.BLUE}'.encode('utf-8')
|
||||
green = f'{Fore.GREEN}'.encode('utf-8')
|
||||
white = f'{Fore.WHITE}'.encode('utf-8')
|
||||
|
||||
|
|
Loading…
Reference in a new issue