Exemplo n.º 1
0
def addRoom(map, room):
    if (room.size_x != 1):
        for x in range(room.room_start_x, room.room_start_x + room.size_x):
            for y in range(room.room_start_y, room.room_start_y + room.size_y):
                pos = utils.getPosInList(x, y)
                if (x == room.room_start_x
                        or x == room.room_start_x + room.size_x - 1):
                    map[pos] = "#"
                elif (y == room.room_start_y
                      or y == room.room_start_y + room.size_y - 1):
                    map[pos] = "#"
                if (x == room.room_start_x and y == room.room_start_y):
                    map[pos] = u'\u2554'.encode('utf-8')
                elif (x == room.room_start_x + room.size_x - 1
                      and y == room.room_start_y + room.size_y - 1):
                    map[pos] = u'\u255D'.encode('utf-8')
                elif (x == room.room_start_x + room.size_x - 1
                      and y == room.room_start_y):
                    map[pos] = u'\u2557'.encode('utf-8')
                elif (x == room.room_start_x
                      and y == room.room_start_y + room.size_y - 1):
                    map[pos] = u'\u255A'.encode('utf-8')
                elif (x == room.room_start_x
                      or x == room.room_start_x + room.size_x - 1):
                    map[pos] = u'\u2551'.encode('utf-8')
                elif (y == room.room_start_y
                      or y == room.room_start_y + room.size_y - 1):
                    map[pos] = u'\u2550'.encode('utf-8')
                else:
                    map[pos] = "."
    return map
Exemplo n.º 2
0
def addMapToWin(map, win):
    for x in range (0, SCR_SIZE_X):
        for y in range (0, SCR_SIZE_Y):
            pos = utils.getPosInList(x, y)
            if (map[pos] == u'\u2554'.encode('utf-8')):
                win.addstr(y, x, u'\u2554'.encode('utf-8'), curses.color_pair(4))
            if (map[pos] == u'\u255D'.encode('utf-8')):
                win.addstr(y, x, u'\u255D'.encode('utf-8'), curses.color_pair(4))
            if (map[pos] == u'\u2557'.encode('utf-8')):
                win.addstr(y, x, u'\u2557'.encode('utf-8'), curses.color_pair(4))
            if (map[pos] == u'\u255A'.encode('utf-8')):
                win.addstr(y, x, u'\u255A'.encode('utf-8'), curses.color_pair(4))
            if (map[pos] == u'\u2551'.encode('utf-8')):
                win.addstr(y, x, u'\u2551'.encode('utf-8'), curses.color_pair(4))
            if (map[pos] == u'\u2550'.encode('utf-8')):
                win.addstr(y, x, u'\u2550'.encode('utf-8'), curses.color_pair(4))
            if (map[pos] == '.'):
                win.addstr(y, x, ".", curses.color_pair(3))
            if (map[pos] == '*'):
                win.addstr(y, x, "*", curses.color_pair(1))
            if (map[pos] == u'\u2667'.encode('utf-8')):
                win.addstr(y, x, u'\u2667'.encode('utf-8'), curses.color_pair(4))
            if (map[pos] == 'B'):
                win.addstr(y, x, "B")
            if (map[pos] == 'S'):
                win.addstr(y, x, "S")
            if (map[pos] == u'\u25E2'.encode('utf-8')):
                win.addstr(y, x, u'\u25E2'.encode('utf-8'), curses.color_pair(5))
            if (map[pos] == door):
                win.addstr(y, x, door, curses.color_pair(4))
            if (map[pos] == path):
                win.addstr(y, x, path, curses.color_pair(2))
    return win
