def solve_ladder(self):
		"""
		Goes through every possible combination of clues
		and checks if the Ladder (constructed by Borya's hand)
		can be solved given those clues. if it can, then we append
		the number of clues in that clue combination to the 
		num_clues_needed list.
		"""
		self.ladder.check_all_but_one()
		if not self.ladder.complete:
			for clue_seq in self.clues:
				if self.num_clues_needed:
					if len(clue_seq)<min(self.num_clues_needed):
						self.ladder = Ladder(self.actual_hand)
						for clue in clue_seq:
							self.ladder.give_clue(clue)
						if self.ladder.complete:
							#print clue_seq
							self.num_clues_needed.append(len(clue_seq))
				else:
					self.ladder = Ladder(self.actual_hand)
					for clue in clue_seq:
						self.ladder.give_clue(clue)
					if self.ladder.complete:
						self.num_clues_needed.append(len(clue_seq))
				self.ladder.clean_up()
	def __init__(self):
		self.num_cards = raw_input()
		cards = raw_input()
		#start = time.clock()
		self.actual_hand = cards.split(' ')
		self.ladder = Ladder(self.actual_hand)
		self.construct_clues()
		#timeit = time.clock() - start
		#print timeit
		#print self.clues
		self.num_clues_needed = list()
		self.solve_ladder()
		self.pick_lowest()
Пример #3
0
    def __init__(self, config):
        self.empty = 'empty'
        self.brick = 'brick'
        self.rang = 'rang'
        self.concrete = 'concrete'
        self.fire_item = 'fire'
        self.config = config
        self.width = config['width']
        self.height = config['height']
        self.size_x = self.config['size_x']
        self.size_y = self.config['size_y']
        self.tk = Tk()
        self.coordinates = [[self.empty] * config['height']
                            for i in range(config['width'])]

        self.canvas = Canvas()
        self.create_rectangle(0,
                              0,
                              self.config['width'],
                              self.config['height'],
                              fill=config['bg'])
        self.canvas.pack(fill=BOTH, expand=1)
        self.wall = Wall(self)
        self.ladder = Ladder(self)
        self.fire = Fire(self)
        self.human = Human(self)
Пример #4
0
def main():
    snakes = []
    ladders = []
    players = []

    num_of_snakes = int(input("Enter the number of snakes\n"))

    while num_of_snakes:
        num_of_snakes -= 1
        head, tail = input().split()
        snakes.append(Snake(int(head), int(tail)))

    num_of_ladders = int(input())

    while num_of_ladders:
        num_of_ladders -= 1
        start, end = input().split()
        ladders.append(Ladder(int(start), int(end)))

    num_of_players = int(input())

    while num_of_players:
        num_of_players -= 1
        name = input()
        players.append(Player(name))

    snake_and_ladder_game_service = SnakeAndLadderService(
        snakes, ladders, players, 100)
    snake_and_ladder_game_service.start_game()
Пример #5
0
 def create_ladders(self):
     """
     Creates ladder for board
     """
     for ladder_point in self.ladder_points:
         Board.ladders.append(
             Ladder(self._get_cell(ladder_point[0]),
                    self._get_cell(ladder_point[1])))
Пример #6
0
def read_ladders(filename) -> List[Ladder]:
    file = open(filename)
    ladders = []

    for line in file:
        ladder_values = line.split()
        start = int(ladder_values[0])
        end = int(ladder_values[1])
        ladders.append(Ladder(start, end))

    file.close()

    return ladders
Пример #7
0
    def configure(self):
        print('\n*************** Configure Board ***************')
        snakes_count = int(input('\nEnter number of snakes: '))
        for x in range(snakes_count):
            pos = input(
                f'\nEnter the start & end position of snake #{x+1}: ').split(',')
            self.snakes.append(Snake(int(pos[0]), int(pos[1])))

        ladders_count = int(input('\nEnter number of ladders: '))
        for x in range(ladders_count):
            pos = input(
                f'\nEnter the start & end position of ladder #{x+1}: ').split(',')
            self.ladders.append(Ladder(int(pos[0]), int(pos[1])))

        players_count = int(input('\nEnter number of players (min. 2): '))
        for x in range(players_count):
            playerName = input(f'\nEnter name of Player #{x+1}: ')
            self.players.append(Player(playerName, 1))
