コード例 #1
0
ファイル: start_game.py プロジェクト: AndreyGolovin85/Andrey
def rungame():
    pygame.init()
    ai_setting = Settings()
    screen_game = pygame.display.set_mode(
        (ai_setting.game_width, ai_setting.game_height))
    pygame.display.set_caption("Panic at the pizzeria")
    # Создание кнопки Play.
    play_button = Button(ai_setting, screen_game, "Play")

    # Создание сковороды.
    pan = Pan(screen_game, ai_setting)
    # Создание пиццы.
    pizza = Pizza(screen_game, ai_setting)
    # Создание группы спрайтов.
    pizzas = Group()
    pans = Group()
    # Объявление переменной stats.
    stats = GameStats(ai_setting)
    # Вывод очков на экран.
    sb = ScoreBoard(ai_setting, screen_game, stats)
    chef = Chef(screen_game, ai_setting, pizza)
    # Вывод колличества пиццы на экран.
    numberspizza = NumbersPizza(ai_setting, screen_game, stats)
    """Основной цикл игры."""
    while True:
        # Обновление экрана.
        screen_game.blit(ai_setting.bg_fon, ai_setting.bg_rect)
        gf.update_screen(screen_game, ai_setting, pizzas, pan, pans, pizza,
                         stats, sb, chef, numberspizza, play_button)
コード例 #2
0
ファイル: install.py プロジェクト: tspannhw/REDstack
def install(config_file):
    """ 
    Coordinates the cluster deployment from start to finish.
    :param: config_file - Path to main configuration file
    :return: None
    """
    logger.info("Beginning the deployment of a cluster")

    # Create a Deploy object
    deploy = Deploy(config_file)

    # Update logging handler to reflect process configuration
    logger.setLevel(deploy.log_level)

    # Build blueprints for ambari
    blueprint_builder = BlueprintBuilder(deploy)
    blueprint_builder.create_all()

    # Create deployment directory
    environment = Environment(deploy)
    environment.create()

    # OST phase
    openstack = Openstack(deploy)

    if deploy.use_existing_openstack:
        openstack.rebuild()
    else:
        openstack.build()

    # Log out the cluster thus far
    with open(os.path.join(deploy.installation_directory, 'cluster.json'),
              'w') as cluster_json_file:
        logger.info(deploy.cluster.to_json())
        cluster_json_file.write(deploy.cluster.to_json())

    # Chef phase
    chef = Chef(deploy)
    chef.converge()

    # Ambari phase
    ambari = Ambari(deploy)
    ambari.install()

    logger.info('REDstack install completed - Ambari: https://{0}:8443'.format(
        deploy.cluster.master_node.floating_ip))
コード例 #3
0
    def __init__(self):

        self.screen = pg.display.set_mode((WIDTH - 200, HEIGHT))
        #self.background = pg.image.load(backgrounds[level-1])
        self.background = pg.image.load('background.png')
        self.screen.blit(pg.image.load('background.png'), (0, 0))

        pg.display.set_caption("Chef War")
        #self.screen.blit(self.background, [250,250])
        self.clock = pg.time.Clock()
        self.running = True
        self.playing = True
        # groups
        self.all_sprites = pg.sprite.Group()
        self.all_blocks = pg.sprite.Group()
        self.all_bullets = pg.sprite.Group()
        self.all_bonus = pg.sprite.Group()
        self.all_superbullets = pg.sprite.Group()

        self.chef1 = Chef(5, 5, chef1_moves, False, self.all_bullets,
                          self.all_sprites, self.all_superbullets)
        self.chef1.cabbage = 100
        self.all_sprites.add(self.chef1)

        #font variable
        self.font1 = pg.font.Font('caligraphy.ttf', 50)
        self.font2 = pg.font.Font('Organo.ttf', 20)
        self.font3 = pg.font.Font('Arial.ttf', 15)
        self.font4 = pg.font.Font('Arial.ttf', 15)
        self.font5 = pg.font.Font('Organo.ttf', 10)
        self.map = maps[1]

        self.block2 = Block(8, 7, 4, False, 4)
        self.block3 = Block(8, 6, 3, False, 1)
        self.block4 = Block(8, 5, 0, True, 0)

        self.g = g = gm.Game(8)

        self.story_progress = True
        self.story_progress2 = True
        self.story_progress3 = True
        self.story_progress4 = True
        self.story_progress5 = True
コード例 #4
0
ファイル: scheduler.py プロジェクト: zjipsen/chef-scheduler
    def __init__(self, start_day=0, start_date=None, num_days=14):
        self.num_days = num_days
        self.start_day = start_day
        self.start_date = start_date

        self.chefs_main = []
        self.chefs_side = []
        self.schedule = [None] * self.num_days
        self.roommates = {}
        self.max_times_per_period = 2
        self.nobody = Chef("-")
コード例 #5
0
ファイル: controller.py プロジェクト: alevor657/blackops
    def add_worker(self, form):
        """
        Adds a worker
        """
        level = int(form['classlvl'])
        worker = None

        backpack = ", "
        backpack = backpack.join(form.getlist('check'))

        if (level == 1):
            worker = Staff(
                name=form["name"],
                classlvl=form["classlvl"],
                backpack=backpack
            )
        elif (level == 2):
            worker = Manager(
                name=form["name"],
                classlvl=form["classlvl"],
                backpack=backpack
            )
        elif (level == 3):
            worker = Chef(
                name=form["name"],
                classlvl=form["classlvl"],
                backpack=backpack
            )

        for item in form.getlist('check'):
            self.own(self.get_material_by_type(item), form['name'])

        if not form.getlist('check'):
            for item in self.session.query(Materials).filter(Materials.owned == worker.name).all():
                self.deown(item)

        self.session.add(worker)
        self.session.commit()
コード例 #6
0
def add_the_squad(scheduler):

	main_chefs = [
		Chef("Alex", unavailable=[Const.MON, Const.THURS]),
		Chef("Maddy", unavailable=[Const.MON, Const.TUES, Const.THURS]),
		Chef("Austin", unavailable=[Const.MON]),
		Chef("John", unavailable=[Const.TUES]),
		Chef("Zana", unavailable=[Const.WED, Const.THURS]),
		Chef("Adam", unavailable=[Const.WED]),
		Chef("Steph"),
	]

	side_chefs = [
		# Chef("Maddy", unavailable=[Const.MON, Const.TUES]),
		Chef("Alex", unavailable=[Const.MON, Const.THURS]),
		Chef("Austin", unavailable=[Const.MON]),
		Chef("John", unavailable=[Const.TUES]),
		Chef("Zana", unavailable=[Const.WED, Const.THURS]),
		# Chef("Adam"),
		Chef("Steph")
	]

	roommates = {
		"Alex": ["Zana"],
		"Zana": ["Alex"],
		"Adam": ["Maddy", "John"],
		"John": ["Adam", "Maddy"],
		"Maddy": ["Adam", "John"],
		"Steph": ["Austin"],
		"Austin": ["Steph"]
	}

	for chef in main_chefs:
		scheduler.add_chef(chef)

	for chef in side_chefs:
		scheduler.add_chef(chef, False)

	scheduler.add_roommate_config(roommates)
コード例 #7
0
def main():
    pygame.init()
    pygame.mixer.init()

    fondo = pygame.image.load("imagenes/cocina.png")
    intro = pygame.image.load("imagenes/intro.png")
    fondorect = fondo.get_rect()
    introrect = intro.get_rect()

    pygame.display.set_caption("Chef Race (Universidad Distrital)")
    pizarra = pygame.image.load("imagenes/pizarra.png")
    sInicio = util.cargar_sonido('sonidos/inicio.wav')
    sHorno = util.cargar_sonido('sonidos/horno.wav')
    sCuchillo = util.cargar_sonido('sonidos/cuchillo.wav')
    sLicuadora = util.cargar_sonido('sonidos/licuadora.wav')
    sPrincipal = util.cargar_sonido('sonidos/principal.wav')

    chef1 = Chef((width - 900, height))
    chef2 = Chef((width - 700, height))
    chef3 = Chef((width - 500, height))
    pizarra1 = Pizarra((width - 900, height))
    pizarra2 = Pizarra((width - 700, height))
    pizarra3 = Pizarra((width - 500, height))
    receta1 = Receta((width, height))
    receta2 = Receta((width + 200, height))
    receta3 = Receta((width + 400, height))

    listaChefs = [chef1, chef2, chef3]
    listaPizarras = [pizarra1, pizarra2, pizarra3]
    listaRecetas = [receta1, receta2, receta3]
    cuchillos = Cuchillos(size)
    licuadora = Licuadora(size)
    horno = Horno(size)

    reloj = pygame.time.Clock()
    fuente1 = pygame.font.Font(None, 70)
    fuente2 = pygame.font.Font(None, 25)
    textoBienvenida = fuente1.render("Bienvenido a Chef Race UD", 1,
                                     (255, 255, 255))
    textoAutor1 = fuente2.render("Marlon Arias", 1, (0, 0, 0))
    textoAutor2 = fuente2.render("David Amado", 1, (0, 0, 0))
    textoAutor3 = fuente2.render("Realizado por:", 1, (0, 0, 0))

    sInicio.play()
    aux = 3

    while aux > 0:
        screen.blit(intro, introrect)
        screen.blit(textoAutor1, (width - 170, height - 680))
        screen.blit(textoAutor2, (width - 170, height - 660))
        screen.blit(textoAutor3, (width - 170, height - 700))
        screen.blit(textoBienvenida, ((width - 880, (height / 2) + 30)))
        pygame.display.update()
        time.sleep(1)
        aux = aux - 1

    sPrincipal.play(1)

    while 1:
        reloj.tick(30)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

            if event.type == pygame.MOUSEBUTTONDOWN:
                for x in range(810, 881):
                    for y in range(137, 257):
                        if event.button == 1 and event.pos == (x, y):
                            chef1.estado = "trabajandoLicuadora1"
                            sLicuadora.play()
                            licuadora.rect.move_ip(-700, +70)
                        elif event.button == 2 and event.pos == (x, y):
                            chef2.estado = "trabajandoLicuadora1"
                            sLicuadora.play()
                            licuadora.rect.move_ip(-505, +70)
                        elif event.button == 3 and event.pos == (x, y):
                            chef3.estado = "trabajandoLicuadora1"
                            sLicuadora.play()
                            licuadora.rect.move_ip(-305, +70)

                for x in range(770, 890):
                    for y in range(282, 402):
                        if event.button == 1 and event.pos == (x, y):
                            chef1.estado = "trabajandoHorno1"
                            sHorno.play()
                            horno.rect.move_ip(-690, +45)
                        elif event.button == 2 and event.pos == (x, y):
                            chef2.estado = "trabajandoHorno1"
                            sHorno.play()
                            horno.rect.move_ip(-490, +45)
                        elif event.button == 3 and event.pos == (x, y):
                            chef3.estado = "trabajandoHorno1"
                            sHorno.play()
                            horno.rect.move_ip(-290, +45)

                for x in range(780, 900):
                    for y in range(27, 125):
                        if event.button == 1 and event.pos == (x, y):
                            chef1.estado = "trabajandoCuchillo1"
                            sCuchillo.play()
                            cuchillos.rect.move_ip(-700, +95)
                        elif event.button == 2 and event.pos == (x, y):
                            chef2.estado = "trabajandoCuchillo1"
                            sCuchillo.play()
                            cuchillos.rect.move_ip(-500, +95)
                        elif event.button == 3 and event.pos == (x, y):
                            chef3.estado = "trabajandoCuchillo1"
                            sCuchillo.play()
                            cuchillos.rect.move_ip(-300, +95)

        for elemento in listaChefs:
            elemento.update()

        time.sleep(0.5)
        screen.blit(fondo, fondorect)

        for elemento in listaChefs:
            screen.blit(elemento.image, elemento.rect)

        for elemento in listaPizarras:
            screen.blit(elemento.image, elemento.rect)

        for elemento in listaRecetas:
            screen.blit(elemento.image, elemento.rect)

        screen.blit(cuchillos.image, cuchillos.rect)
        screen.blit(licuadora.image, licuadora.rect)
        screen.blit(horno.image, horno.rect)

        pygame.display.update()
コード例 #8
0
from chef import Chef
from ChineseChef import ChineseChef

myChef = Chef()
myChef.make_chicken()
myChef.make_special_dish()

myChineseChef = ChineseChef()
myChineseChef.make_special_dish()
myChineseChef.make_fried_rice()
myChineseChef.make_chicken()

