Exemplo n.º 1
0
def run_game():
    #初始化游戏并创建一个屏幕对象
    pygame.init()
    screen_setting = settings()
    screen = pygame.display.set_mode(
        (screen_setting.screen_height, screen_setting.screen_width))
    pygame.display.set_caption("外星人射击")
    ship = Ship(screen_setting, screen)
    stats = GameStats(screen_setting)
    bills = Group()
    waixingrens = Group()
    play_button = Button(screen_setting, screen, "play")
    play_number = Play_numer(screen_setting, screen, stats.ship_number)
    #开始游戏的主循环
    while True:
        game.check(ship, screen_setting, screen, bills, stats, play_button)
        play_number.msg = stats.ship_number
        play_number.prep_msg()
        if stats.game_active:
            ship.move()
            game.creat_w(screen, screen_setting, waixingrens)
            game.bill_move(bills, waixingrens)
            game.waixingren_move(waixingrens)
            game.fail(waixingrens, ship, stats, bills, screen_setting)
        game.rescreen(screen_setting, screen, ship, bills, waixingrens,
                      play_button, stats, play_number)
Exemplo n.º 2
0
 def moveByIndex(self, indX, indY):
     if self.board[indX, indY] == 0:
         drawX = indX * self.width / float(self.size) + self.offset * 1.1
         drawY = indY * self.width / float(self.size) + self.offset * 1.1
         self.board[indX, indY] = self.colormap[self.black]
         self.canvas.create_oval(drawX - self.pitchsize,
                                 drawY - self.pitchsize,
                                 drawX + self.pitchsize,
                                 drawY + self.pitchsize,
                                 width=2,
                                 outline="black",
                                 fill=self.colorpitch[self.black])
         endPoint = check(indX, indY, self.board)
         if endPoint is not None:
             print endPoint
             drawX = endPoint[0] * self.width / float(
                 self.size) + self.offset * 1.1
             drawY = endPoint[1] * self.width / float(
                 self.size) + self.offset * 1.1
             self.canvas.create_oval(drawX - self.pitchsize / 2.0,
                                     drawY - self.pitchsize / 2.0,
                                     drawX + self.pitchsize / 2.0,
                                     drawY + self.pitchsize / 2.0,
                                     width=2,
                                     fill="red",
                                     outline=self.colorpitch[self.black])
             self.end()
         self.black = not self.black
         return True
     else:
         return False
Exemplo n.º 3
0
def loop():
    """main loop catching keyboard and other events."""
    global game_active, menu_active, current_menu
    loop_running = True
    while loop_running == True:
        pygame.time.wait(1)
        event = pygame.event.poll()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                if game_active == True:
                    game.pausegame()
            elif event.key == pygame.K_RETURN:
                if menu_active == True:
                    returned = current_menu.select()
                    if returned != None:
                        current_menu = returned
            elif event.key == pygame.K_LEFT:
                if game_active == True:
                    game.check(0)
            elif event.key == pygame.K_UP:
                if menu_active == True:
                    current_menu.moveup()
                elif game_active == True:
                    game.check(1)
            elif event.key == pygame.K_RIGHT:
                if game_active == True:
                    game.check(2)
            elif event.key == pygame.K_DOWN:
                if menu_active == True:
                    current_menu.movedown()
            elif event.key == pygame.K_s:
                if game_active == True:
                    s.say(_("Your score is {0}.").format(game.score), 1)
            elif event.key == pygame.K_l:
                if game_active == True:
                    s.say(
                        _("You have {0} lives remaining.").format(game.lives),
                        1)
            elif event.key == pygame.K_LCTRL or event.key == pygame.K_RCTRL:
                s.stop()
        if event.type == pygame.USEREVENT:
            if event.code == 1:
                game_active = True
                menu_active = False
            if event.code == 2:
                game_active = False
                menu_active = True
                current_menu = menus.abortprompt.init()
            if event.code == 3:
                game_active = False
                menu_active = True
                current_menu = menus.main_menu.init()
        if game_active == True:
            game.gamechecker()
Exemplo n.º 4
0
def loop():
	"""main loop catching keyboard and other events."""
	global game_active, menu_active, current_menu
	loop_running = True
	while loop_running == True:
		pygame.time.wait(1)
		event = pygame.event.poll ()
		if event.type == pygame.KEYDOWN:
			if event.key == pygame.K_ESCAPE:
				if game_active == True:
					game.pausegame()
			elif event.key ==  pygame.K_RETURN:
				if menu_active == True:
					returned = current_menu.select()
					if returned != None:
						current_menu = returned
			elif event.key == pygame.K_LEFT:
				if game_active == True:
					game.check(0)
			elif event.key == pygame.K_UP:
				if menu_active == True:
					current_menu.moveup()
				elif game_active == True:
					game.check(1)
			elif event.key == pygame.K_RIGHT:
				if game_active == True:
					game.check(2)
			elif event.key == pygame.K_DOWN:
				if menu_active == True:
					current_menu.movedown()
			elif event.key == pygame.K_s:
				if game_active == True:
					s.say(_("Your score is {0}.").format(game.score), 1)
			elif event.key == pygame.K_l:
				if game_active == True:
					s.say (_("You have {0} lives remaining.").format(game.lives), 1)
			elif event.key == pygame.K_LCTRL or event.key == pygame.K_RCTRL:
				s.stop()
		if event.type == pygame.USEREVENT:
			if event.code == 1:
				game_active = True
				menu_active = False
			if event.code == 2:
				game_active = False
				menu_active = True
				current_menu = menus.abortprompt.init()
			if event.code == 3:
				game_active = False
				menu_active = True
				current_menu = menus.main_menu.init()
		if game_active == True:
			game.gamechecker()
Exemplo n.º 5
0
 if userStatus[1] == '2':  #Если в игре
     var = [
         'Назад', 'Налево', 'Направо', 'Вперед'
     ]  #Идем назад налево на право (Функция Move возвращает true когда вышел из лабиринта)
     if event.text in var:
         if game.move(event.user_id, var.index(event.text)):
             data.setUserStatus(event.user_id, 'G0')
             Lsvk.messages.send(
                 user_id=event.user_id,
                 random_id=get_random_id(),
                 keyboard=keyboards.gameMenu(
                     event.user_id).get_keyboard(),
                 message='Поздравляем, ты вышел из лабиринта!')
         else:
             i = game.check(
                 event.user_id
             )  #Если после передвижения, не вышел из лабиринта осматриваемся, возвращает массив отметок
             if len(i) == 2:
                 Lsvk.messages.send(
                     user_id=event.user_id,
                     random_id=get_random_id(),
                     keyboard=keyboards.gameKeyboard(
                         event.user_id).get_keyboard(),
                     message=
                     'Ты пошел к следующей развилке и осмотрелся в поисках отметок\n'
                     + 'Cпереди:' + i[1] + '\nПод ногами:' +
                     i[0])
             if len(i) == 3:
                 Lsvk.messages.send(
                     user_id=event.user_id,
                     random_id=get_random_id(),
Exemplo n.º 6
0
def key_game_right():
	game.check(2)
Exemplo n.º 7
0
def key_game_up():
	game.check(1)
Exemplo n.º 8
0
def key_game_left():
	game.check(0)
Exemplo n.º 9
0
def isEnd(boardarray, curX, curY):
    return check(curX, curY, boardarray)