Exemplo n.º 3
0
def placeDoorsOnMap(roomOne, roomTwo, rooms, map):
    pos_x_one = 0
    pos_y_one = 0
    pos_x_two = 0
    pos_y_two = 0
    if (roomTwo - roomOne == 1):
        if rooms[roomOne].size_x > 1:
            pos_x_one = rooms[roomOne].room_start_x + rooms[roomOne].size_x - 1
            pos_y_one = rooms[roomOne].room_start_y + random.randint(
                2, rooms[roomOne].size_y - 2)
            pos = utils.getPosInList(pos_x_one, pos_y_one)
            map[pos] = display.door
        else:
            pos_x_one = rooms[roomOne].room_start_x
            pos_y_one = rooms[roomOne].room_start_y
            pos = utils.getPosInList(pos_x_one, pos_y_one)
            map[pos] = display.path

        if rooms[roomTwo].size_x > 1:
            pos_x_two = rooms[roomTwo].room_start_x
            pos_y_two = rooms[roomTwo].room_start_y + random.randint(
                2, rooms[roomTwo].size_y - 2)
            pos = utils.getPosInList(pos_x_two, pos_y_two)
            map[pos] = display.door
        else:
            pos_x_two = rooms[roomTwo].room_start_x
            pos_y_two = rooms[roomTwo].room_start_y
            pos = utils.getPosInList(pos_x_two, pos_y_two)
            map[pos] = display.path
        draw_path_east(map, pos_x_one, pos_y_one, pos_x_two, pos_y_two)
    else:
        if rooms[roomOne].size_x > 1:
            pos_x_one = rooms[roomOne].room_start_x + random.randint(
                2, rooms[roomOne].size_x - 2)
            pos_y_one = rooms[roomOne].room_start_y + rooms[roomOne].size_y - 1
            pos = utils.getPosInList(pos_x_one, pos_y_one)
            map[pos] = display.door
        else:
            pos_x_one = rooms[roomOne].room_start_x
            pos_y_one = rooms[roomOne].room_start_y
            pos = utils.getPosInList(pos_x_one, pos_y_one)
            map[pos] = display.path

        if rooms[roomTwo].size_x > 1:
            pos_x_two = rooms[roomTwo].room_start_x + random.randint(
                2, rooms[roomTwo].size_x - 2)
            pos_y_two = rooms[roomTwo].room_start_y
            pos = utils.getPosInList(pos_x_two, pos_y_two)
            map[pos] = display.door
        else:
            pos_x_two = rooms[roomTwo].room_start_x
            pos_y_two = rooms[roomTwo].room_start_y
            pos = utils.getPosInList(pos_x_two, pos_y_two)
            map[pos] = display.path
        draw_path_south(map, pos_x_one, pos_y_one, pos_x_two, pos_y_two)

    return map
Exemplo n.º 4
0
def draw_path_east(map, pos_x_one, pos_y_one, pos_x_two, pos_y_two):
    move_before_turn = random.randint(1, pos_x_two - pos_x_one - 1)
    current_pos_x = pos_x_one
    current_pos_y = pos_y_one

    for i in range(move_before_turn):
        current_pos_x += 1
        map[utils.getPosInList(current_pos_x, current_pos_y)] = display.path
    while current_pos_y < pos_y_two:
        current_pos_y += 1
        map[utils.getPosInList(current_pos_x, current_pos_y)] = display.path
    while current_pos_y > pos_y_two:
        current_pos_y -= 1
        map[utils.getPosInList(current_pos_x, current_pos_y)] = display.path
    while current_pos_x < pos_x_two:
        map[utils.getPosInList(current_pos_x, current_pos_y)] = display.path
        current_pos_x += 1
Exemplo n.º 5
0
def placeObjects(map):
    for x in range(0, display.SCR_SIZE_X):
        for y in range(0, display.SCR_SIZE_Y - 1):
            pos = utils.getPosInList(x, y)
            if (map[pos] == '.' and random.randint(0, 140) == 1):
                map[pos] = "*"
            if (map[pos] == '.' and random.randint(0, 250) == 1):
                map[pos] = u'\u2667'.encode('utf-8')
    return map
Exemplo n.º 6
0
def placeAi(map):
    for x in range(0, display.SCR_SIZE_X):
        for y in range(0, display.SCR_SIZE_Y - 1):
            pos = utils.getPosInList(x, y)
            if (map[pos] == '.' and random.randint(0, 200) == 1):
                map[pos] = 'B'
            if (map[pos] == '.' and random.randint(0, 200) == 1):
                map[pos] = 'S'
    return map