Пример #8
0
def create_wall(wall_group, up_or_down_wall, numb, all_w, hight, ladder_group,
                door_group, traider_group):
    if numb % 3 == 0 and numb != 0 and not up_or_down_wall:
        wall = Wall(up_or_down_wall, True)
        wall_width = wall.rect.width
        wall.rect.x = wall_width * numb
        wall.rect.y = hight
        door_group.add(wall)
    else:
        wall = Wall(up_or_down_wall, False)
        wall_width = wall.rect.width
        wall.rect.x = wall_width * numb
        wall.rect.y = hight
    if numb == 1 and numb != 0 and not up_or_down_wall and not wall.door:
        traider = Traider()
        traider.rect.x = wall.rect.x + wall.rect.w // 2
        traider.rect.y = wall.rect.y + wall.rect.h - traider.rect.h + 20
        traider_group.add(traider)
    if numb % 4 == 0 and numb != 0 and not up_or_down_wall and not wall.door:
        ladder = Ladder()
        ladder.rect.x = wall.rect.x + 50
        ladder.rect.y = wall.rect.y - 35
        ladder_group.add(ladder)
    wall_group.add(wall)
Пример #9
0
def _create_ladder (game, data) :
	ladder = Ladder (default='images/ladder.png')
	ladder.set_pos (_get_coords (data))
	return ladder
class TestLadderMethods(unittest.TestCase):
    def setUp(self):
        mock_db = Database("Test_Ladder",
                           ["Jim", "John", "Bob", "Bill", "Kev"])

        self.ladder = Ladder("Test_Ladder", mock_db)
        self.ladder.table = ["Jim", "John", "Bob", "Bill", "Kev"]

    def test_add_two_new_players(self):
        self.ladder.table = ["Jim", "John", "Bob", "Bill", "Kev"]

        expected_table = [
            "Jim", "John", "Bob", "Bill", "Kev", "Gazza", "Carlson"
        ]

        self.ladder.add_new_score("Gazza", "Carlson")

        for x in range(0, len(self.ladder.table)):
            self.assertEqual(self.ladder.table[x], expected_table[x])

    def test_add_one_new_winning_player(self):
        self.ladder.table = ["Jim", "John", "Bob", "Bill", "Kev"]

        expected_table = ["Jim", "John", "Bob", "Gazza", "Bill", "Kev"]

        self.ladder.add_new_score("Gazza", "Bill")

        for x in range(0, len(self.ladder.table)):
            self.assertEqual(self.ladder.table[x], expected_table[x])

    def test_add_one_new_losing_player(self):
        self.ladder.table = ["Jim", "John", "Bob", "Bill", "Kev"]

        expected_table = ["Jim", "John", "Bob", "Bill", "Kev", "Gazza"]

        self.ladder.add_new_score("John", "Gazza")

        for x in range(0, len(self.ladder.table)):
            self.assertEqual(self.ladder.table[x], expected_table[x])

    def test_existing_competing_players(self):
        self.ladder.table = ["Jim", "John", "Bob", "Bill", "Kev"]

        expected_table = ["Jim", "Bill", "John", "Bob", "Kev"]

        self.ladder.add_new_score("Bill", "John")

        for x in range(0, len(self.ladder.table)):
            self.assertEqual(self.ladder.table[x], expected_table[x])

    def test_print_ladder(self):
        captured_output = StringIO.StringIO()
        sys.stdout = captured_output
        self.ladder.print_ladder()
        expected_output = "+---------------+\n|  Test_Ladder  |\n+-------+-------+\n" \
                          "|  Name |  Rank |\n+-------+-------+\n|  Jim  |   1   |\n" \
                          "|  John |   2   |\n|  Bob  |   3   |\n|  Bill |   4   |\n" \
                          "|  Kev  |   5   |\n+-------+-------+\n"

        self.assertEqual(captured_output.getvalue(), expected_output)

    def test_list_ladders(self):
        captured_output = StringIO.StringIO()
        sys.stdout = captured_output
        self.ladder.list_ladders()
        expected_output = "+-------------+\n| League Name |\n+-------------+\n" \
                          "|  taste_card |\n|     emis    |\n|    global   |\n" \
                          "+-------------+\n"

        self.assertEqual(captured_output.getvalue(), expected_output)

    def test_get_pos(self):
        self.ladder.table = ["Jim", "John", "Bob", "Bill", "Kev"]

        test_cases = [["Bob", 2], ["Gregory", False], [233144, False]]

        for tc in test_cases:
            expected_output = tc[1]
            actual_output = self.ladder.get_pos(tc[0])
            self.assertEqual(expected_output, actual_output)
    def setUp(self):
        mock_db = Database("Test_Ladder",
                           ["Jim", "John", "Bob", "Bill", "Kev"])

        self.ladder = Ladder("Test_Ladder", mock_db)
        self.ladder.table = ["Jim", "John", "Bob", "Bill", "Kev"]
