Now in English!

This release brings support for two languages - portuguese and english!
The language is selected before intro
This release changes severely some code - bugs might happen
If you need a stable version before this update - Releases/v0.2-alpha
This commit is contained in:
nanometer5088
2022-09-06 23:59:46 -03:00
parent 060664a465
commit ad8bda8123
6 changed files with 247 additions and 57 deletions

19
main.py
View File

@@ -1,10 +1,19 @@
def main():
from src.init import inicio
from src.init import inicio, idioma
from src.cartelas import TUI_principal
from src.constants import START
x = inicio()
language = idioma()
if language == "BR":
x = 'src.constants.constants'
elif language == "EN":
x = 'src.constants.constantsen'
import importlib
locale = importlib.import_module(x)
x = inicio(locale)
if x == "instalado":
print(START["librariesinstalled"])
print(locale.START["librariesinstalled"])
return None
TUI_principal()
TUI_principal(locale, language)
main()

View File

@@ -1,4 +1,4 @@
from src.constants import ERRORS, SELECTED, SCOREBOARD, GAME
#from src.constants import ERRORS, SELECTED, SCOREBOARD, GAME
from src.funcoes import aleatorio
def listas():
#Geração de listas a partir do arquivo de cartelas. Essas listas são separadas em
@@ -38,22 +38,30 @@ def cartelas_show():
random = randomold
return resultado
def donotabela(elemento_inicial):
def donotabela(elemento_inicial, language):
#Apresenta na tela uma indicação de qual cartela o usuário alternou
#Esse indicador é baseado no mostrado nas figuras da questão
from colr import color
print(f"""
if language == 'BR':
print(f"""
***************************************************
** Você agora é dono da cartela {color(elemento_inicial, fore=(76, 151, 237))} **
***************************************************
""")
elif language == 'EN':
print(f"""
***************************************************
** You now own the card {color(elemento_inicial, fore=(76, 151, 237))} **
***************************************************
""")
def numerosorteado(random):
def numerosorteado(random, language):
#Apresenta na tela uma indicação de qual número foi sorteado, e
#se alinha de acordo com o número de casas do número sorteado
#Esse indicador é baseado no mostrado nas figuras da questão
from colr import color
print(f"""
if language == 'BR':
print(f"""
***************************************************
** Número Sorteado: {color(random, fore=(76, 151, 237))} **
***************************************************
@@ -62,7 +70,17 @@ def numerosorteado(random):
** Número Sorteado: {color(random, fore=(76, 151, 237))} **
***************************************************
""")
def maketable(elemento_inicial, lista, playerselect, backend_results, modelovitoria, resultado, random):
elif language == 'EN':
print(f"""
***************************************************
** Number drawn: {color(random, fore=(76, 151, 237))} **
***************************************************
""") if random < 10 else print(f"""
***************************************************
** Number drawn: {color(random, fore=(76, 151, 237))} **
***************************************************
""")
def maketable(elemento_inicial, lista, playerselect, backend_results, modelovitoria, resultado, random, locale, language):
from src.funcoes import aleatorio
from prettytable import PrettyTable, DOUBLE_BORDER, DEFAULT
from colr import color
@@ -70,25 +88,25 @@ def maketable(elemento_inicial, lista, playerselect, backend_results, modelovito
#Alterar a cartela escolhida pelo jogador na tabela
#A cartela do jogador é indicada pelo símbolo "■"
if elemento_inicial == "1":
donotabela(elemento_inicial)
playerselect[0], playerselect[1] = SELECTED["player"], SELECTED["notplayer"]
playerselect[2], playerselect[3] = SELECTED["notplayer"], SELECTED["notplayer"]
donotabela(elemento_inicial, language)
playerselect[0], playerselect[1] = locale.SELECTED["player"], locale.SELECTED["notplayer"]
playerselect[2], playerselect[3] = locale.SELECTED["notplayer"], locale.SELECTED["notplayer"]
elif elemento_inicial == "2":
donotabela(elemento_inicial)
playerselect[0], playerselect[1] = SELECTED["notplayer"], SELECTED["player"]
playerselect[2], playerselect[3] = SELECTED["notplayer"], SELECTED["notplayer"]
donotabela(elemento_inicial, language)
playerselect[0], playerselect[1] = locale.SELECTED["notplayer"], locale.SELECTED["player"]
playerselect[2], playerselect[3] = locale.SELECTED["notplayer"], locale.SELECTED["notplayer"]
elif elemento_inicial == "3":
donotabela(elemento_inicial)
playerselect[0], playerselect[1] = SELECTED["notplayer"], SELECTED["notplayer"]
playerselect[2], playerselect[3] = SELECTED["player"], SELECTED["notplayer"]
donotabela(elemento_inicial, language)
playerselect[0], playerselect[1] = locale.SELECTED["notplayer"], locale.SELECTED["notplayer"]
playerselect[2], playerselect[3] = locale.SELECTED["player"], locale.SELECTED["notplayer"]
elif elemento_inicial == "4":
donotabela(elemento_inicial)
playerselect[0], playerselect[1] = SELECTED["notplayer"], SELECTED["notplayer"]
playerselect[2], playerselect[3] = SELECTED["notplayer"], SELECTED["player"]
donotabela(elemento_inicial, language)
playerselect[0], playerselect[1] = locale.SELECTED["notplayer"], locale.SELECTED["notplayer"]
playerselect[2], playerselect[3] = locale.SELECTED["notplayer"], locale.SELECTED["player"]
#Sorteio dos números
elif elemento_inicial == "":
numerosorteado(random)
numerosorteado(random, language)
#lógica de vitórias / derrotas
for i in range(4):
@@ -99,7 +117,7 @@ def maketable(elemento_inicial, lista, playerselect, backend_results, modelovito
for i in range(4):
if backend_results[i] == modelovitoria:
for a in range(4):
if playerselect[a] == SELECTED["player"]:
if playerselect[a] == locale.SELECTED["player"]:
if i == a:
resultado = "vitoria"
else:
@@ -108,13 +126,13 @@ def maketable(elemento_inicial, lista, playerselect, backend_results, modelovito
#Determina se a entrada do usuário é inválida, e aje de acordo
elif elemento_inicial != "1" or elemento_inicial != "2" or elemento_inicial != "3" or elemento_inicial != "4" or elemento_inicial != "":
print(f"""
{ERRORS["invalid"]}
{locale.ERRORS["invalid"]}
Valores possíveis: [1, 2, 3, 4]
""")
#Montagem e apresentação da tabela usando PrettyTable
x = PrettyTable()
x.field_names = ["Dono", "B", "I", "N", "G", "O"]
x.field_names = ["", "B", "I", "N", "G", "O"]
x.add_rows(
[
[playerselect[0], lista[0][0], lista[0][1], lista[0][2], lista[0][3], lista[0][4]],
@@ -130,10 +148,10 @@ def maketable(elemento_inicial, lista, playerselect, backend_results, modelovito
print(x)
#Indica ao jogador as opções de escolha disponíveis
print(GAME["presskey"])
print(locale.GAME["presskey"])
return resultado
def TUI_principal():
def TUI_principal(locale, language):
import os, datetime
from src.funcoes import geralistaaleatoria
@@ -158,7 +176,7 @@ def TUI_principal():
while principal == "":
os.system("cls || clear")
random = listaaleatoria[i]
principal = maketable(elemento_inicial, lista, playerselect, backend_results, modelovitoria, resultado, random)
principal = maketable(elemento_inicial, lista, playerselect, backend_results, modelovitoria, resultado, random, locale, language)
elemento_inicial = input()
if elemento_inicial == "":
i += 1
@@ -167,7 +185,7 @@ def TUI_principal():
#do jogador e a data/hora da partida no arquivo. Conteúdos prévios do arquivo
#são mantidos, caso hajam vencedores anteriores
if principal == "vitoria":
nome = input(SCOREBOARD["win"])
nome = input(locale.SCOREBOARD["win"])
arquivo = open('vencedores.txt', 'a')
arquivo.write(f'{datetime.datetime.now()} - {nome}\n')
arquivo.close()
@@ -175,4 +193,4 @@ def TUI_principal():
#Derrota
#Deseja ao jogador melhor sorte na próxima partida
if principal == "derrota":
print(SCOREBOARD["loss"])
print(locale.SCOREBOARD["loss"])

View File

@@ -1,16 +1,12 @@
START = {
"intro": """
Projeto: Bingo Lite
Algoritmos e Programação II - Turma 02D
Segundo semestre - 2022
Certifique-se que tenha as bibliotecas necessárias instaladas
As bibliotecas podem ser instaladas posteriormente rodando o
arquivo 'setup.py'
Pressione ENTER para continuar
Pressione ENTER para continuar
""",
"libraries": """

View File

@@ -0,0 +1,155 @@
START = {
"intro": """
Project: Bingo Lite
Algorithms and Programming II - Class 02D
Second semester - 2022
Press ENTER to continue
""",
"libraries": """
The program detected that dependencies are not installed
Press ENTER to install the necessary libraries
(Note that you will need to open the program again after completion)
""",
"librariesinstalled": "Dependencies installed successfully.\nOpen the program again\n"}
INTRO = {
"intro1": """
At the beginning of the game, 4 cards will be drawn
and the player will initially own the 1st card.
╔══════╦════╦════╦════╦════╦════╗
║ Dono ║ 1 ║ 2 ║ 3 ║ 4 ║ 5 ║
╠══════╬════╬════╬════╬════╬════╣
║ ■ ║ 4 ║ 16 ║ 40 ║ 45 ║ 49 ║
║ ║ 4 ║ 17 ║ 25 ║ 38 ║ 49 ║
║ ║ 12 ║ 22 ║ 31 ║ 43 ║ 47 ║
║ ║ 12 ║ 23 ║ 31 ║ 39 ║ 45 ║
╚══════╩════╩════╩════╩════╩════╝
Press ENTER to continue
""",
"intro2": """
If the player presses ENTER, a number is drawn and
is marked on the cards in which it is present.
***************************************************
** Number drawn: 43 **
***************************************************
╔══════╦════╦════╦════╦══════╦════╗
║ Dono ║ 1 ║ 2 ║ 3 ║ 4 ║ 5 ║
╠══════╬════╬════╬════╬══════╬════╣
║ ■ ║ 4 ║ 16 ║ 40 ║ 45 ║ 49 ║
║ ║ 4 ║ 17 ║ 25 ║ 38 ║ 49 ║
║ ║ 12 ║ 22 ║ 31 ║ -43- ║ 47 ║
║ ║ 12 ║ 23 ║ 31 ║ 39 ║ 45 ║
╚══════╩════╩════╩════╩══════╩════╝
Press ENTER to continue
""",
"intro3": """
If the player selects another card, he
will become the owner of the chosen card.
***************************************************
** You now own card 2 **
***************************************************
╔══════╦════╦════╦════╦══════╦════╗
║ Dono ║ 1 ║ 2 ║ 3 ║ 4 ║ 5 ║
╠══════╬════╬════╬════╬══════╬════╣
║ ║ 4 ║ 16 ║ 40 ║ 45 ║ 49 ║
║ ■ ║ 4 ║ 17 ║ 25 ║ 38 ║ 49 ║
║ ║ 12 ║ 22 ║ 31 ║ -43- ║ 47 ║
║ ║ 12 ║ 23 ║ 31 ║ 39 ║ 45 ║
╚══════╩════╩════╩════╩══════╩════╝
Press ENTER to continue
""",
"intro4": """
If the card the player has is filled, the player wins.
The program will ask for your name to be included in the list.
The table is styled to represent the end of the game.
The winner will be added to the vencedores.txt file,
along with the match date and time.
+------+------+------+------+------+------+
| Dono | 1 | 2 | 3 | 4 | 5 |
+------+------+------+------+------+------+
| | -4- | 16 | -40- | 45 | -49- |
| ■ | -4- | -17- | -25- | -38- | -49- |
| | -12- | -22- | 31 | -43- | 47 |
| | -12- | 23 | 31 | 39 | 45 |
+------+------+------+------+------+------+
Congratulations! You won!!!
Enter your name to appear on the list of winners:
Press ENTER to continue
""",
"intro5": """
If another card is filled, the game
ends without the player winning.
+------+------+------+------+------+------+
| Dono | 1 | 2 | 3 | 4 | 5 |
+------+------+------+------+------+------+
| | -4- | 16 | -40- | 45 | -49- |
| | -4- | -17- | -25- | -38- | -49- |
| | -12- | -22- | 31 | -43- | 47 |
| ■ | -12- | 23 | 31 | 39 | 45 |
+------+------+------+------+------+------+
Another card has been completed!
Better luck next time!
Press ENTER to continue
""",
"introfinal": """
Ready?
Press ENTER to play!
The tutorial can be done again by removing
the config.json file
"""}
SELECTED = {
"player": "",
"notplayer": " "}
ERRORS = {
"invalid": "Invalid input value",}
WARNING = {
"firstime": """
The program has detected that this is the first time it is playing.
Press ENTER to watch the tutorial.
Alternatively, press 1 to skip the tutorial (Recommended for experienced players)
""",
"firsttimeskip": """
No problem, good game!
The tutorial can be done by removing
the config.json file
Press ENTER to play!
"""}
GAME = {
"presskey": "Select another card (1, 2, 3 or 4) or press ENTER to draw "}
SCOREBOARD = {
"win": """
Congratulations! You won!!!
Enter your name to appear on the list of winners:
""",
"loss": """
Another card has been completed!
Better luck next time!
"""}

View File

@@ -1,10 +1,10 @@
import random
def aleatorio(min, max):
def aleatorio(x, y):
#Retorna um valor aleatório de tamanho a ser determinado
return random.randint(min, max)
return random.randint(x, y)
def geralistaaleatoria(max, quantelementos):
def geralistaaleatoria(x, y):
#Gera uma lista de números à serem sorteados - Esses números são
#únicos e aleatórios.
return random.sample(range(max), k=quantelementos)
return random.sample(range(x), k=y)

View File

@@ -1,27 +1,39 @@
import os
def tutorial():
def idioma():
os.system("cls || clear")
x = int(input("""
Selecione seu idioma
Select your language
1 = Português Brasileiro
2 = English
"""))
if x == 1:
return "BR"
elif x == 2:
return "EN"
def tutorial(locale):
#Tutorial - Busca as informações do constants.py e apresenta na tela em
#formato 'apresentação de slides'
from src.constants import INTRO
os.system("cls || clear")
input(INTRO["intro1"])
input(locale.INTRO["intro1"])
os.system("cls || clear")
input(INTRO["intro2"])
input(locale.INTRO["intro2"])
os.system("cls || clear")
input(INTRO["intro3"])
input(locale.INTRO["intro3"])
os.system("cls || clear")
input(INTRO["intro4"])
input(locale.INTRO["intro4"])
os.system("cls || clear")
input(INTRO["intro5"])
input(locale.INTRO["intro5"])
os.system("cls || clear")
input(INTRO["introfinal"])
input(locale.INTRO["introfinal"])
os.system("cls || clear")
def inicio():
def inicio(locale):
#Início do programa e indrodução para o usuário
from src.constants import WARNING, START
os.system("cls || clear")
x = input(START["intro"])
x = input(locale.START["intro"])
#Detecção e instalação das dependências - Caso não estejam instaladas,
#a instalação ocorre e o programa é encerrado. O usuário é avisado para reiniciar
#o programa ao finalizar
@@ -30,7 +42,7 @@ def inicio():
from colr import color
except ModuleNotFoundError:
os.system("cls || clear")
input(START["libraries"])
input(locale.START["libraries"])
os.system("pip install -r requirements.txt --user")
os.system("cls || clear")
return "instalado"
@@ -44,9 +56,9 @@ def inicio():
config.write('Tutorial_Done=1')
config.close()
os.system("cls || clear")
resposta = input(WARNING["firstime"])
resposta = input(locale.WARNING["firstime"])
if resposta == "":
tutorial()
tutorial(locale)
elif resposta == "1":
os.system("cls || clear")
input(WARNING["firsttimeskip"])
input(locale.WARNING["firsttimeskip"])