コード例 #9
0
from chef import Chef
from chinese_chef import Chines_chef

mychef = Chef()
mychines_chef = Chines_chef()

mychef.lunch()
mychef.dinner()
mychines_chef.noodles()
mychines_chef.dinner()
コード例 #10
0
    def __init__(self, level, chef1_points=0, chef2_points=0):
        pg.mixer.init()
        self.running = True
        if level == 0:
            self.background = pg.image.load('startscreen.png')
        elif level > 0 and level < 6 or level == 8:
            self.background = pg.image.load("background.png")
            self.board = pg.image.load(backimages[0])
            self.door = pg.image.load(backimages[1])
            self.right_margin = pg.image.load(backimages[2])
            self.skip = pg.image.load('SKIP.png')
            self.bonus_image = pg.image.load('BONUS.png')
        elif level == 6:
            if chef1_points > chef2_points:
                self.background = pg.image.load('player1_end.png')
            elif chef2_points > chef1_points:
                self.background = pg.image.load('player2_end.png')
            else:
                self.background = pg.image.load('tie.PNG')
        elif level == 7:
            self.background = pg.image.load('credit.png')
        else:
            g = Game(0)
            g.run()
            self.running = False
        self.screen = pg.display.set_mode((WIDTH, HEIGHT), pg.RESIZABLE)
        pg.display.set_caption("Chef War")
        #self.screen.blit(self.background, [250,250])
        self.level = level
        self.clock = pg.time.Clock()
        #sprite groups
        self.all_sprites = pg.sprite.Group()
        self.all_blocks = pg.sprite.Group()
        self.all_bullets = pg.sprite.Group()
        self.all_bonus = pg.sprite.Group()
        self.all_superbullets = pg.sprite.Group()
        self.chef1_points = chef1_points
        self.chef2_points = chef2_points
        self.transition_image = pg.image.load('transition.png')
        self.show_transition = False
        self.darkmode = False
        print('points:', self.chef1_points, self.chef2_points)

        #light up
        if self.level == 5:
            self.fog = pg.Surface((800, 800))
            self.fog.fill(BLACK)
            self.light_mask1 = pg.image.load(light1).convert_alpha()
            self.light_mask2 = pg.image.load(light2).convert_alpha()
            self.light_mask1 = pg.transform.scale(self.light_mask1, LIGHT_RS)
            self.light_mask2 = pg.transform.scale(self.light_mask2, LIGHT_RS)
            self.light_rect1 = self.light_mask1.get_rect()
            self.light_rect2 = self.light_mask2.get_rect()

        if self.level > 0 and self.level < 6 or level == 8:
            if self.level > 0 and self.level < 6:
                self.map = maps[self.level - 1]
            else:
                self.map = tutorial

            for i in range(20):
                for j in range(20):
                    if self.map[i][j] == 1:
                        bl = Block(j, i, 1)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 2:
                        bl = Block(j, i, 0, True, 0)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 3:
                        bl = Block(j, i, 3, False, 1)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 4:
                        bl = Block(j, i, 2, False, 2)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 5:
                        bl = Block(j, i, 3, False, 3)
                        self.all_sprites
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 6:
                        bl = Block(j, i, 1, False, 4)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 7:
                        bl = Block(j, i, 3, False, 5)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 8:
                        bl = Block(j, i, 2, False, 6)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 'a':
                        self.chef1 = Chef(j, i, chef1_moves, True,
                                          self.all_bullets, self.all_sprites,
                                          self.all_superbullets)
                    elif self.map[i][j] == 'b':
                        self.chef2 = Chef(j, i, chef2_moves, False,
                                          self.all_bullets, self.all_sprites,
                                          self.all_superbullets)

            #apend sprite here
            self.all_sprites.add(self.chef1)
            self.all_sprites.add(self.chef2)
コード例 #11
0
from chef import Chef
from chineseChef import ChineseChef

myChef = Chef()
myChef.chicken_soup()

myChineseChef = ChineseChef()
myChineseChef.chicken_soup()
コード例 #12
0
def __init_chef__():
    global chef
    global __CHEF_START_X__
    global __CHEF_START_Y__

    chef = Chef(__CHEF_START_X__, __CHEF_START_Y__)
コード例 #13
0
ファイル: main.py プロジェクト: eduard01a10/python_oop
##This is a basic OOP project with python
from person import Person
from chef import Chef
from manager import Manager
from waiter import Waiter
from dishwasher import Dishwasher
from client import Client

if __name__ == "__main__":

    c = Chef("Jesus", 45, "Male")
    m = Manager("Beto", 72, "Male")
    w = Waiter("Eduardo", 25, "Male")
    d = Dishwasher("Sarah", 33, "Female")
    cl = Client("Female")

    print(
        f"{c.name} is the chef name, is {c.age} years old, and is {c.gender}. {c.cook()}"
    )
    print(
        f"{m.name} is the manager name, is {m.age} years old, and is {m.gender}. {m.management()}"
    )
    print(
        f"{w.name} is the waiter name, is {w.age} years old, and is {w.gender}. {w.serve()}"
    )
    print(
        f"{d.name} is the dishwasher name, is {d.age} years old, and is {d.gender}. {d.wash()}"
    )
    print(f"The client is a {cl.gender} and {cl.order()}")
コード例 #14
0
ファイル: test.py プロジェクト: Nicolas1936/bstorm_ai
from employe import Employe
from chef import Chef
from directeur import Directeur

liste = [
    Employe("NOM1", "PRENOM1", "03/04/1991", 1001),
    Employe("NOM2", "PRENOM2", "03/04/1992", 1002),
    Employe("NOM3", "PRENOM3", "03/04/1993", 1003),
    Employe("NOM4", "PRENOM4", "03/04/1994", 1004),
    Employe("NOM5", "PRENOM5", "03/04/1995", 1005),
    Chef("NOM6", "PRENOM6", "03/04/1996", 1006, "Informatique"),
    Chef("NOM7", "PRENOM7", "03/04/1997", 1007, "Comptabilité"),
    Directeur("NOM8", "PRENOM8", "03/04/1998", 1008, "Informatique",
              "Microsoft")
]

for i in liste:
    print("*************************************")
    i.affiche()