Exemplo n.º 7
0
def placeTrapdoor(map):
    boo = 0
    while boo == 0:
        for x in range(0, display.SCR_SIZE_X):
            for y in range(0, display.SCR_SIZE_Y - 1):
                pos = utils.getPosInList(x, y)
                if (map[pos] == '.' and random.randint(0, 100000) == 1):
                    map[pos] = u'\u25E2'.encode('utf-8')
                    boo = 1
                    break
                ++y
            ++x
    return map
Exemplo n.º 8
0
def run(win, map, stdscr, player):
    map = mapGenerator.initMap()
    player = utils.getFirstStartingPos(map, player)
    monsters = [utils.monster(0)] * 20
    nbMonsters = random.randint(3, 10)
    for i in range(20):
        monsters[i] = utils.monster(i)
    for i in range(nbMonsters):
        pos_monster = utils.getRandomDot(map)
        monsters[i].pos_x = pos_monster[0]
        monsters[i].pos_y = pos_monster[1]
        type = random.randint(1, 4)
        if (type == 1):
            monsters[i].type = utils.BAT
            monsters[i].life = 6 + player.level
            monsters[i].attack = 3 + player.level / 3
        else:
            monsters[i].type = utils.SNAKE
            monsters[i].life = 5 + player.level
            monsters[i].attack = 2 + player.level / 4

    win.clear()
    win = display.addMapToWin(map, win)
    win = display.addStatsToWin(win, player)
    win.addstr(player.pos_y, player.pos_x, display.player,
               curses.color_pair(1))
    for i in range(20):
        if not (monsters[i].type == 'A'):
            win.addstr(monsters[i].pos_y, monsters[i].pos_x, monsters[i].type,
                       curses.color_pair(0))
    win.refresh()

    time.sleep(1)
    c = stdscr.getch()
    while True:
        pos = utils.getPosInList(player.pos_x, player.pos_y)

        if c == 27:
            win.clear()
            win.refresh()
            break

        if (utils.is_monster(pos + display.SCR_SIZE_X, monsters)):
            monster_id = utils.which_monster(pos + display.SCR_SIZE_X,
                                             monsters)
            player.life -= random.randint(0, monsters[monster_id].attack)
        if (utils.is_monster(pos - display.SCR_SIZE_X, monsters)):
            monster_id = utils.which_monster(pos - display.SCR_SIZE_X,
                                             monsters)
            player.life -= random.randint(0, monsters[monster_id].attack)
        if (utils.is_monster(pos + 1, monsters)):
            monster_id = utils.which_monster(pos + 1, monsters)
            player.life -= random.randint(0, monsters[monster_id].attack)
        if (utils.is_monster(pos - 1, monsters)):
            monster_id = utils.which_monster(pos - 1, monsters)
            player.life -= random.randint(0, monsters[monster_id].attack)

        if c == curses.KEY_DOWN and player.pos_y < display.SCR_SIZE_Y - 2:
            if not (map[pos + display.SCR_SIZE_X] == u'\u2550'.encode('utf-8') \
                or map[pos + display.SCR_SIZE_X] == u'\u2551'.encode('utf-8') \
                or map[pos + display.SCR_SIZE_X] == u'\u2554'.encode('utf-8') \
                or map[pos + display.SCR_SIZE_X] == u'\u255D'.encode('utf-8') \
                or map[pos + display.SCR_SIZE_X] == u'\u2557'.encode('utf-8') \
                or map[pos + display.SCR_SIZE_X] == u'\u255A'.encode('utf-8') \
                or map[pos + display.SCR_SIZE_X] == ' '):
                if not utils.is_monster(pos + display.SCR_SIZE_X, monsters):
                    player.pos_y += 1
                else:
                    monster_id = utils.which_monster(pos + display.SCR_SIZE_X,
                                                     monsters)
                    monsters[monster_id].life -= random.randint(
                        0, player.attack)
                    if (monsters[monster_id].life <= 0):
                        monsters[monster_id].type = 'A'
                        player.gold += 30 + player.level / 2
                        player.kill += 1
        if c == curses.KEY_UP and player.pos_y > 0:
            if not (map[pos - display.SCR_SIZE_X] == u'\u2550'.encode('utf-8') \
                or map[pos - display.SCR_SIZE_X] == u'\u2551'.encode('utf-8') \
                or map[pos - display.SCR_SIZE_X] == u'\u2554'.encode('utf-8') \
                or map[pos - display.SCR_SIZE_X] == u'\u255D'.encode('utf-8') \
                or map[pos - display.SCR_SIZE_X] == u'\u2557'.encode('utf-8') \
                or map[pos - display.SCR_SIZE_X] == u'\u255A'.encode('utf-8') \
                or map[pos - display.SCR_SIZE_X] == ' '):
                if not utils.is_monster(pos - display.SCR_SIZE_X, monsters):
                    player.pos_y -= 1
                else:
                    monster_id = utils.which_monster(pos - display.SCR_SIZE_X,
                                                     monsters)
                    monsters[monster_id].life -= random.randint(
                        0, player.attack)
                    if (monsters[monster_id].life <= 0):
                        monsters[monster_id].type = 'A'
                        player.gold += 30 + player.level / 2
                        player.kill += 1
        if c == curses.KEY_RIGHT and player.pos_x < display.SCR_SIZE_X - 2:
            if not (map[pos + 1] == u'\u2550'.encode('utf-8') \
                or map[pos + 1] == u'\u2551'.encode('utf-8') \
                or map[pos + 1] == u'\u2554'.encode('utf-8') \
                or map[pos + 1] == u'\u255D'.encode('utf-8') \
                or map[pos + 1] == u'\u2557'.encode('utf-8') \
                or map[pos + 1] == u'\u255A'.encode('utf-8') \
                or map[pos + 1] == ' '):
                if not utils.is_monster(pos + 1, monsters):
                    player.pos_x += 1
                else:
                    monster_id = utils.which_monster(pos + 1, monsters)
                    monsters[monster_id].life -= random.randint(
                        0, player.attack)
                    if (monsters[monster_id].life <= 0):
                        monsters[monster_id].type = 'A'
                        player.gold += 30 + player.level / 2
                        player.kill += 1
        if c == curses.KEY_LEFT and player.pos_x > 0:
            if not (map[pos - 1] == u'\u2550'.encode('utf-8') \
                or map[pos - 1] == u'\u2551'.encode('utf-8') \
                or map[pos - 1] == u'\u2554'.encode('utf-8') \
                or map[pos - 1] == u'\u255D'.encode('utf-8') \
                or map[pos - 1] == u'\u2557'.encode('utf-8') \
                or map[pos - 1] == u'\u255A'.encode('utf-8') \
                or map[pos - 1] == ' '):
                if not utils.is_monster(pos - 1, monsters):
                    player.pos_x -= 1
                else:
                    monster_id = utils.which_monster(pos - 1, monsters)
                    monsters[monster_id].life -= random.randint(
                        0, player.attack)
                    if (monsters[monster_id].life <= 0):
                        monsters[monster_id].type = 'A'
                        player.gold += 30 + player.level / 2
                        player.kill += 1
        pos = utils.getPosInList(player.pos_x, player.pos_y)
        if map[pos] == u'\u25E2'.encode('utf-8'):
            win.clear()
            player.level += 1
            run(win, map, stdscr, player)
            break
        if map[pos] == '*':
            map[pos] = '.'
            player.gold += 10 + player.level / 10
        elif map[pos] == u'\u2667'.encode('utf-8'):
            map[pos] = '.'
            if (player.life + 10 > player.maxLife):
                player.life = player.maxLife
            else:
                player.life += 10 + player.level / 4
        win.clear()
        win = display.addMapToWin(map, win)
        win = display.addStatsToWin(win, player)
        win.addstr(player.pos_y, player.pos_x, display.player,
                   curses.color_pair(1))
        for i in range(20):
            if not (monsters[i].type == 'A'):
                win.addstr(monsters[i].pos_y, monsters[i].pos_x,
                           monsters[i].type, curses.color_pair(0))
        win.refresh()
        if (player.life <= 0):
            utils.you_died(curses, win, stdscr, player)
            break
        player.turns += 1
        c = stdscr.getch()