Beispiel #1
0
    def new_ship(self, field, length):
        try:
            start = get_input('Input start position for \
{}-ship in format ROW,COL (ex. 1,2): '.format(length))
            d = start.split(',')
            row_start = int(d[0]) - 1
            col_start = int(d[1]) - 1
            ship = []
            pos = [row_start, col_start]
            if (
                        self.is_duplicate(pos) is True or
                        self.check_perimeter(pos, field.size)):
                raise ValueError
            else:
                ship.append(pos)

            if int(length) > 1:
                direction = get_input('Input directions for \
{}-ship (WASD):'.format(length))
                it = int(length) - 1
                while it > 0:
                    if direction == 'w':
                        pos = [row_start - it, col_start]
                    elif direction == 'a':
                        pos = [row_start, col_start - it]
                    elif direction == 's':
                        pos = [row_start + it, col_start]
                    elif direction == 'd':
                        pos = [row_start, col_start + it]

                    if (
                                self.is_duplicate(pos) is True or
                                self.check_perimeter(pos, field.size)):
                        raise ValueError
                    else:
                        ship.append(pos)
                        it -= 1

            self._ships.append(Ship(ship))

        except ValueError:
            print('Wrong position, try again!')
            self.new_ship(field, length)
        except IndexError:
            print('Wrong direction, try again!')
            self.new_ship(field, length)
Beispiel #2
0
    def new_ship(self, field, length):
        try:
            start = get_input('Input start position for \
{}-ship in format ROW,COL (ex. 1,2): '.format(length))
            d = start.split(',')
            row_start = int(d[0]) - 1
            col_start = int(d[1]) - 1
            ship = []
            pos = [row_start, col_start]
            if (self.is_duplicate(pos) is True
                    or self.check_perimeter(pos, field.size)):
                raise ValueError
            else:
                ship.append(pos)

            if int(length) > 1:
                direction = get_input('Input directions for \
{}-ship (WASD):'.format(length))
                it = int(length) - 1
                while it > 0:
                    if direction == 'w':
                        pos = [row_start - it, col_start]
                    elif direction == 'a':
                        pos = [row_start, col_start - it]
                    elif direction == 's':
                        pos = [row_start + it, col_start]
                    elif direction == 'd':
                        pos = [row_start, col_start + it]

                    if (self.is_duplicate(pos) is True
                            or self.check_perimeter(pos, field.size)):
                        raise ValueError
                    else:
                        ship.append(pos)
                        it -= 1

            self._ships.append(Ship(ship))

        except ValueError:
            print('Wrong position, try again!')
            self.new_ship(field, length)
        except IndexError:
            print('Wrong direction, try again!')
            self.new_ship(field, length)
 def new_game(self):
     # PARTY.current_dungeon.start()
     if self.webbed:
         party_size = base.get_input('enter the size of your party: ')
         if int(party_size) is 0:
             base.put("you can't play with zero people, dingus")
             sys.exit()
         # creating all the players in the party
         for a in range(int(party_size)):
             name = base.get_input('enter the name of player %d: ' % a)
             PARTY.add_player(Player(name))
         base.put('Game Start')
         base.put(PARTY.to_str())
         dungeon = Hub(PARTY)
         PARTY.hub = dungeon
         PARTY.current_dungeon = dungeon
         PARTY.current_dungeon.start()
         while (PARTY.end):
             PARTY.handle_player_turn()
             if (PARTY.end):
                 PARTY.current_dungeon.handle_monster_turn()
         base.put("\n\n------------=========GAME OVER=========------------")
     else:
         party_size = base.get_input('enter the size of your party: ')
         if int(party_size) is 0:
             base.put("you can't play with zero people, dingus")
             sys.exit()
         # creating all the players in the party
         for a in range(int(party_size)):
             name = base.get_input('enter the name of player %d: ' % a)
             PARTY.add_player(Player(name))
         base.put('Game Start')
         base.put(PARTY.to_str())
         dungeon = Hub(PARTY)
         PARTY.hub = dungeon
         PARTY.current_dungeon = dungeon
         PARTY.current_dungeon.start()
         while (PARTY.end):
             PARTY.handle_player_turn()
             if (PARTY.end):
                 PARTY.current_dungeon.handle_monster_turn()
         base.put("\n\n------------=========GAME OVER=========------------")
    def do_turn(self, option):
        # effectiveness coefficient
        ec = self.owner.attributes['mana'] / 5
        if option == self.options[0]:
            p = base.make_choice([
                'cast %s' % self.name,
                'rename %s' % self.name,
                'examine %s' % self.name
            ])
            if p == 1:
                name = base.get_input('enter a new name for %s' % self.name)
                self.name = name
                self.options = ['%s' % self.name]

            if p == 2:
                base.put(self.ploop())

            if p == 0:
                if not self.on_cooldown:
                    if not self.is_healing:
                        if not self.aoe:
                            self.murder(self.owner.select_target())
                            self.owner.statuses.append(
                                s.Cooldown(self, self.cooldown_time))
                        else:
                            self.owner.do_aoe_monster(self.murder)
                            self.owner.statuses.append(
                                s.Cooldown(self, self.cooldown_time))
                    else:
                        if not self.aoe:
                            self.murder(self.owner.select_player_target())
                            self.owner.statuses.append(
                                s.Cooldown(self, self.cooldown_time))
                        else:
                            self.owner.do_aoe_player(self.murder)
                            self.owner.statuses.append(
                                s.Cooldown(self, self.cooldown_time))

                else:
                    base.put('%s is on cooldown!' % self.name)