コード例 #15
0
class Game:
	def __init__(self):
		pg.mixer.init()
		self.level = 1
		self.background = pg.image.load(backgrounds[self.level-1])
		self.board = pg.image.load(backimages[0])
		self.door = pg.image.load(backimages[1])
		self.right_margin = pg.image.load(backimages[2])
		self.screen = pg.display.set_mode((WIDTH, HEIGHT), pg.RESIZABLE)
		pg.display.set_caption("Client1")
		#self.screen.blit(self.background, [250,250])	
		self.clock = pg.time.Clock()
		self.running = True
		self.playing = True
		self.waiting = True
		#sprite groups
		self.all_sprites = pg.sprite.Group()		
		self.all_blocks = pg.sprite.Group()
		self.all_bullets = pg.sprite.Group()
		self.all_bonus = pg.sprite.Group()
		self.all_superbullets = pg.sprite.Group()
		for i in range(20):
			map = maps[0]
			for j in range(20): 
				if map[i][j] == 1:
					bl = Block(j, i, 1)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 2:
					bl = Block(j, i, 0, True, 0)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 3:
					bl = Block(j, i, 3, False, 1)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 4:
					bl = Block(j, i, 2, False, 2)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 5:
					bl = Block(j, i, 3, False, 3)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 6:
					bl = Block(j, i, 1, False, 4)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 7:
					bl = Block(j,i, 3, False, 5)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 8:
					bl = Block(j,i, 2, False, 6)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 'b':
					self.chef1 = Chef(j, i, chef1_moves, False, self.all_bullets, self.all_sprites,self.all_superbullets)
					self.all_sprites.add(self.chef1)
					# self.chef1.set_center(j, i)
					# self.chef1.set_cabbage(10)
					# self.chef1.set_life(1)
				elif map[i][j] == 'a':
					self.chef2 = Chef(j, i, chef2_moves, True, self.all_bullets, self.all_sprites, self.all_superbullets)
					self.all_sprites.add(self.chef2)
					# self.chef2.set_center(j, i)
					# self.chef2.set_cabbage(10)
					# self.chef2.set_life(1)

	# def light_up()
		#if self.level == 5:
		self.fog=pg.Surface((800,800))
		self.fog.fill(BLACK)
		self.light_mask1=pg.image.load(light1).convert_alpha()
		self.light_mask2=pg.image.load(light2).convert_alpha()
		self.light_mask1= pg.transform.scale(self.light_mask1,LIGHT_RS)
		self.light_mask2= pg.transform.scale(self.light_mask2,LIGHT_RS)
		self.light_rect1=self.light_mask1.get_rect()
		self.light_rect2=self.light_mask2.get_rect()

		
		
		


	def create(self):
		#0 is nothing
		#1 is empty bl
		#2 is not shootable
		#3 is life - health = 3
		#4 is cabbage - 2
		#5 is point - 3
	
		#def __init__(self, x, y, health, indestructable = False, bonus = 0 ):
		map = maps[self.level - 1]
		for i in range(20):
			for j in range(20): 
				if map[i][j] == 1:
					bl = Block(j, i, 1)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 2:
					bl = Block(j, i, 0, True, 0)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 3:
					bl = Block(j, i, 3, False, 1)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 4:
					bl = Block(j, i, 2, False, 2)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 5:
					bl = Block(j, i, 3, False, 3)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 6:
					bl = Block(j, i, 1, False, 4)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 7:
					bl = Block(j,i, 3, False, 5)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 8:
					bl = Block(j,i, 2, False, 6)
					self.all_sprites.add(bl)
					self.all_blocks.add(bl)
				elif map[i][j] == 'b':
					# self.chef1 = Chef(j, i, chef1_moves, False, self.all_bullets, self.all_sprites,self.all_superbullets)
					# self.all_sprites.add(self.chef1)
					self.chef1.set_center(j, i)
					self.chef1.set_cabbage(10)
					self.chef1.set_life(1)
				elif map[i][j] == 'a':
					# self.chef2 = Chef(j, i, chef1_moves, True, self.all_bullets, self.all_sprites, self.all_superbullets)
					# self.all_sprites.add(self.chef2)
					self.chef2.set_center(j, i)
					self.chef2.set_cabbage(10)
					self.chef2.set_life(1)

					
	def setup_next_level(self):
		for bl in self.all_blocks:
			bl.kill()
		self.level += 1
		self.create()
		self.playing = True

	def update(self):
		
		hit_block = pg.sprite.groupcollide(self.all_blocks, self.all_bullets, False, True)
		hit_block2 = pg.sprite.groupcollide(self.all_blocks, self.all_superbullets, False, False) #if the block turn into the bonus -> True, False
		shoot_chef1 = pg.sprite.spritecollide(self.chef1, self.all_bullets, True)
		shoot_chef2 = pg.sprite.spritecollide(self.chef2, self.all_bullets, True)
		shoot_chef_1 = pg.sprite.spritecollide(self.chef1, self.all_superbullets, True)
		shoot_chef_2 = pg.sprite.spritecollide(self.chef2, self.all_superbullets, True)

		if shoot_chef1 or shoot_chef_1:
			self.chef1.is_hit()
			if self.chef1.get_life == 0:
				self.running= False
			self.chef2_points +=1
		if shoot_chef2 or shoot_chef_2:
			self.chef2.is_hit()
			if self.chef2.get_life == 0:
				self.running= False
			self.chef1_points +=1



		for bl in hit_block.keys():
			bl.decrementHealth()
			if bl.getHealth() == 0:
				if bl.getBonus()==0:
					bl.kill()
				else:
					self.all_bonus.add(bl)
					self.all_blocks.remove(bl)
	
		for bl in hit_block2.keys(): 
			bl.setHealth(0)
			if bl.getHealth() == 0:
				if bl.getBonus()==0:
					bl.kill()
				else:
					self.all_bonus.add(bl)
					self.all_blocks.remove(bl)

		chef1_hit_bonus = pg.sprite.spritecollide(self.chef1, self.all_bonus, True)
		for bonus in chef1_hit_bonus:
			if bonus.getBonus() == 1:
				self.chef1.claim_life()
			elif bonus.getBonus() == 2:
				self.chef1.claim_cabbage()
			elif bonus.getBonus() == 4:
				self.chef1.gainSpeed()
			elif bonus.getBonus() == 5:
				self.chef1.claim_superbullet()
			elif bonus.getBonus() ==6:
				self.chef1.gainLight()
			else:
				self.chef1_points +=1

		chef2_hit_bonus = pg.sprite.spritecollide(self.chef2, self.all_bonus, True)
		for bonus in chef2_hit_bonus:
			if bonus.getBonus() == 1:
				self.chef2.claim_life()
			elif bonus.getBonus() == 2:
				self.chef2.claim_cabbage()
			elif bonus.getBonus() == 4:
				self.chef2.gainSpeed()
			elif bonus.getBonus() == 5:
				self.chef2.claim_superbullet()
			elif bonus.getBonus() ==6:
				self.chef2.gainLight()
			else:
				self.chef2_points +=1

		chef1_old_x = self.chef1.get_x()
		chef1_old_y = self.chef1.get_y()

		chef2_old_x = self.chef2.get_x()
		chef2_old_y = self.chef2.get_y()

		self.all_sprites.update()
		

		chef1_collide_block = pg.sprite.spritecollide(self.chef1, self.all_blocks, False)
		if chef1_collide_block:
			self.chef1.set_x(chef1_old_x)
			self.chef1.set_y(chef1_old_y)
	# 			self.chef1.set_sound(None)

		chef2_collide_block = pg.sprite.spritecollide(self.chef2, self.all_blocks, False)
		if chef2_collide_block:
			self.chef2.set_x(chef2_old_x)
			self.chef2.set_y(chef2_old_y)
	# 			self.chef2.set_sound(None)
	
	def run_level(self):
		pg.mixer.music.load('song.wav')
		pg.mixer.music.play(-1)
		while self.playing:
			if self.chef1.get_speed() == True:
				self.chef1.set_endSpeed()
				elapsed = self.chef1.get_endSpeed() - self.chef1.get_stSpeed()
				if elapsed >= 5.00:
					self.chef1.close_speed()
			
			if self.chef2.get_speed() == True:
				self.chef2.set_endSpeed()
				elapsed = self.chef2.get_endSpeed() - self.chef2.get_stSpeed()
				if elapsed >= 5.00:
					self.chef2.close_speed()

			for bl in self.all_bullets:
				bl.kill()
			# for bl in self.all_superbullets:
			# 	bl.kill()
			#self.clock.tick(FPS)
			self.events()
			lc.handle_timeout(1)
			self.draw()			
			if self.chef1.is_dead() or self.chef2.is_dead():
				if self.level == 5:
					self.running = False
				self.playing = False
		# for spr in self.all_sprites:
		# 	spr.kill()
	
	def level_successful(self):
		if self.playing == False:
			return True
		else: 
			return False
	
	def done(self):
		if self.running == False:
			return True
		else:
			return False

	def events(self):
		for event in pg.event.get():
			if event.type == pg.QUIT:
				if self.playing:
					self.playing = False
				self.running = False
		key = pg.key.get_pressed()
		sending_out = input_t()
		sending_out.player = 1
		if key[pg.K_LEFT]:
			sending_out.move = "left"	  
		elif key[pg.K_RIGHT]:
			sending_out.move = "right"	   
		elif key[pg.K_UP]:
			sending_out.move = "up"		
		elif key[pg.K_DOWN]:
			sending_out.move = "down"	  
		elif key[pg.K_SPACE]:
			sending_out.move = "shoot"	   
		lc.publish("CLIENT_INPUT", sending_out.encode())
	
	def makefog(self):
		self.fog.fill(BLACK)
		# if self.chef2.get_Light():
		# 	self.light_mask1= pg.transform.scale(self.light_mask1,LIGHT_RB)
		# 	self.light_rect1=self.light_mask1.get_rect()
		# 	self.chef2.set_endLight()
		# 	elapsed = self.chef2.get_endLight()-self.chef2.get_stLight()
		# 	if elapsed >= 5.00:
		# 		self.chef2.close_Light()
		# 		self.light_mask1= pg.transform.scale(self.light_mask1,LIGHT_RS)
		# 		self.light_rect1=self.light_mask1.get_rect()

		if self.chef1.get_Light():
			self.light_mask2= pg.transform.scale(self.light_mask2,LIGHT_RB)
			self.light_rect2=self.light_mask2.get_rect()
			self.chef1.set_endLight()
			elapsed = self.chef1.get_endLight()-self.chef1.get_stLight()
			if elapsed >= 5.00:
				self.chef1.close_Light()
				self.light_mask2= pg.transform.scale(self.light_mask2,LIGHT_RS)
				self.light_rect2=self.light_mask2.get_rect()
		
		# self.light_rect1.center=(self.chef2.get_center()[0]-200,self.chef2.get_center()[1]-200)
		self.light_rect2.center=(self.chef1.get_center()[0]-200,self.chef1.get_center()[1]-200)
		# self.fog.blit(self.light_mask1,self.light_rect1)
		self.fog.blit(self.light_mask2,self.light_rect2)
		self.screen.blit(self.fog,(200,200),special_flags=pg.BLEND_MULT)


	def draw(self):
		self.screen.blit(self.background, [200,200])
		self.screen.blit(self.door, [0,200])
		self.screen.blit(self.board, [0, 0])
		self.all_sprites.draw(self.screen)
		#text to print
		# if self.chef2.get_Light():
		# 	t2 = 5.00-self.chef2.get_endLight()+self.chef2.get_stLight()
		# 	text_Light2 = str("%.1f" % t2)
		# else:
		# 	text_Light2 = 'No'
		
		if self.chef1.get_Light():
			t1 = 5.00-self.chef1.get_endLight()+self.chef1.get_stLight()
			text_Light1 = str("%.1f" % t1)
		else:
			text_Light1 = 'No'
		
		
		if self.chef2.get_speed():
			t4 = 5.00-self.chef2.get_endSpeed()+self.chef2.get_stSpeed()
			text_Speed2 = str("%.1f" % t4)
		else:
			text_Speed2 = 'No'
		
		if self.chef1.get_speed():
			t3 = 5.00-self.chef1.get_endSpeed()+self.chef1.get_stSpeed()
			text_Speed1 = str("%.1f" % t3)
		else:
			text_Speed1 = 'No'
		
		
		draw_text(self.screen, str(self.level), 55, 550, 40)#level
		draw_text(self.screen, str(self.chef2.get_cabbage()), 25, 100, 85)#c2 cabbage
		draw_text(self.screen, str(self.chef1.get_cabbage()), 25, 810, 85)#c1 cabbage
		draw_text(self.screen, str(self.chef2.get_life()), 25, 100, 127)#c2 life
		draw_text(self.screen, str(self.chef1.get_life()), 25, 810, 127)#c1 life
		draw_text(self.screen, str(self.chef2.get_point()), 40, 380, 130)#c2 score
		draw_text(self.screen, str(self.chef1.get_point()), 40, 600, 130)#c1 score
		draw_text(self.screen, str(self.chef2.get_superbullet()), 25, 225, 127)#c2 superbullet
		draw_text(self.screen, str(self.chef1.get_superbullet()), 25, 930, 127)#c1 superbullet
		draw_text(self.screen, text_Speed2, 25, 100, 167)#c2 speed up
		draw_text(self.screen, text_Speed1, 25, 810, 167)#c1 speed up
		draw_text(self.screen, text_Light2, 25, 225, 85)#c2 light up
		draw_text(self.screen, text_Light1, 25, 930, 85)#c1 light up



		if self.level == 5:
			self.makefog()
		pg.display.update()


	def get_block(self, x, y):
		for bl in self.all_blocks:
			if bl.get_x() == x and bl.get_y() == y:
				return bl


	def show_start_screen(self):
		background = pg.image.load('startscreen.png')
		self.screen.blit(background, [0,0])
		pg.display.update()
	
		# waiting = True
		#click = pg.mouse.get_pressed()
		while self.waiting:
			lc.handle_timeout(10)
			for event in pg.event.get():
				if event.type == pg.QUIT:
					pg.quit()
				mouse = pg.mouse.get_pos()
				if event.type == pg.MOUSEBUTTONDOWN:
					if 700 <  mouse[0] < 800 and 600 < mouse[1] < 850:				
						background = pg.image.load("missing2.png")
						start = input_t()
						start.player = 1
						start.move = "start"
						lc.publish("CLIENT_INPUT", start.encode())
						#waiting = False					
					if 212 < mouse[0] < 314 and 862 < mouse[1] < 964:	
						background = pg.image.load("missing2.png")			
						start = input_t()
						start.player = 1
						start.move = "start"
						lc.publish("CLIENT_INPUT", start.encode())
						#waiting = False
					if 42 < mouse[0] < 144 and 862 < mouse[1] < 964:	
						background = pg.image.load("missing2.png")			
						start = input_t()
						start.player = 1
						start.move = "start"
						lc.publish("CLIENT_INPUT", start.encode())
						#waiting = False	
					self.screen.blit(background, [0,0])
					pg.display.update()

	def show_waiting_screen(self):
		pass

	def show_go_screen(self):
		pass
コード例 #16
0
# Inheritance is where we can define attributes and functions inside of a class, 
# create another class, and inherit those attributes.
    # Essentially a class has the functionality of another class you define, but more. (easier for big classes)
from chef import Chef
newchef = Chef() # Giving the Chef class attributes to "newchef"
newchef.make_chicken() # Checking if newchef has Chef's attributes.

# Let's assume we want to make another class called "Chinese Chef" that does everything generic "Chef" does.
    # First let's import from chinese_chef.py.
from chinese_chef import Chinese_Chef
new_chinese_chef = Chinese_Chef()
new_chinese_chef.make_fried_rice() # Checking if new_chinese_chef has Chinese_Chef's attributes.

# The more efficient way (without copying and pasting to class Chinese_Chef) is to inherit.
class Chinese_Chef_2(Chef): # Be sure to import the class in the parentheses first.
    def make_special_dish(self):
        print("The chef has made congee.") # Overriding the inherited "chef makes BBQ ribs" attribute.
    def make_fried_rice(self):
        print("The chef has made fried rice.")

new_Chinese_Chef_2 = Chinese_Chef_2() # Don't forget to define an object.
new_Chinese_Chef_2.make_fried_rice() # And the inheritance worked!
コード例 #17
0
from chef import Chef

