Exemple #1
0
 def __init__(self, engine, color, axis_get_func):
     Entity.__init__(self, engine)
     self.color = color
     self.get_axis = axis_get_func
     self.pos = pos(0, 0) 
     self.velocity = pos(0, 0)
     self._speed = 1.0
Exemple #2
0
    def reset(self):

        buf = 0.0
        # Reset player positions
        #positions = [pos(buf, buf), pos(self.size[0]-buf, buf), pos(self.size[0]-buf, self.size[1]-buf), pos(buf, self.size[1]-buf)]
        positions = [pos(self.size[0]*(i+1)/(1.0 + len(self.players)), self.size[1]-80) for i in xrange(len(self.players))] 
        for i, p in enumerate(self.players):
            p.pos = positions[i]
            p.velocity = pos(0, 0)
        
        self.entities = []
        self.entitysprites = pygame.sprite.RenderPlain() 
    
        self.game_over = False
        self.points = 5
 def __init__(self, posx, posy, index, map):
     self.__map = map
     self.__pos = pos(posx, posy)
     self.__index = index
     self.__name = ("P" + str(index))
     self.__healPower = random.randint(5, self.HEAL_CAP - 5)
     self.__is_used = False  #record whether it is used
Exemple #4
0
 def unoccupied_position(self):
     randx = random.randint(0, self.__D - 1)
     randy = random.randint(0, self.__D - 1)
     while self.__lands[randx][randy].occupied_obj != None:
         randx = random.randint(0, self.__D - 1)
         randy = random.randint(0, self.__D - 1)
     return pos(randx, randy)
Exemple #5
0
 def onClickMap(self,event):
     (c,f)=self.map.OnClick(event)
     print str(c)+','+str(f)
     cell=self.W.board.cell(pos.pos(c,f))
     if cell.is_hab():
         self.SELECTEDBUG=cell.hab[0]
         self.refresh_labels()
Exemple #6
0
    def add_bug(self,b,posi=None):
        # d=b.diet()
        # if d==HERB:
        #     h.color=HERBCOLOR
        # elif d==CARN:
        #     h.color=CARNCOLOR
        # else:
        #     h.color=OMNICOLOR
        self.bugcount+=1
        ident=hex(self.bugcount)[2:]
        b.id=ident
        #b.board=self.board
        if not b.board:
            b.board.append(self.board)

        # ToDo: If posi out of bounds generate random
        if posi==None:
            # Generates a random pos
            p=pos.pos()
        else:
            p=posi

        b.pos=p
        #self.habs.append(h)
        # Addes the bug to the list of living bugs
        self.bugs[ident]=b

        self.board.cell(p).set_hab(b)
        logger.info('Added bug '+ident)
Exemple #7
0
	def draw7(self):
		thumb_size = pos(self.thumb.get_size())
		surf_size = self.surf.get_size()
		scale = self.img.get_size() / thumb_size
		for x in self.path:
			pygame.draw.circle(self.thumb, palette[3],
			  tuple((x + self.imgrect.topleft) / scale), 2)
Exemple #8
0
def readinidata(path):
	strp = lambda s, d=",": [int(x) for x in s.split(d)]
	path = path
	fh = open(path, "r")
	append = None
	inidata = dict()
	for line in fh:
		line = line.rstrip()
		if len(line) == 0:
			continue
		elif line[0] == "\t":
			if append is None:
				err("Error: invalid input: {}".format(line))
			inidata[append] += line.lstrip()
			continue
		line = line.split(None, 1)
		if len(line) != 2:
			continue
		append = line[0]
		if append in ("rect", "startpos", "endpos", "labyrinth", "path"):
			inidata[append] = line[1]
		else:
			err("Error: invalid input: {}".format(" ".join(line)))
			exit(1)
	for k, v in inidata.items():
		if k == "rect":
			inidata[k] = pygame.Rect(*strp(v))
		elif k in ("startpos", "endpos"):
			inidata[k] = pos(*strp(v))
		elif k == "path":
			inidata[k] = parse_path(v)
		else:
			assert(k == "labyrinth")
	return inidata
