class EditSession: def __init__(self,file): self.file = file self.code = '' self.module = 'ARCEDIT' self.covers = [] self.backcovers = [] self.currentcov = None self.startup() def writecode(self,code): self.code = self.code + code f = open(self.file,'a') f.write(code) f.close() def startup(self): code = ''' /* /* Check that the user is starting the module from /* the correct place /* &if not [show program] = ARC &then &do &ty MODULE ERROR: &ty Cannot start %s from [show program] &return &error &end &else &do %s &end /* ================================================== ''' % (self.module,self.module) self.writecode(code) def edit(self,name,feature='' ): self.currentcov = Cover(name,self.file) if feature == '': code = ''' edit %s ''' % self.currentcov.name else: if feat == 'poly': feat = 'polygon' self.currentcov.checktopology(feat) code = ''' edit %s %s ''' % (self.currentcov.name,feat) self.writecode(code) if self.currentcov.name not in self.covers: self.covers.append(self.currentcov.name) return self.currentcov
def run(self): """实现主要逻辑""" while True: # 显示封面 Cover().run() while self.starting: # 设置游戏最大帧率为60 pygame.time.Clock().tick(60) # 绘制背景 self.background_draw() # 绘制玩家飞机 self.player_draw() # 绘制玩家击毁动画 self.player_destory() # 判断游戏是否结束 if self.gameover() == True: break # 生成敌机 self.create_enemies() # 移动敌机 self.enemies_move() # 绘制敌机 self.enemies1.draw(self.screen) # 绘制敌机击毁动画 self.enemies_destory() # 显示子弹 self.bullets_draw() # bomb掉下来 self.bomb_down() # 获得bomb self.get_bomb() self.get_bullet() # 监听键盘事件 key_pressed = pygame.key.get_pressed() if not self.player.is_hit: if key_pressed[K_UP]: self.player.moveUp() if key_pressed[K_DOWN]: self.player.moveDown() if key_pressed[K_LEFT]: self.player.moveLeft() if key_pressed[K_RIGHT]: self.player.moveRight() self.pause_resume() # 暂停功能 pygame.display.update() # 是否重新游戏 while not self.starting: if True == self.restart(): break
def __init__(self,name,filename): Cover.__init__(self,name,filename) # A features table showing feature classes and # related feat_codes self.features = {'point': ['aircrft_flty']} self.items = {'point': ['area', 'perimeter', '%s#' % self.name, '%s-id' % self.name, 'feat_code', 'name', 'facility', 'q_info', 'ufi', 'symbol', 'feat_wid', 'orientation', 'old_ufi'] }
def checktopology(self,feat): # Check that DOES have point topology Cover.checktopology(self,'point') # Check that it DOESNT have other topology or features. feats = string.join(self.features.keys()) allfeats = ['point','arc','polygon'] for f in allfeats: if f not in self.features.keys(): Cover.checkextratopology(self,f,feats) Cover.checkextrafeatures(self,f,feats)
def edit(self,name,feature='' ): self.currentcov = Cover(name,self.file) if feature == '': code = ''' edit %s ''' % self.currentcov.name else: if feat == 'poly': feat = 'polygon' self.currentcov.checktopology(feat) code = ''' edit %s %s ''' % (self.currentcov.name,feat) self.writecode(code) if self.currentcov.name not in self.covers: self.covers.append(self.currentcov.name) return self.currentcov
def gen_table(self, mapName): table = [[tile_content(self) for i in range(Dimesions.TABLE_WIDTH)] for j in range(Dimesions.TABLE_HEIGHT)] img = Image.open(mapName) pixels = img.load() for j in range(img.size[1]): for i in range(img.size[0]): p = pixels[i, j] content = "\u00B7" if isinstance(p, tuple): if p[0] == p[1] and p[1] == p[2] and p[0] == p[2]: if p[0] <= 128: content = Cover(self, int((256 - p[0]) / 32)) if p[0] >= 255: content = tile_content(self) else: if p[0] == 0 and p[1] == 0 and p[2] == 255: content = Station(self, location(i, j), None) self.stations.append(content) table[i][j] = content return table
from Cover import Cover from List import List vcover = Cover('I5308VM','same.aml') fcover = Cover('COAST','same.aml') l1 = vcover.getitems('arc') l2 = fcover.getitems('arc') l3 = l1[7:0] l4 = l2[7:0] code = ''' &ty %s &ty %s ''' % (l3.isequal(l4),l3[2]) vcover.writecode(code)
def __init__(self, cover, file): Cover.__init__(self, cover.name, file) self = cover.reselect("point", "feat_code = 'building'")