myChef = Chef()
myChef.make_salad()
コード例 #18
0
class Game:
    def __init__(self):
        pg.mixer.init()
        self.level = 1
        self.background = pg.image.load(backgrounds[self.level - 1])
        self.board = pg.image.load(backimages[0])
        self.door = pg.image.load(backimages[1])
        self.right_margin = pg.image.load(backimages[2])
        self.screen = pg.display.set_mode((WIDTH, HEIGHT), pg.RESIZABLE)
        pg.display.set_caption("Client2")
        #self.screen.blit(self.background, [250,250])
        self.clock = pg.time.Clock()
        self.running = True
        self.playing = True
        self.waiting = True
        self.inf1 = ''
        self.inf2 = ''
        self.release = True
        self.pressTime = time.time()

        #sprite groups
        self.all_sprites = pg.sprite.Group()
        self.all_blocks = pg.sprite.Group()
        self.all_bullets = pg.sprite.Group()
        self.all_bonus = pg.sprite.Group()
        self.all_superbullets = pg.sprite.Group()
        for i in range(20):
            map = maps[0]
            for j in range(20):
                if map[i][j] == 1:
                    bl = Block(j, i, 1)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 2:
                    bl = Block(j, i, 0, True, 0)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 3:
                    bl = Block(j, i, 3, False, 1)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 4:
                    bl = Block(j, i, 2, False, 2)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 5:
                    bl = Block(j, i, 3, False, 3)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 6:
                    bl = Block(j, i, 1, False, 4)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 7:
                    bl = Block(j, i, 3, False, 5)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 8:
                    bl = Block(j, i, 2, False, 6)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 'b':
                    self.chef1 = Chef(j, i, chef1_moves, False,
                                      self.all_bullets, self.all_sprites,
                                      self.all_superbullets, self.all_blocks)
                    self.all_sprites.add(self.chef1)
                    # self.chef1.set_center(j, i)
                    # self.chef1.set_cabbage(10)
                    # self.chef1.set_life(1)
                elif map[i][j] == 'a':
                    self.chef2 = Chef(j, i, chef2_moves, True,
                                      self.all_bullets, self.all_sprites,
                                      self.all_superbullets, self.all_blocks)
                    self.all_sprites.add(self.chef2)
                    # self.chef2.set_center(j, i)
                    # self.chef2.set_cabbage(10)
                    # self.chef2.set_life(1)

    # def light_up()
    #if self.level == 5:
        self.fog = pg.Surface((800, 800))
        self.fog.fill(BLACK)
        self.light_mask1 = pg.image.load(light1).convert_alpha()
        self.light_mask2 = pg.image.load(light2).convert_alpha()
        self.light_mask1 = pg.transform.scale(self.light_mask1, LIGHT_RS)
        self.light_mask2 = pg.transform.scale(self.light_mask2, LIGHT_RS)
        self.light_rect1 = self.light_mask1.get_rect()
        self.light_rect2 = self.light_mask2.get_rect()

    def move(self):
        if self.inf1 == 'left':
            self.chef1.move_left()
            #print("get message")
        elif self.inf1 == 'right':
            self.chef1.move_right()
            #print("get message")
        elif self.inf1 == 'up':
            self.chef1.move_forward()
            #print("get message")
        elif self.inf1 == 'down':
            self.chef1.move_backward()
            #print("get message")
        elif self.inf1 == 'shoot':
            #print("get message")
            self.chef1.shoot()

        if self.inf2 == 'left':
            self.chef2.move_left()
            #print("get message")
        elif self.inf2 == 'right':
            self.chef2.move_right()
            #print("get message")
        elif self.inf2 == 'up':
            self.chef2.move_forward()
            #print("get message")
        elif self.inf2 == 'down':
            self.chef2.move_backward()
            #print("get message")
        elif self.inf2 == 'shoot':
            self.chef2.shoot()

    def create(self):
        #0 is nothing
        #1 is empty bl
        #2 is not shootable
        #3 is life - health = 3
        #4 is cabbage - 2
        #5 is point - 3

        #def __init__(self, x, y, health, indestructable = False, bonus = 0 ):
        map = maps[self.level - 1]
        for i in range(20):
            for j in range(20):
                if map[i][j] == 1:
                    bl = Block(j, i, 1)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 2:
                    bl = Block(j, i, 0, True, 0)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 3:
                    bl = Block(j, i, 3, False, 1)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 4:
                    bl = Block(j, i, 2, False, 2)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 5:
                    bl = Block(j, i, 3, False, 3)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 6:
                    bl = Block(j, i, 1, False, 4)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 7:
                    bl = Block(j, i, 3, False, 5)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 8:
                    bl = Block(j, i, 2, False, 6)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 'b':
                    # self.chef1 = Chef(j, i, chef1_moves, False, self.all_bullets, self.all_sprites,self.all_superbullets)
                    # self.all_sprites.add(self.chef1)
                    self.chef1.set_center(j, i)
                    self.chef1.set_cabbage(40)
                    self.chef1.set_life(1)
                    self.chef1.set_block_group(self.all_blocks)
                elif map[i][j] == 'a':
                    # self.chef2 = Chef(j, i, chef1_moves, True, self.all_bullets, self.all_sprites, self.all_superbullets)
                    # self.all_sprites.add(self.chef2)
                    self.chef2.set_center(j, i)
                    self.chef2.set_cabbage(40)
                    self.chef2.set_life(1)
                    self.chef2.set_block_group(self.all_blocks)

    def setup_next_level(self):
        for bul in self.all_bullets:
            bul.kill()
        for sbul in self.all_superbullets:
            sbul.kill()
        for bl in self.all_blocks:
            bl.kill()
        for bn in self.all_bonus:
            bn.kill()
        if not self.waiting:
            self.level += 1
            self.create()
        self.playing = True

    def update(self):
        self.move()
        self.reset_inf()
        hit_block = pg.sprite.groupcollide(self.all_blocks, self.all_bullets,
                                           False, True)
        hit_block2 = pg.sprite.groupcollide(
            self.all_blocks, self.all_superbullets, False,
            False)  #if the block turn into the bonus -> True, False
        shoot_chef1 = pg.sprite.spritecollide(self.chef1, self.all_bullets,
                                              True)
        shoot_chef2 = pg.sprite.spritecollide(self.chef2, self.all_bullets,
                                              True)
        shoot_chef_1 = pg.sprite.spritecollide(self.chef1,
                                               self.all_superbullets, True)
        shoot_chef_2 = pg.sprite.spritecollide(self.chef2,
                                               self.all_superbullets, True)

        if shoot_chef1 or shoot_chef_1:
            self.chef1.is_hit()
            # 	if self.chef1.get_life == 0:
            # 		self.playing= False
            self.chef2.claim_point()
            self.chef2.claim_point()
        if shoot_chef2 or shoot_chef_2:
            self.chef2.is_hit()
            # 	if self.chef2.get_life == 0:
            # 		print('client 2 should be dead')
            # 		self.playing= False
            self.chef1.claim_point()
            self.chef1.claim_point()

        for bl in hit_block.keys():
            bl.decrementHealth()
            if bl.getHealth() == 0:
                if bl.getBonus() == 0:
                    bl.kill()
                    sound = pg.mixer.Sound('blockcrack.wav')
                    sound.play()
                else:
                    sound = pg.mixer.Sound('powerupblock.wav')
                    sound.play()
                    self.all_bonus.add(bl)
                    self.all_blocks.remove(bl)

        for bl in hit_block2.keys():
            bl.setHealth(0)
            if bl.getHealth() == 0:
                if bl.getBonus() == 0:
                    bl.kill()
                    sound = pg.mixer.Sound('blockcrack.wav')
                    sound.play()
                else:
                    sound = pg.mixer.Sound('powerupblock.wav')
                    sound.play()
                    self.all_bonus.add(bl)
                    self.all_blocks.remove(bl)

        chef1_hit_bonus = pg.sprite.spritecollide(self.chef1, self.all_bonus,
                                                  True)
        for bonus in chef1_hit_bonus:
            if bonus.getBonus() == 1:
                self.chef1.claim_life()
            elif bonus.getBonus() == 2:
                self.chef1.claim_cabbage()
            elif bonus.getBonus() == 4:
                self.chef1.gainSpeed()
            elif bonus.getBonus() == 5:
                self.chef1.claim_superbullet()
            elif bonus.getBonus() == 6:
                self.chef1.gainLight()
            else:
                self.chef1.claim_point()

        chef2_hit_bonus = pg.sprite.spritecollide(self.chef2, self.all_bonus,
                                                  True)
        for bonus in chef2_hit_bonus:
            if bonus.getBonus() == 1:
                self.chef2.claim_life()
            elif bonus.getBonus() == 2:
                self.chef2.claim_cabbage()
            elif bonus.getBonus() == 4:
                self.chef2.gainSpeed()
            elif bonus.getBonus() == 5:
                self.chef2.claim_superbullet()
            elif bonus.getBonus() == 6:
                self.chef2.gainLight()
            else:
                self.chef1.claim_point()

        # chef1_old_x = self.chef1.get_x()
        # chef1_old_y = self.chef1.get_y()

        # chef2_old_x = self.chef2.get_x()
        # chef2_old_y = self.chef2.get_y()

        self.all_sprites.update()

    # 	chef1_collide_block = pg.sprite.spritecollide(self.chef1, self.all_blocks, False)
    # 	if chef1_collide_block:
    # 		self.chef1.set_x(chef1_old_x)
    # 		self.chef1.set_y(chef1_old_y)
    # # 			self.chef1.set_sound(None)

    # 	chef2_collide_block = pg.sprite.spritecollide(self.chef2, self.all_blocks, False)
    # 	if chef2_collide_block:
    # 		self.chef2.set_x(chef2_old_x)
    # 		self.chef2.set_y(chef2_old_y)
    # # 			self.chef2.set_sound(None)

    def run_level(self):
        pg.mixer.music.load('song.wav')
        pg.mixer.music.play(-1)
        while self.playing:

            # for bl in self.all_bullets:
            # 	bl.kill()
            # for bl in self.all_superbullets:
            # 	bl.kill()
            self.clock.tick(FPS)
            self.events()
            lc.handle_timeout(1)
            self.update()
            self.draw()
            # if self.chef1.is_dead() or self.chef2.is_dead():
            # 	if self.level == 5:
            # 		self.running = False
            # 	self.playing = False
            # for spr in self.all_sprites:
            # 	spr.kill()
            if self.chef1.is_dead():
                out = input_t()
                out.player = 1
                out.motion = "dead"
                lc.publish("TO SERVER", out.encode())
                if self.level == 5:
                    self.running = False
                self.playing = False
            elif self.chef2.is_dead():
                out = input_t()
                out.player = 2
                out.motion = "dead"
                lc.publish("TO SERVER", out.encode())
                if self.level == 5:
                    self.running = False
                self.playing = False

    def level_successful(self):
        if self.playing == False:
            return True
        else:
            return False

    def done(self):
        if self.running == False:
            return True
        else:
            return False

    def events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                # if self.playing:
                # 	self.playing = False
                # self.running = False
                pg.quit()
        key = pg.key.get_pressed()
        sending_out = input_t()
        sending_out.player = 2
        judgeTime = time.time()
        if key[pg.K_LEFT]:
            if judgeTime - self.pressTime > 0.1:
                sending_out.motion = "left"
                self.release = False
                lc.publish("TO SERVER", sending_out.encode())
                self.pressTime = time.time()
        elif key[pg.K_RIGHT]:
            if judgeTime - self.pressTime > 0.1:
                sending_out.motion = "right"
                self.release = False
                lc.publish("TO SERVER", sending_out.encode())
                self.pressTime = time.time()
        elif key[pg.K_UP]:
            if judgeTime - self.pressTime > 0.1:
                sending_out.motion = "up"
                self.release = False
                lc.publish("TO SERVER", sending_out.encode())
                self.pressTime = time.time()
        elif key[pg.K_DOWN]:
            if judgeTime - self.pressTime > 0.1:
                sending_out.motion = "down"
                self.release = False
                lc.publish("TO SERVER", sending_out.encode())
                self.pressTime = time.time()
        elif key[pg.K_SPACE]:
            if judgeTime - self.pressTime > 0.5:
                sending_out.motion = "shoot"
                self.release = False
                lc.publish("TO SERVER", sending_out.encode())
                self.pressTime = time.time()
        else:
            self.release = True

    def makefog(self):
        self.fog.fill(BLACK)
        if self.chef2.get_Light():
            self.light_mask1 = pg.transform.scale(self.light_mask1, LIGHT_RB)
            self.light_rect1 = self.light_mask1.get_rect()
            self.chef2.set_endLight()
            elapsed = self.chef2.get_endLight() - self.chef2.get_stLight()
            if elapsed >= 5.00:
                self.chef2.close_Light()
                self.light_mask1 = pg.transform.scale(self.light_mask1,
                                                      LIGHT_RS)
                self.light_rect1 = self.light_mask1.get_rect()

        # if self.chef1.get_Light():
        # 	self.light_mask2= pg.transform.scale(self.light_mask2,LIGHT_RB)
        # 	self.light_rect2=self.light_mask2.get_rect()
        # 	self.chef1.set_endLight()
        # 	elapsed = self.chef1.get_endLight()-self.chef1.get_stLight()
        # 	if elapsed >= 5.00:
        # 		self.chef1.close_Light()
        # 		self.light_mask2= pg.transform.scale(self.light_mask2,LIGHT_RS)
        # 		self.light_rect2=self.light_mask2.get_rect()

        self.light_rect1.center = (self.chef2.get_center()[0] - 100,
                                   self.chef2.get_center()[1] - 200)
        # self.light_rect2.center=(self.chef1.get_center()[0]-200,self.chef1.get_center()[1]-200)
        self.fog.blit(self.light_mask1, self.light_rect1)
        # self.fog.blit(self.light_mask2,self.light_rect2)
        self.screen.blit(self.fog, (100, 200), special_flags=pg.BLEND_MULT)

    def draw(self):
        self.screen.blit(self.background, [100, 200])
        self.screen.blit(self.right_margin, [900, 200])
        self.screen.blit(self.door, [-100, 200])
        self.screen.blit(self.board, [0, 0])
        self.all_sprites.draw(self.screen)
        #text to print
        if self.chef2.get_Light():
            t2 = 5.00 - self.chef2.get_endLight() + self.chef2.get_stLight()
            text_Light2 = str("%.1f" % t2)
        else:
            text_Light2 = 'No'

        # if self.chef1.get_Light():
        # 	t1 = 5.00-self.chef1.get_endLight()+self.chef1.get_stLight()
        # 	text_Light1 = str("%.1f" % t1)
        # else:
        # 	text_Light1 = 'No'

        if self.chef2.get_speed():
            t4 = 5.00 - self.chef2.get_endSpeed() + self.chef2.get_stSpeed()
            text_Speed2 = str("%.1f" % t4)
        else:
            text_Speed2 = 'No'

        if self.chef1.get_speed():
            t3 = 5.00 - self.chef1.get_endSpeed() + self.chef1.get_stSpeed()
            text_Speed1 = str("%.1f" % t3)
        else:
            text_Speed1 = 'No'

        draw_text(self.screen, str(self.level), 55, 550, 40)  #level
        draw_text(self.screen, str(self.chef2.get_cabbage()), 25, 100,
                  85)  #c2 cabbage
        draw_text(self.screen, str(self.chef1.get_cabbage()), 25, 810,
                  85)  #c1 cabbage
        draw_text(self.screen, str(self.chef2.get_life()), 25, 100,
                  127)  #c2 life
        draw_text(self.screen, str(self.chef1.get_life()), 25, 810,
                  127)  #c1 life
        draw_text(self.screen, str(self.chef2.get_point()), 40, 380,
                  130)  #c2 score
        draw_text(self.screen, str(self.chef1.get_point()), 40, 600,
                  130)  #c1 score
        draw_text(self.screen, str(self.chef2.get_superbullet()), 25, 225,
                  127)  #c2 superbullet
        draw_text(self.screen, str(self.chef1.get_superbullet()), 25, 930,
                  127)  #c1 superbullet
        draw_text(self.screen, text_Speed2, 25, 100, 167)  #c2 speed up
        draw_text(self.screen, text_Speed1, 25, 810, 167)  #c1 speed up
        draw_text(self.screen, text_Light2, 25, 225, 85)  #c2 light up
        draw_text(self.screen, '???', 25, 930, 85)  #c1 light up

        if self.level > 2:
            self.makefog()
        pg.display.update()

    def get_block(self, x, y):
        for bl in self.all_blocks:
            if bl.get_x() == x and bl.get_y() == y:
                return bl

    def show_start_screen(self):
        pg.mixer.music.load('song2.wav')
        pg.mixer.music.play(-1)
        background = pg.image.load('startscreen.png')
        self.screen.blit(background, [0, 0])
        pg.display.update()

        click = False
        # waiting = True
        #click = pg.mouse.get_pressed()
        while self.waiting:
            if click == False:
                lc.handle_timeout(10)
                for event in pg.event.get():
                    if event.type == pg.QUIT:
                        pg.quit()
                    mouse = pg.mouse.get_pos()
                    if 700 < mouse[0] < 800 and 600 < mouse[1] < 850:
                        background = pg.image.load(
                            'startscreen-select-play.png')
                        self.screen.blit(background, [0, 0])
                        if event.type == pg.MOUSEBUTTONDOWN:
                            click = True

                            start = input_t()
                            start.motion = "start"
                            start.player = 2
                            print("client2 click")
                            lc.publish("TO SERVER", start.encode())

                            #waiting = False
                    elif 212 < mouse[0] < 314 and 862 < mouse[1] < 964:
                        background = pg.image.load(
                            'startscreen-select-tut.png')
                        self.screen.blit(background, [0, 0])
                        if event.type == pg.MOUSEBUTTONDOWN:
                            self.tutorial()

                            #waiting = False
                    elif 25 < mouse[0] < 145 and 855 < mouse[1] < 975:
                        background = pg.image.load(
                            'startscreen-select-creds.png')
                        self.screen.blit(background, [0, 0])
                        if event.type == pg.MOUSEBUTTONDOWN:
                            self.show_credit_screen()
                    else:
                        background = pg.image.load('startscreen.png')
                        self.screen.blit(background, [0, 0])
                    pg.display.update()
            else:
                lc.handle_timeout(10)
                print("clicked")
                print(self.background)
                background = pg.image.load("missing1.png")
                self.screen.blit(background, [0, 0])
                pg.display.update()
                for event in pg.event.get():
                    if event.type == pg.QUIT:
                        pg.quit()

    def show_credit_screen(self):
        print("show credit screen")
        background = pg.image.load('credit.png')
        self.screen.blit(background, [0, 0])
        pg.display.update()
        credit = True
        while credit:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    pg.quit()
                mouse = pg.mouse.get_pos()
                if 735 < mouse[0] < 1000 and 915 < mouse[1] < 1000:
                    background = pg.image.load("credit-select-back.png")
                    self.screen.blit(background, [0, 0])
                    if event.type == pg.MOUSEBUTTONDOWN:
                        credit = False
                        self.show_start_screen()
                else:
                    background = pg.image.load('credit.png')
                    self.screen.blit(background, [0, 0])
                pg.display.update()

    def show_end_screen(self):
        if self.chef1.get_point() > self.chef2.get_point():
            background = pg.image.load("lose1.png")
        elif self.chef1.get_point() < self.chef2.get_point():
            background = pg.image.load("player1_end.png")
        else:
            #JUST TEMPORARY
            background = pg.image.load("tie.png")
        self.screen.blit(background, [0, 0])
        pg.display.update()
        while True:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    pg.quit()
                mouse = pg.mouse.get_pos()
                if event.type == pg.MOUSEBUTTONDOWN:
                    if 750 < mouse[0] < 1000 and 920 < mouse[1] < 1000:
                        pg.quit()

    def tutorial(self):
        title = pg.image.load("story title.PNG")
        block1 = Block(7, 6, 1)
        block2 = Block(7, 7, 3, False, 1)
        block3 = Block(7, 8, 3, False, 3)

        blocks = pg.sprite.Group()
        bonus = pg.sprite.Group()
        all_sprites = pg.sprite.Group()
        blocks.add(block1)
        blocks.add(block2)
        blocks.add(block3)
        all_sprites.add(block1)
        all_sprites.add(block2)
        all_sprites.add(block3)

        chef_test = Chef(10, 10, chef2_moves, True, self.all_bullets,
                         all_sprites, self.all_superbullets, blocks)
        all_sprites.add(chef_test)

        click = 0

        tutorial = True
        while tutorial:
            print(click)
            #self.screen.blit(skip, [100, 100])
            self.screen.blit(self.background, [100, 200])
            self.screen.blit(title, [0, 0])
            self.screen.blit(self.right_margin, [900, 200])
            self.screen.blit(self.door, [-100, 200])
            #self.screen.blit(self.board, [0, 0])

            picture_blit = pg.image.load(tutorial_graphics[click])
            if click == 0:
                self.screen.blit(picture_blit, [100, 200])
            elif click == 1:
                self.screen.blit(picture_blit, [100, 200])
                tutorial1 = pg.image.load('tutorial1.PNG')
                self.screen.blit(tutorial1, [0, 0])
            else:
                self.screen.blit(picture_blit, [0, 0])
                all_sprites.draw(self.screen)
            skip = pg.image.load("continue.png")
            skip.set_colorkey(WHITE)
            self.screen.blit(skip, [700, 930])

            self.clock.tick(FPS)
            key = pg.key.get_pressed()
            judgeTime = time.time()
            if key[pg.K_LEFT]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_left()
                    self.pressTime = time.time()
            elif key[pg.K_RIGHT]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_right()
                    self.pressTime = time.time()
            elif key[pg.K_UP]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_forward()
                    self.pressTime = time.time()
            elif key[pg.K_DOWN]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_backward()
                    self.pressTime = time.time()
            elif key[pg.K_SPACE]:
                if judgeTime - self.pressTime > 0.5:
                    chef_test.shoot()
                    self.pressTime = time.time()

            for event in pg.event.get():
                mouse = pg.mouse.get_pos()
                if event.type == pg.QUIT:
                    pg.quit()

                if event.type == pg.MOUSEBUTTONDOWN:
                    if 700 < mouse[0] < 1000 and 930 < mouse[1] < 1000:
                        click += 1
                        if click == 4:
                            #if 100 < mouse[0] < 350 and 100 < mouse[1] < 185:
                            tutorial = False
                            self.show_start_screen()

            hit_block = pg.sprite.groupcollide(blocks, self.all_bullets, False,
                                               True)
            for bl in hit_block.keys():
                bl.decrementHealth()
                if bl.getHealth() == 0:
                    if bl.getBonus() == 0:
                        bl.kill()
                        sound = pg.mixer.Sound('blockcrack.wav')
                        sound.play()
                    else:
                        sound = pg.mixer.Sound('powerupblock.wav')
                        sound.play()
                        bonus.add(bl)
                        blocks.remove(bl)
            hit_bonus = pg.sprite.spritecollide(chef_test, bonus, True)

            all_sprites.update()

            pg.display.update()