Beispiel #5
0
    def shooting(self, field, enemy_ships):
        def valid_shoot_position():
            return (shot is not None) and (shot not in self._shots)

        shot = None
        while not valid_shoot_position():
            try:
                cords_input = get_input('Enter coordinates your shot (x, y): ')
                c = cords_input.split(',')
                row = int(c[0]) - 1
                col = int(c[1]) - 1
                cords = [row, col]
                if self.check_perimeter(cords, field.size):
                    raise ValueError()
                # if (row < 0 or col < 0) or \
                #         (row >= field.size or col >= field.size):
                #     raise ValueError()

                shot = Shot(cords, enemy_ships)
                self._shots.append(shot)
                return shot
            except (IndexError, ValueError):
                print('Wrong input, try again!')
Beispiel #6
0
    def shooting(self, field, enemy_ships):
        def valid_shoot_position():
            return (shot is not None) and (shot not in self._shots)

        shot = None
        while not valid_shoot_position():
            try:
                cords_input = get_input('Enter coordinates your shot (x, y): ')
                c = cords_input.split(',')
                row = int(c[0]) - 1
                col = int(c[1]) - 1
                cords = [row, col]
                if self.check_perimeter(cords, field.size):
                    raise ValueError()
                # if (row < 0 or col < 0) or \
                #         (row >= field.size or col >= field.size):
                #     raise ValueError()

                shot = Shot(cords, enemy_ships)
                self._shots.append(shot)
                return shot
            except (IndexError, ValueError):
                print('Wrong input, try again!')
Beispiel #7
0
    ],
    [
        sg.Text(size=(64, 20), key='-OUTPUT-'),
        sg.Text(size=(10, 10)),
        sg.Text(size=(64, 20), key='-FREQUENCY-')
    ],
]

changes = []
window = sg.Window('Cracking the code', layout)

while True:
    event, values = window.read()
    if event == 'Load':
        filepath = 'result.txt' if values[0] == '' else values[0]
        text = get_input(filepath)
        str_text = ''

        window['-OUTPUT-'].update(format_text_string(text))
        frequency_stat = count_frequency(text)
        window['-FREQUENCY-'].update(frequency_stat)
    elif event == 'Change':
        if len(values[1].split()) != len(values[2].split()):
            raise Exception('Different amount of elements')

        substitute = {}
        for s, d in zip(values[1].split(), values[2].split()):
            substitute.update({s: d + ' '})

        changes.append(substitute)
        text = change_text(text, substitute)
	def do_turn(self):
		if base.IS_WEB_VERSION:
			base.put(self.get_info())
		for x in self.statuses:
			x.do_turn(None)
		ireallyhatemylife=len(self.owner.current_dungeon.things)
		for a in range(ireallyhatemylife):
			# im not entirely sure what's going on here, but 'a' is an int
			# so it will never be an instance of monster.
			if isinstance(a,Monster):
				if not a.alive:
					self.owner.current_dungeon.things.remove(a)
					a-=1
					ireallyhatemylife-=1
		# since action points can be removed in the statuses, we need to check it here
		if self.action_points > 0:
			args = self.return_options()[base.make_choice(self.return_options())]
			if args == 'save':
				if dill:
					name = base.get_input('enter the name of your save: ')
					if not os.path.exists('%s/saves/' % base.BASE_DIR):
						os.makedirs('%s/saves/' % base.BASE_DIR)

					path = '%s/saves/%s.dunce' % (base.BASE_DIR,name)
					# have to create the file before we take a dump in it
					with open(path,'w+'):
						pass
					dill.dump_session(path)

			if args == 'load':
				li = []
				if os.path.exists('%s/saves/' % base.BASE_DIR):
					for dirpath, dirname, filename in os.walk('%s/saves/' % base.BASE_DIR):
						for fi in filename:
							if '.dunce' in fi:
								li.append(fi)
				else:
					base.put('no saves to choose from!')
				op = base.make_choice(li,"savefile")
				if dill:
					if op is not None:
						go = False
						base.put('loading session')
						self.action_points = 0
						dill.load_session('%s/saves/%s' % (base.BASE_DIR,li[op]))
				else:
					base.put('save/load support is disabled because you haven\'t installed dill!')


			if args == 'exit room':
				# door should be the INDEX of the returned list, ie 0 1 2 3
				door = base.make_choice([a for a in self.party.current_dungeon.active_room.get_neighbors().keys()],'room')
				self.party.current_dungeon.active_room.move_to(door)

			## This is the examine method.
			if args == 'examine':
				s = ''
				for ind, a in enumerate(self.party.current_dungeon.active_room.things):
					if ind != len(self.party.current_dungeon.active_room.things) - 1:
						s+='a %s, ' % a.examine(self)
					else:
						s+='and a %s.' % a.examine(self)
				if not s:
					s = 'absolutely nothing.'
				base.put('you examine the room and notice %s' % s)


			# if p == 2:
			# 	base.put('you can\'t do that yet, lol')


			if args == 'shop':
				self.party.current_dungeon.enter_shop()

			if args == 'enter a dungeon':
				self.party.current_dungeon.leave_dungeon()

			if args == 'repair':
				self.party.current_dungeon.repair_items()

			for a in self.inventory:
				if isinstance(a,weapons.Weapon):
					if a.equipped: a.do_turn(args)
				else:
					a.do_turn(args)

			if not isinstance(self.party.current_dungeon,dungeon.Hub):
				for a in self.party.current_dungeon.active_room.things:
					if isinstance(a,thing.InteractiveObject):
						a.do_turn(args)
		self.action_points -= 1
Beispiel #9
0
 def __init__(self, human=True):
     self._human = human
     self._ships = []
     self._shots = []
     self.name = get_input('Please enter Player name: ')
Beispiel #10
0
 def __init__(self, human=True):
     self._human = human
     self._ships = []
     self._shots = []
     self.name = get_input('Please enter Player name: ')