class BoryaSolved(object):
	def __init__(self):
		self.num_cards = raw_input()
		cards = raw_input()
		#start = time.clock()
		self.actual_hand = cards.split(' ')
		self.ladder = Ladder(self.actual_hand)
		self.construct_clues()
		#timeit = time.clock() - start
		#print timeit
		#print self.clues
		self.num_clues_needed = list()
		self.solve_ladder()
		self.pick_lowest()
		#timit = time.clock() - start
		#print timeit

	def construct_clues(self):
		"""
		constructs the total number of possible clue
		combinations that could yield us with revealing
		Borya's hand. We use the list of edges in the ladder
		to do this.
		"""
		self.clues = list()
		edges = self.ladder.edges
		#print self.ladder.edges
		for edge in edges:
			ind = edges.index(edge)
			edges.remove(edge)
			self.construct_clues_recursively([edge.value], edges)
			edges.insert(ind, edge)

	def construct_clues_recursively(self, clue_seq, edges):
		"""
		constructs combinations of clues.
		helper method for construct_clues
		"""
		if sorted(clue_seq) not in self.clues:
			self.clues.append(sorted(clue_seq))
		if len(edges) >= 1:
			for edge in edges:
				ind = edges.index(edge)
				edges.remove(edge)
				clues = [clue for clue in clue_seq]
				clues.append(edge.value)
				self.construct_clues_recursively(clues, edges)
				edges.insert(ind, edge)

	def solve_ladder(self):
		"""
		Goes through every possible combination of clues
		and checks if the Ladder (constructed by Borya's hand)
		can be solved given those clues. if it can, then we append
		the number of clues in that clue combination to the 
		num_clues_needed list.
		"""
		self.ladder.check_all_but_one()
		if not self.ladder.complete:
			for clue_seq in self.clues:
				if self.num_clues_needed:
					if len(clue_seq)<min(self.num_clues_needed):
						self.ladder = Ladder(self.actual_hand)
						for clue in clue_seq:
							self.ladder.give_clue(clue)
						if self.ladder.complete:
							#print clue_seq
							self.num_clues_needed.append(len(clue_seq))
				else:
					self.ladder = Ladder(self.actual_hand)
					for clue in clue_seq:
						self.ladder.give_clue(clue)
					if self.ladder.complete:
						self.num_clues_needed.append(len(clue_seq))
				self.ladder.clean_up()

	def pick_lowest(self):
		"""
		out of all the possible clue combinations that can
		reveal Borya's hand, the minimum number of num_clues_needed
		is printed.
		"""
		#print self.num_clues_needed
		if self.num_clues_needed:
			print min(self.num_clues_needed)
		else:
			print 0
Пример #13
0
from ladder import Player, Match, Ladder

ethan = Player("Ethan")
caz = Player("Caz")
mads = Player("Mads")
chris = Player("Chris")
flora = Player("Flora")

Lad = Ladder("Competition", [ethan, caz, flora, chris, mads])

Lad.ShowLadder()

print(chris.position)

Lad.AddMatch(flora, chris, "today", ((6, 4), (7, 6)))

Lad.AddMatch(ethan, caz, "today2", ((6, 4), (7, 6)))

Lad.ShowLadder()