# for i in range (5):

# 	g1 = Game(i+1)
# 	lc.subscribe("SERVER_OUTPUT", get_my_handler(g1))
# 	g1.run()
# 	pg.quit()

# for i in range (5):
# 	g1 = Game(i+1)
# 	subscription = lc.subscribe("SERVER_OUTPUT", get_my_handler(g1))
# 	g1.show_start_screen()
# 	while g1.running:
# 		g1.run()
# 		g1.show_go_screen()
# 	lc.unsubscribe(subscription)
# pg.quit()

    def show_transition_screen(self):
        self.waiting = True
        if self.level == 2:
            background = pg.image.load("darktransition.png")
            background = pg.transform.scale(background, (1000, 1000))
            self.screen.blit(background, [0, 0])
            skip = pg.image.load("continue.PNG")
            self.screen.blit(skip, [700, 930])
        else:
            background = pg.image.load('transition.png')
            self.screen.blit(background, [0, 0])
        if not self.level == 2:
            draw_text(self.screen, str(self.level), 55, 550, 375)
            draw_text(self.screen, str(self.chef2.get_point()), 40, 380,
                      465)  #c2 score
            draw_text(self.screen, str(self.chef1.get_point()), 40, 600,
                      465)  #c1 score
        pg.display.update()
        while self.waiting:
            lc.handle_timeout(1)
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    pg.quit()
                mouse = pg.mouse.get_pos()
                if event.type == pg.MOUSEBUTTONDOWN:
                    if 700 < mouse[0] < 1000 and 900 < mouse[1] < 1000:
                        background = pg.image.load("missing2.png")
                        self.screen.blit(background, [0, 0])
                        pg.display.update()
                        next = input_t()
                        next.player = 2
                        next.motion = "start"
                        lc.publish("TO SERVER", next.encode())
                        #waiting = False
    def reset_inf(self):
        self.inf1 = ''
        self.inf2 = ''
コード例 #19
0
#-------------------------------------------------------------
# Classes and Objects
# - Create your own data type using class
# - Define your own data type
#
#-------------------------------------------------------------

from student import Student
from chineseChef import ChineseChef
from chef import Chef

student1 = Student("1111", "Anna", "Business", 3.1, False)
student2 = Student("2222", "Alex", "Computer Science", 3.8, False)
print(student2.name)

# Using object functions
print(student2.isOnHonorRoll())

mychef = Chef()
mychineseChef = ChineseChef()

mychef.makeSpecialDish()
mychineseChef.makeSpecialDish()
コード例 #20
0
    def tutorial(self):
        title = pg.image.load("story title.PNG")
        block1 = Block(7, 6, 1)
        block2 = Block(7, 7, 3, False, 1)
        block3 = Block(7, 8, 3, False, 3)

        blocks = pg.sprite.Group()
        bonus = pg.sprite.Group()
        all_sprites = pg.sprite.Group()
        blocks.add(block1)
        blocks.add(block2)
        blocks.add(block3)
        all_sprites.add(block1)
        all_sprites.add(block2)
        all_sprites.add(block3)

        chef_test = Chef(10, 10, chef2_moves, True, self.all_bullets,
                         all_sprites, self.all_superbullets, blocks)
        all_sprites.add(chef_test)

        click = 0

        tutorial = True
        while tutorial:
            print(click)
            #self.screen.blit(skip, [100, 100])
            self.screen.blit(self.background, [100, 200])
            self.screen.blit(title, [0, 0])
            self.screen.blit(self.right_margin, [900, 200])
            self.screen.blit(self.door, [-100, 200])
            #self.screen.blit(self.board, [0, 0])

            picture_blit = pg.image.load(tutorial_graphics[click])
            if click == 0:
                self.screen.blit(picture_blit, [100, 200])
            elif click == 1:
                self.screen.blit(picture_blit, [100, 200])
                tutorial1 = pg.image.load('tutorial1.PNG')
                self.screen.blit(tutorial1, [0, 0])
            else:
                self.screen.blit(picture_blit, [0, 0])
                all_sprites.draw(self.screen)
            skip = pg.image.load("continue.png")
            skip.set_colorkey(WHITE)
            self.screen.blit(skip, [700, 930])

            self.clock.tick(FPS)
            key = pg.key.get_pressed()
            judgeTime = time.time()
            if key[pg.K_LEFT]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_left()
                    self.pressTime = time.time()
            elif key[pg.K_RIGHT]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_right()
                    self.pressTime = time.time()
            elif key[pg.K_UP]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_forward()
                    self.pressTime = time.time()
            elif key[pg.K_DOWN]:
                if judgeTime - self.pressTime > 0.05:
                    chef_test.move_backward()
                    self.pressTime = time.time()
            elif key[pg.K_SPACE]:
                if judgeTime - self.pressTime > 0.5:
                    chef_test.shoot()
                    self.pressTime = time.time()

            for event in pg.event.get():
                mouse = pg.mouse.get_pos()
                if event.type == pg.QUIT:
                    pg.quit()

                if event.type == pg.MOUSEBUTTONDOWN:
                    if 700 < mouse[0] < 1000 and 930 < mouse[1] < 1000:
                        click += 1
                        if click == 4:
                            #if 100 < mouse[0] < 350 and 100 < mouse[1] < 185:
                            tutorial = False
                            self.show_start_screen()

            hit_block = pg.sprite.groupcollide(blocks, self.all_bullets, False,
                                               True)
            for bl in hit_block.keys():
                bl.decrementHealth()
                if bl.getHealth() == 0:
                    if bl.getBonus() == 0:
                        bl.kill()
                        sound = pg.mixer.Sound('blockcrack.wav')
                        sound.play()
                    else:
                        sound = pg.mixer.Sound('powerupblock.wav')
                        sound.play()
                        bonus.add(bl)
                        blocks.remove(bl)
            hit_bonus = pg.sprite.spritecollide(chef_test, bonus, True)

            all_sprites.update()

            pg.display.update()
