-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configure docker and add initial game features
Signed-off-by: lucas.souza <[email protected]>
- Loading branch information
1 parent
c83a969
commit 44b253c
Showing
9 changed files
with
442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM python:3.11-slim | ||
|
||
ENV POSTGRES_USER=carbon_user | ||
ENV POSTGRES_PASSWORD=carbon_password | ||
ENV POSTGRES_DB=carbon2185 | ||
ENV POSTGRES_HOST=postgres | ||
ENV POSTGRES_PORT=5432 | ||
|
||
WORKDIR /app | ||
|
||
COPY . /app | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
libpq-dev \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
CMD ["python", "carbon2185/main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '3.9' | ||
services: | ||
postgres: | ||
image: postgres:15 | ||
container_name: carbon2185_db | ||
environment: | ||
POSTGRES_USER: carbon_user | ||
POSTGRES_PASSWORD: carbon_password | ||
POSTGRES_DB: carbon2185 | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- pgdata:/var/lib/postgresql/data | ||
|
||
volumes: | ||
pgdata: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
from game.database import create_connection | ||
|
||
SCHEMA_SQL = """ | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
CREATE TABLE IF NOT EXISTS Inventario ( | ||
id_inventario UUID DEFAULT uuid_generate_v4(), | ||
quantidade_itens INT NOT NULL, | ||
capacidade_maxima INT NOT NULL, | ||
PRIMARY KEY (id_inventario) | ||
); | ||
CREATE TABLE IF NOT EXISTS Classe ( | ||
id_classe UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
tipo VARCHAR(20) NOT NULL CHECK (tipo IN ('daimyo', 'hacker', 'scoundrel')), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
hp_bonus INT NOT NULL, | ||
dano_bonus INT NOT NULL, | ||
energia_bonus INT NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Faccao ( | ||
id_faccao UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
tipo VARCHAR(20) NOT NULL CHECK (tipo IN ('yakuza', 'triad')), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
ideologia VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Distrito ( | ||
id_distrito UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
range_maximo INT NOT NULL, | ||
quantidade_personagens INT NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS CelulaMundo ( | ||
id_celula UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id_distrito UUID REFERENCES Distrito(id_distrito), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
destino VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Personagem ( | ||
id_personagem UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
tipo VARCHAR(10) NOT NULL CHECK (tipo IN ('pc', 'npc')) | ||
); | ||
CREATE TABLE IF NOT EXISTS PC ( | ||
id_personagem UUID PRIMARY KEY REFERENCES Personagem(id_personagem), | ||
id_celula UUID REFERENCES CelulaMundo(id_celula), | ||
id_faccao UUID REFERENCES Faccao(id_faccao), | ||
id_classe UUID REFERENCES Classe(id_classe), | ||
id_inventario UUID REFERENCES Inventario(id_inventario), | ||
energia INT NOT NULL, | ||
dano INT NOT NULL, | ||
hp INT NOT NULL, | ||
hp_atual INT NOT NULL, | ||
nivel INT NOT NULL, | ||
xp INT NOT NULL, | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS NPC ( | ||
id_personagem UUID PRIMARY KEY REFERENCES Personagem(id_personagem), | ||
tipo VARCHAR(20) NOT NULL CHECK (tipo IN ('comerciante', 'inimigo')) | ||
); | ||
CREATE TABLE IF NOT EXISTS Comerciante ( | ||
id_comerciante UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id_personagem UUID REFERENCES NPC(id_personagem), | ||
id_celula UUID REFERENCES CelulaMundo(id_celula), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Inimigo ( | ||
id_inimigo UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id_personagem UUID REFERENCES NPC(id_personagem), | ||
id_celula UUID REFERENCES CelulaMundo(id_celula), | ||
dano INT NOT NULL, | ||
xp INT NOT NULL, | ||
hp INT NOT NULL, | ||
hp_atual INT NOT NULL, | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Missao ( | ||
id_missao UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
dificuldade INT NOT NULL, | ||
objetivo VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Interacao ( | ||
id_interacao UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
personagem_origem UUID REFERENCES Personagem(id_personagem), | ||
personagem_destino UUID REFERENCES Personagem(id_personagem) | ||
); | ||
CREATE TABLE IF NOT EXISTS Dialogo ( | ||
id_interacao UUID PRIMARY KEY REFERENCES Interacao(id_interacao), | ||
mensagem_atual VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Item ( | ||
id_item UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
tipo VARCHAR(20) NOT NULL CHECK (tipo IN ('equipamento', 'objeto_mapa')) | ||
); | ||
CREATE TABLE IF NOT EXISTS Equipamento ( | ||
id_item UUID PRIMARY KEY REFERENCES Item(id_item), | ||
tipo VARCHAR(20) NOT NULL CHECK (tipo IN ('armadura', 'arma', 'implante_cibernetico')) | ||
); | ||
CREATE TABLE IF NOT EXISTS Armadura ( | ||
id_item UUID PRIMARY KEY REFERENCES Equipamento(id_item), | ||
id_celula UUID REFERENCES CelulaMundo(id_celula), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
valor INT NOT NULL, | ||
hp_bonus INT NOT NULL, | ||
raridade VARCHAR(100) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Arma ( | ||
id_item UUID PRIMARY KEY REFERENCES Equipamento(id_item), | ||
id_celula UUID REFERENCES CelulaMundo(id_celula), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
valor INT NOT NULL, | ||
raridade VARCHAR(100) NOT NULL, | ||
municao INT NOT NULL, | ||
dano INT NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS ImplanteCibernetico ( | ||
id_item UUID PRIMARY KEY REFERENCES Equipamento(id_item), | ||
id_celula UUID REFERENCES CelulaMundo(id_celula), | ||
nome VARCHAR(100) NOT NULL, | ||
descricao VARCHAR(100) NOT NULL, | ||
valor INT NOT NULL, | ||
raridade VARCHAR(100) NOT NULL, | ||
custo_energia INT NOT NULL, | ||
dano INT NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS InstanciaItem ( | ||
id_instancia_item UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id_inventario UUID REFERENCES Inventario(id_inventario), | ||
id_item UUID REFERENCES Item(id_item) | ||
); | ||
CREATE TABLE IF NOT EXISTS InstanciaInimigo ( | ||
id_instancia_inimigo UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id_inimigo UUID REFERENCES Inimigo(id_inimigo), | ||
id_celula UUID REFERENCES CelulaMundo(id_celula), | ||
hp INT NOT NULL, | ||
hp_atual INT NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS Loja ( | ||
id_loja UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id_comerciante UUID REFERENCES Comerciante(id_comerciante), | ||
id_instancia_item UUID REFERENCES InstanciaItem(id_instancia_item) | ||
); | ||
""" | ||
|
||
|
||
def create_tables(conn): | ||
cursor = conn.cursor() | ||
cursor.execute(SCHEMA_SQL) | ||
|
||
conn.commit() | ||
cursor.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import psycopg2 | ||
from psycopg2 import sql | ||
|
||
def create_connection(): | ||
conn = psycopg2.connect( | ||
dbname="carbon2185", | ||
user="carbon_user", | ||
password="carbon_password", | ||
host="0.0.0.0", | ||
port="5432" | ||
) | ||
return conn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from game.models import create_pc, create_npc, interact_with_npc | ||
from game.utils import display_message | ||
|
||
def start_game(conn): | ||
""" | ||
Inicia o jogo, apresentando as opções e gerenciando o fluxo principal. | ||
""" | ||
display_message("Bem-vindo ao Carbon2185!") | ||
while True: | ||
print("\nEscolha uma opção:") | ||
print("1. Criar Personagem") | ||
print("2. Ver Missões") | ||
print("3. Interagir com NPC") | ||
print("4. Sair") | ||
|
||
choice = input("Escolha: ") | ||
if choice == "1": | ||
create_character(conn) | ||
elif choice == "2": | ||
view_missions(conn) | ||
elif choice == "3": | ||
interact_with_npc(conn) | ||
elif choice == "4": | ||
display_message("Saindo do jogo. Até a próxima!") | ||
break | ||
else: | ||
display_message("Opção inválida. Tente novamente.") | ||
|
||
def create_character(conn): | ||
""" | ||
Gerencia a criação de um personagem. | ||
""" | ||
print("\nCriação de Personagem:") | ||
nome = input("Digite o nome do personagem: ") | ||
descricao = input("Descreva seu personagem: ") | ||
energia = int(input("Energia inicial: ")) | ||
dano = int(input("Dano inicial: ")) | ||
hp = int(input("HP inicial: ")) | ||
|
||
# Criação do personagem no banco de dados | ||
create_pc(conn, nome, descricao, energia, dano, hp) | ||
display_message(f"Personagem {nome} criado com sucesso!") | ||
|
||
def view_missions(conn): | ||
""" | ||
Exibe as missões disponíveis no jogo. | ||
""" | ||
cursor = conn.cursor() | ||
cursor.execute("SELECT id_missao, nome, descricao FROM Missao") | ||
missions = cursor.fetchall() | ||
|
||
print("\nMissões Disponíveis:") | ||
for mission in missions: | ||
print(f"- {mission[1]}: {mission[2]} (ID: {mission[0]})") | ||
|
||
cursor.close() | ||
|
||
def interact_with_npc(conn): | ||
""" | ||
Gerencia a interação com um NPC. | ||
""" | ||
print("\nInteração com NPC:") | ||
npc_id = int(input("Digite o ID do NPC: ")) | ||
|
||
# Interação com o NPC no banco de dados | ||
cursor = conn.cursor() | ||
cursor.execute("SELECT nome, descricao FROM NPC WHERE id_personagem = %s", (npc_id,)) | ||
npc = cursor.fetchone() | ||
|
||
if npc: | ||
display_message(f"Você encontrou {npc[0]}: {npc[1]}") | ||
# Logica de interação com o NPC | ||
interact_with_npc(conn, npc_id) | ||
else: | ||
display_message("NPC não encontrado.") | ||
|
||
cursor.close() |
Oops, something went wrong.