Lad.Compute_Ladder_Statistics()

# print(chris.position_history)
def main():

    sdl2.ext.init()
    window = sdl2.ext.Window("3d", size=(640, 480))
    window.show()

    window_surface = window.get_surface()
    pixels = sdl2.ext.PixelView(window_surface)

    running = True

    camera = Camera(640, 480)
    ladder = Ladder(50, 50, STEP_COUNT)

    operation = R
    selected_axis = Y

    is_changed = True

    last_frame_time = time.time()

    while running:
        events = sdl2.ext.get_events()
        for event in events:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
            elif event.type == sdl2.SDL_MOUSEBUTTONUP:
                x, y = ctypes.c_int(0), ctypes.c_int(0)
                sdl2.mouse.SDL_GetMouseState(ctypes.byref(x), ctypes.byref(y))
                print(x.value, y.value)
                break
            elif event.type == SDL_KEYDOWN:
                if event.key.keysym.sym == SDLK_z:
                    print('selected Z')
                    selected_axis = Z
                elif event.key.keysym.sym == SDLK_x:
                    print('selected X')
                    selected_axis = X
                elif event.key.keysym.sym == SDLK_y:
                    print('selected Y')
                    selected_axis = Y

                elif event.key.keysym.sym == SDLK_t:
                    print('selected translating')
                    operation = T
                elif event.key.keysym.sym == SDLK_s:
                    print('selected scaling')
                    operation = S
                elif event.key.keysym.sym == SDLK_r:
                    print('selected rotating')
                    operation = R
                elif event.key.keysym.sym == SDLK_c:
                    print('selected camera')
                    operation = C

                elif event.key.keysym.sym == SDLK_RIGHT or event.key.keysym.sym == SDLK_LEFT:
                    sign = 1 if event.key.keysym.sym == SDLK_RIGHT else -1
                    is_changed = True
                    if operation == T:
                        if selected_axis == X:
                            ladder.translate_x(sign * D_DISTANCE)
                        elif selected_axis == Y:
                            ladder.translate_y(sign * D_DISTANCE)
                        elif selected_axis == Z:
                            ladder.translate_z(sign * D_DISTANCE)
                    elif operation == S:
                        if event.key.keysym.sym == SDLK_RIGHT:
                            ladder.plus_scale()
                        else:
                            ladder.minus_scale()
                    elif operation == R:
                        if selected_axis == X:
                            ladder.rotate_x(sign * D_ANGLE)
                        elif selected_axis == Y:
                            ladder.rotate_y(sign * D_ANGLE)
                        elif selected_axis == Z:
                            ladder.rotate_z(sign * D_ANGLE)
                    elif operation == C:
                        camera.change_p(sign * D_CAMERA_P)

        curr_time = time.time()

        if curr_time - last_frame_time > FRAME_INTERVAL:
            ladder.rotate_y(5)
            is_changed = True
            last_frame_time = curr_time

        if is_changed:
            is_changed = False
            clear(window_surface)
            draw_projection(pixels, camera, [ladder])
            window.refresh()

    sdl2.ext.quit()
    return 0
Пример #15
0
SCREEN_HEIGHT = 720
setup(SCREEN_WIDTH, SCREEN_HEIGHT)

couter = 0
flag = clone()
flag.pu()
register_shape("flag.gif")
flag.shape("flag.gif")
flag.ht()
flag.goto(470, 105)
flag.st()
bgcolor("lightgray")
enemy = Enemy()
yposi = -301
for i in range(2):
    ladder = Ladder(510, yposi + 10)
    yposi = -101
yposi = -201
for i in range(2):
    ladder2 = Ladder(-505, yposi + 10)
    yposi = -1

player = Player()
tracer(0)

BARREL_AMOUNT = 3
current_time = 0
position_list = []
FPS = 1 / 80  #frames per second
barrel_list = []
start_pos = -SCREEN_HEIGHT / 2 + 50
Пример #16
0
 def __init__(self, name):
     self.name = name
     self.ladder = Ladder(name)