Exemple #9
0
    def __init__(self, posx, posy, index, map):
        self.__pos = pos(posx, posy)
        self.__index = index
        self.__map = map

        self.__name = "W" + str(index)
        self.__health = self.HEALTH_CAP
        self.__magic_crystal = 10
Exemple #10
0
	def mbup4(self, ev):
		thumb_size = pos(self.thumb.get_size())
		surf_size = self.surf.get_size()
		scale = self.img.get_size() / thumb_size
		thumb_topleft = pos(
			0 if thumb_size[0] == surf_size[0]
			  else abs(thumb_size[0] - surf_size[0]) >> 1,
			0 if thumb_size[1] == surf_size[1]
			  else abs(thumb_size[1] - surf_size[1]) >> 1,
		)
		self.endpos = ev.pos
		self.imgendpos = (self.endpos - thumb_topleft) * scale
		if self.imgrect.collidepoint(self.imgendpos) == 0:
			self.next_state = True
		else:
			self.endpos = self.imgendpos / scale + thumb_topleft
		self.updated = True
Exemple #11
0
    def process(self):
        Entity.process(self)

        self.pos += self.velocity

        wall_dist = 10.0
        buf = wall_dist + self.radius
        # Check position boundaries
        if self.pos[0] < buf:
           self.pos = pos(buf, self.pos[1]) 
        if self.pos[0] > self.engine.size[0]-buf:
           self.pos = pos(self.engine.size[0]-buf, self.pos[1]) 
        if self.pos[1] < buf:
            self.pos = pos(self.pos[0], buf)
        if self.pos[1] > self.engine.size[1]-buf:
            self.pos = pos(self.pos[0], self.engine.size[1]-buf)

        self.velocity *= 0.8 
Exemple #12
0
def parse_path(s):
	l = []
	while len(s) > 0:
		f = s.find(")")
		if f < 0:
			break
		p, s = s[s.find("(") + 1:f], s[f + 1:]
		l.append(pos(tuple(int(x.strip()) for x in p.split(","))))
	return l
Exemple #13
0
 def checkTreasure(self):
     '''
     No pre conditions are made for this method.
     :return: notifies the user that we found treasure and we store the steps.
     '''
     if self.matrix[self.nextState.row][self.nextState.col] == "T":
         x = copy.deepcopy(self.stackObject.items)
         position = pos(self.nextState.row, self.nextState.col)
         self.treasures[position] = x
Exemple #14
0
	def draw5(self):
		self.surf.fill(palette[2])
		s = self.states[self.state]["title"] + "-/|\\"[self.tok % 4]
		self.tok += 1
		fs = self.font.render(s, False, palette[0])
		self.surf.blit(fs,
		  pos(self.surf.get_rect().center) - fs.get_rect().center)
		del fs
		return False
Exemple #15
0
    def process(self):
        Entity.process(self)

        speed = 0.8

        self.pos = pos(self.pos[0], self.pos[1] + speed)
        if self.pos[1] > self.engine.size[1]:
            self.engine.lose_point()
            self.kill_self()
Exemple #16
0
    def sow(self):
        logger.info('Sowing...')
        m=BOARDWIDTH*BOARDHEIGHT*self.sowrate/1000
        logger.debug('Start sowing '+str(m)+' cells')
        for i in range(0,int(m)):
            #x=numpy.random.randint(0,BOARDSIZE/5)*5
            x=numpy.random.randint(0,BOARDWIDTH)
            y=numpy.random.randint(0,BOARDHEIGHT)

            self.board.cell(pos.pos(x,y)).grow_food()
        logger.debug('End sowing')
