Exemple #1
0
    def __init__(self,
                 num_steps,
                 dt,
                 t_start,
                 num_people,
                 do_minute_by_minute=False):

        # create a clock.
        self.clock = temporal.Temporal()
        self.clock.dt = dt
        self.clock.t_univ = t_start
        self.clock.set_time()

        # store the initial time [minutes] in universal time
        self.t_start = t_start

        # the final time of the simulation in universal time
        self.t_end = self.t_start + num_steps * dt

        # create a home
        self.home = home.Home(self.clock)

        # list of persons
        self.people = []

        # the schedule
        self.schedule = scheduler.Scheduler(clock=self.clock, num_people=num_people, \
                                            do_minute_by_minute=do_minute_by_minute)

        return
Exemple #2
0
 def __init__(self):
     super().__init__()  # Se inicia la ventana
     #self.rasp_variables()
     self.variables()
     self.teclado = None
     self.title("Sanosil 1.0.0")  # Título de la interfaz
     self.overrideredirect(True)  # Se elimina la barra superior
     self.config(bg="white", cursor="dot")
     #self.geometry("%dx%d" % (self.winfo_screenwidth(),
     #                self.winfo_screenheight()))
     self.geometry("%dx%d" % (self.width, self.height))
     #self.actualizar_temp_humedad()
     self.frames.append(home.Home(self))
Exemple #3
0
    def set_lang(self, lang):
        self.lang = lang
        print("lang set to {}".format(self.lang))
        self.frame_welcome.destroy()

        self.frame_home = home.Home(self.master, self)
        self.frame_home.grid(row=1, column=0, sticky="news")

        self.current_frame = self.frame_explain = explain.Explain(self.master, self)
        #self.frame_explain.pack(fill=tk.BOTH, expand=True)
        self.frame_explain.grid(row=0,column=0, sticky="news")

        self.master.grid_rowconfigure(0, weight=7)
        self.master.grid_rowconfigure(1, weight=1)
Exemple #4
0
    def build(self):
        self.icon = 'images/icon.png'
        kv_file = resource_path(os.path.join('templates', 'navigation.kv'))
        main_widget = Builder.load_file(kv_file)
        episode_page_class = episode_page.Episode_Page(name='ep_page')
        home_class = home.Home(name='home')
        file_chooser_class = file_chooser.File_Chooser(name='file_chooser')
        criterea_selection_class = criterea_selection.Criterea_Selection(
            name='crits')
        main_widget.ids.scr_mngr.add_widget(criterea_selection_class)
        main_widget.ids.scr_mngr.add_widget(home_class)
        main_widget.ids.scr_mngr.add_widget(episode_page_class)
        Global.EPISODE_PAGE_CLASS = episode_page_class
        Global.HOME_CLASS = home_class

        Global.MAIN_WIDGET = main_widget

        # home_class.load_anime_list()
        return main_widget
def test_bullish_macd_cross(search):

    # Set up the Driver
    driver = driverutils.get_driver(is_windowless=True)
    driver.set_window_size(1350, 900)

    # Initialize the Pages Needed
    page = home.Home(driver)
    url = instance.predefined_scans_base + instance.searches[search]
    # Try the Test
    try:
        driver.get(url)
        assert page.load_page()
        assert page.sort_page()
        matrix = page.make_table()
        return matrix
    # If it fails, let pytest fail
    except Exception as e:
        pytest.fail()
    # Even if it passes or fails, always close the browser at the end
    finally:
        driver.close()
Exemple #6
0
if __name__ == "__main__":
    # standard libaries
    import sys
    import sqlite3

    # external libaries
    from PyQt5 import QtCore, QtGui, QtWidgets, uic

    # local imports
    from backend import database_connection as db
    import home

    # ensure the main database exists
    sql_query = """
	CREATE TABLE IF NOT EXISTS 'user-data' (
	USER_ID 	INTEGER 		PRIMARY KEY,
	USERNAME  	TEXT	(1, 100)	NOT NULL,
	PASSWORD  	TEXT    (1, 100)	NOT NULL,
	IMPORTED	INTEGER (1, 1),
	EMAIL		TEXT 	(1, 100)
	);"""
    db.c.execute(sql_query)
    db.conn.commit()

    # create mainwindow as home screen
    app = QtWidgets.QApplication(sys.argv)
    window = home.Home()
    app.exec_()
Exemple #7
0
# dependencies
from PyQt5.QtWidgets import QApplication, QStackedWidget
from PyQt5.QtCore import Qt

# local modules
import reader
import home
import constants as const
import signals

QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
app = QApplication(sys.argv)

sigs = signals.Signals()

home_window = home.Home(sigs, const.directory)
home_window.showMaximized()
reader_window = reader.Reader(sigs, )

stack = QStackedWidget()
stack.addWidget(home_window)
stack.addWidget(reader_window)
stack.setWindowTitle("Manga Viewer")


def open_reader(book: str):
    reader_window.open_book(book)
    stack.setCurrentIndex(1)


def close_reader():
Exemple #8
0
 def home(self):
     import home
     self.f.destroy()
     home.Home(self.master)
