diff --git a/__pycache__/dungeon.cpython-310.pyc b/__pycache__/dungeon.cpython-310.pyc new file mode 100644 index 0000000..3565628 Binary files /dev/null and b/__pycache__/dungeon.cpython-310.pyc differ diff --git a/__pycache__/map.cpython-310.pyc b/__pycache__/map.cpython-310.pyc new file mode 100644 index 0000000..493dbad Binary files /dev/null and b/__pycache__/map.cpython-310.pyc differ diff --git a/__pycache__/player.cpython-310.pyc b/__pycache__/player.cpython-310.pyc new file mode 100644 index 0000000..53a088e Binary files /dev/null and b/__pycache__/player.cpython-310.pyc differ diff --git a/__pycache__/wall.cpython-310.pyc b/__pycache__/wall.cpython-310.pyc new file mode 100644 index 0000000..6ac7ff2 Binary files /dev/null and b/__pycache__/wall.cpython-310.pyc differ diff --git a/angband.py b/angband.py new file mode 100644 index 0000000..99ee75e --- /dev/null +++ b/angband.py @@ -0,0 +1,36 @@ +from retro.game import Game +from player import Player +from dungeon import Dungeon +from random import sample +from wall import Wall +from map import ( + board_edges, + inner_board, + level_one, +) + +print("Welcome to AngBAD (a poor representation of Angband)!\n") + +race = input("Choose your race (Human, Elf, Dwarf): ").capitalize() +while race not in ["Human", "Elf", "Dwarf"]: + print("Invalid race. Please choose Human, Elf, or Dwarf.") + race = input("Choose your race (Human, Elf, Dwarf): ").capitalize() + +class_ = input("Choose your class (Warrior, Mage, Rogue): ").capitalize() +while class_ not in ["Warrior", "Mage", "Rogue"]: + print("Invalid class. Please choose Warrior, Mage, or Rogue.") + class_ = input("Choose your class (Warrior, Mage, Rogue): ").capitalize() + +print(f"\nYou've chosen to play as a {race} {class_}.") +input("Press Enter to continue. Good luck!") + +board_size = (25,25) +x,y = board_size +walls = [Wall(position) for position in board_edges(board_size)] +level = [Wall(position) for position in level_one(board_size)] +game = Game(walls + level, {}, board_size = board_size) +game.add_agent(Player((x//2,y//2),race,class_)) + + + +game.play() \ No newline at end of file diff --git a/dungeon.py b/dungeon.py new file mode 100644 index 0000000..585f823 --- /dev/null +++ b/dungeon.py @@ -0,0 +1,27 @@ +# dungeon.py +# ------------ +# By Pat Wick +# This module defines a dungeon generation algorithm. I +# still need to figure out what that might actually mean + +class Dungeon: + board_size = (10,10) + board_width = 10 + board_height = 10 + position = (0,0) + dungeon_map = [["."] * board_width] * board_height + + + for row in range(board_height): + for col in range(board_width): + if row == 0 or row == board_height-1: + dungeon_map[row][col] = "#" + else: + if col == 0 or col == board_width-1: + dungeon_map[row][col] = "#" + else: + dungeon_map[row][col] = "." + + def __init__(self, position): + self.position = position + self.name = "dungeon" \ No newline at end of file diff --git a/map.py b/map.py new file mode 100644 index 0000000..108950e --- /dev/null +++ b/map.py @@ -0,0 +1,49 @@ +from retro.game import Game +from random import sample +from player import Player +from wall import Wall + +def board_edges(board_size): + x,y = board_size + positions = [] + top = [(i,0) for i in range(x)] + bottom = [(i,y-1) for i in range(x)] + left = [(0,j) for j in range(1,y-1)] + right = [(x-1,j) for j in range(1,y-1)] + return top + bottom + left + right + +def inner_board(board_size): + x,y = board_size + positions = [] + for i in range(1,x-1): + for j in range(1,y-1): + positions.append((i,j)) + return positions + +def level_one(board_size): + x,y = board_size + positions = [] + for i in range(1,x-1): + for j in range(1,y//4): + if i <= x // 4 or i >= x - (x // 4): + positions.append((i,j)) + for i in range(1,x//4): + for j in range((y - (y // 4)), y-1): + positions.append((i,j)) + + # for i in range(1,x-1): + # for j in range(1,y-1): + # if i >=4 and i <= 7 or i >= 13 and i <= 16: + # if j >= 4 and j <= 7 or j >= 13 and j <= 16: + # positions.append((i,j)) + return positions + +def level_two(board_size): + x,y = board_size + positions = [] + for i in range(1,x-1): + for j in range(1,y-1): + if i >=4 and i <= 7 or i >= 13 and i <= 16: + if j >= 4 and j <= 7 or j >= 13 and j <= 16: + positions.append((i,j)) + return positions \ No newline at end of file diff --git a/player.py b/player.py new file mode 100644 index 0000000..6d35182 --- /dev/null +++ b/player.py @@ -0,0 +1,48 @@ +# player.py +# ------------ +# By Pat Wick +# This module defines a player agent class. This is intended +# to be used in an implementation of an adventure game but could +# generally be adapted for other player character uses. + +from retro.agent import ArrowKeyAgent + +class Player: + character = "O" + name = "player" + level = 1 + + def __init__(self, position, race, class_): + self.position = position + if class_.capitalize() == "Warrior": + self.color = "red" + elif class_.capitalize() == "Rogue": + self.color = "green" + else: + self.color = "blue" + + def handle_keystroke(self, keystroke, game): + x, y = self.position + if keystroke.name in ("KEY_LEFT", "KEY_RIGHT"): + if keystroke.name == "KEY_LEFT": + new_position = (x - 1, y) + else: + new_position = (x + 1, y) + if game.on_board(new_position): + if game.is_empty(new_position): + self.position = new_position + + if keystroke.name in ("KEY_DOWN", "KEY_UP"): + if keystroke.name == "KEY_DOWN": + new_position = (x, y + 1) + else: + new_position = (x, y - 1) + if game.on_board(new_position): + if game.is_empty(new_position): + self.position = new_position + + def get_agent_in_position(self, position, game): + + agents = game.get_agents_by_position()[position] + if agents: + return agents[0] \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index c447dd7..8fa1998 100644 --- a/poetry.lock +++ b/poetry.lock @@ -393,13 +393,13 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "retro-games" -version = "0.1.2" +version = "0.1.3" description = "A simple framework for Terminal-based games" optional = false python-versions = ">=3.10,<4.0" files = [ - {file = "retro_games-0.1.2-py3-none-any.whl", hash = "sha256:5f906c2755c7ab7328120a1f38164e806c6d27e7433d47995648bda01817284b"}, - {file = "retro_games-0.1.2.tar.gz", hash = "sha256:b6cb2212c6c8fba011b37a36e638477922d2de8cb5834412963e1cbd240d9a8f"}, + {file = "retro_games-0.1.3-py3-none-any.whl", hash = "sha256:7567c3a65cf5deb855bded8db810a66902b9706349dde415b6254de087a6d8f9"}, + {file = "retro_games-0.1.3.tar.gz", hash = "sha256:a95fbeacdf903761b4c70522dd25f858d9802dcd701e900b95b7535f0014f266"}, ] [package.dependencies] diff --git a/wall.py b/wall.py new file mode 100644 index 0000000..65c2930 --- /dev/null +++ b/wall.py @@ -0,0 +1,6 @@ +class Wall: + #name = "wall" + character = "█" + + def __init__(self,position): + self.position = position \ No newline at end of file