Exemple #17
0
    def __init__(self, content, initialpos, colors):

        # Functionality Setup
        self.mappings = {
        }  #Mappings of the points in (i,j) coordinates of the matrix to the actual canvas (x,y) coords
        self.currentState = pos(
        )  #Position object that lets us know about the current state
        self.nextState = pos(
        )  #Position object that lets us know about the next state
        self.treasures = {
        }  #Treasure dictionary that maps out the treasure positions to the path stack
        self.stackObject = Stack(
        )  #Stack object that allows us to store our orientations (North, East, etc.)
        self.matrix = content  #Two dimensional python list to store the rows and columns
        self.initialpos = initialpos  #Position object that lets us know at what point in the matrix we have started
        self.colors = colors

        # Check if colors are not empty
        for item in self.colors:
            if self.colors[item] is None or self.colors[item] == "":
                self.colors = {
                    "W": "red",
                    "M": "blue",
                    "T": "yellow",
                    ".": "white",
                    "TR": "blue"
                }
                break

        # Turtle Window GUI Setup
        self.row = len(content)
        self.col = len(content[0])
        self.canvaswidth = 1500
        self.canvasheight = 1500
        self.window = turtle.Screen()
        self.window.setup(width=self.canvaswidth, height=self.canvasheight)
        self.John = turtle.Turtle()
        self.John.speed(0)

        self.draw()
        self.window.exitonclick()
Exemple #18
0
    def __init__(self, engine):
        pygame.sprite.Sprite.__init__(self)
        self.load_sprite()

        #self.image = pygame.transform.scale(self.image, (48, 48))
        self.radius = self.rect.size[0]/2.0

        self.engine = engine
        self._pos = pos(0, 0)
        self.color = (0, 0, 0)
        self.die = False
        self.life = 100
        self.sprite = pygame.sprite.Sprite
Exemple #19
0
	def mbup2(self, ev):
		if self.mrect is None:
			return
		setbottomright(self.mrect, ev.pos)
		self.mrect.normalize()
		thumb_size = pos(self.thumb.get_size())
		surf_size = self.surf.get_size()
		scale = self.img.get_size() / thumb_size
		thumb_topleft = pos(
			0 if thumb_size[0] == surf_size[0]
			  else abs(thumb_size[0] - surf_size[0]) >> 1,
			0 if thumb_size[1] == surf_size[1]
			  else abs(thumb_size[1] - surf_size[1]) >> 1,
		)
		self.mrect.clip(pygame.Rect(thumb_topleft, thumb_size))
		if self.mrect.size == (0, 0):
			self.mrect = None
			return
		self.mrect.topleft -= thumb_topleft
		self.imgrect = shrinkfit(self.img,
		  pygame.Rect(self.mrect.topleft * scale, self.mrect.size * scale))
		self.mrect = pygame.Rect(self.imgrect.topleft / scale + thumb_topleft,
		  self.imgrect.size / scale)
		self.updated = True
Exemple #20
0
	def draw(self):
		global palette
		size = pos(self.surf.get_size())
		if self.thumb is None:
			self.thumb = fitscale(self.img, size)
		self.surf.fill(palette[0])
		d = self.optional("draw")
		if d is not None and d == False:
			return
		self.surf.blit(self.thumb, (size - self.thumb.get_size()) / (2, 2))
		fs = self.font.render(self.fname, False, palette[3])
		self.surf.blit(fs, size - fs.get_size())
		del fs
		fs = self.font.render(self.states[self.state]["title"], False, palette[3])
		self.surf.blit(fs, (0, 0))
		del fs
Exemple #21
0
    def getfileContents(self):
        '''
        Returns the file contents in the form of a matrix in order to further parse the data.
        :return: A tuple that includes a two dimensional python list and the
        '''

        # -------------Extract the number of rows and columns from 'f_line'-----------
        f_line = self.f.readline()  # reads the first line
        list_f_line = f_line.split(" ")
        numRows = int(list_f_line[0])
        numCols = int(list_f_line[1])
        # ----------------------------------------------------------------------------

        # ----------------Extract the entire matrix into nested lists.----------------
        untrimmed_f_lines = self.f.read().splitlines(
        )  # Untrimmed rows of characters, which include the whitespace characters
        trimmed_f_lines = [
        ]  # Trimmed rows of characters, which don't include the whitespace characters

        for line in untrimmed_f_lines:
            tmpstr = []
            for char in line:
                if char == " ":
                    continue
                else:
                    tmpstr.append(char)
            trimmed_f_lines.append(tmpstr)

        matrix = copy.deepcopy(
            trimmed_f_lines
        )  # Create a deep copy of the trimmed nested list for the matrix
        # ------------------------------------------------------------------------------

        # --------------Find where M is initially and store its position------------------
        # --------------Recall that indices start at 0, not 1-----------------------------

        for line in matrix:
            for char in line:
                if char == 'M':
                    initialpos = pos(matrix.index(line), line.index(char))
                else:
                    continue
        # ------------------------------------------------------------------------------

        return (matrix, initialpos)
