예제 #1
0
def test_starting_state():
    """
    Assert that created starting state (board and robots) contains the correct instances of objects.
    """
    ss = get_start_state("maps/test_3.json")
    assert isinstance(ss, State)
    assert isinstance(ss.robots, list)
    assert isinstance(ss.robots[0], Robot)
    assert isinstance(ss.board, dict)
    assert isinstance(ss.board[0, 0], list)
    assert isinstance(ss.board[0, 0][0], Tile)
예제 #2
0
def test_play_game(test_name):
    """
    Play the game with given map.
    """
    map_file = Path("tests/") / test_name / "map.json"
    commands_file = Path("tests/") / test_name / "commands.yaml"
    if not commands_file.exists():
        commands_file = None

    state = get_start_state(map_file)
    stop_fields = get_start_tiles(state._board, "stop")

    commands = read_commands(commands_file)

    assign_cards_to_robots(commands, state)
    assign_prerequisites_to_robots(commands, state)

    # Leave it here for debugging purpose :)
    # for robot in state.robots:
    #     print(robot.program)
    #     print(robot.damages)
    #     print(robot.flags)
    #     print(robot.lives)
    #     print(robot.power_down)
    #     print(robot.start_coordinates)

    apply_all_effects(state, registers=get_registers(commands))
    compare_results_with_robots(commands, state)

    # for robot in state.robots:
    #     print(robot.program)
    #     print(robot.damages)
    #     print(robot.flags)
    #     print(robot.lives)
    #     print(robot.power_down)
    #     print(robot.start_coordinates)

    for robot in state.robots:
        robot_field = state.robots.index(robot) + 1
        assert robot.coordinates == stop_fields[robot_field]["coordinates"]
        assert robot.direction == stop_fields[robot_field]["tile_direction"]
예제 #3
0
from backend import get_start_state, apply_all_effects
from frontend import create_window, draw_state

# load JSON map data from the backend module
if len(sys.argv) == 1:
    map_name = "maps/test_effects.json"

# if other map should be loaded, use extra argument "maps/MAP_NAME.json"
# when calling game.py by Python
# for example: python game.py maps/test_2.json
else:
    map_name = sys.argv[1]

# Get start state of the game from the backend module.
state = get_start_state(map_name)

# Load pyglet graphic window from the frontend module.
window = create_window(state)


@window.event
def on_draw():
    """
    Draw the game state (board and robots).
    """

    window.clear()
    draw_state(state, window)

예제 #4
0
def read_commands_and_state():
    commands = get_commands("tests/test_gear/commands.yaml")
    state = get_start_state("tests/test_gear/map.json")
    return commands, state
예제 #5
0
    - call pyglet window, various backend and frontend functions
"""

import backend
import frontend
import pyglet

# load JSON map data from the backend module
# currently the actual map is a constant, in future probably asks the player to choose
map_name = "./maps/test_3.json"
data = backend.get_data(map_name)

# load pyglet graphic window from the frontend module
window = frontend.init_window(frontend.WINDOW_WIDTH, frontend.WINDOW_HEIGHT)

state = backend.get_start_state(data)

# load pyglet sprites by the frontend module
images = frontend.load_images(state, frontend.TILE_WIDTH, frontend.TILE_HEIGHT)
robots = frontend.load_robots(state, frontend.TILE_WIDTH, frontend.TILE_HEIGHT)


@window.event
def on_draw():
    """
    this function clears the graphic window
    and finally draws the board game
    """
    window.clear()
    frontend.draw_board(images, robots)