Пример #17
0
class Game:
    sprite_size = sprite_width, sprite_height = 32, 32
    screen_size = screen_width, screen_height = 320, 224
    screen_scale = 2
    screen = False
    canvas = False
    running = False
    state = State()
    clock = False
    tps = 60
    game_objects = [[], [], [], []]
    clouds = []
    player_hearts = []

    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode(
            (self.screen_width * self.screen_scale,
             self.screen_height * self.screen_scale))
        pygame.display.set_caption("InfoWest Tower Security")
        self.clock = pygame.time.Clock()
        self.graphics = Graphics()
        self.canvas = Canvas(self)

        self.timer = Timer()

        self.turn_counter = TurnCounter()
        self.game_objects[State.STATE_GAME_BATTLE].append(self.turn_counter)

        # === Game Objects ===
        self.title_screen = Object(self, (0, 0), self.screen_size,
                                   Graphic([self.graphics.title_screen], [0]))
        self.background = Object(self, (0, 0), self.screen_size,
                                 Graphic([self.graphics.background], [0]))
        self.player = Player(
            self,
            (((self.screen_width / self.sprite_width) / 2) * self.sprite_width,
             self.screen_height - self.sprite_height), (32, 32),
            Graphic([
                self.graphics.player_walk_0, self.graphics.player_walk_1,
                self.graphics.player_walk_2
            ], [10, 10, 10]))
        self.heart = Object(self, (self.screen_width - 18, 2), (16, 16),
                            Graphic([self.graphics.heart_full], [0]))
        self.heart_bar = Object(self, (self.screen_width - 14, 22), (8, 38),
                                color=(250, 15, 15))
        self.armour = Object(self, (self.screen_width - 18, 64), (16, 16),
                             Graphic([self.graphics.armour], [0]))
        self.armour_bar = Object(self, (self.screen_width - 14, 84), (8, 38),
                                 color=(100, 100, 100))
        self.ladder = Ladder(self, int(self.screen_width / self.sprite_width),
                             int(self.screen_height / self.sprite_height),
                             (0, 0))
        self.game_over = Object(self, (0, 0), self.screen_size,
                                Graphic([self.graphics.game_over], [0]))
        self.game_objects[State.STATE_GAME_MENU].append(self.title_screen)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.background)
        for i in range(7):
            cloudtype = randint(0, 2)
            types = [
                self.graphics.cloud_1, self.graphics.cloud_2,
                self.graphics.cloud_3
            ]
            cloud = Object(self, (randint(
                0, self.screen_width), randint(0, self.screen_height - 75)),
                           (24, 24), Graphic([types[cloudtype]], [0]))
            cloud.set_velocity(random.uniform(1, 1.5), 0)
            self.clouds.append(cloud)
            self.game_objects[State.STATE_GAME_CLIMB].append(cloud)

        self.game_objects[State.STATE_GAME_CLIMB].append(self.player)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.heart)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.heart_bar)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.armour)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.armour_bar)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.background)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.player)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.heart_bar)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.heart)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.armour)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.armour_bar)
        self.game_objects[State.STATE_GAME_OVER].append(self.game_over)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.ladder)

        timer_lengths = []
        for i in range(self.timer.max):
            timer_lengths.append(self.timer.max / 8)
        self.action_timer = ActionTimer(
            self, (0, 0), self.sprite_size,
            Graphic([self.graphics.timer_face], [0]),
            Graphic([
                self.graphics.timer_needle_n, self.graphics.timer_needle_ne,
                self.graphics.timer_needle_e, self.graphics.timer_needle_se,
                self.graphics.timer_needle_s, self.graphics.timer_needle_sw,
                self.graphics.timer_needle_w, self.graphics.timer_needle_nw
            ], timer_lengths))
        self.game_objects[State.STATE_GAME_CLIMB].append(self.action_timer)

        self.menu_battle = Menu(self, (0, self.screen_height),
                                ["Attack", "Defend", "Item"],
                                pointer=Graphic([self.graphics.menu_arrow],
                                                [0]))
        self.game_objects[State.STATE_GAME_BATTLE].append(self.menu_battle)

        self.game_objects[State.STATE_GAME_CLIMB].append(self.player)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.player)

        self.floor_text = Text(self, (4, self.screen_height - 28),
                               str(self.player.floor), 24, (255, 255, 255))
        self.game_objects[State.STATE_GAME_CLIMB].append(self.floor_text)

    def update(self):
        self.clock.tick(self.tps)
        self.timer.tick()

        self.handle_inputs()
        self.handle_events()

        self.heart_bar.size = (self.heart_bar.size[0],
                               (self.player.health * 38) / 100)
        self.armour_bar.size = (self.armour_bar.size[0],
                                (self.player.armour * 38) / 100)

        self.floor_text.text = str(self.player.floor)

        for obj in self.game_objects[self.state.get_state()]:
            obj.update()

        for cloud in self.clouds:
            if cloud.position[0] > self.screen_width:
                cloud.position = (-16, randint(0, self.screen_height - 75))

    def render(self):
        self.canvas.render()
        pygame.display.flip()

    def loop(self):
        self.running = True
        while self.running:
            self.update()
            self.render()

        sys.exit()

    def handle_inputs(self):
        keys = pygame.key.get_pressed()
        if keys[pygame.K_ESCAPE]:
            pygame.event.post(pygame.event.Event(pygame.QUIT, {}))

    def new_state(self, state):
        self.state.set_state(state)
        if state == State.STATE_GAME_BATTLE:
            self.player.velocity = [0, 0]
            self.player.graphic.graphics = [self.graphics.player_idle]
            self.player.graphic.times = [1]
            self.player.position = (
                ((self.screen_width / self.sprite_width) / 2) *
                self.sprite_width, self.screen_height - self.sprite_height)
            self.player.floor += 1
            self.turn_counter.enemies = [
                Enemy(self, ((self.screen_width / 2) -
                             (self.sprite_width / 2), self.sprite_height),
                      (32, 32), 100, 50,
                      Graphic([self.graphics.enemy_bug_1], [0]))
            ]
            for e in self.turn_counter.enemies:
                self.game_objects[State.STATE_GAME_BATTLE].append(e)
        if state == State.STATE_GAME_CLIMB:
            if self.player.floor > 1:
                self.background.graphic.graphics[
                    0] = self.graphics.background_blank
            else:
                self.background.graphic.graphics[0] = self.graphics.background
            self.ladder.__init__(self,
                                 int(self.screen_width / self.sprite_width),
                                 int(self.screen_height / self.sprite_height),
                                 (0, 0))
            self.player.set_health(100)
            self.player.previous_rung = (0, 0)
            self.player.velocity = (0, 0)
            self.player.position = (
                ((self.screen_width / self.sprite_width) / 2) *
                self.sprite_width, self.screen_height - self.sprite_height)

    def handle_events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.running = False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    pygame.event.post(
                        pygame.event.Event(Event.EVENT_CHANGE_ITEM, {}))
                if event.key == pygame.K_SPACE:
                    if self.state.get_state() == State.STATE_GAME_MENU:
                        pygame.event.post(
                            pygame.event.Event(Event.EVENT_CHANGE_STATE,
                                               state=State.STATE_GAME_CLIMB))
                    if self.state.get_state() == State.STATE_GAME_OVER:
                        pygame.event.post(
                            pygame.event.Event(Event.EVENT_CHANGE_STATE,
                                               state=State.STATE_GAME_CLIMB))
                    elif self.state.get_state(
                    ) != State.STATE_GAME_MENU and self.state.get_state(
                    ) != State.STATE_GAME_OVER:
                        pygame.event.post(
                            pygame.event.Event(Event.EVENT_USE_ITEM, {}))
                if self.state.get_state() == State.STATE_GAME_BATTLE:
                    self.menu_battle.handle_event(event)
            if event.type == Event.EVENT_CHANGE_STATE:
                self.canvas.transition(event.state)
            if event.type == Event.EVENT_TIMER_AT_0:
                #if random.randrange(0,10) == 0:
                #radio_wave = RadioWave(self, self.sprite_size, Graphic([self.graphics.enemy_wave],[0]))
                #self.game_objects[State.STATE_GAME_CLIMB].append(radio_wave)
                pass
            self.player.handle_event(event)