Exemple #22
0
def handle_sentence(request):

    sentence = request.POST['sentence']
    print sentence
    words = nltk.word_tokenize(sentence)
    print words
    tagged = nltk.pos_tag(words)
    print tagged

    grammarInfo = pos()
    grammarDictToDisplay = {}
    request.session['original_sentence'] = sentence
    request.session['list'] = []
    for pair in tagged:
        try:
            request.session['list'].append((pair[0], grammarInfo[pair[1]]))
        except KeyError:
            pass
    print '*' * 50
    print request.session.items()
    return redirect('success')
Exemple #23
0
    def OnDraw(self,event=None):
        dc = wx.PaintDC(self)
        dc.Clear()
        dc.SetPen(wx.Pen(wx.BLACK,1.5))

        c1=self.coords.column
        f1=self.coords.row
        f2=f1+TILESHEIGHT
        c2=c1+TILESWIDTH

        if f2>BOARDHEIGHT:
            f2=BOARDHEIGHT
            f1=f2-TILESHEIGHT
        if c2>BOARDWIDTH:
            c2=BOARDWIDTH
            c1=c2-TILESHEIGHT

        for y in range(f1,f2):
            for x in range(c1,c2):
                a=self.W.board.cell(pos.pos(x,y))
                if a.is_hab():
                    b=a.hab[0]
                    d=b.diet()
                    if d==HERB:
                        color=HERBCOLOR
                    elif d==CARN:
                        color=CARNCOLOR
                    else:
                        color=OMNICOLOR
                elif a.has_food(CARN):
                    color=RED
                elif a.has_food(HERB):
                    color=GREEN
                else:
                    color=BROWN
                dc.SetBrush(wx.Brush(color, wx.SOLID))
                # ToDo: Try to accelerate with DrawRectangleList
                dc.DrawRectangle((x-c1)*TILESIZE,(y-f1)*TILESIZE,TILESIZE,TILESIZE)
Exemple #24
0
	def draw2(self):
		global palette
		if self.mrect is not None:
			mrect = self.mrect
			mrect.size = mrect.size + pos(1, 1)
			pygame.draw.rect(self.surf, palette[3], mrect, 1)
Exemple #25
0
 def __init__(self, posx, posy, index, map):
     self._map = map
     self.__pos = pos(posx, posy)
     self.__index = index
Exemple #26
0
 def spawn(self):
     if randint(0, 50) == 0:
         drone = Drone(self)
     
         drone.pos = pos(randint(20, self.size[0]-20*2), -drone.radius-2)
         self.add_entity(drone)
Exemple #27
0
 def create_world(self):
     l=self.preload('./prog')
     B=bug.bug()
     B.compile(l)
     self.W=world.world()
     self.W.add_bug(B,pos.pos(2,1))
Exemple #28
0
 def __init__(self):
     self.color = (0, 0, 0)
     self.width = 2
     self.damage = 10 
     self.pos1 = pos(0, 0)
     self.pos2 = pos(0, 0)
