def get_players(self): name1 = raw_input("Enter player one's name\n") name2 = raw_input("Enter player two's name\n") random_num = randint(0, 1) if random_num == 0: print name1, 'will use the marker X and will go first' print name2, 'will use the marker O and will go second' p1 = player.Player1(name1) p2 = player.Player2(name2) else: print name2, 'will use the marker X and will go first' print name1, 'will use the marker O and will go second' p1 = player.Player1(name2) p2 = player.Player2(name1) players = [p1, p2] return players
def spawn(self): # 파이어보이 생성 및 좌표 지정 self.player1 = player.Player1() self.player1.setPos(100, 500) self.addItem(self.player1) # 워터걸 생성 및 좌표 지정 self.player2 = player.Player2() self.player2.setPos(100 - 50, 500) self.addItem(self.player2)
def read_player(line, marker): player_re = 'player([#\w]*)' player_list = re.findall(player_re, line)[0].split('#')[1:4] if marker == 'X': p = player.Player1(player_list[0], int(player_list[1]), int(player_list[2])) else: p = player.Player2(player_list[0], int(player_list[1]), int(player_list[2])) return p
def __init__(self): QGraphicsScene.__init__(self) # 60hz에 가까운 주기로 새로고침함(16ms에 1번 = 960ms(0.96초)에 16번) self.timer = QBasicTimer() self.timer.start(FRAME_TIME_MS, self) self.cleared = False self.gameover = False self.gameover_bg = QGraphicsPixmapItem(QPixmap("gameover.png")) self.gameover_bg.setScale(0.57) # 배경 사진 설정 bg = QGraphicsPixmapItem() bg.setPixmap(QPixmap("bg_brick.png")) bg.setScale(0.25) self.addItem(bg) # 맵 조성 self.terrain1 = SolidRect(0, 560, 800, 40) # 제일 밑 땅. self.addItem(self.terrain1) self.terrain2 = SolidRect(0, 440, 500, 40) self.addItem(self.terrain2) # 맵 object 추가 self.f_door = f_door() self.f_door.setPos(0, 440 - 64) self.addItem(self.f_door) self.w_door = w_door() self.w_door.setPos(60, 440 - 64) self.addItem(self.w_door) self.slide_v1 = Slide_V(440, 480, 60, 80) self.addItem(self.slide_v1) self.button_v1 = Button(Slide_V, 200, 550) self.addItem(self.button_v1) self.button_v2 = Button(Slide_V, 200, 430) self.addItem(self.button_v2) # 파이어보이 생성 및 좌표 지정 self.player1 = player.Player1() self.player1.setPos(60, 500) self.addItem(self.player1) # 워터걸 생성 및 좌표 지정 self.player2 = player.Player2() self.player2.setPos(120, 500) self.addItem(self.player2)
def __init__(self): QGraphicsScene.__init__(self) # 60hz에 가까운 주기로 새로고침함(16ms에 1번 = 960ms(0.96초)에 16번) self.timer = QBasicTimer() self.timer.start(FRAME_TIME_MS, self) self.cleared = False # 배경 사진 설정 bg = QGraphicsPixmapItem() bg.setPixmap(QPixmap("bg_brick.png")) bg.setScale(0.25) self.addItem(bg) # 맵 조성 self.terrain1 = SolidRect(0, 580, 800, 40) # 제일 밑 땅. self.addItem(self.terrain1) self.terrain2 = SolidRect(60, 480, 120, 40) self.addItem(self.terrain2) self.terrain3 = SolidRect(620, 480, 120, 40) self.addItem(self.terrain3) self.terrain4 = SolidRect(120, 400, 560, 40) self.addItem(self.terrain4) # 맵 object 추가 self.f_door = f_door() self.f_door.setPos(629, 400 - 64) self.addItem(self.f_door) self.w_door = w_door() self.w_door.setPos(121, 400 - 64) self.addItem(self.w_door) # 파이어보이 생성 및 좌표 지정 self.player1 = player.Player1() self.player1.setPos(0, 500) self.addItem(self.player1) # 워터걸 생성 및 좌표 지정 self.player2 = player.Player2() self.player2.setPos(750, 500) self.addItem(self.player2)
def __init__(self): QGraphicsScene.__init__(self) # 60hz에 가까운 주기로 새로고침함(16ms에 1번 = 960ms(0.96초)에 16번) self.timer = QBasicTimer() self.timer.start(FRAME_TIME_MS, self) self.mainscene = True self.keys_pressed = set() self.cleared = False bg = QGraphicsPixmapItem() bg.setPixmap(QPixmap("bg_end.png")) bg.setScale(0.57) self.addItem(bg) self.player1 = player.Player1() self.player1.setPos(50, 0) self.addItem(self.player1) self.player2 = player.Player2() self.player2.setPos(700, 0) self.addItem(self.player2)
def start_game(cli=False, ai=False): wzglobals.attack_started = [True] wzglobals.background = \ pygame.image.load(current_folder+'/misc/bg_sample.gif') # wzglobals.background = wzglobals.background.convert() # wzglobals.background = pygame.Surface(wzglobals.screen.get_size()) wzglobals.background = wzglobals.background.convert_alpha() wzglobals.cards_of_element_shower_element = "water" # wzglobals.background.fill((0, 0, 0)) background_backup = wzglobals.background.copy() # font.set_bold(0) wzglobals.games_cards[0]['water'] = cards.water_cards_deck.cards[:] wzglobals.games_cards[0]['fire'] = cards.fire_cards_deck.cards[:] wzglobals.games_cards[0]['air'] = cards.air_cards_deck.cards[:] wzglobals.games_cards[0]['earth'] = cards.earth_cards_deck.cards[:] wzglobals.games_cards[0]['life'] = cards.life_cards_deck.cards[:] wzglobals.games_cards[0]['death'] = cards.death_cards_deck.cards[:] if wzglobals.player1: wzglobals.player1.enemy = None wzglobals.player2.enemy = None wzglobals.player1 = player.Player1() wzglobals.player1.nickname = wzglobals.nick wzglobals.player2 = player.Player2() wzglobals.player1.enemy = wzglobals.player2 wzglobals.player2.enemy = wzglobals.player1 wzglobals.player = wzglobals.player1 # 0 1 2 3 4 //Расположение # 5 6 7 8 9 wzglobals.cardbox0 = \ cardbox.Cardbox((22, 46), wzglobals.player1, 0) # 0 место на поле wzglobals.cardbox1 = \ cardbox.Cardbox((172, 46), wzglobals.player1, 1) # 1 место на поле wzglobals.cardbox2 = \ cardbox.Cardbox((322, 46), wzglobals.player1, 2) # 2 место на поле wzglobals.cardbox3 = \ cardbox.Cardbox((472, 46), wzglobals.player1, 3) # 3 место на поле wzglobals.cardbox4 = \ cardbox.Cardbox((622, 46), wzglobals.player1, 4) # 4 место на поле wzglobals.cardbox5 = \ cardbox.Cardbox((22, 238), wzglobals.player2, 5) # 5 место на поле wzglobals.cardbox6 = \ cardbox.Cardbox((172, 238), wzglobals.player2, 6) # 6 место на поле wzglobals.cardbox7 = \ cardbox.Cardbox((322, 238), wzglobals.player2, 7) # 7 место на поле wzglobals.cardbox8 = \ cardbox.Cardbox((472, 238), wzglobals.player2, 8) # 8 место на поле wzglobals.cardbox9 = \ cardbox.Cardbox((622, 238), wzglobals.player2, 9) # 9 место на поле wzglobals.cardboxes = [ wzglobals.cardbox0, wzglobals.cardbox1, wzglobals.cardbox2, wzglobals.cardbox3, wzglobals.cardbox4, wzglobals.cardbox5, wzglobals.cardbox6, wzglobals.cardbox7, wzglobals.cardbox8, wzglobals.cardbox9 ] # Ссылки на объекты for tcardbox in wzglobals.cardboxes: if pygame.version.vernum < (1, 9, 1): tcardbox.normal_rect = copy.deepcopy(tcardbox.rect) tcardbox.opposite_rect = \ copy.deepcopy(tcardbox.get_opposite_cardbox().rect) else: tcardbox.normal_rect = tcardbox.rect.copy() tcardbox.opposite_rect = \ tcardbox.get_opposite_cardbox().rect.copy() wzglobals.castlabel = cards.CastLabel() # Окошко здоровья верхнего игрока healthwindow.HealthWindowEnemy((175, 10)) healthwindow.HealthWindow((167, 557)) # Окошко здоровья нижнего игрока # Кнопки колод стихий первого игрока elementbutton.WaterElementShower((246, 2)) elementbutton.FireElementShower((337, 2)) elementbutton.AirElementShower((419, 2)) elementbutton.EarthElementShower((509, 2)) elementbutton.LifeElementShower((590, 2)) elementbutton.DeathElementShower((668, 2)) # Кнопки колод стихий второго игрока wzglobals.water_element_button = \ elementbutton.WaterElementButton((11, 427)) wzglobals.fire_element_button = \ elementbutton.FireElementButton((56, 427)) wzglobals.air_element_button = \ elementbutton.AirElementButton((101, 427)) wzglobals.earth_element_button = \ elementbutton.EarthElementButton((146, 427)) wzglobals.life_element_button = \ elementbutton.LifeElementButton((191, 427)) wzglobals.death_element_button = \ elementbutton.DeathElementButton((236, 427)) # Кнопки завершения хода первого и второго игрока. completethecoursebutton.CompleteTheCourseButton((758, 378)) # Окна выбора карты стихии wzglobals.cardofelementsshower = \ cardsofelementshower.CardsOfElementShower() wzglobals.nickname2 = \ nickname_window.NicknameWindow((142, 530), 'Guest') wzglobals.player2.nickname = 'Guest' wzglobals.nickname1 = \ nickname_window.NicknameWindow((22, 0), wzglobals.nick) if ai: wzglobals.player2.ai = True wzglobals.nickname2.set_nickname('Computer') wzglobals.player2.nickname = 'Computer' # стрелочки для сдвига карт в колоде # wzglobals.leftarrow = cardsofelementshower.LeftArrow((356, 489)) # wzglobals.rightarrow = cardsofelementshower.RightArrow((739, 491)) if not cli: wzglobals.gameinformationpanel.display('Battle Started') wzglobals.cli = False sockets.query = lambda x: x else: val = sockets.connect() if not val: wzglobals.gameinformationpanel.display('Cant connect to server.') menu.menu_main() wzglobals.stage = False return 0 else: wzglobals.importantmessage = important_message.MessageWindow( 'We are waiting for another player') sockets.query = sockets.query_ wzglobals.cli = True server_thread = threading.Thread(target=server_handler) server_thread.start() if not wzglobals.cli: player.switch_position() # ************************************************************************** wzglobals.screen.blit(wzglobals.background, (0, 0)) wzglobals.panels.update() wzglobals.interface.update() pygame.display.flip() sockets.query({ "action": "join", "nickname": wzglobals.nick }) # входим в игру while wzglobals.stage == 1: # if wzglobals.turn_ended and len(cards_attacking) = 0: # for cardbox in wzglobals.cardboxes: # cardbox.opposite = not cardbox.opposite for event in pygame.event.get(): wzglobals.event_handler.event(event) wzglobals.panels.update() wzglobals.interface.update() wzglobals.ccards_1.update() wzglobals.ccards_2.update() wzglobals.cardofelementsshower.update() wzglobals.cards_in_deck.update() wzglobals.card_info_group.update() wzglobals.information_group.update() # interface_up_layer.update() wzglobals.screen.blit(wzglobals.background, (0, 0)) # wzglobals.background.fill((0, 0, 0)) wzglobals.background = background_backup.copy() if wzglobals.animation == "N": for item in (animations.animations_running + animations.cards_attacking + animations.cards_dying): del item animations.animations_running = [] animations.cards_attacking = [] animations.cards_dying = [] if (not len(animations.animations_running) and len(wzglobals.attack_started)): if not wzglobals.cli: player.switch_position() for animation_running in animations.animations_running: animation_running.run() if not (len(wzglobals.attack_started) and len(wzglobals.cards_attacking)): if not wzglobals.cli: player.switch_position() pygame.display.flip() clock.tick(50)