コード例 #21
0
from chef import Chef
from japChef import JapChef

chef1 = Chef()
chef1.make_special_dish()

chef2 = JapChef()
chef2.make_chicken()
chef2.make_special_dish()
コード例 #22
0
class Game:
    def __init__(self, level, chef1_points=0, chef2_points=0):
        pg.mixer.init()
        self.running = True
        if level == 0:
            self.background = pg.image.load('startscreen.png')
        elif level > 0 and level < 6 or level == 8:
            self.background = pg.image.load("background.png")
            self.board = pg.image.load(backimages[0])
            self.door = pg.image.load(backimages[1])
            self.right_margin = pg.image.load(backimages[2])
            self.skip = pg.image.load('SKIP.png')
            self.bonus_image = pg.image.load('BONUS.png')
        elif level == 6:
            if chef1_points > chef2_points:
                self.background = pg.image.load('player1_end.png')
            elif chef2_points > chef1_points:
                self.background = pg.image.load('player2_end.png')
            else:
                self.background = pg.image.load('tie.PNG')
        elif level == 7:
            self.background = pg.image.load('credit.png')
        else:
            g = Game(0)
            g.run()
            self.running = False
        self.screen = pg.display.set_mode((WIDTH, HEIGHT), pg.RESIZABLE)
        pg.display.set_caption("Chef War")
        #self.screen.blit(self.background, [250,250])
        self.level = level
        self.clock = pg.time.Clock()
        #sprite groups
        self.all_sprites = pg.sprite.Group()
        self.all_blocks = pg.sprite.Group()
        self.all_bullets = pg.sprite.Group()
        self.all_bonus = pg.sprite.Group()
        self.all_superbullets = pg.sprite.Group()
        self.chef1_points = chef1_points
        self.chef2_points = chef2_points
        self.transition_image = pg.image.load('transition.png')
        self.show_transition = False
        self.darkmode = False
        print('points:', self.chef1_points, self.chef2_points)

        #light up
        if self.level == 5:
            self.fog = pg.Surface((800, 800))
            self.fog.fill(BLACK)
            self.light_mask1 = pg.image.load(light1).convert_alpha()
            self.light_mask2 = pg.image.load(light2).convert_alpha()
            self.light_mask1 = pg.transform.scale(self.light_mask1, LIGHT_RS)
            self.light_mask2 = pg.transform.scale(self.light_mask2, LIGHT_RS)
            self.light_rect1 = self.light_mask1.get_rect()
            self.light_rect2 = self.light_mask2.get_rect()

        if self.level > 0 and self.level < 6 or level == 8:
            if self.level > 0 and self.level < 6:
                self.map = maps[self.level - 1]
            else:
                self.map = tutorial

            for i in range(20):
                for j in range(20):
                    if self.map[i][j] == 1:
                        bl = Block(j, i, 1)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 2:
                        bl = Block(j, i, 0, True, 0)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 3:
                        bl = Block(j, i, 3, False, 1)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 4:
                        bl = Block(j, i, 2, False, 2)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 5:
                        bl = Block(j, i, 3, False, 3)
                        self.all_sprites
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 6:
                        bl = Block(j, i, 1, False, 4)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 7:
                        bl = Block(j, i, 3, False, 5)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 8:
                        bl = Block(j, i, 2, False, 6)
                        self.all_sprites.add(bl)
                        self.all_blocks.add(bl)
                    elif self.map[i][j] == 'a':
                        self.chef1 = Chef(j, i, chef1_moves, True,
                                          self.all_bullets, self.all_sprites,
                                          self.all_superbullets)
                    elif self.map[i][j] == 'b':
                        self.chef2 = Chef(j, i, chef2_moves, False,
                                          self.all_bullets, self.all_sprites,
                                          self.all_superbullets)

            #apend sprite here
            self.all_sprites.add(self.chef1)
            self.all_sprites.add(self.chef2)

    def run(self):
        music = ['sountrack.wav', 'song.wav', 'song2.wav']
        music_playing = music[2]
        if self.level == 0 or self.level > 3 or self.level == 8:
            music_playing = music[2]
        elif self.level > 0 or self.level < 3:
            music_playing = music[1]
        self.playing = True
        pg.mixer.music.load(music_playing)
        pg.mixer.music.play(-1)
        while self.playing:
            self.clock.tick(FPS)
            self.events()
            if self.level > 0 and self.level < 6:
                if self.chef1.is_dead() or self.chef2.is_dead():
                    self.show_transition = True
                else:
                    self.update()
            elif self.level == 8:
                self.update()
            if self.show_transition == False:
                self.draw()
            else:
                self.transition()

    def update(self):

        hit_block = pg.sprite.groupcollide(self.all_blocks, self.all_bullets,
                                           False, True)
        hit_block2 = pg.sprite.groupcollide(
            self.all_blocks, self.all_superbullets, False,
            False)  #if the block turn into the bonus -> True, False
        shoot_chef1 = pg.sprite.spritecollide(self.chef1, self.all_bullets,
                                              True)
        shoot_chef2 = pg.sprite.spritecollide(self.chef2, self.all_bullets,
                                              True)
        shoot_chef_1 = pg.sprite.spritecollide(self.chef1,
                                               self.all_superbullets, True)
        shoot_chef_2 = pg.sprite.spritecollide(self.chef2,
                                               self.all_superbullets, True)

        if shoot_chef1 or shoot_chef_1:
            self.chef1.is_hit()
            if self.chef1.get_life == 0:
                self.running = False
            self.chef2_points += 1
        if shoot_chef2 or shoot_chef_2:
            self.chef2.is_hit()
            if self.chef2.get_life == 0:
                self.running = False
            self.chef1_points += 1

        for bl in hit_block.keys():
            bl.decrementHealth()
            if bl.getHealth() == 0:
                if bl.getBonus() == 0:
                    bl.kill()
                else:
                    self.all_bonus.add(bl)
                    self.all_blocks.remove(bl)

        for bl in hit_block2.keys():
            bl.setHealth(0)
            if bl.getHealth() == 0:
                if bl.getBonus() == 0:
                    bl.kill()
                else:
                    self.all_bonus.add(bl)
                    self.all_blocks.remove(bl)

        chef1_hit_bonus = pg.sprite.spritecollide(self.chef1, self.all_bonus,
                                                  True)
        for bonus in chef1_hit_bonus:
            if bonus.getBonus() == 1:
                self.chef1.claim_life()
            elif bonus.getBonus() == 2:
                self.chef1.claim_cabbage()
            elif bonus.getBonus() == 4:
                self.chef1.gainSpeed()
            elif bonus.getBonus() == 5:
                self.chef1.claim_superbullet()
            elif bonus.getBonus() == 6:
                self.chef1.gainLight()
            else:
                self.chef1_points += 2

        chef2_hit_bonus = pg.sprite.spritecollide(self.chef2, self.all_bonus,
                                                  True)
        for bonus in chef2_hit_bonus:
            if bonus.getBonus() == 1:
                self.chef2.claim_life()
            elif bonus.getBonus() == 2:
                self.chef2.claim_cabbage()
            elif bonus.getBonus() == 4:
                self.chef2.gainSpeed()
            elif bonus.getBonus() == 5:
                self.chef2.claim_superbullet()
            elif bonus.getBonus() == 6:
                self.chef2.gainLight()
            else:
                self.chef2_points += 2

        chef1_old_x = self.chef1.get_x()
        chef1_old_y = self.chef1.get_y()

        chef2_old_x = self.chef2.get_x()
        chef2_old_y = self.chef2.get_y()

        self.all_sprites.update()

        chef1_collide_block = pg.sprite.spritecollide(self.chef1,
                                                      self.all_blocks, False)
        if chef1_collide_block:
            self.chef1.set_x(chef1_old_x)
            self.chef1.set_y(chef1_old_y)
    # 			self.chef1.set_sound(None)

        chef2_collide_block = pg.sprite.spritecollide(self.chef2,
                                                      self.all_blocks, False)
        if chef2_collide_block:
            self.chef2.set_x(chef2_old_x)
            self.chef2.set_y(chef2_old_y)

    # 			self.chef2.set_sound(None)

    def events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                print("Quit")
                if self.playing:
                    self.playing = False
                self.running = False

    def makefog(self):
        self.fog.fill(BLACK)
        if self.chef2.get_Light():
            self.light_mask1 = pg.transform.scale(self.light_mask1, LIGHT_RB)
            self.light_rect1 = self.light_mask1.get_rect()
            self.chef2.set_endLight()
            elapsed = self.chef2.get_endLight() - self.chef2.get_stLight()
            if elapsed >= 5.00:
                self.chef2.close_Light()
                self.light_mask1 = pg.transform.scale(self.light_mask1,
                                                      LIGHT_RS)
                self.light_rect1 = self.light_mask1.get_rect()

        if self.chef1.get_Light():
            self.light_mask2 = pg.transform.scale(self.light_mask2, LIGHT_RB)
            self.light_rect2 = self.light_mask2.get_rect()
            self.chef1.set_endLight()
            elapsed = self.chef1.get_endLight() - self.chef1.get_stLight()
            if elapsed >= 5.00:
                self.chef1.close_Light()
                self.light_mask2 = pg.transform.scale(self.light_mask2,
                                                      LIGHT_RS)
                self.light_rect2 = self.light_mask2.get_rect()

        self.light_rect1.center = (self.chef2.get_center()[0] - 100,
                                   self.chef2.get_center()[1] - 200)
        self.light_rect2.center = (self.chef1.get_center()[0] - 100,
                                   self.chef1.get_center()[1] - 200)
        self.fog.blit(self.light_mask1, self.light_rect1)
        self.fog.blit(self.light_mask2, self.light_rect2)
        self.screen.blit(self.fog, (100, 200), special_flags=pg.BLEND_MULT)

    def draw(self):
        if self.level == 0:
            self.screen.blit(self.background, [0, 0])

            if self.level == 0:
                mouse = pg.mouse.get_pos()
                click = pg.mouse.get_pressed()
                if 700 < mouse[0] < 800 and 600 < mouse[1] < 850:
                    self.background = pg.image.load(
                        'startscreen-select-play.png')
                    if click[0] == 1:
                        g = Game(1)
                        g.run()
                        self.playing = False
                elif 212 < mouse[0] < 314 and 862 < mouse[1] < 964:
                    self.background = pg.image.load(
                        'startscreen-select-tut.png')
                    if click[0] == 1:
                        t = tut.Tutorial()
                        t.run()
                        self.playing = False
                elif 42 < mouse[0] < 144 and 862 < mouse[1] < 964:
                    self.background = pg.image.load(
                        'startscreen-select-creds.png')
                    if click[0] == 1:
                        g = Game(7)
                        g.run()
                        self.playing = False
                else:
                    self.background = pg.image.load('startscreen.png')
            self.all_sprites.draw(self.screen)

        elif self.level > 0 and self.level < 6 or self.level == 8:
            self.screen.blit(self.right_margin, [900, 200])
            self.screen.blit(self.door, [-100, 200])
            self.screen.blit(self.background, [100, 200])
            if self.level == 8:
                self.screen.blit(self.bonus_image, [0, 0])
            else:
                self.screen.blit(self.board, [0, 0])
            mouse = pg.mouse.get_pos()
            click = pg.mouse.get_pressed()
            if self.level == 8:
                self.screen.blit(self.skip, [740, 910, 210, 50])
                if 740 < mouse[0] < 950 and 910 < mouse[1] < 960:
                    self.skip = pg.image.load('SKIP-select.png')
                    if click[0] == 1:
                        g = Game(1)
                        g.run()
                        self.playing = False
                else:
                    self.skip = pg.image.load('SKIP.png')
            self.all_sprites.draw(self.screen)
            #text to print
            if self.chef2.get_Light():
                t2 = 5.00 - self.chef2.get_endLight() + self.chef2.get_stLight(
                )
                text_Light2 = str("%.1f" % t2)
            else:
                text_Light2 = 'No'

            if self.chef1.get_Light():
                t1 = 5.00 - self.chef1.get_endLight() + self.chef1.get_stLight(
                )
                text_Light1 = str("%.1f" % t1)
            else:
                text_Light1 = 'No'

            if self.chef2.get_speed():
                t4 = 5.00 - self.chef2.get_endSpeed() + self.chef2.get_stSpeed(
                )
                text_Speed2 = str("%.1f" % t4)
            else:
                text_Speed2 = 'No'

            if self.chef1.get_speed():
                t3 = 5.00 - self.chef1.get_endSpeed() + self.chef1.get_stSpeed(
                )
                text_Speed1 = str("%.1f" % t3)
            else:
                text_Speed1 = 'No'

            if self.level != 8:
                draw_text(self.screen, str(self.level), 55, 550, 40)  #level
                draw_text(self.screen, str(self.chef1.get_cabbage()), 25, 100,
                          85)  #c2 cabbage
                draw_text(self.screen, str(self.chef2.get_cabbage()), 25, 810,
                          85)  #c1 cabbage
                draw_text(self.screen, str(self.chef1.get_life()), 25, 100,
                          127)  #c2 life
                draw_text(self.screen, str(self.chef2.get_life()), 25, 810,
                          127)  #c1 life
                draw_text(self.screen, str(self.chef1_points), 40, 380,
                          130)  #c2 score
                draw_text(self.screen, str(self.chef2_points), 40, 600,
                          130)  #c1 score
                draw_text(self.screen, str(self.chef1.get_superbullet()), 25,
                          225, 127)  #c2 superbullet
                draw_text(self.screen, str(self.chef2.get_superbullet()), 25,
                          930, 127)  #c1 superbullet
                draw_text(self.screen, text_Speed1, 25, 100, 167)  #c2 speed up
                draw_text(self.screen, text_Speed2, 25, 810, 167)  #c1 speed up
                draw_text(self.screen, text_Light1, 25, 225, 85)  #c2 light up
                draw_text(self.screen, text_Light2, 25, 930, 85)  #c1 light up

            if self.level == 5:
                self.makefog()
            #self.chef1.get_all_bullets.draw(self.screen)
        elif self.level == 6:
            self.screen.blit(self.background, [0, 0])
            # pg.draw.rect(self.screen, BLACK, [740,910,210,50])
            mouse = pg.mouse.get_pos()
            click = pg.mouse.get_pressed()
            if 740 < mouse[0] < 950 and 910 < mouse[1] < 960:
                if self.chef1_points > self.chef2_points:
                    self.background = pg.image.load(
                        'player1_end-select-back.png')
                else:
                    self.background = pg.image.load(
                        'player2_end-select-back.png')
                if click[0] == 1:
                    g = Game(7)
                    g.run()
                    self.playing = False
            else:
                if self.chef1_points > self.chef2_points:
                    self.background = pg.image.load('player1_end.png')
                else:
                    self.background = pg.image.load('player2_end.png')
        else:
            self.screen.blit(self.background, [0, 0])
            mouse = pg.mouse.get_pos()
            click = pg.mouse.get_pressed()
            if 740 < mouse[0] < 950 and 910 < mouse[1] < 960:
                self.background = pg.image.load('credit-select-back.png')
                if click[0] == 1:
                    g = Game(0)
                    g.run()
                    self.playing = False
            else:
                self.background = pg.image.load('credit.png')
        pg.display.update()

        def show_start_screen(self):
            pass

        def show_go_screen(self):
            pass

    def transition(self):
        mouse = pg.mouse.get_pos()
        click = pg.mouse.get_pressed()
        if self.darkmode:
            self.transition_image = pg.image.load('darktransition.png')
            self.screen.blit(self.transition_image, [0, 0])
            self.screen.blit(self.skip, [740, 910, 210, 50])
            if 740 < mouse[0] < 950 and 910 < mouse[1] < 960:
                self.skip = pg.image.load('SKIP-select.png')
                if click[0] == 1:
                    self.darkmode = False
                    g = Game(5, self.chef1_points, self.chef2_points)
                    g.run()
                    self.running = False
                    self.playing = False
                    self.show_transition = False

            else:
                self.skip = pg.image.load('SKIP.png')
        else:
            self.screen.blit(self.transition_image, [0, 0])
            if 750 < mouse[0] < 965 and 925 < mouse[1] < 975:
                self.transition_image = pg.image.load(
                    'transition-next-select.png')
                if click[0] == 1:
                    if self.level == 4:
                        self.darkmode = True
                    else:
                        g = Game(self.level + 1, self.chef1_points,
                                 self.chef2_points)
                        g.run()
                        self.running = False
                        self.playing = False
                        self.show_transition = False
            else:
                self.transition_image = pg.image.load('transition.png')
            draw_text(self.screen, str(self.level), 55, 550, 380)
            draw_text(self.screen, str(self.chef1_points), 60, 350,
                      460)  #c2 score
            draw_text(self.screen, str(self.chef2_points), 60, 600,
                      460)  #c1 score
        pg.display.update()
