Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code according to PEP8 #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
472 changes: 472 additions & 0 deletions character/Scripts/Activate.ps1

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions character/Scripts/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi

if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
unset VIRTUAL_ENV_PROMPT
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="E:\character_creation_module\character"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/Scripts:$PATH"
export PATH

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(character) ${PS1:-}"
export PS1
VIRTUAL_ENV_PROMPT="(character) "
export VIRTUAL_ENV_PROMPT
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
34 changes: 34 additions & 0 deletions character/Scripts/activate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@echo off

rem This file is UTF-8 encoded, so we need to update the current code page while executing it
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
set _OLD_CODEPAGE=%%a
)
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" 65001 > nul
)

set VIRTUAL_ENV=E:\character_creation_module\character

if not defined PROMPT set PROMPT=$P$G

if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%

set _OLD_VIRTUAL_PROMPT=%PROMPT%
set PROMPT=(character) %PROMPT%

if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=

if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%

set PATH=%VIRTUAL_ENV%\Scripts;%PATH%
set VIRTUAL_ENV_PROMPT=(character)

:END
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
set _OLD_CODEPAGE=
)
22 changes: 22 additions & 0 deletions character/Scripts/deactivate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@echo off

if defined _OLD_VIRTUAL_PROMPT (
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
)
set _OLD_VIRTUAL_PROMPT=

if defined _OLD_VIRTUAL_PYTHONHOME (
set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
set _OLD_VIRTUAL_PYTHONHOME=
)

if defined _OLD_VIRTUAL_PATH (
set "PATH=%_OLD_VIRTUAL_PATH%"
)

set _OLD_VIRTUAL_PATH=

set VIRTUAL_ENV=
set VIRTUAL_ENV_PROMPT=

:END
Binary file added character/Scripts/flake8.exe
Binary file not shown.
Binary file added character/Scripts/isort-identify-imports.exe
Binary file not shown.
Binary file added character/Scripts/isort.exe
Binary file not shown.
Binary file added character/Scripts/pip.exe
Binary file not shown.
Binary file added character/Scripts/pip3.10.exe
Binary file not shown.
Binary file added character/Scripts/pip3.11.exe
Binary file not shown.
Binary file added character/Scripts/pip3.exe
Binary file not shown.
Binary file added character/Scripts/py.test.exe
Binary file not shown.
Binary file added character/Scripts/pycodestyle.exe
Binary file not shown.
Binary file added character/Scripts/pyflakes.exe
Binary file not shown.
Binary file added character/Scripts/pytest.exe
Binary file not shown.
Binary file added character/Scripts/python.exe
Binary file not shown.
Binary file added character/Scripts/pythonw.exe
Binary file not shown.
5 changes: 5 additions & 0 deletions character/pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
home = C:\Users\Диор\AppData\Local\Programs\Python\Python311
include-system-site-packages = false
version = 3.11.0
executable = C:\Users\Диор\AppData\Local\Programs\Python\Python311\python.exe
command = C:\Users\Диор\AppData\Local\Programs\Python\Python311\python.exe -m venv E:\character_creation_module\character
7 changes: 7 additions & 0 deletions choice_class.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"char_class": "����� �������� ���������, �� �������� ������ ������: ������� � warrior, ��� � mage, ������ � healer:",
"warrior": "������� � ������� ���� �������� ���. �������, ���������� � ��������.",
"mage": "��� � ���������� ���� �������� ���. �������� ������� �����������.",
"healer": "������ � �������������� �����������. ������� ���� �� �������, ���� � �����.",
"approve_choice": "'����� (Y), ����� ����������� �����, ��� ����� ������ ������, ����� ������� ������� ��������� '"
}
69 changes: 38 additions & 31 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
# coding: utf-8
import json
import os
from random import randint


def attack(char_name, char_class):
comment = 'нанёс урон противнику равный '
if char_class == 'warrior':
return (f'{char_name} нанёс урон противнику равный {5 + randint(3, 5)}')
return (f'{char_name} {comment} {5 + randint(3, 5)}')
if char_class == 'mage':
return (f'{char_name} нанёс урон противнику равный {5 + randint(5, 10)}')
return (f'{char_name} {comment} {5 + randint(5, 10)}')
if char_class == 'healer':
return (f'{char_name} нанёс урон противнику равный {5 + randint(-3, -1)}')
return (f'{char_name} {comment} {5 + randint(-3, -1)}')


def defence(char_name, char_class):
defence = ['блокировал', 'урона']
if char_class == 'warrior':
return (f'{char_name} блокировал {10 + randint(5, 10)} урона')
return (f'{char_name} {defence[0]} {10 + randint(5, 10)} {defence[1]}')
if char_class == 'mage':
return (f'{char_name} блокировал {10 + randint(-2, 2)} урона')
return (f'{char_name} {defence[0]} {10 + randint(-2, 2)} {defence[1]}')
if char_class == 'healer':
return (f'{char_name} блокировал {10 + randint(2, 5)} урона')
return (f'{char_name} {defence[0]} {10 + randint(2, 5)} {defence[1]}')