Exemple #9
0
def main():
    #初始化
    pygame.init()
    screen = pygame.display.set_mode((630,630))
    pygame.display.set_caption("坦克大战")
    #加载图片
    bg_img = pygame.image.load('./images/others/background.png')
    #时钟 用来避免循环过快
    clock = pygame.time.Clock()
    #游戏玩家数量
    num_player = 2
    #关卡
    stage = 1
    num_stage = 2
    #定义是否GG
    is_gameover = False
    #用来控制tank什么时候变换状态
    switch_time = 0
    need_switch_tank = False
    player1_moving = False
    player2_moving = False
    #坦克的射击间隔
    could_shoot = True
    shoot_space = 0
    #主循环
    while not is_gameover:
        #stage += 2
        
        #home
        myhome = home.Home()
        
        #map
        stage_map = scene.Map(stage)
        #创建精灵组
        tanksGroup = pygame.sprite.Group()
        mytanksGroup = pygame.sprite.Group()
        enemytanksGroup = pygame.sprite.Group()
        
        bulletsGroup = pygame.sprite.Group()
        mybulletsGroup = pygame.sprite.Group()
        enemybulletsGroup = pygame.sprite.Group()
        
        #创建player1实例并加入精灵组
        tank_player1 = tanks.myTank(1)
        tanksGroup.add(tank_player1)
        mytanksGroup.add(tank_player1)
        
        tank_player2 = tanks.myTank(2)
        tanksGroup.add(tank_player2)
        mytanksGroup.add(tank_player2)
        while True:
            if is_gameover :
                break
            #如果关卡结束 则is_gameover = False  break
            
            #当点击叉叉时关闭该游戏
            for event in pygame.event.get():
                if event.type == QUIT:
                    exit()
            #背景
            screen.blit(bg_img,(0,0))
            #home
            screen.blit(myhome.home,myhome.rect)
            #石头墙 
            for each in stage_map.brickGroup:
                screen.blit(each.brick,each.rect)
            #钢墙
            for each in stage_map.ironGroup:
                screen.blit(each.iron,each.rect)
            #冰
            for each in stage_map.iceGroup:
                screen.blit(each.ice,each.rect)
            #河流
            for each in stage_map.riverGroup:
                screen.blit(each.river,each.rect)
            #树
            for each in stage_map.treeGroup:
                screen.blit(each.tree,each.rect)
            #设置每刷新n次tank的状态就变一次
            switch_time += 1
            if switch_time == 5:
                switch_time = 0
                need_switch_tank = not need_switch_tank
            #刷新射击间隔
            shoot_space += 1
            if shoot_space == 15:
                could_shoot = True
                shoot_space = 0
            #获得玩家的键盘输入值
            key_pressed = pygame.key.get_pressed()
            #player1 
            #WSAD -> 上下左右
            #空格键射击
            if key_pressed[pygame.K_w]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_up(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True  #在这里每次都把moving改成True 在blit之后又改为False 可以实现moving的值交替循环 使得每次刷新都blit不一样的贴图 以达成动画效果 
            elif key_pressed[pygame.K_s]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_down(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_a]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_left(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_d]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_right(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            if key_pressed[pygame.K_SPACE]:
                if could_shoot:
                    tank_player1.shoot(mybulletsGroup)
                    could_shoot = False
            #player2
            #上下左右键控制
            #小键盘'0'键射击
            if key_pressed[pygame.K_UP]:
                tanksGroup.remove(tank_player2)
                tank_player2.move_up(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player2)
                player2_moving = True  #在这里每次都把moving改成True 在blit之后又改为False 可以实现moving的值交替循环 使得每次刷新都blit不一样的贴图 以达成动画效果 
            elif key_pressed[pygame.K_DOWN]:
                tanksGroup.remove(tank_player2)
                tank_player2.move_down(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player2)
                player2_moving = True
            elif key_pressed[pygame.K_LEFT]:
                tanksGroup.remove(tank_player2)
                tank_player2.move_left(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player2)
                player2_moving = True
            elif key_pressed[pygame.K_RIGHT]:
                tanksGroup.remove(tank_player2)
                tank_player2.move_right(tanksGroup,stage_map.brickGroup,stage_map.ironGroup,myhome)
                tanksGroup.add(tank_player2)
                player2_moving = True
            if key_pressed[pygame.K_KP0]:
                if could_shoot:
                    tank_player2.shoot(mybulletsGroup)
                    could_shoot = False
            # blit我方坦克
            if need_switch_tank and player1_moving:
                screen.blit(tank_player1.tank_0, (tank_player1.rect.left, tank_player1.rect.top))
                player1_moving = False
            else:
                screen.blit(tank_player1.tank_1, (tank_player1.rect.left, tank_player1.rect.top))
                
            if num_player > 1:
                if need_switch_tank and player2_moving:
                    screen.blit(tank_player2.tank_0, (tank_player2.rect.left, tank_player2.rect.top))
                    player2_moving = False
                else:
                    screen.blit(tank_player2.tank_1, (tank_player2.rect.left, tank_player2.rect.top))
            
            #我方子弹
            for each_bullet in mybulletsGroup:
                if each_bullet.being == True:
                    each_bullet.move()
                    screen.blit(each_bullet.bullet,each_bullet.rect)
                    #碰撞土墙brick
                    if pygame.sprite.spritecollide(each_bullet, stage_map.brickGroup, True, None):
                        each_bullet.being = False
                else :
                    mybulletsGroup.remove(each_bullet)
            #循环的最后一个操作:刷新屏幕
            pygame.display.flip()
            clock.tick(60)
Exemple #10
0
def main():
    paths = home.Home().home()
    return render_template('home.html', paths=paths)
Exemple #11
0
def main():
    # 初始化
    pygame.init()
    pygame.mixer.init()
    screen = pygame.display.set_mode((630, 630))
    pygame.display.set_caption("坦克大战-出品人:钟洪")
    # 加载图片
    bg_img = pygame.image.load("./images/others/background.png")
    # 加载音效
    add_sound = pygame.mixer.Sound("./audios/add.wav")
    add_sound.set_volume(1)
    bang_sound = pygame.mixer.Sound("./audios/bang.wav")
    bang_sound.set_volume(1)
    blast_sound = pygame.mixer.Sound("./audios/blast.wav")
    blast_sound.set_volume(1)
    fire_sound = pygame.mixer.Sound("./audios/fire.wav")
    fire_sound.set_volume(1)
    Gunfire_sound = pygame.mixer.Sound("./audios/Gunfire.wav")
    Gunfire_sound.set_volume(1)
    hit_sound = pygame.mixer.Sound("./audios/hit.wav")
    hit_sound.set_volume(1)
    start_sound = pygame.mixer.Sound("./audios/start.wav")
    start_sound.set_volume(1)
    # 开始界面
    num_player = show_start_interface(screen, 630, 630)
    # 播放游戏开始的音乐
    start_sound.play()
    # 关卡
    stage = 0
    num_stage = 2
    # 游戏是否结束
    is_gameover = False
    # 时钟
    clock = pygame.time.Clock()
    # 主循环
    while not is_gameover:
        # 关卡
        stage += 1
        if stage > num_stage:
            break
        show_switch_stage(screen, 630, 630, stage)
        # 该关卡坦克总数量
        enemytanks_total = min(stage * 18, 5)
        # 场上存在的敌方坦克总数量
        enemytanks_now = 0
        # 场上可以存在的敌方坦克总数量
        enemytanks_now_max = min(max(stage * 2, 4), 2)
        # 精灵组
        tanksGroup = pygame.sprite.Group()
        mytanksGroup = pygame.sprite.Group()
        enemytanksGroup = pygame.sprite.Group()
        bulletsGroup = pygame.sprite.Group()
        mybulletsGroup = pygame.sprite.Group()
        enemybulletsGroup = pygame.sprite.Group()
        myfoodsGroup = pygame.sprite.Group()
        # 自定义事件
        # 	-生成敌方坦克事件
        genEnemyEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(genEnemyEvent, 100)
        # 	-敌方坦克静止恢复事件
        recoverEnemyEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(recoverEnemyEvent, 8000)
        # 	-我方坦克无敌恢复事件
        noprotectMytankEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(noprotectMytankEvent, 8000)
        # 关卡地图
        map_stage = scene.Map(stage)
        # 我方坦克
        tank_player1 = tanks.myTank(1)
        tanksGroup.add(tank_player1)
        mytanksGroup.add(tank_player1)
        if num_player > 1:
            tank_player2 = tanks.myTank(2)
            tanksGroup.add(tank_player2)
            mytanksGroup.add(tank_player2)
        is_switch_tank = True
        player1_moving = False
        player2_moving = False
        # 为了轮胎的动画效果
        time = 0
        # 敌方坦克
        for i in range(0, 3):
            if enemytanks_total > 0:
                enemytank = tanks.enemyTank(i)
                tanksGroup.add(enemytank)
                enemytanksGroup.add(enemytank)
                enemytanks_now += 1
                enemytanks_total -= 1
        # 大本营
        myhome = home.Home()
        # 出场特效
        appearance_img = pygame.image.load(
            "./images/others/appear.png").convert_alpha()
        appearances = []
        appearances.append(appearance_img.subsurface((0, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((48, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((96, 0), (48, 48)))
        # 关卡主循环
        while True:
            if is_gameover is True:
                break
            if enemytanks_total < 1 and enemytanks_now < 1:
                is_gameover = False
                break
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == genEnemyEvent:
                    if enemytanks_total > 0:
                        if enemytanks_now < enemytanks_now_max:
                            enemytank = tanks.enemyTank()
                            if not pygame.sprite.spritecollide(
                                    enemytank, tanksGroup, False, None):
                                tanksGroup.add(enemytank)
                                enemytanksGroup.add(enemytank)
                                enemytanks_now += 1
                                enemytanks_total -= 1
                if event.type == recoverEnemyEvent:
                    for each in enemytanksGroup:
                        each.can_move = True
                if event.type == noprotectMytankEvent:
                    for each in mytanksGroup:
                        mytanksGroup.protected = False
            # 检查用户键盘操作
            key_pressed = pygame.key.get_pressed()
            # 玩家一
            # WSAD -> 上下左右
            # 空格键射击
            if key_pressed[pygame.K_w]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_up(tanksGroup, map_stage.brickGroup,
                                     map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_s]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_down(tanksGroup, map_stage.brickGroup,
                                       map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_a]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_left(tanksGroup, map_stage.brickGroup,
                                       map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_d]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_right(tanksGroup, map_stage.brickGroup,
                                        map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_SPACE]:
                if not tank_player1.bullet.being:
                    fire_sound.play()
                    tank_player1.shoot()
            # 玩家二
            # ↑↓←→ -> 上下左右
            # 小键盘0键射击
            if num_player > 1:
                if key_pressed[pygame.K_UP]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_up(tanksGroup, map_stage.brickGroup,
                                         map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_DOWN]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_down(tanksGroup, map_stage.brickGroup,
                                           map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_LEFT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_left(tanksGroup, map_stage.brickGroup,
                                           map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_RIGHT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_right(tanksGroup, map_stage.brickGroup,
                                            map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_KP0]:
                    if not tank_player2.bullet.being:
                        fire_sound.play()
                        tank_player2.shoot()
            # 背景
            screen.blit(bg_img, (0, 0))
            # 石头墙
            for each in map_stage.brickGroup:
                screen.blit(each.brick, each.rect)
            # 钢墙
            for each in map_stage.ironGroup:
                screen.blit(each.iron, each.rect)
            # 冰
            for each in map_stage.iceGroup:
                screen.blit(each.ice, each.rect)
            # 河流
            for each in map_stage.riverGroup:
                screen.blit(each.river, each.rect)
            # 树
            for each in map_stage.treeGroup:
                screen.blit(each.tree, each.rect)
            time += 1
            if time == 5:
                time = 0
                is_switch_tank = not is_switch_tank
            # 我方坦克
            if tank_player1 in mytanksGroup:
                if is_switch_tank and player1_moving:
                    screen.blit(
                        tank_player1.tank_0,
                        (tank_player1.rect.left, tank_player1.rect.top))
                    player1_moving = False
                else:
                    screen.blit(
                        tank_player1.tank_1,
                        (tank_player1.rect.left, tank_player1.rect.top))
                if tank_player1.protected:
                    screen.blit(
                        tank_player1.protected_mask1,
                        (tank_player1.rect.left, tank_player1.rect.top))
            if num_player > 1:
                if tank_player2 in mytanksGroup:
                    if is_switch_tank and player2_moving:
                        screen.blit(
                            tank_player2.tank_0,
                            (tank_player2.rect.left, tank_player2.rect.top))
                        player1_moving = False
                    else:
                        screen.blit(
                            tank_player2.tank_1,
                            (tank_player2.rect.left, tank_player2.rect.top))
                    if tank_player2.protected:
                        screen.blit(
                            tank_player1.protected_mask1,
                            (tank_player2.rect.left, tank_player2.rect.top))
            # 敌方坦克
            for each in enemytanksGroup:
                # 出生特效
                if each.born:
                    if each.times > 0:
                        each.times -= 1
                        if each.times <= 10:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 20:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 30:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 40:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 50:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 60:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 70:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 80:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 90:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                    else:
                        each.born = False
                else:
                    if is_switch_tank:
                        screen.blit(each.tank_0,
                                    (each.rect.left, each.rect.top))
                    else:
                        screen.blit(each.tank_1,
                                    (each.rect.left, each.rect.top))
                    if each.can_move:
                        tanksGroup.remove(each)
                        each.move(tanksGroup, map_stage.brickGroup,
                                  map_stage.ironGroup, myhome)
                        tanksGroup.add(each)
            # 我方子弹
            for tank_player in mytanksGroup:
                if tank_player.bullet.being:
                    tank_player.bullet.move()
                    screen.blit(tank_player.bullet.bullet,
                                tank_player.bullet.rect)
                    # 子弹碰撞敌方子弹
                    for each in enemybulletsGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(
                                    tank_player.bullet, each):
                                tank_player.bullet.being = False
                                each.being = False
                                enemybulletsGroup.remove(each)
                                break
                        else:
                            enemybulletsGroup.remove(each)
                    # 子弹碰撞敌方坦克
                    for each in enemytanksGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(
                                    tank_player.bullet, each):
                                if each.is_red == True:
                                    myfood = food.Food()
                                    myfood.generate()
                                    myfoodsGroup.add(myfood)
                                    each.is_red = False
                                each.blood -= 1
                                each.color -= 1
                                if each.blood < 0:
                                    bang_sound.play()
                                    each.being = False
                                    enemytanksGroup.remove(each)
                                    enemytanks_now -= 1
                                    tanksGroup.remove(each)
                                else:
                                    each.reload()
                                tank_player.bullet.being = False
                                break
                        else:
                            enemytanksGroup.remove(each)
                            tanksGroup.remove(each)
                    # 子弹碰撞石头墙
                    if pygame.sprite.spritecollide(tank_player.bullet,
                                                   map_stage.brickGroup, True,
                                                   None):
                        tank_player.bullet.being = False
                    '''
					# 等价方案(更科学点)
					for each in map_stage.brickGroup:
						if pygame.sprite.collide_rect(tank_player.bullet, each):
							tank_player.bullet.being = False
							each.being = False
							map_stage.brickGroup.remove(each)
							break
					'''
                    # 子弹碰钢墙
                    if tank_player.bullet.stronger:
                        if pygame.sprite.spritecollide(tank_player.bullet,
                                                       map_stage.ironGroup,
                                                       True, None):
                            tank_player.bullet.being = False
                    else:
                        if pygame.sprite.spritecollide(tank_player.bullet,
                                                       map_stage.ironGroup,
                                                       False, None):
                            tank_player.bullet.being = False
                    '''
					# 等价方案(更科学点)
					for each in map_stage.ironGroup:
						if pygame.sprite.collide_rect(tank_player.bullet, each):
							tank_player.bullet.being = False
							if tank_player.bullet.stronger:
								each.being = False
								map_stage.ironGroup.remove(each)
							break
					'''
                    # 子弹碰大本营
                    if pygame.sprite.collide_rect(tank_player.bullet, myhome):
                        tank_player.bullet.being = False
                        myhome.set_dead()
                        is_gameover = True
            # 敌方子弹
            for each in enemytanksGroup:
                if each.being:
                    if each.can_move and not each.bullet.being:
                        enemybulletsGroup.remove(each.bullet)
                        each.shoot()
                        enemybulletsGroup.add(each.bullet)
                    if not each.born:
                        if each.bullet.being:
                            each.bullet.move()
                            screen.blit(each.bullet.bullet, each.bullet.rect)
                            # 子弹碰撞我方坦克
                            for tank_player in mytanksGroup:
                                if pygame.sprite.collide_rect(
                                        each.bullet, tank_player):
                                    if not tank_player.protected:
                                        bang_sound.play()
                                        tank_player.life -= 1
                                        if tank_player.life < 0:
                                            mytanksGroup.remove(tank_player)
                                            tanksGroup.remove(tank_player)
                                            if len(mytanksGroup) < 1:
                                                is_gameover = True
                                        else:
                                            tank_player.reset()
                                    each.bullet.being = False
                                    enemybulletsGroup.remove(each.bullet)
                                    break
                            # 子弹碰撞石头墙
                            if pygame.sprite.spritecollide(
                                    each.bullet, map_stage.brickGroup, True,
                                    None):
                                each.bullet.being = False
                                enemybulletsGroup.remove(each.bullet)
                            '''
							# 等价方案(更科学点)
							for one in map_stage.brickGroup:
								if pygame.sprite.collide_rect(each.bullet, one):
									each.bullet.being = False
									one.being = False
									enemybulletsGroup.remove(one)
									break
							'''
                            # 子弹碰钢墙
                            if each.bullet.stronger:
                                if pygame.sprite.spritecollide(
                                        each.bullet, map_stage.ironGroup, True,
                                        None):
                                    each.bullet.being = False
                            else:
                                if pygame.sprite.spritecollide(
                                        each.bullet, map_stage.ironGroup,
                                        False, None):
                                    each.bullet.being = False
                            '''
							# 等价方案(更科学点)
							for one in map_stage.ironGroup:
								if pygame.sprite.collide_rect(each.bullet, one):
									each.bullet.being = False
									if each.bullet.stronger:
										one.being = False
										map_stage.ironGroup.remove(one)
									break
							'''
                            # 子弹碰大本营
                            if pygame.sprite.collide_rect(each.bullet, myhome):
                                each.bullet.being = False
                                myhome.set_dead()
                                is_gameover = True
                else:
                    enemytanksGroup.remove(each)
                    tanksGroup.remove(each)
            # 家
            screen.blit(myhome.home, myhome.rect)
            # 食物
            for myfood in myfoodsGroup:
                if myfood.being and myfood.time > 0:
                    screen.blit(myfood.food, myfood.rect)
                    myfood.time -= 1
                    for tank_player in mytanksGroup:
                        if pygame.sprite.collide_rect(tank_player, myfood):
                            # 消灭当前所有敌人
                            if myfood.kind == 0:
                                for _ in enemytanksGroup:
                                    bang_sound.play()
                                enemytanksGroup = pygame.sprite.Group()
                                enemytanks_total -= enemytanks_now
                                enemytanks_now = 0
                            # 敌人静止
                            if myfood.kind == 1:
                                for each in enemytanksGroup:
                                    each.can_move = False
                            # 子弹增强
                            if myfood.kind == 2:
                                add_sound.play()
                                tank_player.bullet.stronger = True
                            # 使得大本营的墙变为钢板
                            if myfood.kind == 3:
                                map_stage.protect_home()
                            # 坦克获得一段时间的保护罩
                            if myfood.kind == 4:
                                add_sound.play()
                                for tank_player in mytanksGroup:
                                    tank_player.protected = True
                            # 坦克升级
                            if myfood.kind == 5:
                                add_sound.play()
                                tank_player.up_level()
                            # 坦克生命+1
                            if myfood.kind == 6:
                                add_sound.play()
                                tank_player.life += 1
                            myfood.being = False
                            myfoodsGroup.remove(myfood)
                            break
                else:
                    myfood.being = False
                    myfoodsGroup.remove(myfood)
            pygame.display.flip()
            clock.tick(60)
    if not is_gameover:
        show_end_interface(screen, 630, 630, True)
    else:
        show_end_interface(screen, 630, 630, False)
Exemple #12
0
    def main(self):
        pygame.init()
        pygame.mixer.init()
            
        pygame.display.set_caption("坦克大战")       
        # 背景
        backgroundImage = pygame.image.load("image/background.png")
        self.startInterface(630, 630)
        # 游戏开始的时间
        time1 = pygame.time.get_ticks()
        # 游戏主循环
        while not self.isOver:
            self.stage += 1
            if self.stage > self.totalStages:
                break
            if self.isDifficult:
                self.stage = 10
            self.switchStage(630, 630)
            # 音效
            gameMusic = music.Music()
            if self.closeMusic:
                gameMusic.closeMusic()
            gameMusic.start()
            #该关卡敌方坦克总数量
            totalEnemyTanks = 19 + self.stage
            #场上存在的敌方坦克总数量
            existEnemyTanks = 0
            #场上可以存在的敌方坦克总数量
            canExistEnemyTanks = min(max(self.stage * 2, 4), 8)
            #定义精灵组:坦克,我方坦克,敌方坦克,敌方子弹
            self.allTankGroup = pygame.sprite.Group()
            self.mytankGroup = pygame.sprite.Group()
            self.allEnemyGroup = pygame.sprite.Group()
            self.mediumEnemyGroup = pygame.sprite.Group() #中型坦克
            self.heavyEnemyGroup = pygame.sprite.Group()  #重型坦克
            self.lightEnemyGroup = pygame.sprite.Group()  #轻型坦克
            self.enemyBulletGroup = pygame.sprite.Group()
        
            #创建地图 
            gameMap = block.Map(self.stage)
            #创建我方坦克
            myTank1 = myTank.MyTank(1)
            self.allTankGroup.add(myTank1)
            self.mytankGroup.add(myTank1)
            if self.playerNum != 1:
                myTank2 = myTank.MyTank(2)
                self.allTankGroup.add(myTank2)
                self.mytankGroup.add(myTank2)
            # 创建敌方坦克 
            for i in range(1, 4):
                if totalEnemyTanks > 0:
                    totalEnemyTanks -= 1
                    existEnemyTanks += 1
                    enemy = enemyTank.EnemyTank(i)
                    self.allTankGroup.add(enemy)
                    self.allEnemyGroup.add(enemy)
                    if enemy.kind == 2:
                        self.mediumEnemyGroup.add(enemy)
                        continue
                    if enemy.kind == 3:
                        self.heavyEnemyGroup.add(enemy)
                        continue
                    self.lightEnemyGroup.add(enemy)
            
            
            
            
            # 自定义事件
            # 创建敌方坦克延迟200
            DELAYEVENT = pygame.constants.USEREVENT
            pygame.time.set_timer(DELAYEVENT, 200)
            # 创建敌方子弹延迟1000
            ENEMYBULLETNOTCOOLINGEVENT = pygame.constants.USEREVENT + 1
            pygame.time.set_timer(ENEMYBULLETNOTCOOLINGEVENT, 1000)
            # 创建我方子弹延迟200
            MYBULLETNOTCOOLINGEVENT = pygame.constants.USEREVENT + 2
            pygame.time.set_timer(MYBULLETNOTCOOLINGEVENT, 200)

            clock = pygame.time.Clock()
            # 大本营
            myhome = home.Home()
            # 关卡主循环
            while True:
                if self.isOver:
                    break
                if totalEnemyTanks < 1 and existEnemyTanks < 1:
                    self.isOver = False
                    break   
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        pygame.quit()
                        sys.exit()
                    
                    # 我方子弹冷却事件
                    if event.type == MYBULLETNOTCOOLINGEVENT:
                        myTank1.bulletNotCooling = True
                        if self.playerNum != 1:
                            myTank2.bulletNotCooling = True
                        
                    # 敌方子弹冷却事件
                    if event.type == ENEMYBULLETNOTCOOLINGEVENT:
                        for each in self.allEnemyGroup:
                            each.bulletNotCooling = True
                    
                    # 创建敌方坦克
                    if event.type == DELAYEVENT:
                        if totalEnemyTanks > 0:
                            if existEnemyTanks < canExistEnemyTanks: 
                                enemy = enemyTank.EnemyTank()
                                if pygame.sprite.spritecollide(enemy, self.allTankGroup, False, None):
                                    break
                                self.allEnemyGroup.add(enemy)
                                self.allTankGroup.add(enemy)
                                existEnemyTanks += 1
                                if enemy.kind == 2:
                                    self.mediumEnemyGroup.add(enemy)
                                elif enemy.kind == 3:
                                    self.heavyEnemyGroup.add(enemy)
                                else:
                                    self.lightEnemyGroup.add(enemy)           
                        
                # 检查用户的键盘操作
                key_pressed = pygame.key.get_pressed()
                # 玩家一的移动操作
                myTank1.move1(self.allTankGroup, gameMap.brickGroup, gameMap.ironGroup)
                if key_pressed[pygame.K_SPACE]:
                    if not myTank1.bullet.life and myTank1.bulletNotCooling:
                        gameMusic.fire()
                        myTank1.shoot()
                        myTank1.bulletNotCooling = False
                        
                # 玩家二的移动操作
                if self.playerNum != 1:
                    myTank2.move2(self.allTankGroup, gameMap.brickGroup, gameMap.ironGroup)
                    if key_pressed[pygame.K_KP0]:
                        if not myTank2.bullet.life and myTank2.bulletNotCooling:
                            gameMusic.fire()
                            myTank2.shoot()
                            myTank2.bulletNotCooling = False 
                            
                # 实现各种场景
                self.screen.blit(backgroundImage, (0, 0))
                for each in gameMap.brickGroup:
                    self.screen.blit(each.image, each.rect)        
                for each in gameMap.ironGroup:
                    self.screen.blit(each.image, each.rect)     
                for each in gameMap.grassGroup:
                    self.screen.blit(each.image, each.rect)   
                self.screen.blit(myhome.home, myhome.rect) 
                # 我方坦克1
                print(myTank1.life)
                if myTank1.life > 0:
                    self.screen.blit(myTank1.tank_R0, (myTank1.rect.left, myTank1.rect.top))
                # 我方坦克2
                if self.playerNum != 1: 
                    if myTank2.life > 0:
                        self.screen.blit(myTank2.tank_R0, (myTank2.rect.left, myTank2.rect.top))
                # 敌方坦克
                enemy.cartoon()
                enemy.creatImage(self.allEnemyGroup, self.allTankGroup, self.screen, gameMap.brickGroup, gameMap.ironGroup)
            
                        
                # 我方坦克1子弹
                if myTank1.createBulletImage(self.screen, self.enemyBulletGroup, self.heavyEnemyGroup, self.mediumEnemyGroup, self.lightEnemyGroup, gameMap.brickGroup, gameMap.ironGroup, myhome, gameMusic) == -1:
                    existEnemyTanks -= 1
                    totalEnemyTanks -= 1
                
                # 我方坦克2子弹
                if self.playerNum != 1:
                    if myTank2.createBulletImage(self.screen, self.enemyBulletGroup, self.heavyEnemyGroup, self.mediumEnemyGroup, self.lightEnemyGroup, gameMap.brickGroup, gameMap.ironGroup, myhome, gameMusic) == -1:
                        existEnemyTanks -= 1
                        totalEnemyTanks -= 1

                # 绘制敌人子弹
                if self.playerNum == 1:
                    enemy.createBulletImage(self.screen, self.allEnemyGroup, self.enemyBulletGroup, myTank1, gameMusic, self.playerNum, gameMap, myhome)
                    if myTank1.life == 0 or myhome.alive == False:
                        self.isOver = True
                    
                if self.playerNum != 1:
                    enemy.createBulletImage(self.screen, self.allEnemyGroup, self.enemyBulletGroup, myTank1, gameMusic, self.playerNum, gameMap, myhome, myTank2)
                    if myTank1.life == 0 and myTank2.life == 0:
                        self.isOver = True
                    if myhome.alive == False:
                        self.isOver = True
                
                pygame.display.flip()
                clock.tick(60)
        time2 = pygame.time.get_ticks()
        self.time = time2 - time1
        if not self.isOver:
            self.endInterface(630, 630, True, self.time)
        else:
            self.endInterface(630, 630, False, self.time)
Exemple #13
0
def main():
    # initialization
    pygame.init()
    pygame.mixer.init()
    screen = pygame.display.set_mode((630, 630))
    pygame.display.set_caption("Tank War []=")
    # Loading image
    bg_img = pygame.image.load("./images/others/background.png")
    heart_img = pygame.image.load("./images/heart.png")
    # Load sound
    add_sound = pygame.mixer.Sound("./audios/add.wav")
    add_sound.set_volume(1)
    bang_sound = pygame.mixer.Sound("./audios/bang.wav")
    bang_sound.set_volume(1)
    blast_sound = pygame.mixer.Sound("./audios/blast.wav")
    blast_sound.set_volume(1)
    fire_sound = pygame.mixer.Sound("./audios/fire.wav")
    fire_sound.set_volume(1)
    Gunfire_sound = pygame.mixer.Sound("./audios/Gunfire.wav")
    Gunfire_sound.set_volume(1)
    hit_sound = pygame.mixer.Sound("./audios/hit.wav")
    hit_sound.set_volume(1)
    start_sound = pygame.mixer.Sound("./audios/start.wav")
    start_sound.set_volume(1)
    # Start interface
    num_player = show_start_interface(screen, 630, 630)
    # Play the music at the beginning of the game
    start_sound.play()
    # Level
    stage = 0
    num_stage = 2
    dead = 0
    # Whether the game is over
    is_gameover = False
    # clock
    clock = pygame.time.Clock()
    # Main loop
    while not is_gameover:
        # Level
        stage += 1
        if stage > num_stage:
            break
        show_switch_stage(screen, 630, 630, stage)
        # The total number of checkpoint tanks
        enemytanks_total = min(stage * 18, 80)
        # The total number of enemy tanks present on the field
        enemytanks_now = 0
        # The total number of enemy tanks that can exist on the field
        enemytanks_now_max = min(max(stage * 2, 4), 8)
        # Elf group
        tanksGroup = pygame.sprite.Group()
        mytanksGroup = pygame.sprite.Group()
        enemytanksGroup = pygame.sprite.Group()
        bulletsGroup = pygame.sprite.Group()
        mybulletsGroup = pygame.sprite.Group()
        enemybulletsGroup = pygame.sprite.Group()
        myfoodsGroup = pygame.sprite.Group()
        # Custom event
        # 	- Generate enemy tank events
        genEnemyEvent = pygame.constants.USEREVENT + 0
        pygame.time.set_timer(genEnemyEvent, 100)
        # 	- enemy tank stationary recovery event
        recoverEnemyEvent = pygame.constants.USEREVENT + 1
        pygame.time.set_timer(recoverEnemyEvent, 8000)
        # 	- Our tank invincible recovery event
        noprotectMytankEvent = pygame.constants.USEREVENT + 2
        pygame.time.set_timer(noprotectMytankEvent, 8000)
        # Level map
        map_stage = scene.Map(stage)
        # Our tank
        tank_player1 = tanks.myTank(1)
        tanksGroup.add(tank_player1)
        mytanksGroup.add(tank_player1)
        if num_player > 1:
            tank_player2 = tanks.myTank(2)
            tanksGroup.add(tank_player2)
            mytanksGroup.add(tank_player2)
        is_switch_tank = True
        player1_moving = False
        player2_moving = False
        # For the animation of the tire
        time = 0
        # Enemy tank
        for i in range(0, 3):
            if enemytanks_total > 0:
                enemytank = tanks.enemyTank(i)
                tanksGroup.add(enemytank)
                enemytanksGroup.add(enemytank)
                enemytanks_now += 1
                enemytanks_total -= 1
        # Base camp
        myhome = home.Home()
        # Appearance effects
        appearance_img = pygame.image.load(
            "./images/others/appear.png").convert_alpha()
        appearances = []
        appearances.append(appearance_img.subsurface((0, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((48, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((96, 0), (48, 48)))
        # Level main loop
        while True:
            if is_gameover is True:
                break
            if enemytanks_total < 1 and enemytanks_now < 1:
                is_gameover = False
                break
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        quit()
                if event.type == genEnemyEvent:
                    if enemytanks_total > 0:
                        if enemytanks_now < enemytanks_now_max:
                            enemytank = tanks.enemyTank()
                            if not pygame.sprite.spritecollide(
                                    enemytank, tanksGroup, False, None):
                                tanksGroup.add(enemytank)
                                enemytanksGroup.add(enemytank)
                                enemytanks_now += 1
                                enemytanks_total -= 1
                if event.type == recoverEnemyEvent:
                    for each in enemytanksGroup:
                        each.can_move = True
                if event.type == noprotectMytankEvent:
                    for each in mytanksGroup:
                        mytanksGroup.protected = False
            # Check user keyboard operations
            key_pressed = pygame.key.get_pressed()
            # Player one
            # WASD -> up and down
            # Space bar shooting
            if key_pressed[pygame.K_w]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_up(tanksGroup, map_stage.brickGroup,
                                     map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_s]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_down(tanksGroup, map_stage.brickGroup,
                                       map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_a]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_left(tanksGroup, map_stage.brickGroup,
                                       map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_d]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_right(tanksGroup, map_stage.brickGroup,
                                        map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_SPACE]:
                if not tank_player1.bullet.being:
                    fire_sound.play()
                    tank_player1.shoot()
            # Player teo
            # ↑↓←→ -> Up, down, left and right
            # Keypad 0 key shot
            if num_player > 1:
                if key_pressed[pygame.K_UP]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_up(tanksGroup, map_stage.brickGroup,
                                         map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_DOWN]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_down(tanksGroup, map_stage.brickGroup,
                                           map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_LEFT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_left(tanksGroup, map_stage.brickGroup,
                                           map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_RIGHT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_right(tanksGroup, map_stage.brickGroup,
                                            map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_KP0]:
                    if not tank_player2.bullet.being:
                        fire_sound.play()
                        tank_player2.shoot()
            # background
            screen.blit(bg_img, (0, 0))
            # Stone wall
            for each in map_stage.brickGroup:
                screen.blit(each.brick, each.rect)
            # Steel wall
            for each in map_stage.ironGroup:
                screen.blit(each.iron, each.rect)
            time += 1
            if time == 5:
                time = 0
                is_switch_tank = not is_switch_tank
            # Our tank
            if tank_player1 in mytanksGroup:
                if is_switch_tank and player1_moving:
                    screen.blit(
                        tank_player1.tank_0,
                        (tank_player1.rect.left, tank_player1.rect.top))
                    player1_moving = False
                else:
                    screen.blit(
                        tank_player1.tank_1,
                        (tank_player1.rect.left, tank_player1.rect.top))
                if tank_player1.protected:
                    screen.blit(
                        tank_player1.protected_mask1,
                        (tank_player1.rect.left, tank_player1.rect.top))
            if num_player > 1:
                if tank_player2 in mytanksGroup:
                    if is_switch_tank and player2_moving:
                        screen.blit(
                            tank_player2.tank_0,
                            (tank_player2.rect.left, tank_player2.rect.top))
                        player1_moving = False
                    else:
                        screen.blit(
                            tank_player2.tank_1,
                            (tank_player2.rect.left, tank_player2.rect.top))
                    if tank_player2.protected:
                        screen.blit(
                            tank_player1.protected_mask1,
                            (tank_player2.rect.left, tank_player2.rect.top))
            # Enemy tank
            for each in enemytanksGroup:
                # Birth effect
                if each.born:
                    if each.times > 0:
                        each.times -= 1
                        if each.times <= 10:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 20:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 30:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 40:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 50:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 60:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 70:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 80:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 90:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                    else:
                        each.born = False
                else:
                    if is_switch_tank:
                        screen.blit(each.tank_0,
                                    (each.rect.left, each.rect.top))
                    else:
                        screen.blit(each.tank_1,
                                    (each.rect.left, each.rect.top))
                    if each.can_move:
                        tanksGroup.remove(each)
                        each.move(tanksGroup, map_stage.brickGroup,
                                  map_stage.ironGroup, myhome)
                        tanksGroup.add(each)
            # Our bullets
            for tank_player in mytanksGroup:
                if tank_player.bullet.being:
                    tank_player.bullet.move()
                    screen.blit(tank_player.bullet.bullet,
                                tank_player.bullet.rect)
                    # Bullet colliding with enemy bullets
                    for each in enemybulletsGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(
                                    tank_player.bullet, each):
                                tank_player.bullet.being = False
                                each.being = False
                                enemybulletsGroup.remove(each)
                                break
                        else:
                            enemybulletsGroup.remove(each)
                    # Bullet colliding with enemy tank
                    for each in enemytanksGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(
                                    tank_player.bullet, each):
                                if each.is_red == True:
                                    myfood = food.Food()
                                    myfood.generate()
                                    myfoodsGroup.add(myfood)
                                    each.is_red = False
                                each.blood -= 1
                                each.color -= 1
                                if each.blood < 0:
                                    bang_sound.play()
                                    each.being = False
                                    enemytanksGroup.remove(each)
                                    enemytanks_now -= 1
                                    tanksGroup.remove(each)
                                else:
                                    each.reload()
                                tank_player.bullet.being = False
                                break
                        else:
                            enemytanksGroup.remove(each)
                            tanksGroup.remove(each)
                    # Bullet collision stone wall
                    if pygame.sprite.spritecollide(tank_player.bullet,
                                                   map_stage.brickGroup, True,
                                                   None):
                        tank_player.bullet.being = False
                    # Bullet hitting steel wall
                    if tank_player.bullet.stronger:
                        if pygame.sprite.spritecollide(tank_player.bullet,
                                                       map_stage.ironGroup,
                                                       True, None):
                            tank_player.bullet.being = False
                    else:
                        if pygame.sprite.spritecollide(tank_player.bullet,
                                                       map_stage.ironGroup,
                                                       False, None):
                            tank_player.bullet.being = False
                    # Bullet hits the base camp
                    if pygame.sprite.collide_rect(tank_player.bullet, myhome):
                        tank_player.bullet.being = False
                        myhome.set_dead()
                        is_gameover = True
            # Enemy bullet
            for each in enemytanksGroup:
                if each.being:
                    if each.can_move and not each.bullet.being:
                        enemybulletsGroup.remove(each.bullet)
                        each.shoot()
                        enemybulletsGroup.add(each.bullet)
                    if not each.born:
                        if each.bullet.being:
                            each.bullet.move()
                            screen.blit(each.bullet.bullet, each.bullet.rect)
                            # Bullet colliding with our tank
                            for tank_player in mytanksGroup:
                                if pygame.sprite.collide_rect(
                                        each.bullet, tank_player):
                                    if not tank_player.protected:
                                        bang_sound.play()
                                        tank_player.life -= 1
                                        dead += 1
                                        if tank_player.life < 0:
                                            mytanksGroup.remove(tank_player)
                                            tanksGroup.remove(tank_player)
                                            if len(mytanksGroup) < 1:
                                                is_gameover = True
                                        else:
                                            tank_player.reset()
                                    each.bullet.being = False
                                    enemybulletsGroup.remove(each.bullet)
                                    break
                            # Bullet collision stone wall
                            if pygame.sprite.spritecollide(
                                    each.bullet, map_stage.brickGroup, True,
                                    None):
                                each.bullet.being = False
                                enemybulletsGroup.remove(each.bullet)
                            # Bullet hitting steel wall
                            if each.bullet.stronger:
                                if pygame.sprite.spritecollide(
                                        each.bullet, map_stage.ironGroup, True,
                                        None):
                                    each.bullet.being = False
                            else:
                                if pygame.sprite.spritecollide(
                                        each.bullet, map_stage.ironGroup,
                                        False, None):
                                    each.bullet.being = False
                            # Bullet hits the base camp
                            if pygame.sprite.collide_rect(each.bullet, myhome):
                                each.bullet.being = False
                                myhome.set_dead()
                                is_gameover = True
                else:
                    enemytanksGroup.remove(each)
                    tanksGroup.remove(each)
            # Home
            if dead == 0:
                screen.blit(heart_img, (580, 590))
                screen.blit(heart_img, (560, 590))
                screen.blit(heart_img, (540, 590))
            if dead == 1:
                screen.blit(heart_img, (580, 590))
                screen.blit(heart_img, (560, 590))
            if dead == 2:
                screen.blit(heart_img, (580, 590))
            screen.blit(myhome.home, myhome.rect)
            # Food
            for myfood in myfoodsGroup:
                if myfood.being and myfood.time > 0:
                    screen.blit(myfood.food, myfood.rect)
                    myfood.time -= 1
                    for tank_player in mytanksGroup:
                        if pygame.sprite.collide_rect(tank_player, myfood):
                            # Destroy all current enemies
                            if myfood.kind == 0:
                                for _ in enemytanksGroup:
                                    bang_sound.play()
                                enemytanksGroup = pygame.sprite.Group()
                                enemytanks_total -= enemytanks_now
                                enemytanks_now = 0
                            # Enemy still
                            if myfood.kind == 1:
                                for each in enemytanksGroup:
                                    each.can_move = False
                            # Bullet enhancement
                            if myfood.kind == 2:
                                add_sound.play()
                                tank_player.bullet.stronger = True
                            # Make the wall of the base camp into a steel plate
                            if myfood.kind == 3:
                                map_stage.protect_home()
                            # The tank gets a protective cover for a while
                            if myfood.kind == 4:
                                add_sound.play()
                                for tank_player in mytanksGroup:
                                    tank_player.protected = True
                            # Tank upgrade
                            if myfood.kind == 5:
                                add_sound.play()
                                tank_player.up_level()
                            # Tank life +1
                            if myfood.kind == 6:
                                add_sound.play()
                                tank_player.life += 1
                            myfood.being = False
                            myfoodsGroup.remove(myfood)
                            break
                else:
                    myfood.being = False
                    myfoodsGroup.remove(myfood)
            pygame.display.flip()
            clock.tick(60)
    if not is_gameover:
        show_end_interface(screen, 630, 630, True)
    else:
        show_end_interface(screen, 630, 630, False)
Exemple #14
0
import home

import sys
from subprocess import call
import time
import bluetooth

call(['sudo', 'hciconfig', 'hci0', 'down'])
call(['sudo', 'hciconfig', 'hci0', 'up'])

home = home.Home()

while True:
    result = bluetooth.lookup_name("8C:1A:BF:92:EC:85", timeout=10)

    home.tick(result != None)

    if (result != None):
        time.sleep(5)
conn.commit()
conn.execute(
    "INSERT OR REPLACE INTO car_available(car_name,mileage,model,available) VALUES ('Chevrolt',40,'PQR768',-1)"
)
conn.commit()
conn.execute(
    "INSERT OR REPLACE INTO car_available(car_name,mileage,model,available) VALUES ('Hyundai',33,'AKM987',-1)"
)
conn.commit()
conn.execute(
    "INSERT OR REPLACE INTO car_available(car_name,mileage,model,available) VALUES ('Range Rover',18,'QWT123',-1)"
)
conn.commit()
conn.execute(
    "INSERT OR REPLACE INTO car_available(car_name,mileage,model,available) VALUES ('Ferrari',19,'HJE765',-1)"
)
conn.commit()
conn.execute(
    "INSERT OR REPLACE INTO car_available(car_name,mileage,model,available) VALUES ('peugeot',18,'MNB176',-1)"
)
conn.commit()
conn.execute(
    "INSERT OR REPLACE INTO car_available(car_name,mileage,model,available) VALUES ('Lotus',19,'MNB765',-1)"
)
conn.commit()

root = Tk()
root.title("Car Rental")
mb = w.Home(root)

root.mainloop()
 def gotoHome(self):
     home = h.Home()
     widget.addWidget(home)
     widget.setCurrentIndex(widget.currentIndex() + 1)
 def add_rooms():
     user_home = home.Home(rooms_of_home, rooms_of_home, user_info[1])
     # print(user_home)
     fill_db(home_db,
             [user_info[0], user_info[1], rooms_dict, user_home])
Exemple #18
0
	def logout(self):
		self.window = home.Home()
		self.hide()
 def backtoHome(self):
     home = h.Home()
     m.widget.addWidget(home)
     m.widget.setCurrentIndex(m.widget.currentIndex() + 1)
Exemple #20
0
def main():
    # Initial audio
    pygame.init()
    pygame.mixer.init()
    screen = pygame.display.set_mode((630, 630))
    pygame.display.set_caption("Tian's first Game Project")
    # Loading pictures
    bg_img = pygame.image.load("./images/others/background.png")
    # Load the sound
    add_sound = pygame.mixer.Sound("./audios/add.wav")
    add_sound.set_volume(1)
    bang_sound = pygame.mixer.Sound("./audios/bang.wav")
    bang_sound.set_volume(1)
    blast_sound = pygame.mixer.Sound("./audios/blast.wav")
    blast_sound.set_volume(1)
    fire_sound = pygame.mixer.Sound("./audios/fire.wav")
    fire_sound.set_volume(1)
    Gunfire_sound = pygame.mixer.Sound("./audios/Gunfire.wav")
    Gunfire_sound.set_volume(1)
    hit_sound = pygame.mixer.Sound("./audios/hit.wav")
    hit_sound.set_volume(1)
    start_sound = pygame.mixer.Sound("./audios/start.wav")
    start_sound.set_volume(1)
    # Start interface
    num_player = show_start_interface(screen, 630, 630)
    # Play the start of the game on music
    start_sound.play()
    # mission
    stage = 0
    num_stage = 2
    # Is the game over?
    is_gameover = False
    # Clock
    clock = pygame.time.Clock()
    # main loop
    while not is_gameover:
        # mission
        stage += 1
        if stage > num_stage:
            break
        # Total number of tanks in the level
        enemytanks_total = min(stage * 18, 80)
        # Total number of enemy tanks present on the field
        enemytanks_now = 0
        # Total number of enemy tanks that can be present on the field
        enemytanks_now_max = min(max(stage * 2, 4), 8)
        # The spirit group
        tanksGroup = pygame.sprite.Group()
        mytanksGroup = pygame.sprite.Group()
        enemytanksGroup = pygame.sprite.Group()

        bulletsGroup = pygame.sprite.Group()
        mybulletsGroup = pygame.sprite.Group()
        enemybulletsGroup = pygame.sprite.Group()
        myfoodsGroup = pygame.sprite.Group()

        # Custom event
        # Generates an enemy tank event
        genEnemyEvent = pygame.constants.USEREVENT + 0
        pygame.time.set_timer(genEnemyEvent, 100)
        # enemy tank freeze recovery event
        recoverEnemyEvent = pygame.constants.USEREVENT + 1
        pygame.time.set_timer(recoverEnemyEvent, 8000)
        # Our tank invincible recovery event
        noprotectMytankEvent = pygame.constants.USEREVENT + 2
        pygame.time.set_timer(noprotectMytankEvent, 8000)

        # Levels map
        map_stage = scene.Map(stage)
        # Our tanks
        tank_player1 = tanks.myTank(1)
        tanksGroup.add(tank_player1)
        mytanksGroup.add(tank_player1)
        if num_player > 1:
            tank_player2 = tanks.myTank(2)
            tanksGroup.add(tank_player2)
            mytanksGroup.add(tank_player2)
        is_switch_tank = True
        player1_moving = False
        player2_moving = False
        # For the tire animation
        time = 0
        # The enemy tanks
        for i in range(0, 3):
            if enemytanks_total > 0:
                enemytank = tanks.enemyTank(i)
                tanksGroup.add(enemytank)
                enemytanksGroup.add(enemytank)
                enemytanks_now += 1
                enemytanks_total -= 1
        # Base
        myhome = home.Home()
        # special effects
        appearance_img = pygame.image.load(
            "./images/others/appear.png").convert_alpha()
        appearances = []
        appearances.append(appearance_img.subsurface((0, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((48, 0), (48, 48)))
        appearances.append(appearance_img.subsurface((96, 0), (48, 48)))
        # Level main loop
        while True:
            if is_gameover is True:
                break
            if enemytanks_total < 1 and enemytanks_now < 1:
                is_gameover = False
                break
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == genEnemyEvent:
                    if enemytanks_total > 0:
                        if enemytanks_now < enemytanks_now_max:
                            enemytank = tanks.enemyTank()
                            if not pygame.sprite.spritecollide(
                                    enemytank, tanksGroup, False, None):
                                tanksGroup.add(enemytank)
                                enemytanksGroup.add(enemytank)
                                enemytanks_now += 1
                                enemytanks_total -= 1
                if event.type == recoverEnemyEvent:
                    for each in enemytanksGroup:
                        each.can_move = True
                if event.type == noprotectMytankEvent:
                    for each in mytanksGroup:
                        mytanksGroup.protected = False
            # Check user keyboard actions
            key_pressed = pygame.key.get_pressed()
            # Player 1
            # WSAD -> up down left right
            # Spacebar shooting
            if key_pressed[pygame.K_w]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_up(tanksGroup, map_stage.brickGroup,
                                     map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_s]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_down(tanksGroup, map_stage.brickGroup,
                                       map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_a]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_left(tanksGroup, map_stage.brickGroup,
                                       map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_d]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_right(tanksGroup, map_stage.brickGroup,
                                        map_stage.ironGroup, myhome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            elif key_pressed[pygame.K_SPACE]:
                if not tank_player1.bullet.being:
                    fire_sound.play()
                    tank_player1.shoot()
            # Player 2
            # ↑↓ <- -> up down left right
            # Keypad 0 key shooting
            if num_player > 1:
                if key_pressed[pygame.K_UP]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_up(tanksGroup, map_stage.brickGroup,
                                         map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_DOWN]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_down(tanksGroup, map_stage.brickGroup,
                                           map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_LEFT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_left(tanksGroup, map_stage.brickGroup,
                                           map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_RIGHT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_right(tanksGroup, map_stage.brickGroup,
                                            map_stage.ironGroup, myhome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_0]:
                    if not tank_player2.bullet.being:
                        fire_sound.play()
                        tank_player2.shoot()
            # Background
            screen.blit(bg_img, (0, 0))
            # Stone Wall
            for each in map_stage.brickGroup:
                screen.blit(each.brick, each.rect)
            # Steel wall
            for each in map_stage.ironGroup:
                screen.blit(each.iron, each.rect)
            # Ice
            for each in map_stage.iceGroup:
                screen.blit(each.ice, each.rect)
            # River
            for each in map_stage.riverGroup:
                screen.blit(each.river, each.rect)
            # Tree
            for each in map_stage.treeGroup:
                screen.blit(each.tree, each.rect)
            time += 1
            if time == 5:
                time = 0
                is_switch_tank = not is_switch_tank
            # Our tanks
            if tank_player1 in mytanksGroup:
                if is_switch_tank and player1_moving:
                    screen.blit(
                        tank_player1.tank_0,
                        (tank_player1.rect.left, tank_player1.rect.top))
                    player1_moving = False
                else:
                    screen.blit(
                        tank_player1.tank_1,
                        (tank_player1.rect.left, tank_player1.rect.top))
                if tank_player1.protected:
                    screen.blit(
                        tank_player1.protected_mask1,
                        (tank_player1.rect.left, tank_player1.rect.top))
            if num_player > 1:
                if tank_player2 in mytanksGroup:
                    if is_switch_tank and player2_moving:
                        screen.blit(
                            tank_player2.tank_0,
                            (tank_player2.rect.left, tank_player2.rect.top))
                        player1_moving = False
                    else:
                        screen.blit(
                            tank_player2.tank_1,
                            (tank_player2.rect.left, tank_player2.rect.top))
                    if tank_player2.protected:
                        screen.blit(
                            tank_player1.protected_mask1,
                            (tank_player2.rect.left, tank_player2.rect.top))
            # The enemy tanks
            for each in enemytanksGroup:
                # Born special effects
                if each.born:
                    if each.times > 0:
                        each.times -= 1
                        if each.times <= 10:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 20:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 30:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 40:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 50:
                            screen.blit(appearances[1],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 60:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 70:
                            screen.blit(appearances[2],
                                        (3 + each.x * 12 * 24, 3))
                        elif each.times <= 80:
                            screen.blit(appearances[1],
                                        (33 + each.x * 12 * 24, 3))
                        elif each.times <= 90:
                            screen.blit(appearances[0],
                                        (3 + each.x * 12 * 24, 3))
                    else:
                        each.born = False
                else:
                    if is_switch_tank:
                        screen.blit(each.tank_0,
                                    (each.rect.left, each.rect.top))
                    else:
                        screen.blit(each.tank_1,
                                    (each.rect.left, each.rect.top))
                    if each.can_move:
                        tanksGroup.remove(each)
                        each.move(tanksGroup, map_stage.brickGroup,
                                  map_stage.ironGroup, myhome)
                        tanksGroup.add(each)
            # Our bullet
            for tank_player in mytanksGroup:
                if tank_player.bullet.being:
                    tank_player.bullet.move()
                    screen.blit(tank_player.bullet.bullet,
                                tank_player.bullet.rect)
                    # Bullets collide with enemy bullets
                    for each in enemybulletsGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(
                                    tank_player.bullet, each):
                                tank_player.bullet.being = False
                                each.being = False
                                enemybulletsGroup.remove(each)
                                break
                        else:
                            enemybulletsGroup.remove(each)
                    # The bullets collided with the enemy tank
                    for each in enemytanksGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(
                                    tank_player.bullet, each):
                                if each.is_red == True:
                                    myfood = food.Food()
                                    myfood.generate()
                                    myfoodsGroup.add(myfood)
                                    each.is_red = False
                                each.blood -= 1
                                each.color -= 1
                                if each.blood < 0:
                                    bang_sound.play()
                                    each.being = False
                                    enemytanksGroup.remove(each)
                                    enemytanks_now -= 1
                                    tanksGroup.remove(each)
                                else:
                                    each.reload()
                                tank_player.bullet.being = False
                                break
                        else:
                            enemytanksGroup.remove(each)
                            tanksGroup.remove(each)
                    # The bullet struck the stone wall
                    # if pygame.sprite.spritecollide(tank_player.bullet, map_stage.brickGroup, True, None):
                    #     tank_player.bullet.being = False
                    for each in map_stage.brickGroup:
                        if pygame.sprite.collide_rect(tank_player.bullet,
                                                      each):
                            tank_player.bullet.being = False
                            each.being = False
                            map_stage.brickGroup.remove(each)
                            break

                    # The bullet struck the steel wall
                    if tank_player.bullet.stronger:
                        if pygame.sprite.spritecollide(tank_player.bullet,
                                                       map_stage.ironGroup,
                                                       True, None):
                            tank_player.bullet.being = False
                    else:
                        if pygame.sprite.spritecollide(tank_player.bullet,
                                                       map_stage.ironGroup,
                                                       False, None):
                            tank_player.bullet.being = False

                    # Bullet hits the base camp
                    if pygame.sprite.collide_rect(tank_player.bullet, myhome):
                        tank_player.bullet.being = False
                        myhome.set_dead()
                        is_gameover = True
            # Enemy bullet
            for each in enemytanksGroup:
                if each.being:
                    if each.can_move and not each.bullet.being:
                        enemybulletsGroup.remove(each.bullet)
                        each.shoot()
                        enemybulletsGroup.add(each.bullet)
                    if not each.born:
                        if each.bullet.being:
                            each.bullet.move()
                            screen.blit(each.bullet.bullet, each.bullet.rect)

                            # Bullet colliding with our tank
                            for tank_player in mytanksGroup:
                                if pygame.sprite.collide_rect(
                                        each.bullet, tank_player):
                                    if not tank_player.protected:
                                        bang_sound.play()
                                        tank_player.life -= 1
                                        if tank_player.life < 0:
                                            mytanksGroup.remove(tank_player)
                                            tanksGroup.remove(tank_player)
                                            if len(mytanksGroup) < 1:
                                                is_gameover = True
                                        else:
                                            tank_player.reset()
                                    each.bullet.being = False
                                    enemybulletsGroup.remove(each.bullet)
                                    break
                            # The bullet struck the stone wall
                            if pygame.sprite.spritecollide(
                                    each.bullet, map_stage.brickGroup, True,
                                    None):
                                each.bullet.being = False
                                enemybulletsGroup.remove(each.bullet)

                            # The bullet struck the steel wall
                            if each.bullet.stronger:
                                if pygame.sprite.spritecollide(
                                        each.bullet, map_stage.ironGroup, True,
                                        None):
                                    each.bullet.being = False
                            else:
                                if pygame.sprite.spritecollide(
                                        each.bullet, map_stage.ironGroup,
                                        False, None):
                                    each.bullet.being = False

                            # The bullet struck the home base
                            if pygame.sprite.collide_rect(each.bullet, myhome):
                                each.bullet.being = False
                                myhome.set_dead()
                                is_gameover = True
                else:
                    enemytanksGroup.remove(each)
                    tanksGroup.remove(each)
            # home
            screen.blit(myhome.home, myhome.rect)
            # food
            for myfood in myfoodsGroup:
                if myfood.being and myfood.time > 0:
                    screen.blit(myfood.food, myfood.rect)
                    myfood.time -= 1
                    for tank_player in mytanksGroup:
                        if pygame.sprite.collide_rect(tank_player, myfood):
                            # destroy all current enemies
                            if myfood.kind == 0:
                                for _ in enemytanksGroup:
                                    bang_sound.play()
                                enemytanksGroup = pygame.sprite.Group()
                                enemytanks_total -= enemytanks_now
                                enemytanks_now = 0
                            # The enemy stop
                            if myfood.kind == 1:
                                for each in enemytanksGroup:
                                    each.can_move = False
                            # The bullet enhancement
                            if myfood.kind == 2:
                                add_sound.play()
                                tank_player.bullet.stronger = True
                            # To turn the walls of the base camp into steel plates
                            if myfood.kind == 3:
                                map_stage.protect_home()
                            # The tank gets a shield for a period of time
                            if myfood.kind == 4:
                                add_sound.play()
                                for tank_player in mytanksGroup:
                                    tank_player.protected = True
                            # Tanks upgrade
                            if myfood.kind == 5:
                                add_sound.play()
                                tank_player.up_level()
                            # Tanks lisfe+1
                            if myfood.kind == 6:
                                add_sound.play()
                                tank_player.life += 1
                            myfood.being = False
                            myfoodsGroup.remove(myfood)
                            break
                else:
                    myfood.being = False
                    myfoodsGroup.remove(myfood)
            pygame.display.flip()
            clock.tick(60)
    if not is_gameover:
        show_end_interface(screen, 630, 630, True)
    else:
        show_end_interface(screen, 630, 630, False)
Exemple #21
0
import bootScreen
import bootUp

from PIL import ImageTk
from PIL import Image as ImagePIL

tk = Tk()
#tk.overrideredirect(1)#fullscreen!

queue = queue.Queue(0)


screenWidth = tk.winfo_screenwidth()
screenHeight = tk.winfo_screenheight()

canvas = Canvas(tk, width=screenWidth, height=screenHeight, highlightthickness=0)
canvas.pack() #New Canvas

readWrite = readwrite.ReadWrite(pickle, ImagePIL, ImageTk)

_thread.start_new_thread(bootUp.BootUp, (queue,))#start background booting

bt = bootScreen.BootStart(canvas, tk, readWrite, time, queue) #start screen booting
bt.start()

canvas.delete("all") #when the screen is done booting...

h = home.Home(canvas, tk, readWrite, time) #prep home menu

tk.mainloop()
def main():
    pygame.init()
    # 构造屏幕宽高为 630 * 630
    screen = pygame.display.set_mode([630 , 630])
    # 设置窗口上方显示的文字
    pygame.display.set_caption("坦克大战-xx_cc")
    # 刷新一下
    # pygame.display.update()

    # 默认关数
    stage = 0
    # 总关数
    stage_Num = 2
    # 游戏是否结束
    is_GameOver = False
    # 时钟
    clock = pygame.time.Clock()

    # 显示主页面
    player = show_interface_start(screen, 630, 630)

    # 加载音频
    sound_volume = 1
    add_sound = pygame.mixer.Sound("./audios/add.wav")
    bang_sound = pygame.mixer.Sound("./audios/bang.wav")
    blast_sound = pygame.mixer.Sound("./audios/blast.wav")
    fire_sound = pygame.mixer.Sound("./audios/fire.wav")
    gunfire_sound = pygame.mixer.Sound("./audios/Gunfire.wav")
    hit_sound = pygame.mixer.Sound("./audios/hit.wav")
    start_sound = pygame.mixer.Sound("./audios/start.wav")

    # 设置音量
    add_sound.set_volume(sound_volume)
    bang_sound.set_volume(sound_volume)
    blast_sound.set_volume(sound_volume)
    fire_sound.set_volume(sound_volume)
    gunfire_sound.set_volume(sound_volume)
    hit_sound.set_volume(sound_volume)
    start_sound.set_volume(sound_volume)

    # 游戏主循环
    while not is_GameOver:
        stage += 1
        if stage > stage_Num:
            break

        # 游戏开始音效
        start_sound.play()

        # 显示当前关数界面 1s时间
        show_change_stage(screen, 630, 630, stage)

        # 该关卡坦克总数量
        enemytanks_total = min(stage * 18 ,80)
        # 场上存在的地方坦克总数量
        enemytanks_now = 0
        # 场上可以存在的地方坦克总数量
        enemytanks_now_max = min((max(stage * 2, 4), 8))

        # 精灵组
        tanksGroup = pygame.sprite.Group()
        myTanksGroup = pygame.sprite.Group()
        enemyTanksGroup = pygame.sprite.Group()
        bulletsGroup = pygame.sprite.Group()
        mybulletsGroup = pygame.sprite.Group()
        enemybulletsGroup = pygame.sprite.Group()
        myfoodsGroup = pygame.sprite.Group()

        # 自定义事件
        # 生成敌方坦克事件
        genEnemyEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(genEnemyEvent, 100)

        # 敌方坦克静止恢复事件
        recoverEnemyEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(recoverEnemyEvent, 8000)

        # 我方坦克无敌恢复事件
        noprotextMyTankEvent = pygame.constants.USEREVENT
        pygame.time.set_timer(noprotextMyTankEvent, 8000)

        # 显示背景
        bg_img = pygame.image.load("./images/others/background.png")
        screen.blit(bg_img, (0, 0))

        # 显示大本营
        # 在外部模块使用其他模块的类创建对象时,需要:模块名字+类名创建
        myHome = home.Home()

        # 绘制地图
        map_stage = scene.Map(stage)

        # 添加我方坦克
        tank_player1 = tanks.myTank(1)
        tanksGroup.add(tank_player1)
        myTanksGroup.add(tank_player1)
        if player > 1:
            tank_player2 = tanks.myTank(2)
            tanksGroup.add(tank_player2)
            myTanksGroup.add(tank_player2)

        is_switch_tank = True
        player1_moving = False
        player2_moving = False

        # 为了轮胎的动画效果
        time = 0
        # 敌方坦克
        for i in range(0,3):
            if enemytanks_total > 0:
                enemytank = tanks.enemyTank(i)
                tanksGroup.add(enemytank)
                enemyTanksGroup.add(enemytank)
                enemytanks_now += 1
                enemytanks_total -= 1

        appearance_img = pygame.image.load("./images/others/appear.png").convert_alpha()
        appearance = []
        appearance.append(appearance_img.subsurface((0,0),(48,48)))
        appearance.append(appearance_img.subsurface((48,0),(48,48)))
        appearance.append(appearance_img.subsurface((96,0),(48,48)))


        # 实时监听用户操作事件 1. 用户点击事件 2. 用户点击键盘
        while True:
            if is_GameOver is True:
                break
            if enemytanks_total < 1 and enemytanks_now < 1:
                is_GameOver = False
                break

            # 遍历所有事件
            for event in pygame.event.get():
                # 如果点击了关闭
                if event.type == QUIT:
                    # 关闭屏幕
                    sys.exit()
                if event.type == genEnemyEvent:
                    if enemytanks_total > 0:
                        if enemytanks_now < enemytanks_now_max:
                            enemytank = tanks.enemyTank()
                            if not pygame.sprite.spritecollide(enemytank, tanksGroup, False, None):
                                tanksGroup.add(enemytank)
                                enemyTanksGroup.add(enemytank)
                                enemytanks_now += 1
                                enemytanks_total -= 1

                if event.type == recoverEnemyEvent:
                    for each in enemyTanksGroup:
                        each.can_move = True

                if event.type == noprotextMyTankEvent:
                    for each in myTanksGroup:
                        each.protected = False

            # 刷新背景
            screen.blit(bg_img,(0,0))

            # 监听用户按键事件
            key_pressed = pygame.key.get_pressed()
            if key_pressed[pygame.K_w]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            if key_pressed[pygame.K_s]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            if key_pressed[pygame.K_a]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            if key_pressed[pygame.K_d]:
                tanksGroup.remove(tank_player1)
                tank_player1.move_right(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                tanksGroup.add(tank_player1)
                player1_moving = True
            if key_pressed[pygame.K_SPACE]:
                if not tank_player1.bullet.being:
                    fire_sound.play()
                    tank_player1.shoot()

            # 玩家二
            if player > 1:
                if key_pressed[pygame.K_UP]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_DOWN]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_LEFT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_RIGHT]:
                    tanksGroup.remove(tank_player2)
                    tank_player2.move_right(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                    tanksGroup.add(tank_player2)
                    player2_moving = True
                elif key_pressed[pygame.K_0]:
                    if not  tank_player2.bullet.being:
                        fire_sound.play()
                        tank_player2.shoot()

            # 绘制大本营
            screen.blit(myHome.home, myHome.rect)

            # 绘制地图元素(砖块等)
            for eachBrick in map_stage.brickGroup:
                screen.blit(eachBrick.brick, eachBrick.rect)

            for eachIron in map_stage.ironGroup:
                screen.blit(eachIron.iron, eachIron.rect)

            for eachIce in map_stage.iceGroup:
                screen.blit(eachIce.ice, eachIce.rect)

            for eachRiver in map_stage.riverGroup:
                screen.blit(eachRiver.river, eachRiver.rect)

            for eachTree in map_stage.treeGroup:
                screen.blit(eachTree.tree, eachTree.rect)

            time += 1
            if time == 5:
                time = 0
                is_switch_tank = not is_switch_tank

            # 绘制本方坦克
            if tank_player1 in myTanksGroup:
                if is_switch_tank and player1_moving:
                    screen.blit(tank_player1.tank_0, tank_player1.rect)
                    player1_moving = False
                else:
                    screen.blit(tank_player1.tank_1, tank_player1.rect)
                # 如果有保护罩
                if tank_player1.protected:
                    screen.blit(tank_player1.protected_mask1, tank_player1.rect)
            if player > 1:
                if tank_player2 in myTanksGroup:
                    if is_switch_tank and player2_moving:
                        screen.blit(tank_player2.tank_0, tank_player2.rect)
                        player1_moving = False
                    else:
                        screen.blit(tank_player2.tank_1, tank_player2.rect)

                    if tank_player2.protected:
                        screen.blit(tank_player2.protected_mask1, tank_player2.rect)

            # 绘制敌方坦克
            for each in enemyTanksGroup:
                # 出生特效
                if each.born:
                    if each.times > 0:
                        each.times -= 1
                        if each.times <= 10:
                            screen.blit(appearance[2],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 20:
                            screen.blit(appearance[1],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 30:
                            screen.blit(appearance[0],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 40:
                            screen.blit(appearance[2],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 50:
                            screen.blit(appearance[1],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 60:
                            screen.blit(appearance[0],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 70:
                            screen.blit(appearance[2],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 80:
                            screen.blit(appearance[1],(3 + each.x * 12 * 24, 3))
                        elif each.times <= 90:
                            screen.blit(appearance[0],(3 + each.x * 12 * 24, 3))
                    else:
                        each.born = False
                else:
                    if is_switch_tank:
                        screen.blit(each.tank_0, each.rect)
                    else:
                        screen.blit(each.tank_1, each.rect)

                    if each.can_move:
                        tanksGroup.remove(each)
                        each.move(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myHome)
                        tanksGroup.add(each)

            # 我方子弹
            for tank_player in myTanksGroup:
                if tank_player.bullet.being:
                    tank_player.bullet.move()
                    screen.blit(tank_player.bullet.bullet, tank_player.bullet.rect)

                    # 子弹碰撞敌方子弹
                    for each in enemybulletsGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(tank_player.bullet, each):
                                tank_player.bullet.being = False
                                each.bing = False
                                enemybulletsGroup.remove(each)
                                break
                        else:
                            enemybulletsGroup.remove(each)

                    # 子弹碰撞敌方坦克
                    for each in enemyTanksGroup:
                        if each.being:
                            if pygame.sprite.collide_rect(tank_player.bullet, each):
                                if each.is_Red == True:
                                    myfood = food.Food()
                                    myfood.generate()
                                    myfoodsGroup.add(myfood)
                                    each.is_Red = False
                                each.blood -= 1
                                each.color -= 1
                                if each.blood < 0:
                                    bang_sound.play()
                                    each.being = False
                                    enemyTanksGroup.remove(each)
                                    enemytanks_now -= 1
                                    tanksGroup.remove(each)
                                else:
                                    each.reload()
                                tank_player.bullet.being = False
                                break
                        else:
                            enemyTanksGroup.remove(each)
                            tanksGroup.remove(each)

                    # 子弹碰撞石头墙
                    for each in map_stage.brickGroup:
                        if pygame.sprite.collide_rect(tank_player.bullet, each):
                            tank_player.bullet.being = False
                            each.being = False
                            map_stage.brickGroup.remove(each)
                            break

                    # 子弹碰撞钢墙
                    for each in map_stage.ironGroup:
                        if pygame.sprite.collide_rect(tank_player.bullet, each):
                            tank_player.bullet.being = False
                            if tank_player.bullet.stronger:
                                each.being = False
                                map_stage.ironGroup.remove(each)
                            break

                    # 子弹碰撞大本营
                    if pygame.sprite.collide_rect(tank_player.bullet, myHome):
                        tank_player.bullet.being = False
                        myHome.set_Dead()
                        is_GameOver = True
                        break
            # 敌方子弹
            for each in enemyTanksGroup:
                if each.being:
                    if each.can_move and not each.bullet.being:
                        enemyTanksGroup.remove(each.bullet)
                        each.shoot()
                        enemybulletsGroup.add(each.bullet)
                    if not each.born:
                        if each.bullet.being:
                            each.bullet.move()
                            screen.blit(each.bullet.bullet, each.bullet.rect)
                            # 子弹碰撞我方坦克
                            for tank_player in myTanksGroup:
                                if pygame.sprite.collide_rect(each.bullet, tank_player):

                                    if tank_player.protected:
                                        tank_player.protected = False
                                    else:
                                        tank_player.life -= 1
                                    if tank_player.life < 0:
                                        myTanksGroup.remove(tank_player)
                                        tanksGroup.remove(tank_player)
                                        if len(myTanksGroup) < 1:
                                            is_GameOver = True
                                    else:
                                        tank_player.reset()

                                    each.bullet.being = False
                                    enemybulletsGroup.remove(each.bullet)
                                    brick

                            # 子弹碰撞石头墙
                            for brick in map_stage.brickGroup:
                                if pygame.sprite.collide_rect(each.bullet, brick):
                                    each.bullet.being = False
                                    enemybulletsGroup.remove(each.bullet)
                                    brick.being = False
                                    map_stage.brickGroup.remove(brick)
                                    break

                            # 子弹碰撞钢墙
                            for iron in map_stage.ironGroup:
                                if pygame.sprite.collide_rect(each.bullet, iron):
                                    each.bullet.being = False
                                    if each.bullet.stronger:
                                        iron.being = False
                                        map_stage.ironGroup.remove(iron)
                                    break

                            # 子弹碰撞大本营
                            if pygame.sprite.collide_rect(each.bullet, myHome):
                                each.bullet.being = False
                                myHome.set_Dead()
                                is_GameOver = True
                                break
                else:
                    enemyTanksGroup.remove(each)
                    tanksGroup.remove(each)


            # 食物
            for myfood in myfoodsGroup:
                if myfood.being and myfood.time > 0:
                    screen.blit(myfood.food, myfood.rect)
                    myfood.time -= 1
                    for tanke_player in myTanksGroup:
                        if pygame.sprite.collide_rect(tank_player, myfood):
                            # 消灭当前所有敌人
                            if myfood.kind == 0:
                                for _ in enemyTanksGroup:
                                    bang_sound.play()
                                enemyTanksGroup = pygame.sprite.Group()
                                enemytanks_total -= enemytanks_now
                                enemytanks_now = 0

                            # 敌人静止
                            if myfood.kind == 1:
                                for each in enemyTanksGroup:
                                    each.can_move = False

                            # 子弹增强
                            if myfood.kind == 2:
                                add_sound.play()
                                tank_player.bullet.stronger = True

                            # 是大本营的墙变为刚板
                            if myfood.kind == 3:
                                map_stage.protect_home()

                            # 坦克获得一段时间的保护罩
                            if myfood.kind == 4:
                                add_sound.play()
                                for tank_player in myfoodsGroup:
                                    tank_player.protected = True

                            # 坦克升级
                            if myfood.kind == 5:
                                add_sound.play()
                                tank_player.up_level()

                            # 坦克生命 + 1
                            if myfood.kind == 6:
                                add_sound.play()
                                tank_player.lefe += 1

                            myfood.being = False
                            myfoodsGroup.remove(myfood)
                            break
                else:
                    myfood.being = False
                    myfoodsGroup.remove(myfood)

            pygame.display.flip()
            clock.tick(60)

        if not is_GameOver:
            show_interface_end(screen, 630,630, True)
        else:
            show_interface_end(screen,630,630, False)