コード例 #23
0
    def __init__(self):
        pg.mixer.init()
        self.level = 1
        self.background = pg.image.load(backgrounds[self.level - 1])
        self.board = pg.image.load(backimages[0])
        self.door = pg.image.load(backimages[1])
        self.right_margin = pg.image.load(backimages[2])
        self.screen = pg.display.set_mode((WIDTH, HEIGHT), pg.RESIZABLE)
        pg.display.set_caption("Client2")
        #self.screen.blit(self.background, [250,250])
        self.clock = pg.time.Clock()
        self.running = True
        self.playing = True
        self.waiting = True
        self.inf1 = ''
        self.inf2 = ''
        self.release = True
        self.pressTime = time.time()

        #sprite groups
        self.all_sprites = pg.sprite.Group()
        self.all_blocks = pg.sprite.Group()
        self.all_bullets = pg.sprite.Group()
        self.all_bonus = pg.sprite.Group()
        self.all_superbullets = pg.sprite.Group()
        for i in range(20):
            map = maps[0]
            for j in range(20):
                if map[i][j] == 1:
                    bl = Block(j, i, 1)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 2:
                    bl = Block(j, i, 0, True, 0)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 3:
                    bl = Block(j, i, 3, False, 1)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 4:
                    bl = Block(j, i, 2, False, 2)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 5:
                    bl = Block(j, i, 3, False, 3)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 6:
                    bl = Block(j, i, 1, False, 4)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 7:
                    bl = Block(j, i, 3, False, 5)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 8:
                    bl = Block(j, i, 2, False, 6)
                    self.all_sprites.add(bl)
                    self.all_blocks.add(bl)
                elif map[i][j] == 'b':
                    self.chef1 = Chef(j, i, chef1_moves, False,
                                      self.all_bullets, self.all_sprites,
                                      self.all_superbullets, self.all_blocks)
                    self.all_sprites.add(self.chef1)
                    # self.chef1.set_center(j, i)
                    # self.chef1.set_cabbage(10)
                    # self.chef1.set_life(1)
                elif map[i][j] == 'a':
                    self.chef2 = Chef(j, i, chef2_moves, True,
                                      self.all_bullets, self.all_sprites,
                                      self.all_superbullets, self.all_blocks)
                    self.all_sprites.add(self.chef2)
                    # self.chef2.set_center(j, i)
                    # self.chef2.set_cabbage(10)
                    # self.chef2.set_life(1)

    # def light_up()
    #if self.level == 5:
        self.fog = pg.Surface((800, 800))
        self.fog.fill(BLACK)
        self.light_mask1 = pg.image.load(light1).convert_alpha()
        self.light_mask2 = pg.image.load(light2).convert_alpha()
        self.light_mask1 = pg.transform.scale(self.light_mask1, LIGHT_RS)
        self.light_mask2 = pg.transform.scale(self.light_mask2, LIGHT_RS)
        self.light_rect1 = self.light_mask1.get_rect()
        self.light_rect2 = self.light_mask2.get_rect()
