def create_squirrel(ai_settings, screen, squirrels, squirrel_number, row_number): """Create a squirrel and place it in the row.""" squirrel = Squirrel(ai_settings, screen) squirrel_width = squirrel.rect.width squirrel.x = squirrel_width + 2 * squirrel_width * squirrel_number squirrel.rect.x = squirrel.x squirrel.rect.y = squirrel.rect.height + 2 * squirrel.rect.height * row_number squirrels.add(squirrel)
def __init__(self, x, y, group): Boss.__init__(self, x, y, group=group) Squirrel.__init__(self, x, y, group=group) self.hp = 30500 self.damage = 90 self.xp_for_main_hero = 950 self.for_fase_time = self.hp // 2000 + 4 self.type = 'f' self.rect.height += 1 self.magic_time = 0
def enemy_move(self): '''Фазы теже что и у первого босса, но с другими цифрами. Но поведение перемещения унаследовано от белки.''' Squirrel.enemy_move(self) self.for_fase_time = self.hp // 1000 + 6 self.for_magic_time = self.for_fase_time // 2 self.speed = 3 - (self.hp // 7000) + 4 if not self.was_hp and self.hp < 7501: self.change_hp(10000) self.was_hp = True if time.time() - self.fase_time > self.for_fase_time: if self.hp < 30000: self.change_hp(1000) self.set_fase_time() self.hp_color = (255, 0, 10) return self.do_enemys() if time.time() - self.fase_time > 3: self.hp_color = (100, 255, 100)
def create_fleet(ai_settings, screen, dobie,squirrels): """Create a full fleet of squirrels""" # Create a squirrel and find the number of suirrels in a row. # Spacing between each squirel is equal to one squirrel width squirrel = Squirrel(ai_settings, screen) squirrel_width = squirrel.rect.width number_squirrels_x = get_number_squirrels_x(ai_settings, squirrel.rect.width) number_rows = get_number_rows(ai_settings, dobie.rect.height, squirrel.rect.height) # create the first row of squirrels for row_number in range(number_rows): for squirrel_number in range(number_squirrels_x): # Create an squirrel and place it in the row. create_squirrel(ai_settings, screen, squirrels, squirrel_number, row_number)
def __init__(self, world_map, N_GROUND_TILES=1): self.MAP = world_map self.WIDTH_TILES = len(self.MAP[0]) self.HEIGHT_TILES = len(self.MAP) self.N_GROUND_TILES = N_GROUND_TILES self.GROUND_LAYER: List[List[dict]] = \ [[{} for x in range(self.WIDTH_TILES)] for y in range(self.HEIGHT_TILES)] for x in range(self.WIDTH_TILES): for y in range(self.HEIGHT_TILES): self.GROUND_LAYER[y][x]['tileidx'] = \ random.randint(0, self.N_GROUND_TILES-1) self.squirrel = Squirrel(self, Point(23, 22), Direction.DOWN) self.squirrels = [] self.foxes = [] self.nuts = {}
def index(): if request.method == "POST": squirrels.append(Squirrel(request.form['name'])) return redirect(url_for('index')) return render_template("index.html", squirrels=squirrels)
from flask import Flask, redirect, url_for, render_template, request from flask_modus import Modus from squirrel import Squirrel app = Flask(__name__) modus = Modus(app) rodger = Squirrel(name='rodger') sue = Squirrel(name='sue') patricia = Squirrel(name='patricia') squirrels = [rodger, sue, patricia] @app.route('/') def root(): return redirect(url_for('index')) @app.route('/squirrels', methods=["GET", "POST"]) def index(): if request.method == "POST": squirrels.append(Squirrel(request.form['name'])) return redirect(url_for('index')) return render_template("index.html", squirrels=squirrels) @app.route('/squirrels/new') def new(): return render_template("new.html")
class Editor(QsciScintilla): ARROW_MARKER_NUM = 8 def __init__(self,parent,text,nfile): QsciScintilla.__init__(self,parent) self.parent = parent self.errorLines = [] self.setText(text) if(config.encoding() == Encoding.ASCII): self.setUtf8(False) #print "ascii set" else: self.setUtf8(True) #print "unicode set" if(eol == 0): self.setEolMode(self.EolWindows) elif(eol == 1): self.setEolMode(self.EolUnix) else: self.setEolMode(self.EolMac) if(config.whiteSpace()): self.setWhitespaceVisibility(True) self.cursorPositionChanged.connect(self.parent.updateLine) #self.linesChanged.connect(self.changeMarginWidht()) #Indicator #self.setIndicatorForegroundColor(self.colorStyle.color) #self.setIndicatorOutlineColor(self.colorStyle.paper) #Marker self.markerDefine(QsciScintilla.RightArrow,self.ARROW_MARKER_NUM) self.markerDefine(Auto.auto_error,0) self.font = QFont(config.fontName(),config.fontSize()) #self.font.setFixedPitch(True) self.setFont(self.font) self.fontmetrics = QFontMetrics(self.font) self.setMarginsFont(self.font) # Margin 0 is used for line numbers self.setMarginSensitivity(0, True) #self.connect(self,SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'),self.on_margin_clicked) self.setCaretLineVisible(True) #Code-Complete self.registerImage(0,Auto.auto_class2) self.registerImage(1,Auto.auto_method) self.registerImage(2,Auto.auto_field) self.registerImage(3,Auto.auto_package) self.setAutoCompletionThreshold(config.thresh()) self.setAutoCompletionSource(QsciScintilla.AcsAPIs) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setBackspaceUnindents(True) self.setAutoCompletionCaseSensitivity(True) self.setIndentationsUseTabs(True) self.setTabIndents(True) self.setAutoIndent(True) self.setMargin(config.margin()) self.setIndent(config.indent()) self.setTabWidth(config.tabwidth()) #self.copyAvailable.connect(self.highlightWord) #self.indicatorClicked.connect(self.indicate) self.setIndicatorOutlineColor(QColor("#000000")) self.indicatorDefine(self.INDIC_BOX) #self.setFolding(QsciScintilla.BoxedTreeFoldStyle) #self.setAutoCompletionSource(QsciScintilla.AcsAll) #self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') #self.setIndentation(5,25) #self.setSelectionBackgroundColor() #self.setSelectionForegroundColor() #self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK,11,QColor(220,220,220)) self.setLanguage(nfile) self.setEditorStyle() #important must not change this position self.setApi("emo") def setApi(self, text): self.api = QsciAPIs(self.lexer) self.api.load(ospathjoin(apiDir,text+".api")) self.api.prepare() self.lexer.setAPIs(self.api) #Very important do not change line otherwise gg self.setLexer(self.lexer) #Very important do not change line otherwise gg editStyle = config.readStyle() self.setMarginsBackgroundColor(QColor(editStyle["margin"])) '''This is done cause the margin color is set only when lexer is set dont know maybe a bug''' def setEditorStyle(self): ''' Bolldy some problem here the margin bg color is not set when init'ed ''' ''' But when i change it in the styles menu it changes sad''' editStyle = config.readStyle() self.setCaretLineBackgroundColor(QColor(editStyle["caret"])) self.setMarginsBackgroundColor(QColor(editStyle["margin"])) self.setMarkerBackgroundColor(QColor(editStyle["marker"]),self.ARROW_MARKER_NUM) self.lexer.setColors(editStyle) def setLanguage(self,nfile): ext = Format.get(nfile) if ext == 0: self.lexer = CPP(self) elif ext == 1: self.lexer = CSharp(self) elif ext == 2: self.lexer = CSS(self) elif ext == 3: self.lexer = HTML(self) elif ext == 4: self.lexer = Java(self) elif ext == 5: self.lexer = JavaScript(self) elif ext == 6: self.lexer = Lua(self) elif ext == 7: self.lexer = Neko(self) elif ext == 8: self.lexer = Python(self) elif ext == 9: self.lexer = SQL(self) elif ext == 10: self.lexer = Squirrel(self) elif ext == 11: self.lexer = XML(self) elif ext == 12: self.lexer = YAML(self) else: self.lexer = Squirrel(self) self.lexer.setDefaultFont(self.font) def highlightWord(self, bool): if(bool): print "yes" def indicate(self, line, index , key): print line def on_margin_clicked(self, nmargin, nline, modifiers): # Toggle marker for the line the margin was clicked on if self.markersAtLine(nline) != 0: self.markerDelete(nline, self.ARROW_MARKER_NUM) else: self.markerAdd(nline, self.ARROW_MARKER_NUM) #fix this lines not showing properly def addError(self,lineno): '''First delete all present markers then add new lines or errors''' '''sqc can only find out 1 error line just like an interpreter''' if(len(self.errorLines) == 0): self.errorLines.append(lineno-1) self.markerAdd(lineno-1, 0) #print self.errorLines #if self.markersAtLine() != 0: # self.markerDelete(self.errorLines.pop(i), 0) # for i in range(len(self.errorLines)): # #if self.markersAtLine(self.errorLines.pop(i)) != 0: # self.markerDelete(self.errorLines.pop(i), 0) #assert self.errorLines == [] def reset(self): if(len(self.errorLines) != 0): for i in self.errorLines: self.markerDelete(i, 0) self.errorLines[:] = [] def setNewFont(self,font): self.setFont(font) self.lexer.setFont(font) def setFontSize(self): self.font.setPointSize(config.fontSize()) self.lexer.setFont(self.font) def setMargin(self,mar): if(mar == 1): self.setMarginLineNumbers(1, True) if(self.lines()<1000): self.setMarginWidth(1, QString("-----")) else: self.setMarginWidth(1, QString("---------")) else: self.setMarginLineNumbers(1, False) ''' Because of white margin color cant show it''' self.setMarginWidth(1, QString("---")) def setMarginHide(self,bool): if(bool): self.setMarginWidth(1, QString("")) else: self.setMarginWidth(1, QString("---")) def setIndent(self,val): if(val == 0): self.setIndentationGuides(False) else: self.setIndentationGuides(True) def setThreshold(self,val): self.setAutoCompletionThreshold(val) def setLine(self,lineno): self.setFocus(True) ''' lineno -1 is for parser which points to next line''' self.setCursorPosition(int(lineno)-1,0) self.setCaretLineVisible(True) def getLine(self): print self.getCursorPosition() """ findFirst ( const QString & expr, bool re, bool cs, bool wo, bool wrap, bool forward = true, int line = -1, int index = -1, bool show = true, bool posix = false ) [virtual] """ def findText(self,text,re,cs,wo,bk): if(text != ''): done = self.findFirst(text,re,cs,wo,True,not bk) return done def replaceText(self,text): self.replace(text) def replaceFindText(self,text): self.replace(text)
def setLanguage(self,nfile): ext = Format.get(nfile) if ext == 0: self.lexer = CPP(self) elif ext == 1: self.lexer = CSharp(self) elif ext == 2: self.lexer = CSS(self) elif ext == 3: self.lexer = HTML(self) elif ext == 4: self.lexer = Java(self) elif ext == 5: self.lexer = JavaScript(self) elif ext == 6: self.lexer = Lua(self) elif ext == 7: self.lexer = Neko(self) elif ext == 8: self.lexer = Python(self) elif ext == 9: self.lexer = SQL(self) elif ext == 10: self.lexer = Squirrel(self) elif ext == 11: self.lexer = XML(self) elif ext == 12: self.lexer = YAML(self) else: self.lexer = Squirrel(self) self.lexer.setDefaultFont(self.font)
name = "" EXIT = 9 while selection != EXIT: print "Enter your selection:" print "1. Squirrel login" print "2. Hide Acorn" print "3. Retrieve Acorn" print "4. Write squirrels to file" print "5. Write acorns to file" print "9. Exit" while selection < 1 or (selection > 5 and selection != EXIT): selection = input (name + "> ") if selection == 1: print "Squirrel login..." squirrel = Squirrel() name = squirrel.make_name() if name in squirrels: squirrel = squirrels[name] print "Returning squirrel has acorns at:" for acorn in squirrel.acorns: acorn.show() print "Ready to retrieve or add new acorns..." else: squirrels[name] = squirrel print "New squirrel. Ready to add new acorns..." elif selection == 2: print "Hide acorn..." new_acorn = Acorn() print name new_acorn.set_owner(name)
def _init_squirrels(self, nsquirrels): self.world.squirrels.clear() for i in range(nsquirrels): squirrel = Squirrel(self, self.world.random_point(), Direction.RIGHT) self.world.squirrels.append(squirrel)
def load_level(self, file_name): with open(script_dir + file_name, encoding='utf8') as file_object: self.level_file = file_object.read() for string in self.level_file.split('\n'): object, x_cor, y_cor, *dop = string.split() sleep = False without = False sleep_now = False without_now = False is_dekor = False is_go_right = True how_much_go = False is_right = 0 is_up = 0 speed_atack = 1 position = 1 if dop: if dop[0] == 'sleep': sleep = True sleep_now = int(dop[1]) elif dop[0] == 'without': without = True without_now = int(dop[1]) elif dop[0] == 'dekor': is_dekor = True elif dop[0] == 'go': how_much_go = int(dop[1]) is_go_right = int(dop[2]) if len(dop) > 2 else False elif dop[0] == 'is_right': is_right = 1 elif dop[0] == 'is_up': is_up = 1 elif object == 'gun': if dop: speed_atack = float(dop[0]) if len(dop) > 1: position = int(dop[1]) if len(dop) > 1 and dop[1] == 'is_up': is_up = 1 if 'dirt' == object: self.blocks_on_level_list.append( Blocks(int(x_cor), int(y_cor), sleep_block=sleep, sleep_now=sleep_now, without=without, without_now=without_now, is_dekor=is_dekor, group=[self.blocks_group, self.all_sprites_group])) elif 'stone_wall' == object: self.blocks_on_level_list.append( Blocks(int(x_cor), int(y_cor), where_image='images\Blocks\stone_wall.png', sleep_block=sleep, sleep_now=sleep_now, without=without, without_now=without_now, is_dekor=is_dekor, group=[self.blocks_group, self.all_sprites_group])) elif 'board' == object: self.blocks_on_level_list.append( Blocks(int(x_cor), int(y_cor), where_image='images\Blocks\\board.png', sleep_block=sleep, sleep_now=sleep_now, without=without, without_now=without_now, is_dekor=is_dekor, group=[self.blocks_group, self.all_sprites_group])) elif 'bush' == object: self.blocks_on_level_list.append( Dekor(x=int(x_cor), y=int(y_cor), where_image='images\dekor\Bush.png', sleep_block=sleep, sleep_now=sleep_now, without=without, without_now=without_now, is_dekor=is_dekor, group=[self.blocks_group, self.all_sprites_group])) elif 'gold' == object: self.blocks_on_level_list.append( Blocks(int(x_cor), int(y_cor), where_image='images\Blocks\gold.png', sleep_block=sleep, sleep_now=sleep_now, without=without, without_now=without_now, is_dekor=is_dekor, group=[self.blocks_group, self.all_sprites_group])) elif 'rainbow_block' == object: self.blocks_on_level_list.append( Rainbow_blocks( int(x_cor), int(y_cor), sleep_block=sleep, sleep_now=sleep_now, without=without, without_now=without_now, is_dekor=is_dekor, group=[self.blocks_group, self.all_sprites_group])) elif 'cook' == object: self.item_list.append( Cookies(int(x_cor), int(y_cor), group=[ self.item_to_take_group, self.all_sprites_group ])) elif 'mega_cook' == object: self.item_list.append( Cookies(int(x_cor), int(y_cor), mega_cook=True, group=[ self.item_to_take_group, self.all_sprites_group ])) elif 'final_boss_wall' == object: self.blocks_on_level_list.append( Blocks(int(x_cor), int(y_cor), sleep_block=sleep, sleep_now=sleep_now, without=without, without_now=without_now, is_dekor=is_dekor, where_image='images\Blocks\\final_boss_wall.png', group=[self.blocks_group, self.all_sprites_group])) elif 'shell' == object: self.shell_list.append( Shell(int(x_cor), int(y_cor), is_right=is_right, is_up=is_up, group=[self.shell_group, self.all_sprites_group])) elif 'gun' == object: self.person_list.append( Gun(int(x_cor), int(y_cor), speed_atack=speed_atack, position=position, group=[self.persons_group, self.all_sprites_group])) elif 'esh' == object: self.person_list.append( Enemy(x=int(x_cor), y=int(y_cor), how_much_go_right=int(dop[0]) if dop else 30, how_much_go_left=int(dop[0]) if dop else 30, hp=800 if self.level_number != '19' else 1, group=[self.persons_group, self.all_sprites_group])) elif 'spike' == object: self.blocks_on_level_list.append( Spikes(x=int(x_cor), y=int(y_cor), group=[self.blocks_group, self.all_sprites_group])) elif 'squirrel' == object: self.person_list.append( Squirrel( x=int(x_cor), y=int(y_cor), main_hero=self.main_hero, how_much_go_right=how_much_go if how_much_go else 40, how_much_go_left=how_much_go if how_much_go else 40, is_go_right=is_go_right, group=[self.persons_group, self.all_sprites_group])) elif 'Homa' == object: if self.main_hero: self.persons_group.remove(self.main_hero) self.main_hero = Homa( int(x_cor), int(y_cor), complexity=self.complexiry, group=[self.persons_group, self.all_sprites_group]) elif 'boss_1' == object: self.boss = Boss( x=int(x_cor), y=int(y_cor), group=[self.persons_group, self.all_sprites_group]) elif 'person_boss_1' == object: self.person_list.append( Boss(x=int(x_cor), y=int(y_cor), group=[self.persons_group, self.all_sprites_group])) elif 'text' == object: self.image_text = pygame.font.SysFont('arial', 22).render( dop[0].replace('_', ' '), 1, (0, 255, 0))
def others_persons(self): self.magic_in_blocks() if not self.boss: all_dead = True else: all_dead = False for person in self.person_list: if not person.is_dead: person.give_object_list( [i for i in self.blocks_on_level_list if not i.sleep_now] + self.item_list + [self.main_hero] + self.magic_list) object = person.enemy_move() if self and object: self.shell_list.append(object) person.fall() all_dead = False else: if person.do_heart: if random.randrange(0, 2): self.item_list.append( Hearts(*person.rect.topright, group=[ self.item_to_take_group, self.all_sprites_group ])) else: self.item_list.append( Cookies(*person.rect.topright, group=[ self.item_to_take_group, self.all_sprites_group ])) person.do_heart = False self.persons_group.remove(person) if all_dead and self.person_list: for block in self.blocks_on_level_list: block.enemy_disappear() self.person_list.clear() if self.level_number == '203': self.person_list.append( Homa(x=800, y=-100, speed=5, group=[self.persons_group, self.all_sprites_group])) if self.boss: self.boss.give_object_list( [i for i in self.blocks_on_level_list if not i.sleep_now] + self.item_list + [self.main_hero] + self.magic_list) if self.boss.enemy_move(): for i in range(random.randrange(2, 5)): self.person_list.append( Enemy( x=random.randrange(200, 700), y=random.randrange(50, 800) - 900, speed=random.randrange(3, 6), hp=random.randrange(400, 800), group=[self.persons_group, self.all_sprites_group])) for _ in range(random.randrange(0, 4)): sq = Squirrel( x=random.randrange(200, 700), y=random.randrange(50, 800) - 900, speed=random.randrange(4, 6), hp=random.randrange(600, 1000), group=[self.persons_group, self.all_sprites_group]) sq.set_hero(self.main_hero) self.person_list.append(sq) if self.boss.type == 'f': gun = Gun( x=random.randrange(100, 700), y=random.randrange(50, 800) - 1200, speed_atack=5, position=random.randrange(0, 4), group=[self.persons_group, self.all_sprites_group]) self.person_list.append(gun) if self.boss.type == 'f': boss_magic = self.boss.do_magic() if boss_magic: self.shell_list.append(boss_magic) self.all_sprites_group.add(boss_magic) self.magic_group.add(boss_magic) self.boss.fall()