示例#1
0
def main(stdscr):
    cursor = Cursor(stdscr)
    url = utils.ip + "token/get"
    token = utils.request(url)['token']
    grid = Grid(stdscr, x_limit, y_limit, cursor)
 
    sel_bool = False
    sel_soldiers = []
    
    while True:
        key = stdscr.getch()

        # quit game
        if key == ord('q'):
            exit(stdscr)
    
        # create soldier
        elif key == ord('c'):
            create_soldier(token)
        
        # move cursor
        elif key in directions:
            cursor.move_cursor(key)
        
        # select tiles
        elif key == ord('s') and not sel_bool:
            cursor.select()
            key = 0
            sel_bool = True
            sel_soldiers = []

        # finish selecting
        elif key is ord('s') and sel_bool:
            cursor.deselect()
            x_r = sorted((cursor.select_coords[0], cursor.x))
            y_r = sorted((cursor.select_coords[1], cursor.y))
            debug_file.write(str(x_r) + "\n" + str(y_r) + "\n")
            for x in range(x_r[0], x_r[1]+1):
                for y in range(y_r[0], y_r[1]+1):
                    if (x,y) in grid.grid:
                        debug_file.write("inserting")
                        sel_soldiers.append(grid.grid[(x,y)])
            sel_bool = False
        if key is ord('q'):
            exit(stdscr)
    
        # move soldiers (soldiers must be selected first)
        elif key == ord('m'):
            key = 69
            debug_file.write(str(sel_soldiers))
            if sel_soldiers:
                debug_file.write("moving soldiers\n")   
                move_soldiers(cursor.position(), sel_soldiers)
                sel_bool = False
        elif key == ord('d'):
            raise Exception(grid.request())
        
        grid.debug(str(key))
        grid.update(key, sel_bool)
        grid.display()
示例#2
0
def build_until_square_satisfies_criteria(end, check, calculate):
    squares = SquareMap()
    cursor = Cursor(mode=Mode.build_x, x=0, y=0, max_degree=0)
    square: Square
    while cursor.id == 1 or not check(square, end):
        square = Square(id=cursor.id, x=cursor.x, y=cursor.y, data=calculate(squares, cursor.x, cursor.y))
        squares.add(square)
        cursor.move_cursor()
    return squares