Skip to content

Commit

Permalink
Merge pull request #15 from Jaz7Mutant/net
Browse files Browse the repository at this point in the history
release v1.0
  • Loading branch information
Jaz7Mutant authored May 7, 2019
2 parents 366d954 + fad14b6 commit ab26a28
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Typing Trainer Game
Версия: 0.99.9 бета
Версия: 1.0
Автор: Даниил JazzMutant Толстоухов ([email protected])

## Описание
Expand Down Expand Up @@ -28,4 +28,10 @@
Для игры по сети необходимо создать комнату с необходимыми настройками, дождаться подключения других игроков и запустить игру. После завершения раунда всем игрокам приходит таблица результатов.

## Подробности реализации
Ахаххаха, я только пьяному смогу объяснить как это работает, ибо пока писал, я совершенствовался и понимал, что предыдущий код -- полная лажа. Тестов нет, но будут (я постараюсь). Да и надо бы прибраться в коде, хоть немного
Все модули игры находятся в папке `typetrainer`. Модуль `game` отвечает за проведение раунда, то есть взаимодействия с пользователем. Модули `*_menu` реализуют визуализацию и интерфейс. `socket_client` содержит в себе инструментарий для сетевой игры.
Класс `Game` формирует статистику или же количество очков, в зависимости от режима игры.
Тексты формируются классом `TextGenerator`

Тесты пожно найти в папке `tests`
`typetrainer\game.py 95 18 81%`
`typetrainer\texts_generator.py 34 6 82%`
4 changes: 3 additions & 1 deletion typetrainer/multiplayer_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def create_room():

socket_client.room_create(room_name, password, menu.get_user_name(False),
int(max_players), game_type, text_number)
time.sleep(0.5)
while socket_client.current_room_TOKEN == '':
time.sleep(0.5)
lobby(True)


Expand Down Expand Up @@ -145,5 +146,6 @@ def browse_rooms():
time.sleep(1)
while WAITING_FOR_RESPONSE:
time.sleep(0.2)
print('hui')
if CONNECTION:
lobby(False)
2 changes: 1 addition & 1 deletion typetrainer/settings.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[GENERAL]
VERSION = 0.99.9 beta
VERSION = 1.0
INPUT_ENCODING = cp866
FILE_ENCODING = utf-8

Expand Down
30 changes: 14 additions & 16 deletions typetrainer/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
CURRENT_ROOM_NAME = ''
CURRENT_GAME_TYPE = ''
CURRENT_TEXT_NUMBER = 1


ROOMS_SHOWED = False
LOADED = False


Expand Down Expand Up @@ -90,24 +89,25 @@ def get_rooms(data):
counter = 1
for room in Rooms:
print('%s. %-10s %-8s' % (counter, room['name'], room['players']))
# TODO check
counter += 1
if counter > 1:
room_number = input('Choose a room to connect: ')
try:
int(room_number)
except ValueError:
multiplayer_menu.WAITING_FOR_RESPONSE = False
return
if int(room_number) >= counter:
print('Incorrect room')
time.sleep(0.5)
multiplayer_menu.WAITING_FOR_RESPONSE = False
# TODO Check multiplayer
return
password = input('Password: ')
room_join(int(room_number) - 1, password, menu.get_user_name(False))
time.sleep(0.8)
time.sleep(0.8)
multiplayer_menu.WAITING_FOR_RESPONSE = False
global ROOMS_SHOWED
ROOMS_SHOWED = True


@sio.on("joined")
Expand Down Expand Up @@ -159,7 +159,6 @@ def started(data):
"""
if not data['err']:
if data['room'] == current_room_TOKEN:
# print("Start")
multiplayer_menu.GAME_START = True
elif data['err'] == 406:
print("Room already started")
Expand Down Expand Up @@ -208,8 +207,9 @@ def end_game(data):
player['username'],
player['score']))
else:
print(f'{counter}. {player["username"]} {player["score"]}')
# TODO Check and remove f-strings
print('%s. %-16s %-8s' % (counter,
player['username'],
player['score']))
counter += 1
elif data['err'] == 401:
print("You need to join")
Expand All @@ -230,17 +230,13 @@ def get_players(data):
counter = 0
for player in data['players']:
if counter == 0:
# print('%s. %-16s L' % (counter, player))
print(str(counter) + '. ' + player + ' L')
print(str(counter) + '. ' + player + ' L')
else:
# print('%s. %-16s' % player)
print(str(counter) + '. ' + player)
# TODO Check
print(str(counter) + '. ' + player)
counter += 1
elif data['err'] == 401:
print("You need to join")
print('Press any key to return')
# TODO formatted output


def room_create(room_name: str, password: str, user_name: str,
Expand All @@ -267,9 +263,11 @@ def room_list():
:return:
Ответ приходит в get_rooms()
"""
global ROOMS_SHOWED
ROOMS_SHOWED = False
sio.emit("rooms")
# time.sleep(1)
# multiplayer_menu.WAITING_FOR_RESPONSE = False
while not ROOMS_SHOWED:
time.sleep(0.3)


def room_join(index: int, password: str, username: str):
Expand Down

0 comments on commit ab26a28

Please sign in to comment.