コード例 #1
0
ファイル: mapgrid.py プロジェクト: svuolli/coldworld
    def __init__(self, world):
        self.grid = []
        self.images = map(lambda f: loadImage("images/" + f), [
            "tree1.png",
            "tree2.png",
            "tree3.png",
            "tree4.png",
            "tree5.png",
            "tree6.png",
            "tree8.png",
            "tree9.png",
            "tree10.png"])
        print self.images

        for line_num in xrange(WORLD_SIZE[1]):
            line = []
            y = line_num * BLOCK_SIZE
            for cell in xrange(WORLD_SIZE[0]):
                on_edge = False
                if cell==0 or cell==WORLD_SIZE[0]-1:
                    on_edge = True
                if line_num==0 or line_num==WORLD_SIZE[1]-1:
                    on_edge = True

                if on_edge or randint(0, 99) < 5:
                    x = cell * BLOCK_SIZE
                    block = Block(world, choice(self.images))
                    image_size = block.image.get_size()
                    block.location = Vector2(x+image_size[0]/2, y+BLOCK_SIZE)
                    line.append(block)
                else:
                    line.append(None)
            self.grid.append(line)
コード例 #2
0
ファイル: miner.py プロジェクト: HadiSheybani/Blockchain
 def mine(self, block : Block):
     while True:
         index = self.__index_generator.next()
         block_object = str(index) + str(block.time_stamp) + str(block.data) + str(block.pre_hash)
         block_hash = self.__hash_generator.generate(block_object)
         if self.__policy.check(block_hash):
             block.index = index
             block.block_hash = block_hash
             return block
コード例 #3
0
 def test_CreateABlockChainWhenAddBlockToItThenGetChainShouldReturnAListOfBlocks(
         self):
     blockchain = BlockChain()
     block = Block(0)
     blockchain.add_block(block)
     assert_that(blockchain.get_chain(), instance_of(list))
     assert_that(blockchain.get_chain()[0].index, equal_to(0))
コード例 #4
0
 def test_CreateABlockWithoutInputThenItsPropertyShouldBeNone(self):
     block = Block()
     assert_that(block.index, none())
     assert_that(block.time_stamp, none())
     assert_that(block.data, none())
     assert_that(block.pre_hash, none())
     assert_that(block.block_hash, none())
コード例 #5
0
def restore_blocks(mydb):
    mycol = mydb["blocks"]  #create collection
    mylist = mycol.find()
    for data_block in mylist:
        block = Block(data_block["x"], data_block["y"])
        block.is_mine = data_block["is_mine"]
        block.is_monster = data_block["is_monster"]
        block.is_super_monster = data_block["is_super_monster"]
        block.is_key = data_block["is_key"]
        block.is_exit = data_block["is_exit"]
        block.is_open = data_block["is_open"]
    for blocks in Data.blocks:
        for block in blocks:
            if (not block):
                continue
            elif block.is_open:
                block.restore()
コード例 #6
0
def build_block():
    for x in range(st.NUMBER_COLUMN):
        for y in range(st.NUMBER_ROW):
            if not (x == st.NUMBER_COLUMN / 2 and y == st.NUMBER_ROW / 2):
                block = Block(st.SIZE_BORDER + st.SIZE * x,
                              st.SIZE_BORDER + st.SIZE * y)
                if not random.randint(0,
                                      st.DENSITY_MINES) and block.is_empty():
                    block.is_mine = True
                elif not random.randint(
                        0, st.DENSITY_MONSTERS) and block.is_empty():
                    block.is_monster = True
                elif not random.randint(
                        0, st.DENSITY_SUPERMONSTERS) and block.is_empty():
                    block.is_super_monster = True
コード例 #7
0
 def test_CreateABlockWhenSetAPropertyThenItCouldNotBeSetAgain(self):
     block = Block(0, 0, "hello", "123", "456")
     block.index = 1
     block.time_stamp = 1
     block.data = "bye"
     block.pre_hash = "789"
     block.block_hash = "100"
     assert_that(block.index, equal_to(0))
     assert_that(block.time_stamp, equal_to(0))
     assert_that(block.data, equal_to("hello"))
     assert_that(block.pre_hash, equal_to("123"))
     assert_that(block.block_hash, equal_to("456"))
コード例 #8
0
ファイル: dict2block.py プロジェクト: HadiSheybani/Blockchain
 def convert(self, block_dict: dict):
     if "index" not in block_dict:
         raise ValueError('No Index Value')
     if 'time_stamp' not in block_dict:
         raise ValueError('No Time Stamp Value')
     if 'data' not in block_dict:
         raise ValueError('No Data Value')
     if 'pre_hash' not in block_dict:
         raise ValueError('No PreHash Value')
     if 'block_hash' not in block_dict:
         raise ValueError('No BlockHash Value')
     return Block(int(block_dict['index']), int(block_dict['time_stamp']),
                  block_dict['data'], block_dict['pre_hash'],
                  block_dict['block_hash'])
コード例 #9
0
ファイル: human.py プロジェクト: svuolli/coldworld
    def process(self, time_passed):
        self.hunger -= time_passed*2.5
        self.thirst -= time_passed*2.5
        self.heat -= time_passed*2.5
        self.age += time_passed
    
        pressed = pygame.key.get_pressed()
        move_vector = (0, 0)
        if(self.joycontrol == -1):
            for m in (self.key_map[key] for key in self.key_map if pressed[key]):
                move_vector = map(sum, zip(move_vector, m))
        else:
            x = self.joystick.get_axis(0)
            y = self.joystick.get_axis(1)

            if math.fabs(x) < 0.1:
                x = 0.
            if math.fabs(y) < 0.1:
                y = 0.
                
            move_vector = Vector2(x,y)
            

        self.heading = Vector2(move_vector)
        if move_vector[0] < 0.0:
            self.left_facing = True
        elif move_vector[0] > 0.0:
            self.left_facing = False

        if self.heading.get_length() > 0.0:
            self.frame_timer -= time_passed
            if self.frame_timer < 0.0:
                self.frame_timer = FRAME_TIME
                self.current_frame += 1
                if self.current_frame >= len(self.images_rf):
                    self.current_frame = 0
    
        GameEntity.process(self, time_passed)
        hare = self.world.get_close_entity("hare", self.location, 80)
        if hare:
            self.hunger = min(self.hunger+20.0, 120.0)
            self.world.remove_entity(hare)
            self.world.hare_count -= 1
            self.sounds["eat"].play()
        fire = self.world.get_close_entity("fire", self.location, 80)
        if fire:
            self.heat = min(self.heat+time_passed*20.0, 120)
        water = self.world.get_close_entity("water", self.location, 80)
        if water:
            self.thirst = min(self.thirst+time_passed*20.0, 120)

        if self.hunger < 0.0 or self.heat < 0.0 or self.thirst < 0.0:
            self.world.remove_entity(self)
            self.world.human_count -= 1
            tomb_stone = Block(self.world, loadImage("images/tomb.png"))
            tomb_stone.location = self.location
            self.world.add_entity(tomb_stone)
        
        self.hunger_image_index = min(5,int(6.0*self.hunger/120.0))
        self.thirst_image_index = min(5,int(6.0*self.thirst/120.0))
        self.heat_image_index = min(5,int(6.0*self.heat/120.0))