def special(char_name, char_class):
if char_class == 'warrior':
return (f'{char_name} применил специальное умение «Выносливость {80 + 25}»')
special_info = ['применил специальное умение']
if char_class == 'warrior':
return (f'{char_name} {special_info[0]} "Выносливость" {80 + 25}»')
if char_class == 'mage':
return (f'{char_name} применил специальное умение «Атака {5 + 40}»')
return (f'{char_name} {special_info[0]} Атака {5 + 40}»')
if char_class == 'healer':
return (f'{char_name} применил специальное умение «Защита {10 + 30}»')


return (f'{char_name} {special_info[0]} Защита {10 + 30}»')


def start_training(char_name, char_class):
if char_class == 'warrior':
print(f'{char_name}, ты Воитель — отличный боец ближнего боя.')
if char_class == 'mage':
print(f'{char_name}, ты Маг — превосходный укротитель стихий.')
if char_class == 'healer':
print(f'{char_name}, ты Лекарь — чародей, способный исцелять раны.')
print('Потренируйся управлять своими навыками.')
print('Введи одну из команд: attack — чтобы атаковать противника, defence — чтобы блокировать атаку противника или special — чтобы использовать свою суперсилу.')
print('Если не хочешь тренироваться, введи команду skip.')

# Transfer character description to JSON
path_to_person = os.path.join(os.path.dirname(__file__), 'person.txt')
path_to_welcome = os.path.join(os.path.dirname(__file__), 'welcome.txt')
with open(path_to_person) as f:
info_person = json.loads(f.read())
print(info_person[char_class])
with open(path_to_welcome) as f:
print(f.read())
cmd = None
while cmd != 'skip':
cmd = input('Введи команду: ')
Expand All @@ -47,18 +55,17 @@ def start_training(char_name, char_class):
print(special(char_name, char_class))
return 'Тренировка окончена.'


def choice_char_class():
approve_choice = None
char_class = None
choice_class = os.path.join(os.path.dirname(__file__), 'choice_class.txt')
with open(choice_class) as f:
info = json.loads(f.read())
while approve_choice != 'y':
char_class = input('Введи название персонажа, за которого хочешь играть: Воитель — warrior, Маг — mage, Лекарь — healer: ')
if char_class == 'warrior':
print('Воитель — дерзкий воин ближнего боя. Сильный, выносливый и отважный.')
if char_class == 'mage':
print('Маг — находчивый воин дальнего боя. Обладает высоким интеллектом.')
if char_class == 'healer':
print('Лекарь — могущественный заклинатель. Черпает силы из природы, веры и духов.')
approve_choice = input('Нажми (Y), чтобы подтвердить выбор, или любую другую кнопку, чтобы выбрать другого персонажа ').lower()
char_class = input(info['char_class'])
print(info.get(char_class, 'Нет такого персонажа'))
approve_choice = input(info['approve_choice']).lower()
return char_class


Expand All @@ -72,6 +79,6 @@ def main():
print('Воитель, Маг, Лекарь')
char_class = choice_char_class()
print(start_training(char_name, char_class))


main()

main()
4 changes: 4 additions & 0 deletions person.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"warrior": "�� ������� � �������� ���� �������� ���.",
"mage": "�� ��� � ������������ ���������� ������.",
"healer": "�� ������ � �������, ��������� �������� ����."
}
34 changes: 34 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<<<<<<< HEAD
def start_training(char_name, char_class):

# Transfer character description to JSON
path_to_person = os.path.join(os.path.dirname(__file__), 'person.txt')
path_to_welcome = os.path.join(os.path.dirname(__file__), 'welcome.txt')
with open(path_to_person) as f:
info_person = json.loads(f.read())
print(char_class == info_person)

with open(path_to_welcome) as f:
print(f.read())
cmd = None
while cmd != 'skip':
cmd = input('Введи команду: ')
if cmd == 'attack':
print(attack(char_name, char_class))
if cmd == 'defence':
print(defence(char_name, char_class))
if cmd == 'special':
print(special(char_name, char_class))
return 'Тренировка окончена.'
=======
# coding: utf-8
import json
import os

choice_class = os.path.join(os.path.dirname(__file__), 'choice_class.txt')
with open(choice_class) as f:

info = json.loads(f.read())

print(info['warrior'])
>>>>>>> d568a2c1e99a655e05fa95aaec28ac107e2282b7
3 changes: 3 additions & 0 deletions welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
������������ ��������� ������ ��������.
����� ���� �� ������: attack � ����� ��������� ����������, defence � ����� ����������� ����� ���������� ��� special � ����� ������������ ���� ���������.
���� �� ������ �������������, ����� ������� skip.