Exemple #29
0
    def __do_layout(self):
        # begin wxGlade: MyFrame1.__do_layout

        # Main container
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        # Container for map and controls
        sizer_4=wx.FlexGridSizer(1,3,0,0)

        # Map and scrollbars
        # ToDo: Make the map and scrollbars a single control
        sizer_map=wx.FlexGridSizer(2,2,0,0)
        panel=wx.Panel(self,size=(MAPWIDTH,MAPHEIGHT))
        self.map = DrawMap(panel, self.W,pos.pos(0,0))
        self.map.Bind(wx.EVT_LEFT_DOWN, self.onClickMap)

        vbar=wx.ScrollBar(self,style=wx.SB_VERTICAL,size=(16,MAPHEIGHT))
        vbar.SetScrollbar(0,TILESHEIGHT,BOARDHEIGHT,TILESHEIGHT)
        vbar.Bind(wx.EVT_SCROLL,self.onScroll)

        hbar=wx.ScrollBar(self,style=wx.SB_HORIZONTAL,size=(MAPWIDTH,16))
        hbar.SetScrollbar(0,TILESWIDTH,BOARDWIDTH,TILESWIDTH)
        hbar.Bind(wx.EVT_SCROLL,self.onScroll)
        sizer_map.Add(self.map,0,0,0)
        sizer_map.Add(vbar,0,0,0)
        sizer_map.Add(hbar,0,0,0)

        # Container for controls
        ##################################
        sizer_5 = wx.BoxSizer(wx.VERTICAL)

        # Adds map
        sizer_4.Add(sizer_map, 1, 0, 0)

        # Play buttons
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_6.Add(self.play_button, 0, 0, 0)
        sizer_6.Add(self.step_button, 0, 0, 0)
        sizer_6.Add(self.stop_button, 0, 0, 0)

        sizer_7=wx.BoxSizer(wx.VERTICAL)
        #sizer_7.Add(self.label_sow, 1, wx.ALIGN_BOTTOM, 0)
        sizer_7.Add(item=self.label_sow,proportion=0,flag=wx.ALIGN_BOTTOM)
        sizer_7.Add(self.sow_slider,0,0,0)

        # World info
        grid_sizer_1 = wx.FlexGridSizer(2, 2, 0, 0)
        grid_sizer_1.Add(self.label_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_cycle, 0, 0, 0)
        grid_sizer_1.Add(self.label_2, 0, 0, 0)
        grid_sizer_1.Add(self.label_bugs, 0, 0, 0)

        grid_sizer_2=wx.FlexGridSizer(3,2,0,0)
        grid_sizer_2.Add(self.label_3, 0, 0, 0)
        grid_sizer_2.Add(self.label_bugid, 0, 0, 0)
        grid_sizer_2.Add(self.label_4, 0, 0, 0)
        grid_sizer_2.Add(self.label_bugage, 0, 0, 0)
        grid_sizer_2.Add(self.label_5, 0, 0, 0)
        grid_sizer_2.Add(self.label_bugenergy, 0, 0, 0)

        #bug_panel=wx.Panel(self,style=wx.RAISED_BORDER)
        #bug_panel.SetSizerAndFit(grid_sizer_2)
        #bug_panel.SetSizer(grid_sizer_2)

        sizer_ops=wx.BoxSizer(wx.VERTICAL)
        for i in range(0,4):
            sizer_ops.Add(self.text_ops[i])

        # Adds:
        # Buttons
        sizer_5.Add(sizer_6, 1, 0, 0)
        # Sow slider
        sizer_5.Add(sizer_7, 1, 0, 0 )
        # World info
        sizer_5.Add(grid_sizer_1, 1, wx.EXPAND, 0)
        #sizer_5.Add(bug_panel, 1, wx.EXPAND, 0)
        # Bug info
        sizer_5.Add(grid_sizer_2, 1, wx.EXPAND, 0)
        # Bug ops
        sizer_5.Add(sizer_ops,1, 0, 0)



        ##################################
        # Container for file controls
        ##################################
        sizer_filectrls=wx.BoxSizer(wx.VERTICAL)
        sizer_file1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_file1.Add(self.loadbug_button,0,0,0)
        sizer_file1.Add(self.savebug_button,0,0,0)
        sizer_file2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_file2.Add(self.loadworld_button,0,0,0)
        sizer_file2.Add(self.saveworld_button,0,0,0)
        sizer_filectrls.Add(sizer_file1)
        sizer_filectrls.Add(sizer_file2)

        # Adds controls and buginfo sizers
        sizer_4.Add(sizer_5, 1, 0, 0)
        sizer_4.Add(sizer_filectrls,1,0,0)

        sizer_3.Add(sizer_4, 1, 0, 0)
        self.SetSizer(sizer_3)
        sizer_3.Fit(self)
        self.Layout()