def input(events): global ostatnio_x global ostatnio_y for event in events: if event.type == QUIT: print "harakiri" sys.exit(0) else: screen.fill((blue)) #x, y = pygame.mouse.get_pos() x, y = pobierz_wspolrzedne(event, ostatnio_x, ostatnio_y) screen.blit(grafika_wody, (0, 0)) # pygame.draw.rect(screen, red, (0,0,500,660)) #screen.blit(grafika_ryby, (x-szerokosc_ryby/2, y-wysokosc_ryby/2)) draw_figure(event, screen, x, y) ostatnio_x, ostatnio_y = x, y Mapa.draw_pietro(screen) pygame.display.flip() if x < 500 : sound.play() else: # screen.blit(grafika_ogien, (500,330)) pygame.display.flip()
def run(): global Hora global Minuto t = InicioSim #Crea Trenes #CreacionTrenes() Fin = 24 * 60 * 60 L1 = Thread(target=GestorDeLinea, args=[0], name='L1').start() L5 = Thread(target=GestorDeLinea, args=[1], name='L5').start() L9 = Thread(target=GestorDeLinea, args=[2], name='L9').start() LA = Thread(target=GestorDeLinea, args=[3], name='LA').start() Ventana = Mapa() Ventana.run() while not (t == Fin): Hora = int(t / 3600) Minuto = int((t % 3600) / 60) sleep(IncrementoTiempo / 60) t += IncrementoTiempo #print(Hora,":",Minuto) return
def inicializacao(c, q, mapa_x, mapa_y, t_min, t_max, denom, matrizes, individuals_objects, pesos, nome_base, a): prototipos = [] individuals = [] individuals.extend(individuals_objects) mapa = Mapa(individuals, mapa_x, mapa_y, q, nome_base, a) # cria a matriz de deltas for cluster in mapa.mapa.flat: cluster.pesos = pesos for cluster2 in mapa.mapa.flat: cluster.deltas[cluster2.point] = delta(cluster.point, cluster2.point) # Etapa de afetação for objeto in mapa.objetos: criterios = [ (mapa.calcula_criterio_adaptativo(objeto, denom, matrizes, cluster.point), cluster) for cluster in mapa.mapa.flat ] (menor_criterio, menor_criterio_cluster) = min(criterios) # Insere o objeto no cluster de menor critério mapa.mapa[menor_criterio_cluster.point.x, menor_criterio_cluster.point.y].inserir_objeto(objeto) objeto.set_cluster(mapa.mapa[menor_criterio_cluster.point.x, menor_criterio_cluster.point.y]) return mapa
def jugar(mapa, personaje): test = True while test: Mapa.imprime_mapa(mapa) move = getch.getch() x = personaje.get('pos_x') y = personaje.get('pos_y') x_bak = x y_bak = y if move == 'A': x -= 1 elif move == 'B': x += 1 elif move == 'C': y += 1 elif move == 'D': y -= 1 elif move == str(chr(27)): i = Menuses.menuses(1) if i == 2: test = False if Mapa.comprueba_casilla(mapa, x, y): Personaje.modifica_posicion(personaje, x, y) mapa, error = Personaje.inserta_personaje( personaje, mapa ) #en vez de retornar error, yo haria que se ocupara de eso esta funcion if not error: aire = Mapa.genera_casilla(' ', 0, 0) mapa[x_bak][y_bak] = aire
def inicializacao(c, q, mapa_x, mapa_y, t_min, t_max, denom, matrizes, individuals_objects): prototipos = [] individuals = [] individuals.extend(individuals_objects) mapa = Mapa(individuals, mapa_x, mapa_y, q) for cluster in mapa.mapa.flat: for cluster2 in mapa.mapa.flat: cluster.deltas[cluster2.point] = delta(cluster.point, cluster2.point) for obj in mapa.objetos: obj.set_pertinencias(mapa_x * mapa_y) # Etapa de afetação for objeto in mapa.objetos: criterios = [ (mapa.calcula_criterio_fuzzy(objeto, denom, matrizes, cluster.point), cluster) for cluster in mapa.mapa.flat ] (menor_criterio, menor_criterio_cluster) = min(criterios) # Insere o objeto no cluster de menor critério mapa.mapa[menor_criterio_cluster.point.x, menor_criterio_cluster.point.y].inserir_objeto(objeto) objeto.set_cluster(mapa.mapa[menor_criterio_cluster.point.x, menor_criterio_cluster.point.y]) return mapa
def menu_inventario(inventario, mapa): import Mapa ancho = Mapa.ancho_mapa(mapa) largo = len(inventario) * 2 HUD = [] for i in range(largo): HUD.append([' '] * ancho) for i in range(largo): for j in range(ancho): if i % 2 == 1 or j == 0 or j == ancho - 1: HUD[i][j] = '#' for i in range(len(inventario)): for j in range(len(inventario[i])): HUD[i * 2][j + 4] = inventario[i][j] i = 0 seleccionado = False while not seleccionado: import os os.system('cls' if os.name == 'nt' else 'clear') for j in range(len(inventario)): if i == j: HUD[j * 2][2] = '>' else: HUD[j * 2][2] = ' ' import Mapa Mapa.imprime_mapa(mapa) for j in range(largo): for k in range(ancho): print(HUD[j][k], end="") print() print('Selecciona un item de tu inventario con las flechas y el intro') x = getch.getch() if x == 'A' and i > 0: i = i - 1 elif x == 'A': i = len(inventario) - 1 elif x == 'B' and i < len(inventario) - 1: i = i + 1 elif x == 'B': i = 0 elif x == '\n': seleccionado = True return i
def main(): MapaNuevo = Mapa.Mapa() if (MapaNuevo.cargar_mapa()): #Esta es una instancia del agente que creamos. posicion_inicial = [2, 12] Bichito = Agente.Agente(posicion_inicial, '0') #Ciclo de movimiento del agente a través del mapa, con el método del agente #, el print del mapa y un sleep del time, todo esto para crear una simulación de # interfaz. explorar = True while explorar: MapaNuevo.print_mapa(Bichito.ubicacion) MapaNuevo.actualizar_contador(Bichito.ubicacion) explorar = Bichito.moverse( MapaNuevo.ver_campos_continuos(Bichito.ubicacion)) #MapaNuevo.print_contadores() time.sleep(1) else: print("¡Mapa con errores!")
def resetMapa(): global MAPA, inicio, fim MAPA = mp.retornarMapa01() inicio = No(mp.inicio[0], mp.inicio[1]) fim = No(mp.fim[0], mp.fim[1])
def randMapa(): global MAPA, inicio, fim MAPA = mp.retornarMapaRandom() inicio = No(mp.inicio[0], mp.inicio[1]) fim = No(mp.fim[0], mp.fim[1])
import Menuses import Mapa import Personaje import os import Juega i = Menuses.menuses(0) if i == 0: path = './partida/mapa1.txt' mapa = Mapa.genera_mapa(path) Mapa.imprime_mapa(mapa) person = Personaje.crear_personaje() pj_insertado = True while (pj_insertado): mapa, pj_insertado = Personaje.inserta_personaje(person, mapa) if pj_insertado: new_x = input('Indica posicion del personaje x:') new_y = input('Indica posicion del personaje y:') new_x = int(new_x) new_y = int(new_y) Personaje.modifica_posicion(person, new_x, new_y) Juega.jugar(mapa, person) os.system('clear') #elif i == 1: #Cargar partida #else: #Salir print('GG WP')
# expandir os filhos de um determinado no. # # AUTOR: Allainn Christiam Jacinto Tavares # # NOME DO PROJETO: Projeto estilos de busca em um mapa # # INSTITUIÇÃO: UTFPR # ################################################################################### import Mapa as mp inicio = None fim = None MAPA = mp.retornarMapa01() def resetMapa(): global MAPA, inicio, fim MAPA = mp.retornarMapa01() inicio = No(mp.inicio[0], mp.inicio[1]) fim = No(mp.fim[0], mp.fim[1]) def randMapa(): global MAPA, inicio, fim MAPA = mp.retornarMapaRandom() inicio = No(mp.inicio[0], mp.inicio[1]) fim = No(mp.fim[0], mp.fim[1])
def mostrarUbicacion(self, ubicacion): m = Mapa(ubicacion, ubicacion) m.mostrarUbicacion() return
def mostrarRuta(self, origen, destino): m = Mapa(origen, destino) m.mostrarRuta()
def main(): screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("ARKANOID Hussay") #variables punto=0 pop= pygame.mixer.Sound("sonido/pop.wav") pala=Pala.Pala(WIDTH,HEIGHT) bola = Bola.Bola(WIDTH,HEIGHT) #MAPA.................ARKANOID mapa1=Mapa.mapa() ladrillos=mapa1.mapa1() clock = pygame.time.Clock() vidas = 5 juego=True pygame.mixer.music.load("sonido/Beat-1.mp3") pygame.mixer.music.set_volume(0.4) pygame.mixer.music.play(-1) while juego==True: time = clock.tick(60) keys = pygame.key.get_pressed() for eventos in pygame.event.get(): if eventos.type == QUIT: sys.exit(0) a=bola.actualizar(time,WIDTH,HEIGHT,pala) vidas=vidas-a pala.mover(time,keys,WIDTH) a=0 ladri=len(ladrillos) for lista in range(ladri): punt=ladrillos[a].colision(bola,time) a=a+1 punto=punto+punt if vidas<=0: gameover = fuente.render("GAME OVER", 0, (0, 0, 0)) screen.blit(gameover, (100,160)) elif punto==ladri*100: pantalla.fill ((255,255,255)) gameover = fuente.render("GANASTE", 0, (0, 0, 0)) screen.blit(gameover, (100,160)) else: screen.fill((255,255,255)) screen.blit(bola.image,bola.rect) screen.blit(pala.image,pala.rect) b=0 for ac in range(ladri): screen.blit(ladrillos[b].image,ladrillos[b].rect) b=b+1 pygame.display.flip()
The program works this way: 1.- We have two diferent maps (dictionaries): the first one is the terrain (wich is subdivided in cells) and the second one is the army (agents). Both maps are complementary, for instance, supose that the position (x,y) of the map is ocuppied (occ atribute of the Cell class) then the army map must have an agent whoose coordinates (the coord atribute of the Agent class) are x & y. There are soldiers of two armies: red and blue. 2.- Values of both maps must be initialized to start the battle. 3.- The battle is a cycle, for every iteration each soldier of both sides will execute the rutines of vision, movement and fighting, in this order. Note: It is in the fighting rutine were one soldier may kill another soldier, to accomplish soldier elimination status atribute changes to False. 4. The battle ends when the cycle is completed """ """"Aqui se crea un mapa de 10x10 con valores aleatorios.""" """ A 10x10 map is created, with random values""" mapa = Mapa (10,10,-1,-1,-1,-1); """Aqui se inserta el numero de soldados tanto rojos como azules.""" """Inserts the number of red and blue soldiers """ num_red=input("inserta el numero de soldados rojos ") num_blu=input("inserta el numero de soldados azules ") """Se declaran contadores para el id. de cada soldado y para llevar el conteo de soldados rojos y azules al momento de agregarlos a la lista (este conteo esta dado por las variables r y a respectivamente). Las variables cadena_a y cadena_r son solo para imprimir los agentes que pertenecen a los bandos rojo y azul.""" """Counters are declared for each soldiers id, and to count red and blue soldiers when they are added to the list (we compute this numbers by using the r and a variables). The variables string_a and string_r are just for printing the agents who belong to each side (red and blue)""" id=0
El funcionamiento del programa es a grandes rasgos es el siguiente: 1.-Se tienen dos "mapas" (diccionarios) por separado: uno solo del terreno (que a su vez esta formado por Celdas) y otro solo del ejercito(a su vez formado por Agentes). Cabe mencionar que ambos mapas son complementarios, por ejemplo: supongamos que en el mapa de terreno la posicion (x,y) esta ocupada (atributo occ de la clase Celda), entonces en el mapa del ejercito debera existir un agente cuyas coordenadas (el atributo coords de la clase Agente) sean precisamente x & y. Cabe mencionar que en cuanto a soldados se refiere existen dos bandos: rojo y azul. 2.-Se inicializan los valores de ambos mapas y comienza "la batalla". 3.-La batalla es un ciclo donde por cada iteracion, cada soldado de cada bando ejecutara las acciones de ver,moverse y pelear en ese orden. Nota: en la accion de pelear es cuando un soldado elimina a otro, para lograr esta eliminacion simplemente al atributo status del soldado eliminado se le pone en False. 4.-Finalmente la batalla termina cuando se haya terminado el ciclo. """ """"Aqui se crea un mapa de 10x10 con valores aleatorios.""" mapa = Mapa (10,10,-1,-1,-1,-1); """Aqui se inserta el numero de soldados tanto rojos como azules.""" num_red=input("inserta el numero de soldados rojos ") num_blu=input("inserta el numero de soldados azules ") """Se declaran contadores para el id. de cada soldado y para llevar el conteo de soldados rojos y azules al momento de agregarlos a la lista (este conteo esta dado por las variables r y a respectivamente). Las variables cadena_a y cadena_r son solo para imprimir los agentes que pertenecen a los bandos rojo y azul.""" id=0 r=0 a=0 cadena_r="Agentes rojos: " cadena_a="Agentes azules: " """Se definen los vectores de personalidad para los agentes rojos (personalidad_r), y los azules (personalidad_a)."""