Example #1
0
from setting import Setting

pygame.init()  # pygame 初始化,必须有,且必须在开头

clock = pygame.time.Clock()  # 用于控制循环刷新频率的对象
screen = pygame.display.set_mode((Setting.win_w, Setting.win_h))
screen.fill(Color.WHITE)
pygame.display.set_caption(Setting.game_name)
pygame.font.init()
pygame.mixer.init()



game = Game(screen=screen, clock=clock)
game.prepare()
game.play()
game.end()

# eric = PlayerHuman('Eric', is_viewer=True)
# players = [
#     eric,
#     PlayerAi('大乔'),
#     PlayerAi('貂蝉'),
#     PlayerAi('西施'),
# ]
# prevailing_wind = '东'
# hand = HandS(players=players, flower=True, prevailing_wind=prevailing_wind, screen=screen, clock=clock, viewer=eric)
# hand.prepare()
# hand.deal()

# for test propose only!
Example #2
0
#''' # uncomment this opening triple quote when commenting out one elsewhere
import sys
from mahjong.game import Game, Hand, UserIO, Question, HandEnding, HandResult

if '--game' in sys.argv:
    game = Game(extra_hands=False)
else:
    game = Hand(None)
print('Note: all indexes are **1-based**.')
print('This is a rudimentary text-based mahjong implementation.')
print("It's purely as a proof-of-concept/manual testing method.")
print("It requires trust that each player won't look at the other's privacy.")
print("Please don't actually use this. Make something even a tiny bit better.")
print("With that said, let's start.")

question = game.play()
while question is not None:
    if isinstance(question, UserIO):
        if question.question == Question.READY_Q:
            input('Hit Enter when ready for the next round.')
            question = question.answer()
            continue
        hand_minus_tile = [
            tile for tile in question.hand if tile is not question.arrived
        ]
        print('Question for Player #%s' % question.player.seat.value)
        print('Draw/Last discard: %s;' % question.arrived, 'Concealed:',
              ', '.join(map(str, hand_minus_tile)))
        print('Shown:', '\t'.join(map(str, question.shown)), '- Bonuses:',
              '|'.join(map(str, question.player.bonus)))
        if question.question == Question.DISCARD_WHAT: