コード例 #1
0
    def __init__(self, level=1):
        cv2.namedWindow('PlayGame', cv2.WINDOW_AUTOSIZE)
        self.level = level
        if self.level == 1:
            pathBackGround = 'imgsrc/resizedforrest.png'
            pathHoney = 'imgsrc/TransparentHoney.png'
            pathHero = 'imgsrc/Transparentpooh.png'
            pathEnemy = 'imgsrc/bee.png'
        elif self.level == 2:
            pathBackGround = 'imgsrc/resizedforrest.png'
            pathHoney = 'imgsrc/TransparentHoney.png'
            pathHero = 'imgsrc/Transparentpooh.png'
            pathEnemy = 'imgsrc/bee.png'
        elif self.level == 3:
            pathBackGround = 'imgsrc/resizedmap.png'
            pathHoney = 'imgsrc/comic1.png'
            pathHero = 'imgsrc/Transparentbear.png'
            pathEnemy = 'imgsrc/resizedpolice.png'
            self.value = [0, 260, 280, 280, 620, 270, 380, 590]

        self.backGround = cv2.imread(pathBackGround)
        self.honey = cv2.imread(pathHoney, -1)
        self.hero = cv2.imread(pathHero, -1)
        self.enemy = cv2.imread(pathEnemy, -1)

        self.windowSize = self.backGround.shape[:2]
        self.copy = self.backGround.copy()
        cv2.rectangle(self.copy, (695, 0), (self.windowSize[1], 35), (255, 255, 255), -1)
        self.collisionWatcher = CollisionWatcher(self.windowSize)
        self.bear = Bear(900, 400, self.hero)
        self.bee = Enemy(100, 100, self.enemy)
        self.cards = []
        self.collisionWatcher.setBear(self.bear)
        self.collisionWatcher.setEnemy(self.bee)
        self.collisionWatcher.setCards(self.cards)
コード例 #2
0
    def __init__(self, forest_size):

        self.forest_size = forest_size

        self.forest = []
        self.trees = []
        self.lumberjacks = []
        self.bears = []

        self.month_counter = 0

        for row in range(forest_size):
            for col in range(forest_size):

                # Roll for tree
                if random.randint(1, 100) < 50:
                    self.trees.append(Tree(row, col, self.forest_size, 12))

                # Roll for lumberjack
                if random.randint(1, 100) < 10:
                    self.lumberjacks.append(Lumberjack(row, col, self.forest_size))

                # Roll for bears
                if random.randint(1, 100) < 2:
                    self.bears.append(Bear(row, col, self.forest_size))

        print("In a {0}x{1} forest:".format(self.forest_size, self.forest_size))
        print("Starting with {0} trees.".format(len(self.trees)))
        print("Starting with {0} lumberjacks.".format(len(self.lumberjacks)))
        print("Starting with {0} bears.".format(len(self.bears)))

        thread.start_new_thread(self.start_display, ())
コード例 #3
0
def tzst_create_file_only(tmpdir):
    """
    create a note with just a file (filename required).

    Creating a note with just a file and no title or text fails on the note
    being empty. After creating the note as here, there's no evidence of the
    file in the note.

    Aha! I was overwriting the file content with the file name. Let's try it
    again...

    Well, when I pass both file and filename, with the file content base64
    encoded, what I get is 'File not in a valid base64 form'. It's not clear
    what the problem is. Guess I'll need to reach out to bear again.
    """
    pytest.dbgfunc()
    cub = Bear()
    testfile = tmpdir.join("bear-test-data")
    # data = "".join(["This is a file for testing bear\n",
    #                 "It contains a couple of lines\n",
    #                 "and is going to be inserted into a bear note\n"])
    data = "A"
    testfile.write(data)
    frob = base64.b64encode(data.encode())
    note = cub.create(title=beartest_title(),
                      file=frob,
                      filename=testfile.strpath)
    if not note:
        pytest.fail("create returned empty result")
    cub.trash(id=note['identifier'])
コード例 #4
0
def test_instantiate():
    """
    Make sure pytest is working
    """
    pytest.dbgfunc()
    cub = Bear()
    assert 'open_note' in dir(cub)
コード例 #5
0
def test_open_tag_fail():
    """
    Test for bear.open_tag(). Use fixture tnt.
    """
    pytest.dbgfunc()
    cub = Bear()
    with pytest.raises(Bearror) as err:
        cub.open_tag(name="no such tag")
    assert "Tag 'no such tag' was not found" in str(err.value)
コード例 #6
0
    def __generate_random_river__(self, qty):
        for i in range(0, qty):
            random_num = random.randint(0, 2)

            if random_num == 0:
                self.__river__.append(None)
            elif random_num == 1:
                self.__river__.append(Fish(0, random.randint(1, 2)))
            elif random_num == 2:
                self.__river__.append(Bear(0, random.randint(1, 2), 0))
コード例 #7
0
 def prepare_values(item):
     if item == '---':
         return None
     elif item[0] == 'B':
         gender = 1 if item[1] == 'F' else 2
         age = int(item[2])
         return Bear(age, gender, 0)
     elif item[0] == 'F':
         gender = 1 if item[1] == 'F' else 2
         age = int(item[2])
         return Fish(age, gender)
コード例 #8
0
ファイル: fixtures.py プロジェクト: tbarron/bearomator
def tnt():
    """
    Create a note with defined content, yield to the test, then trash the note
    """
    tid = uuid.uuid4()
    data = {
        'title':
        "pytest tmpnote {}".format(str(tid)),
        'text':
        "Original text",
        'addtext': ("Added text ='>< # // \"foobar\"\n"
                    "* bullet line\n"
                    "- todo line\n"
                    "+ plus +\n"
                    ". period .\n"
                    ", comma ,\n"
                    "! bang !\n"
                    "? question mark ?\n"
                    "| pipe |\n"
                    "\\ backslash \\\n"
                    "tab\t\t\tline\n"
                    "` grave `\n"
                    "$ dollar line\n"
                    "@ at sign @\n"
                    "^ caret ^\n"
                    "& ampersand &\n"
                    ": colon line\n"
                    "% percent line %\n"
                    "~ tilde ~\n"
                    "{ curly brace }\n"
                    "( parenthesis line )\n"
                    "[ square bracket line ]"),
        'addtags': ["newtag1", "newtag2"],
        'cub':
        Bear(),
        'unique_tag':
        tid.hex,
        'tags':
        "pytest,tmpnote,testing," + tid.hex
    }

    result = data["cub"].create(title=data['title'],
                                text=data['text'],
                                tags=data['tags'])
    note = data["cub"].open_note(id=result['identifier'], show_window="no")
    data['id'] = result['identifier']
    data['pre'] = note['note']
    (data['hdr'], data['body']) = note['note'].split("\n", 1)
    yield data
    data["cub"].trash(id=data['id'])
コード例 #9
0
def test_create_tttp(title, text, tags, ts):
    """
    Test the create function with different possible arg combinations
    """
    pytest.dbgfunc()
    cub = Bear()
    kw = {}
    if title:
        kw['title'] = title
    if text:
        kw['text'] = text
    if tags:
        kw['tags'] = tags
    if ts:
        kw['timestamp'] = ts
    note = cub.create(**kw)
    if not note:
        pytest.fail("create returned empty result")
    cub.trash(id=note['identifier'])
コード例 #10
0
    def pass_year(self):

        print("Year {0} Report:".format(self.month_counter/12))

        print("Forest has {0} trees, {1} lumberjacks, and {2} bears."
              .format(len(self.trees), len(self.lumberjacks), len(self.bears)))

        # Check lumber and reset to 0 for every lumberjack
        total_lumber = sum([lumberjack.lumber for lumberjack in self.lumberjacks])
        print("Lumber gathered: {0}".format(total_lumber))
        for lumberjack in self.lumberjacks:
            lumberjack.lumber = 0

        # Hire new lumberjacks based on the amount of lumber gathered. Too little lumber? Fire a jack at random.
        if total_lumber >= len(self.lumberjacks):
            for new_lumberjacks in range(0, floor(total_lumber / len(self.lumberjacks))):
                x_pos = random.choice(range(self.forest_size))
                y_pos = random.choice(range(self.forest_size))
                self.lumberjacks.append(Lumberjack(x_pos, y_pos, self.forest_size))
        elif len(self.lumberjacks) > 1:  # Can't go below 1
            random.shuffle(self.lumberjacks)
            self.lumberjacks.pop()

        # Check mawings and reset to 0 for every bear
        total_mawings = sum([bear.maws for bear in self.bears])
        print("Bear mawings: {0}".format(total_mawings))
        for bear in self.bears:
            bear.maws = 0

        # If there are no mawings for a year, add a bear, otherwise, remove one at random
        if total_mawings == 0:
            x_pos = random.choice(range(self.forest_size))
            y_pos = random.choice(range(self.forest_size))
            self.bears.append(Bear(x_pos, y_pos, self.forest_size))
        else:
            random.shuffle(self.bears)
            self.bears.pop()
コード例 #11
0
ファイル: play_ball.py プロジェクト: cathig/PlayBall
    def __init__(self):
        """Initialize the game, and create game resources."""
        pygame.init()
        self.settings = Settings()

        # Set the window size and title bar text
        # Windowed
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        # Full screen
        # self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        # self.settings.screen_width = self.screen.get_rect().width
        # self.settings.screen_height = self.screen.get_rect().height
        pygame.display.set_caption("Play Ball!")

        # Create an instance to store game statistics.
        self.stats = GameStats(self)

        self.bear = Bear(self)
        self.balls = pygame.sprite.Group()
        self.dog = Dog(self)

        # Make the Play button.
        self.play_button = Button(self, "Play")
コード例 #12
0
 def generate_bears(self, num):
     bears=[]
     for i in range(num):
         bear = Bear()
         bears.append(bear)
     return bears
コード例 #13
0
    def setUp(self):
        self.tmp_config_path = mkstemp()[1]

        self.bear = Bear(settings_path=self.tmp_config_path)
        self.bear.config['settings']['db_path'] = ':memory:'
        self.bear.initialize_db()
コード例 #14
0
ファイル: common.py プロジェクト: kalashnikof/alaska_test
 def generate_bear(self, bear_type):
     return Bear(
         bear_type=bear_type,
         bear_name=self.generate_random_str(),
         bear_age=round(random.uniform(1, 50), 1),
     )
コード例 #15
0
# Testing the inherited classes - get_name exists only in the base class Animal

from lizard import Lizard
from gorilla import Gorilla
from bear import Bear
from snake import Snake

lizard1 = Lizard("Sweetiepie")
gorilla1 = Gorilla("Howard")
bear1 = Bear("Dolly")
snake1 = Snake("Hzzzz")

print(lizard1.get_name())
print(gorilla1.get_name())
print(bear1.get_name())
print(snake1.get_name())

# print(help(bear1))
help(bear1)