Пример #18
0
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode(
            (self.screen_width * self.screen_scale,
             self.screen_height * self.screen_scale))
        pygame.display.set_caption("InfoWest Tower Security")
        self.clock = pygame.time.Clock()
        self.graphics = Graphics()
        self.canvas = Canvas(self)

        self.timer = Timer()

        self.turn_counter = TurnCounter()
        self.game_objects[State.STATE_GAME_BATTLE].append(self.turn_counter)

        # === Game Objects ===
        self.title_screen = Object(self, (0, 0), self.screen_size,
                                   Graphic([self.graphics.title_screen], [0]))
        self.background = Object(self, (0, 0), self.screen_size,
                                 Graphic([self.graphics.background], [0]))
        self.player = Player(
            self,
            (((self.screen_width / self.sprite_width) / 2) * self.sprite_width,
             self.screen_height - self.sprite_height), (32, 32),
            Graphic([
                self.graphics.player_walk_0, self.graphics.player_walk_1,
                self.graphics.player_walk_2
            ], [10, 10, 10]))
        self.heart = Object(self, (self.screen_width - 18, 2), (16, 16),
                            Graphic([self.graphics.heart_full], [0]))
        self.heart_bar = Object(self, (self.screen_width - 14, 22), (8, 38),
                                color=(250, 15, 15))
        self.armour = Object(self, (self.screen_width - 18, 64), (16, 16),
                             Graphic([self.graphics.armour], [0]))
        self.armour_bar = Object(self, (self.screen_width - 14, 84), (8, 38),
                                 color=(100, 100, 100))
        self.ladder = Ladder(self, int(self.screen_width / self.sprite_width),
                             int(self.screen_height / self.sprite_height),
                             (0, 0))
        self.game_over = Object(self, (0, 0), self.screen_size,
                                Graphic([self.graphics.game_over], [0]))
        self.game_objects[State.STATE_GAME_MENU].append(self.title_screen)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.background)
        for i in range(7):
            cloudtype = randint(0, 2)
            types = [
                self.graphics.cloud_1, self.graphics.cloud_2,
                self.graphics.cloud_3
            ]
            cloud = Object(self, (randint(
                0, self.screen_width), randint(0, self.screen_height - 75)),
                           (24, 24), Graphic([types[cloudtype]], [0]))
            cloud.set_velocity(random.uniform(1, 1.5), 0)
            self.clouds.append(cloud)
            self.game_objects[State.STATE_GAME_CLIMB].append(cloud)

        self.game_objects[State.STATE_GAME_CLIMB].append(self.player)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.heart)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.heart_bar)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.armour)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.armour_bar)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.background)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.player)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.heart_bar)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.heart)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.armour)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.armour_bar)
        self.game_objects[State.STATE_GAME_OVER].append(self.game_over)
        self.game_objects[State.STATE_GAME_CLIMB].append(self.ladder)

        timer_lengths = []
        for i in range(self.timer.max):
            timer_lengths.append(self.timer.max / 8)
        self.action_timer = ActionTimer(
            self, (0, 0), self.sprite_size,
            Graphic([self.graphics.timer_face], [0]),
            Graphic([
                self.graphics.timer_needle_n, self.graphics.timer_needle_ne,
                self.graphics.timer_needle_e, self.graphics.timer_needle_se,
                self.graphics.timer_needle_s, self.graphics.timer_needle_sw,
                self.graphics.timer_needle_w, self.graphics.timer_needle_nw
            ], timer_lengths))
        self.game_objects[State.STATE_GAME_CLIMB].append(self.action_timer)

        self.menu_battle = Menu(self, (0, self.screen_height),
                                ["Attack", "Defend", "Item"],
                                pointer=Graphic([self.graphics.menu_arrow],
                                                [0]))
        self.game_objects[State.STATE_GAME_BATTLE].append(self.menu_battle)

        self.game_objects[State.STATE_GAME_CLIMB].append(self.player)
        self.game_objects[State.STATE_GAME_BATTLE].append(self.player)

        self.floor_text = Text(self, (4, self.screen_height - 28),
                               str(self.player.floor), 24, (255, 255, 255))
        self.game_objects[State.STATE_GAME_CLIMB].append(self.floor_text)