Пример #1
0
def test_base():
    factory = WorldGetter(3)
    _map = Map(factory.get_map())
    _map.pos = factory.get_pos()
    objects = Objects(factory.get_objects())
    player = Player(factory.get_player())
    i = 30
    gui = GUI(player, _map, objects, None)
    gui.fps = 30
    gui.paused = True
    while player.is_alive:
        gui.turn()
        if gui.paused == False:
            objects.trains[1].line_idx = 1
            if objects.trains[1].position == 4:
                objects.trains[1].speed = -1
            elif objects.trains[1].position == 0:
                objects.trains[1].speed = 1
            objects.trains[1].position += objects.trains[1].speed
            objects.trains[1].line_idx = 10
            if objects.trains[2].position == 5:
                objects.trains[2].speed = -1
            elif objects.trains[2].position == 0:
                objects.trains[2].speed = 1
            objects.trains[2].position += objects.trains[2].speed
            if i > 0:
                i -= 1
            else:
                player.is_alive = False

    gui.close()
Пример #2
0
    def __init__(self, map_path=DEFAULT_MAP):
        self.map = Map(self)

        self.map_path = map_path
        self.load_map()

        self.player = Player(self.map.getPlayerStartPos())
Пример #3
0
def get_world():
    factory = WorldGetter(3)

    player = Player(factory.get_player())
    map_ = Map(factory.get_map())
    map_.pos = factory.get_pos()
    objects = Objects(factory.get_objects())

    return World(player, map_, objects)
Пример #4
0
def test_get_neighbors_pos():

    factory = WorldGetter(3)
    map_graph = Map(factory.get_map())

    pos = Position(None, 2, 1)
    assert (map_graph.get_neighbors_pos(pos) == [
        Position(2), Position(None, 2, 2)
    ])
Пример #5
0
def test_valid():
    factory = WorldGetter(3)

    player = Player(factory.get_player())
    map_graph = Map(factory.get_map())
    objects = Objects(factory.get_objects())

    strategy = Strategy(player, map_graph, objects)
    strategy.get_invalid_pos = lambda x: {}

    reserv_pos = {
        1: {
            0: Position(None, 1, 3),
            1: Position(2),
            2: Position(None, 12, 1)
        },
        2: {
            0: Position(None, 2, 2),
            1: Position(None, 2, 1),
            2: Position(None, 2, 2)
        }
    }

    strategy.trains_reservations = reserv_pos
    train = objects.trains[1]
    print(strategy.valid(train, Position(None, 1, 1), Position(1)))
Пример #6
0
def parse_map_xml(root):
    map_id = int(root.get("id"))
    year = root.find("yearPublished").text
    image_tag = root.find("unprocessed")
    image_url = image_tag.get("url")
    if (image_tag.attrib.__contains__("width")
            and image_tag.attrib.__contains__("height")
        ):  #width and height tags not availible on pdfs
        image_height_to_width_ratio = (int(image_tag.get("width"))) / (int(
            image_tag.get("height")))
    else:
        image_height_to_width_ratio = 1
    thumbnail_tags = root.findall("thumbnail")
    thumbnails = []
    for tag in thumbnail_tags:
        if (tag.attrib.__contains__("width")):
            width = int(tag.get("width"))
            height = int(float(width) * image_height_to_width_ratio)
            thumbnails.append(Thumbnail(width, height, tag.get("url")))
        else:
            height = int(tag.get("height"))
            width = int(float(height) / image_height_to_width_ratio)
            thumbnails.append(Thumbnail(width, height, tag.get("url")))

    parent_id = root.find("skiArea").get("id")
    return Map(map_id, year, thumbnails, image_url, parent_id)
Пример #7
0
 def get_move(self, train: Train, map_graph: Map):
     if train.speed == 0:
         train.arrival()
         if train.position is None:  # Если поезд ещё не начинал путь
             train.departure(self.home,
                             map_graph.get_first_neighbor(self.home)
                             )  # Отправляем его к первому соседнему городу
             line = map_graph.get_line(train.departure_point,
                                       train.arrival_point)
             return Move(line, 1, train.idx)
         if train.current_point != self.home:  # Если поезд прибыл не домой
             train.departure(train.current_point,
                             self.home)  # Отправляем поезд домой
             line = map_graph.get_line(train.departure_point,
                                       train.arrival_point)
             return Move(line, 1, train.idx)
         self.in_progress = False
Пример #8
0
    def __init__(self, map: Map) -> None:
        self.map = map

        coor = map.get_def_ball_coor()
        self.x = coor[0]
        self.y = coor[1]

        self.height_direction = random.randint(0, 1) == 1
        self.width_direction = random.randint(0, 1) == 1
Пример #9
0
class Model:
    """Model du jeu"""
    def __init__(self, map_path=DEFAULT_MAP):
        self.map = Map(self)

        self.map_path = map_path
        self.load_map()

        self.player = Player(self.map.getPlayerStartPos())

    def load_map(self):
        self.map.load(self.map_path)

    def check_player_collision(self):
        playerX, playerY = self.player.getPosition()
        for element in self.map.array:
            if check_collision(playerX, playerY, self.player.getWidth(),
                               self.player.getHeight(), element.pos[0],
                               element.pos[1], element.width, element.height):
                break

    def tick(self):
        self.player.move()
        for element in self.map.array:
            element.play()
        self.check_player_collision()
        if randrange(0, 100) % 26 == 0:
            self.map.add_random_asteroid()

        if self.player.isShooting():
            projectile = Projectile(10, self.player.getAngle(), 0, 0,
                                    self.player.getPosition(), 20, 40)
            self.map.add_obj(projectile)

    def getPlayer(self):
        return self.player
Пример #10
0
def test_correct_init():
    factory = WorldGetter(3)

    map_graph = Map(factory.get_map())
Пример #11
0
 def read_map(self):
     layer = self.write_message('MAP', {"layer": 0})[1]
     return Map(layer)
Пример #12
0
import networkx as nx
import matplotlib.pyplot as plt
import math
from util.WorldGetter import WorldGetter
from model.Map import Map

import json
G = nx.Graph()

factory = WorldGetter(3)
_map = Map(factory.get_map())
_map.pos = dict([(i + 1, (i // 10 / 10, (i % 10) / 10))
                 for i in range(0, 100)])

print(_map.pos)

nx.draw_networkx_nodes(_map.Graph, _map.pos, node_color='k')
nx.draw_networkx_labels(_map.Graph, _map.pos, font_color='w')
nx.draw_networkx_edges(_map.Graph, _map.pos, width=1.0, edge_color="k")

plt.show()
import threading
import time
from tkinter import Tk

from grafics.Windows_manager import Window
from model.Model import Model, Player
from model.Map import Map
from model.Ball import Ball
from netcode.server.server_v1 import Server
from util.log import log

log("configing")
map = Map(60, 30)
ball = Ball(map)

player1 = Player(True, map)
player2 = Player(False, map)

model = Model(ball, map, player1, player2, 30)

window = Tk()
app = Window(map, player1, player2, window)

log("start main loop")


def run_server(model, name):  #отримання координатних даних, які змінюються
    server = Server()
    server.run(model)

Пример #14
0
 def paintEvent(self, e):
     map = Map()
     map.create_level_floor()
     self.pintarMapa(map)