コード例 #1
0
 def init(self):
     self.head: Location = Location(10, 10)
     self.body: List[Body] = [
         Body(Location(10, 11), Direction.UP),
         Body(Location(10, 12), Direction.UP),
         Body(Location(10, 13), Direction.UP)
     ]
     self.direction = Direction.UP
コード例 #2
0
    def move(self, game):
        """
        The logic of moving the snake that includes collision detection and eating too.
        :return: whether the snake is still alive
        """
        # next location
        x, y = self.head.get_location()
        old_direction = self.direction
        # Calculate the next coordinate based on moving direction
        new = Location(*[sum(i) for i in zip((x, y), self.direction.value)])

        # verify valid move
        collision = self.check_collision(*new.get_location())

        if not collision:
            self.head.set_location(*new.get_location())
            self._add_body_part(Location(x, y), old_direction)

            # check whether he found food
            if self.check_for_food(game.board, new.get_location()):
                game.board.generate_food()
                game.score_inc(500)
            else:
                self.body.pop(-1)

        return not collision
コード例 #3
0
class Board:
    """Represent the game board"""
    def __init__(self, size):
        self.table_size = size
        self.food_location = Location(0, 0)

        self.generate_food()

    def get_food_location(self):
        return self.food_location.get_location()

    def generate_food(self):
        self.food_location = Location(*random_position())
コード例 #4
0
ファイル: MainController.py プロジェクト: jesseharte/StochSim
 def simulateOnce(self, showCanvas=True):
     self.virus.spread()
     
     numFlyingIndividuals = self.settings.numFlyingIndividuals
     flyingIndividuals = random.sample(self.individuals, numFlyingIndividuals)
     for flyInd in flyingIndividuals:
         (x, y, z) = self.factory.generateLocation()
         flyInd.location = Location(x, y, z)
     
     
     if showCanvas: 
         self.mainView.updateCanvas(self.individuals)
     
     self.simResults.registerTimeEpoch()
コード例 #5
0
ファイル: Student.py プロジェクト: Arbonik/oopFirst
    def __init__(self):
        # место жительства, выдается случайно
        self.location = Location.random()
        # отображение имени, типа студента, места жительства
        self.name = Repository.getRandomName(
        ) + " (" + self.__class__.__name__ + ")\n" + str(self.location.name)
        # оценки студента
        self.ratings = list()
        # учебная группа студента
        self.studentGroup = None

        #     Модификатор живущего отдельно студента
        if self.location is Location.HOME:
            self.ability = self.ability + 10
コード例 #6
0
    def post(self):
        self.response.out.write(self.request)
        lat = self.request.get("lat")
        long = self.request.get("long")
        email = self.request.get("email")

        location = Location(parent=Location.location_key(email))
        self.response.out.write("location : %s" % location)
        location.lat = lat
        location.long = long
        location.email = email
        location.put()
        self.redirect("/LocSubmit?" + urllib.urlencode({"email": email}))
コード例 #7
0
    def get(self):
        email = self.request.get("email")
        limit = self.request.get("limit")
        query = ""
        if len(limit) > 0 and int(limit) > 0:
            query = "select * from Location where ANCESTOR IS :1 order by datetime desc limit %s" % limit
        else:
            query = "select * from Location where ANCESTOR IS :1 order by datetime desc "

        locations = db.GqlQuery(query, Location.location_key(email))

        retObject = []
        for location in locations:
            record = {}
            record["email"] = location.email
            record["lat"] = location.lat
            record["long"] = location.long
            record["DateTime"] = str(location.datetime)
            retObject.append(record)
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(json.dumps(retObject))
コード例 #8
0
    def get(self):
        email = self.request.get('email')
        locations = db.GqlQuery(
            "select * from Location where ANCESTOR IS :1 order by datetime desc limit 1 ",
            Location.location_key(email))

        for location in locations:
            self.response.out.write(
                'Existing value for : <b>email: %s, lat: %s, long: %s, timestamp: %s</b>'
                % (location.email, location.lat, location.long,
                   location.datetime))

        self.response.out.write("""<html>
        <body>
            <form action="/Location_Post" method="post">
            <div><textarea name="lat" rows="1" cols="20"></textarea>
            <textarea name="long" rows="1" cols="20"></textarea></div>
            <textarea name="email" rows="1" cols="20"></textarea>   
            <div><input type="submit" value="set lat/long"></div>
            </form>
            
            To get data in json: go to <a href="/Location.json">Location.json</a> and pass email as a parameter. eg /location.json?email=rohan.shah 
            </body></html>""")
コード例 #9
0
    def __init__(self, size):
        self.table_size = size
        self.food_location = Location(0, 0)

        self.generate_food()
コード例 #10
0
 def generate_food(self):
     self.food_location = Location(*random_position())
コード例 #11
0
 def generateIndividual(self, sirStatus):
     sphereLoc = self.generateLocation()
     location = Location(x=sphereLoc[0], y=sphereLoc[1], z=sphereLoc[2])
     individual = Individual(self.curIndex, location, sirStatus)
     self.curIndex += 1
     return individual
コード例 #12
0
ファイル: Controller.py プロジェクト: alkremn/WGUPS
 def createLocations(self):
     locations = CustomHashTable()
     addresses = self.getAddresses()
     for i in range(len(addresses)):
         locations[i] = Location(i, addresses[i])
     return locations