コード例 #24
0
class Tutorial:
    def __init__(self):

        self.screen = pg.display.set_mode((WIDTH - 200, HEIGHT))
        #self.background = pg.image.load(backgrounds[level-1])
        self.background = pg.image.load('background.png')
        self.screen.blit(pg.image.load('background.png'), (0, 0))

        pg.display.set_caption("Chef War")
        #self.screen.blit(self.background, [250,250])
        self.clock = pg.time.Clock()
        self.running = True
        self.playing = True
        # groups
        self.all_sprites = pg.sprite.Group()
        self.all_blocks = pg.sprite.Group()
        self.all_bullets = pg.sprite.Group()
        self.all_bonus = pg.sprite.Group()
        self.all_superbullets = pg.sprite.Group()

        self.chef1 = Chef(5, 5, chef1_moves, False, self.all_bullets,
                          self.all_sprites, self.all_superbullets)
        self.chef1.cabbage = 100
        self.all_sprites.add(self.chef1)

        #font variable
        self.font1 = pg.font.Font('caligraphy.ttf', 50)
        self.font2 = pg.font.Font('Organo.ttf', 20)
        self.font3 = pg.font.Font('Arial.ttf', 15)
        self.font4 = pg.font.Font('Arial.ttf', 15)
        self.font5 = pg.font.Font('Organo.ttf', 10)
        self.map = maps[1]

        self.block2 = Block(8, 7, 4, False, 4)
        self.block3 = Block(8, 6, 3, False, 1)
        self.block4 = Block(8, 5, 0, True, 0)

        self.g = g = gm.Game(8)

        self.story_progress = True
        self.story_progress2 = True
        self.story_progress3 = True
        self.story_progress4 = True
        self.story_progress5 = True

    def button(self, msg, x, y, w, h, ic, ac):
        self.mouse = pg.mouse.get_pos()
        self.click = pg.mouse.get_pressed()
        self.screen.blit(pg.image.load('conf.png'), (300, 950))

        if x + w > self.mouse[0] > x and y + h > self.mouse[1] > y:
            self.screen.blit(pg.image.load('conf-select.png'), (300, 950))
            if self.click[0] == 1:
                self.story_progress = False
                self.story2()

    def button2(self, msg, x, y, w, h, ic, ac):
        self.mouse2 = pg.mouse.get_pos()
        self.click2 = pg.mouse.get_pressed()
        if x + w > self.mouse2[0] > x and y + h > self.mouse2[1] > y:
            self.screen.blit(pg.image.load('story2-select-con.png'),
                             (100, 200))
            if self.click2[0] == 1:
                self.story_progress2 = False
                self.players()

    def button3(self, msg, x, y, w, h, ic, ac):
        self.mouse3 = pg.mouse.get_pos()
        self.click3 = pg.mouse.get_pressed()

        self.screen.blit(pg.image.load('conf.png'), (x, y))

        if x + w > self.mouse3[0] > x and y + h > self.mouse3[1] > y:
            self.screen.blit(pg.image.load('conf-select.png'), (x, y))
            if self.click3[0] == 1:
                self.story_progress4 = False
                self.blockex()

    def button4(self, msg, x, y, w, h, ic, ac):
        self.mouse4 = pg.mouse.get_pos()
        self.click4 = pg.mouse.get_pressed()

        self.screen.blit(pg.image.load('bigcon.png'), (x, y))

        if x + w > self.mouse4[0] > x and y + h > self.mouse4[1] > y:
            self.screen.blit(pg.image.load('bigcon-select.png'), (x, y))
            if self.click4[0] == 1:
                self.story_progress3 = False
                self.controls()

    def learnButton(self, msg, x, y, w, h, ic, ac):
        if self.lhold == False:
            self.mousel = pg.mouse.get_pos()
            self.clickl = pg.mouse.get_pressed()
        #pg.draw.rect(self.screen, ac,(x,y,w,h))
        text = self.font2.render(msg, True, (0, 0, 0))
        textRect = text.get_rect()
        textRect.center = ((x + (w / 2)), (y + (h / 2)))
        self.screen.blit(text, textRect)
        if x + w > self.mousel[0] > x and y + h > self.mousel[1] > y:
            if self.clickl[0] == 1:
                #self.lhold = True
                self.story()

    def gameButton(self, msg, x, y, w, h, ic, ac):
        self.mouseg = pg.mouse.get_pos()
        self.clickg = pg.mouse.get_pressed()
        self.screen.blit(pg.image.load('pred.png'), (x, y))
        #pg.draw.rect(self.screen, ac,(x,y,w,h))
        if x + w > self.mouseg[0] > x and y + h > self.mouseg[1] > y:
            self.screen.blit(pg.image.load('pgreen.png'), (x, y))
            if self.clickg[0] == 1:
                self.playing = False
                self.g.run()

    def run(self):
        pg.mixer.music.load('song.wav')
        pg.mixer.music.play(-1)
        while self.playing:
            self.clock.tick(FPS)
            self.events()
            self.update()
            #play the walking sound but will be none if movmt was invalid
            if self.chef1.get_sound() != None:
                #self.chef1.get_sound().play()
                pass

            self.story()

    def update(self):

        hit_block = pg.sprite.groupcollide(self.all_blocks, self.all_bullets,
                                           False, True)
        hit_block2 = pg.sprite.groupcollide(
            self.all_blocks, self.all_superbullets, False,
            False)  #if the block turn into the bonus -> True, False
        shoot_chef1 = pg.sprite.spritecollide(self.chef1, self.all_bullets,
                                              True)
        shoot_chef_1 = pg.sprite.spritecollide(self.chef1,
                                               self.all_superbullets, True)

        if shoot_chef1 or shoot_chef_1:
            self.chef1.is_hit()
            if self.chef1.get_life == 0:
                self.running = False

        for bl in hit_block.keys():
            bl.decrementHealth()
            if bl.getHealth() == 0:
                if bl.getBonus() == 0:
                    bl.kill()
                else:
                    self.all_bonus.add(bl)
                    self.all_blocks.remove(bl)

        for bl in hit_block2.keys():
            bl.setHealth(0)
            if bl.getHealth() == 0:
                if bl.getBonus() == 0:
                    bl.kill()
                else:
                    self.all_bonus.add(bl)
                    self.all_blocks.remove(bl)

        chef1_hit_bonus = pg.sprite.spritecollide(self.chef1, self.all_bonus,
                                                  True)
        for bonus in chef1_hit_bonus:
            if bonus.getBonus() == 1:
                self.chef1.claim_life()
            elif bonus.getBonus() == 2:
                self.chef1.claim_cabbage()
            elif bonus.getBonus() == 4:
                self.chef1.gainSpeed()
            elif bonus.getBonus() == 5:
                self.chef1.claim_superbullet()
            elif bonus.getBonus() == 6:
                self.chef1.gainLight()
            else:
                self.chef1.claim_point()

        chef1_old_x = self.chef1.get_x()
        chef1_old_y = self.chef1.get_y()

        self.all_sprites.update()

        chef1_collide_block = pg.sprite.spritecollide(self.chef1,
                                                      self.all_blocks, False)
        if chef1_collide_block:
            self.chef1.set_x(chef1_old_x)
            self.chef1.set_y(chef1_old_y)

    # 			self.chef1.set_sound(None)

        chef1_old_x = self.chef1.get_x()
        chef1_old_y = self.chef1.get_y()

        self.all_sprites.update()

        chef1_collide_block = pg.sprite.spritecollide(self.chef1,
                                                      self.all_blocks, False)
        if chef1_collide_block:
            self.chef1.set_x(chef1_old_x)
            self.chef1.set_y(chef1_old_y)
            self.chef1.set_sound(None)

    def events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                print("Quit")
                if self.playing:
                    self.playing = False
                self.running = False

    def draw(self):

        # create a text suface object for drawing text
        text = self.font1.render('Chef War', True, (0, 0, 255))
        #self.screen.blit(pg.image.load('sushibar.png'),(400,130))
        textRect = text.get_rect()

        # set the center of the rectangular object.
        textRect.center = (400, 100)

        self.screen.blit(pg.image.load('left_margin.png'), (0, 0))
        self.screen.blit(pg.image.load('right_margin.png'), (800, 0))

        self.screen.blit(text, textRect)

        self.screen.blit(pg.image.load('2-R3.png'), (250, 75))
        self.screen.blit(pg.image.load('1-L2.png'), (620, 75))

        self.screen.blit(pg.image.load('sushi1.png'), (325, 125))
        self.screen.blit(pg.image.load('sushi2.png'), (475, 125))

        pg.display.update()

        self.learnButton("Learn to Play", 250, 500, 300, 50, (0, 0, 0),
                         (255, 0, 0))
        pg.display.update()

    def story(self):
        if self.story_progress == True:
            self.screen.blit(pg.image.load('story title.png'), (0, 0))
            self.screen.blit(pg.image.load('left_margin.png'), (0, 200))
            self.screen.blit(pg.image.load('right_margin.png'), (800, 200))
            self.screen.blit(pg.image.load('story1.png'), (150, 200))
            self.button("next", 350, 950, 200, 50, (0, 0, 0), (194, 81, 77))
            pg.display.update()
        else:
            self.story2()

        #self.screen.fill(pg.Color("black"))
    def story2(self):
        if self.story_progress2 == True:
            self.screen.blit(pg.image.load('story title.png'), (0, 0))
            self.screen.blit(pg.image.load('left_margin.png'), (0, 200))
            self.screen.blit(pg.image.load('right_margin.png'), (800, 200))
            self.screen.blit(pg.image.load('story2.png'), (100, 200))
            self.button2("next", 500, 900, 300, 60, (0, 0, 0), (194, 81, 77))
            pg.display.update()
        else:
            self.players()
        #self.screen.fill(pg.Color("black"))

    def controls(self):
        if self.story_progress4 == True:
            #clear the screen
            self.screen.blit(pg.image.load('background.png'), (200, 200))
            self.screen.blit(pg.image.load('left_margin.png'), (0, 200))
            self.screen.blit(pg.image.load('right_margin.png'), (800, 200))
            self.screen.blit(pg.image.load('p1.png'), (0, 0))
            self.screen.blit(pg.image.load('p2.png'), (0, 600))
            self.button3("next", 793, 850, 200, 50, (0, 0, 0), (194, 81, 77))
            pg.display.update()
        else:
            self.blockex()

    def players(self):
        if self.story_progress3 == True:
            #clear the screen
            self.screen.blit(pg.image.load('players.png'), (5, 5))
            self.screen.blit(pg.image.load('background.png'), (200, 200))
            self.screen.blit(pg.image.load('left_margin.png'), (0, 200))
            self.screen.blit(pg.image.load('right_margin.png'), (800, 200))
            #self.screen.blit(pg.image.load('fill.png'),(0,200))
            self.button4("next", 250, 450, 500, 100, (0, 0, 0), (194, 81, 77))
            pg.display.update()
        else:
            self.controls()

    def blockex(self):
        if self.story_progress5 == True:
            self.screen.blit(pg.image.load('bonus.png'), (0, 0))
            self.screen.blit(pg.image.load('background.png'), (200, 200))
            self.screen.blit(pg.image.load('left_margin.png'), (0, 200))
            self.screen.blit(pg.image.load('right_margin.png'), (800, 200))
            self.all_sprites.draw(self.screen)
            #self.screen.blit(pg.image.load('sushibar.png'),(-10,800))

            self.all_blocks.add(self.block2)
            self.all_blocks.add(self.block3)
            self.all_blocks.add(self.block4)

            self.all_sprites.add(self.block2)
            self.all_sprites.add(self.block3)
            self.all_sprites.add(self.block4)
            self.all_sprites.update()

            self.gameButton("play game!", 860, 325, 100, 190, (0, 0, 0),
                            (255, 0, 0))
            pg.display.update()
コード例 #25
0
ファイル: main.py プロジェクト: Digender/python_tuts
from chef import Chef
from chinese_chef import ChineseChef

chef = Chef('Digender')
chineseChef = ChineseChef('Digender', 'Chinese')

chef.can_make_food()
chineseChef.can_make_chinese_dish()

print('==============================')
print('after overriding method can_make_food()')
print('==============================')
chineseChef.can_make_food()
コード例 #26
0
from chef import Chef

myChef = Chef()
myChef.makes_bbq_dish()


from chinese_chef import Chines_Chef

my_chinese_chef = Chines_Chef()
my_chinese_chef.makes_chinese_dish()

# after inheriting from general Chef
# we can make all other dishes
my_chinese_chef.makes_bbq_dish()
コード例 #27
0
from chef import Chef
from Telugu_chef import telugu_chef

myChef = Chef()
myChef.make_roti()
myChef.make_sabji()
myChef.make_spl_dish()
myChef2 = telugu_chef()
myChef2.make_spl_dish()
myChef2.make_gongura()
コード例 #28
0
from chef import Chef
from chef_chinese import ChineseChef

myChef = Chef()
myChef.make_special_dish()

myChineseChef = ChineseChef()
myChineseChef.make_fried_rice()
myChineseChef.make_special_dish()  # => Inheritance function from Chef
コード例 #29
0
from flask import Flask, request
import datetime
import json
from chef import Chef

app = Flask(__name__)
manager = Chef()
manager.load_conf()


@app.route("/lunch", methods=["GET"])
def select_lunch():
    now = datetime.datetime.now()
    lunch_date = request.args.get('date', None)
    if lunch_date is None:
        lunch_date = now
    else:
        fields = lunch_date.split("-")
        if len(fields) < 3:
            return "Bad Format of Date", 400
        lunch_date = datetime.datetime(year=int(fields[0]),
                                       month=int(fields[1]),
                                       day=int(fields[2]))
    list_dishes = manager.filter_dishes(lunch_date)
    return json.dumps({"dishes": list_dishes}, indent=4), 200


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)
コード例 #30
0
class DialectizerPlugin(plugin.PluginObject):
    """Dialectizer plugin object"""

    commands = None
    data = None
    events = None
    storage = None

    dialectizers = {
        "chef": Chef(),
        "fudd": Fudd(),
        "lower": Lower(),
        "off": Dialectizer(),
        "olde": Olde(),
        "reverse": Reverse(),
        "upper": Upper()
    }

    def setup(self):
        """The list of bridging rules"""

        self.commands = CommandManager()
        self.events = EventManager()
        self.storage = StorageManager()

        self.data = self.storage.get_file(self, "data", YAML,
                                          "plugins/dialectizer/settings.yml")

        self.events.add_callback("MessageSent", self, self.handle_msg_sent, 1)
        self.commands.register_command("dialectizer",
                                       self.dialectizer_command,
                                       self,
                                       "dialectizer.set",
                                       aliases=["dialectiser"])

    def handle_msg_sent(self, event=MessageSent):
        """Handler for general message sent event"""

        if isinstance(event.target, User):
            return

        name = event.caller.name
        target = event.target.name

        with self.data:
            if name not in self.data:
                self.data[name] = {}

            if target not in self.data[name]:
                self.data[name][target] = "off"

        subber = self.dialectizers[self.data[name][target]]

        message = event.message
        message = subber.sub(message)
        event.message = message

    def dialectizer_command(self, protocol, caller, source, command, raw_args,
                            parsed_args):
        """Handler for the dialectizer command"""

        args = raw_args.split()  # Quick fix for new command handler signature
        if isinstance(source, User):
            caller.respond(__("This command only applies to channels."))
            return
        if not len(args) > 0:
            caller.respond(__("Usage: {CHARS}dialectizer <dialectizer>"))
            caller.respond(
                __("Available dialectizers: %s") %
                ", ".join(self.dialectizers.keys()))
            return

        with self.data:
            if protocol.name not in self.data:
                self.data[protocol.name] = {}

            if source.name not in self.data[protocol.name]:
                self.data[protocol.name][source.name] = "off"

            setting = args[0].lower()
            if setting not in self.dialectizers:
                caller.respond(__("Unknown dialectizer: %s") % setting)
                return

            self.data[protocol.name][source.name] = setting
            caller.respond(__("Dialectizer set to '%s'") % setting)