починил все баги
начал доставать всё из базы сделал новую игру
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
directory = "."
|
||||||
|
directory_depth = 1000 # How deep you would like to go
|
||||||
|
extensions_to_consider = [".py"] # Change to ["all"] to include all extensions
|
||||||
|
exclude_filenames = ["venv", ".idea", "__pycache__", "cache", "length.py"]
|
||||||
|
skip_file_error_list = True
|
||||||
|
|
||||||
|
this_file_dir = os.path.realpath(__file__)
|
||||||
|
|
||||||
|
print("Path to ignore:", this_file_dir)
|
||||||
|
print("=====================================")
|
||||||
|
|
||||||
|
|
||||||
|
def _walk(path, depth):
|
||||||
|
"""Recursively list files and directories up to a certain depth"""
|
||||||
|
depth -= 1
|
||||||
|
with os.scandir(path) as p:
|
||||||
|
for entry in p:
|
||||||
|
skip_entry = False
|
||||||
|
for fName in exclude_filenames:
|
||||||
|
if entry.path.endswith(fName):
|
||||||
|
skip_entry = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if skip_entry:
|
||||||
|
print("Skipping entry", entry.path)
|
||||||
|
continue
|
||||||
|
|
||||||
|
yield entry.path
|
||||||
|
if entry.is_dir() and depth > 0:
|
||||||
|
yield from _walk(entry.path, depth)
|
||||||
|
|
||||||
|
|
||||||
|
files = list(_walk(directory, directory_depth))
|
||||||
|
print("=====================================")
|
||||||
|
file_err_list = []
|
||||||
|
line_count = 0
|
||||||
|
len_files = len(files)
|
||||||
|
for i, file_dir in enumerate(files):
|
||||||
|
|
||||||
|
if file_dir == this_file_dir:
|
||||||
|
print("=[Rejected file directory", file_dir, "]=")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not os.path.isfile(file_dir):
|
||||||
|
continue
|
||||||
|
|
||||||
|
skip_File = True
|
||||||
|
for ending in extensions_to_consider:
|
||||||
|
if file_dir.endswith(ending) or ending == "all":
|
||||||
|
skip_File = False
|
||||||
|
|
||||||
|
if not skip_File:
|
||||||
|
try:
|
||||||
|
file = open(file_dir, "r")
|
||||||
|
local_count = 0
|
||||||
|
for line in file:
|
||||||
|
if line != "\n":
|
||||||
|
local_count += 1
|
||||||
|
print("({:.1f}%)".format(100 * i / len_files), file_dir, "|", local_count)
|
||||||
|
line_count += local_count
|
||||||
|
file.close()
|
||||||
|
except Exception as e:
|
||||||
|
file_err_list.append([file_dir, e])
|
||||||
|
continue
|
||||||
|
print("=====================================")
|
||||||
|
print("File Count Errors:", len(file_err_list))
|
||||||
|
if not skip_file_error_list:
|
||||||
|
for file in file_err_list:
|
||||||
|
print(file_err_list)
|
||||||
|
|
||||||
|
print("=====================================")
|
||||||
|
print("Total lines |", line_count)
|
||||||
+13
-19
@@ -1,35 +1,29 @@
|
|||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
from modules import DB
|
||||||
|
|
||||||
|
|
||||||
class Book: # Окно с необходимой информацией
|
class Book: # Окно с необходимой информацией
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def info(screen, event):
|
def info(screen, event):
|
||||||
|
db = DB.UseDB("game")
|
||||||
|
response = db.find_document({})[0]
|
||||||
pg.draw.rect(screen, (38, 33, 55), (85, 0, 520, 500))
|
pg.draw.rect(screen, (38, 33, 55), (85, 0, 520, 500))
|
||||||
pg.draw.rect(screen, (255, 255, 255), (100, 90, 495, 280), 1)
|
pg.draw.rect(screen, (255, 255, 255), (100, 90, 495, 280), 1)
|
||||||
texts = ['День ***', 'Сегодня произошло следующее:', f"{event['name']}\n{event['description']}"]
|
texts = [f'День {response["day"]}', 'Сегодня произошло следующее:',
|
||||||
sizes = [60, 30, 30]
|
f"{event['name']}", f"{event['description']}"]
|
||||||
coords = [(260, 30), (110, 100), (110, 150)]
|
sizes = [60, 30, 30, 30]
|
||||||
|
coords = [(260, 30), (110, 100), (110, 150), (110, 190)]
|
||||||
for i in range(len(texts)):
|
for i in range(len(texts)):
|
||||||
font = pg.font.Font(None, sizes[i])
|
font = pg.font.Font(None, sizes[i])
|
||||||
text = font.render(texts[i], True, (255, 255, 255))
|
text = font.render(texts[i], True, (255, 255, 255))
|
||||||
screen.blit(text, coords[i])
|
screen.blit(text, coords[i])
|
||||||
|
frogs = []
|
||||||
frogs = [('Квакуша', [100, 100]),
|
for i in response["frogs"]:
|
||||||
('Квакша', [100, 100]),
|
frogs.append((i["name"], [i["hp"], i["hunger"]]))
|
||||||
('Квак', [100, 100]),
|
|
||||||
('Ква', [100, 100]),
|
|
||||||
('Кваква', [100, 100]),
|
|
||||||
('Джабба-хатт', [100, 100]),
|
|
||||||
('Квендальф', [100, 100]),
|
|
||||||
('Лягуша', [100, 100]),
|
|
||||||
('Жаба', [100, 100]),
|
|
||||||
('Абажаю', [100, 100]),
|
|
||||||
('Пучеглазый', [100, 100]),
|
|
||||||
('Вафля', [100, 100])] # Имя лягушки со здоровьем и сытостью (как пример)
|
|
||||||
|
|
||||||
font = pg.font.Font(None, 15) # Здесь будет указана информация о некоторых лягушках
|
font = pg.font.Font(None, 15) # Здесь будет указана информация о некоторых лягушках
|
||||||
for col in range(4):
|
for col in range(1):
|
||||||
for row in range(3):
|
for row in range(1):
|
||||||
pg.draw.rect(screen, (255, 255, 255), (100 + 120 * col, 375 + 40 * row, 35, 35),
|
pg.draw.rect(screen, (255, 255, 255), (100 + 120 * col, 375 + 40 * row, 35, 35),
|
||||||
1) # Рамка с портретом лягушки
|
1) # Рамка с портретом лягушки
|
||||||
if col == 0:
|
if col == 0:
|
||||||
@@ -44,5 +38,5 @@ class Book: # Окно с необходимой информацией
|
|||||||
screen.blit(text, (140 + 120 * col, 375 + 40 * row))
|
screen.blit(text, (140 + 120 * col, 375 + 40 * row))
|
||||||
text = font.render(f'{frogs[i][-1][0]}% зд.,', True, (255, 255, 255))
|
text = font.render(f'{frogs[i][-1][0]}% зд.,', True, (255, 255, 255))
|
||||||
screen.blit(text, (140 + 120 * col, 385 + 40 * row))
|
screen.blit(text, (140 + 120 * col, 385 + 40 * row))
|
||||||
text = font.render(f'{frogs[i][-1][1]}% сыт.', True, (255, 255, 255))
|
text = font.render(f'{frogs[i][-1][1]}% голода', True, (255, 255, 255))
|
||||||
screen.blit(text, (140 + 120 * col, 395 + 40 * row))
|
screen.blit(text, (140 + 120 * col, 395 + 40 * row))
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ class UseDB:
|
|||||||
"""
|
"""
|
||||||
Класс для работы с базой данных
|
Класс для работы с базой данных
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, collection_name):
|
def __init__(self, collection_name):
|
||||||
self.series_collection = None
|
self.series_collection = None
|
||||||
self.client = MongoClient('194.61.1.147', 52530)
|
self.client = MongoClient('194.61.1.147', 52530)
|
||||||
@@ -52,3 +53,19 @@ class UseDB:
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
self.series_collection.delete_one(query_elements)
|
self.series_collection.delete_one(query_elements)
|
||||||
|
|
||||||
|
def create_new_game(self):
|
||||||
|
self.series_collection.drop()
|
||||||
|
self.series_collection.insert_one({
|
||||||
|
"day": 0,
|
||||||
|
"frogs": [{
|
||||||
|
"name": "Квакуша",
|
||||||
|
"hp": 100,
|
||||||
|
"hunger": 0
|
||||||
|
}],
|
||||||
|
"money": 0,
|
||||||
|
"save": {
|
||||||
|
"name": "start",
|
||||||
|
"data": "25.01.2023" # TODO:получить дату нормально
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
+20
-2
@@ -1,6 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import pygame_menu
|
import pygame_menu
|
||||||
import configparser
|
import configparser
|
||||||
|
from modules.DB import UseDB
|
||||||
|
|
||||||
|
|
||||||
def set_difficulty(value: dict, _) -> None:
|
def set_difficulty(value: dict, _) -> None:
|
||||||
@@ -21,6 +22,20 @@ def start_the_game() -> None:
|
|||||||
"""
|
"""
|
||||||
Функция запуска игры
|
Функция запуска игры
|
||||||
|
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
config = configparser.ConfigParser() # создаю объект ConfigParser
|
||||||
|
config.read('conf/config.ini') # читаю файл
|
||||||
|
config['Settings']['sound'] = sound # перезаписываю настройку звука
|
||||||
|
with open('conf/config.ini', 'w') as configfile: # открываю файл для записи
|
||||||
|
config.write(configfile) # записываю
|
||||||
|
menu.toggle() # останавливаю меню
|
||||||
|
|
||||||
|
|
||||||
|
def start_new_game() -> None:
|
||||||
|
"""
|
||||||
|
Функция запуска игры
|
||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
config = configparser.ConfigParser() # создаю объект ConfigParser
|
config = configparser.ConfigParser() # создаю объект ConfigParser
|
||||||
@@ -29,6 +44,8 @@ def start_the_game() -> None:
|
|||||||
config['Settings']['sound'] = sound # перезаписываю настройку звука
|
config['Settings']['sound'] = sound # перезаписываю настройку звука
|
||||||
with open('conf/config.ini', 'w') as configfile: # открываю файл для записи
|
with open('conf/config.ini', 'w') as configfile: # открываю файл для записи
|
||||||
config.write(configfile) # записываю
|
config.write(configfile) # записываю
|
||||||
|
db = UseDB("game")
|
||||||
|
db.create_new_game()
|
||||||
menu.toggle() # останавливаю меню
|
menu.toggle() # останавливаю меню
|
||||||
|
|
||||||
|
|
||||||
@@ -56,12 +73,13 @@ surface = pygame.display.set_mode((600, 400)) # создаю полотно
|
|||||||
mytheme = pygame_menu.themes.THEME_DARK.copy() # создаю свою тему
|
mytheme = pygame_menu.themes.THEME_DARK.copy() # создаю свою тему
|
||||||
mytheme.background_color = pygame_menu.baseimage.BaseImage(image_path='styles/background.jpg')
|
mytheme.background_color = pygame_menu.baseimage.BaseImage(image_path='styles/background.jpg')
|
||||||
# натягиваю свой background
|
# натягиваю свой background
|
||||||
menu = pygame_menu.Menu('Welcome', 600, 400, theme=mytheme) # создаю меню
|
menu = pygame_menu.Menu('Toads', 600, 400, theme=mytheme) # создаю меню
|
||||||
menu.add.label("Сложность") # добавляю label сложности
|
menu.add.label("Сложность") # добавляю label сложности
|
||||||
menu.add.selector('', [('Простая', 1), ('Средняя', 2), ('Сложная', 3), ('Проигрывать весело', 4)],
|
menu.add.selector('', [('Простая', 1), ('Средняя', 2), ('Сложная', 3), ('Проигрывать весело', 4)],
|
||||||
onchange=set_difficulty) # добавляю selector с выбором сложности
|
onchange=set_difficulty) # добавляю selector с выбором сложности
|
||||||
menu.add.label("Музыка") # добавляю label музыки
|
menu.add.label("Музыка") # добавляю label музыки
|
||||||
menu.add.selector('', [("Да", 1), ("Нет", 1)], onchange=test) # добавляю selector с выбором настроек музыки
|
menu.add.selector('', [("Да", 1), ("Нет", 1)], onchange=test) # добавляю selector с выбором настроек музыки
|
||||||
menu.add.button('Play', start_the_game) # добавляю кнопку начала игры
|
menu.add.button('Продолжить', start_the_game) # добавляю кнопку начала игры
|
||||||
|
menu.add.button('Новая игра', start_new_game) # добавляю кнопку начала игры
|
||||||
menu.add.button('Quit', pygame_menu.events.EXIT) # добавляю кнопку выхода
|
menu.add.button('Quit', pygame_menu.events.EXIT) # добавляю кнопку выхода
|
||||||
menu.mainloop(surface) # запускаю меню
|
menu.mainloop(surface) # запускаю меню
|
||||||
|
|||||||
+10
-6
@@ -1,5 +1,5 @@
|
|||||||
import pygame as pg
|
import pygame as pg
|
||||||
from modules import Book, GameOver, Mathematics
|
from modules import Book, GameOver, Mathematics, DB
|
||||||
from modules.RewardWindow import RewardWindow
|
from modules.RewardWindow import RewardWindow
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +50,8 @@ class Swamp:
|
|||||||
(self.x, self.y, self.cell_size, self.cell_size), 1)
|
(self.x, self.y, self.cell_size, self.cell_size), 1)
|
||||||
|
|
||||||
font = pg.font.Font(None, 50)
|
font = pg.font.Font(None, 50)
|
||||||
text_string = "Ваш баланс мух составляет: 1000"
|
db = DB.UseDB("game")
|
||||||
|
text_string = f"Ваш баланс мух составляет: {db.find_document({})[0]['money']}"
|
||||||
text = font.render(text_string, True, (255, 255, 255))
|
text = font.render(text_string, True, (255, 255, 255))
|
||||||
size = font.size(text_string)
|
size = font.size(text_string)
|
||||||
screen.blit(text, (350 - (size[0] / 2.), 50))
|
screen.blit(text, (350 - (size[0] / 2.), 50))
|
||||||
@@ -87,12 +88,15 @@ class Swamp:
|
|||||||
def get_cell(self, mouse_pos):
|
def get_cell(self, mouse_pos):
|
||||||
board_width = self.width * self.cell_size
|
board_width = self.width * self.cell_size
|
||||||
board_height = self.height * self.cell_size
|
board_height = self.height * self.cell_size
|
||||||
if self.left_area < mouse_pos[0] < self.left_area + board_width:
|
if self.left_area <= mouse_pos[0] <= self.left_area + board_width:
|
||||||
if self.top_area < mouse_pos[1] < self.top_area + board_height:
|
if self.top_area <= mouse_pos[1] <= self.top_area + board_height:
|
||||||
cell_coords = (mouse_pos[0] - self.top_area) // self.cell_size + 1, \
|
cell_coords = (mouse_pos[0] - self.top_area) // self.cell_size + 1, \
|
||||||
(mouse_pos[1] - self.left_area) // self.cell_size - 1
|
(mouse_pos[1] - self.left_area) // self.cell_size - 1
|
||||||
self.cell_info = self.board[cell_coords[1]][cell_coords[0]]
|
try:
|
||||||
self.time_to_close = 100
|
self.cell_info = self.board[cell_coords[1]][cell_coords[0]]
|
||||||
|
except IndexError:
|
||||||
|
self.cell_info = self.board[-1][cell_coords[0]]
|
||||||
|
self.time_to_close = 10
|
||||||
return cell_coords
|
return cell_coords
|
||||||
elif self.left_book < mouse_pos[0] < self.right_book:
|
elif self.left_book < mouse_pos[0] < self.right_book:
|
||||||
if self.top_book < mouse_pos[1] < self.down_book and self.book_use is False:
|
if self.top_book < mouse_pos[1] < self.down_book and self.book_use is False:
|
||||||
|
|||||||
@@ -1,3 +1,124 @@
|
|||||||
from modules.Mathematics import field_generation
|
import pygame as pg
|
||||||
|
from math import pi
|
||||||
|
from time import sleep
|
||||||
|
from random import *
|
||||||
|
|
||||||
print(field_generation())
|
|
||||||
|
class Game():
|
||||||
|
def __init__(self):
|
||||||
|
self.colors = [tuple([randrange(50, 256) for _ in range(3)]) for _ in range(9)]
|
||||||
|
self.line_color = choice(self.colors)
|
||||||
|
self.right = choice([True, False])
|
||||||
|
self.lose = False
|
||||||
|
self.win = False
|
||||||
|
self.scores = 0
|
||||||
|
|
||||||
|
def render(self, screen): # Создание круга из случайных цветов и стрелки
|
||||||
|
pg.draw.arc(screen, (self.colors[0]),
|
||||||
|
(120, 90, 350, 350), 0, pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[1]),
|
||||||
|
(120, 90, 350, 350), pi / 9, 2 * pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[2]),
|
||||||
|
(120, 90, 350, 350), 2 * pi / 9, 3 * pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[3]),
|
||||||
|
(120, 90, 350, 350), 3 * pi / 9, 4 * pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[4]),
|
||||||
|
(120, 90, 350, 350), 4 * pi / 9, 5 * pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[5]),
|
||||||
|
(120, 90, 350, 350), 5 * pi / 9, 6 * pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[6]),
|
||||||
|
(120, 90, 350, 350), 6 * pi / 9, 7 * pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[7]),
|
||||||
|
(120, 90, 350, 350), 7 * pi / 9, 8 * pi / 9, 7)
|
||||||
|
pg.draw.arc(screen, (self.colors[8]),
|
||||||
|
(120, 90, 350, 350), 8 * pi / 9, pi, 7)
|
||||||
|
pg.draw.line(screen, (self.line_color), [300, 270], [300, 130], 9)
|
||||||
|
|
||||||
|
font = pg.font.Font(None, 50)
|
||||||
|
text = font.render('Счёт:', True, (255, 255, 255))
|
||||||
|
screen.blit(text, (50, 300))
|
||||||
|
text = font.render(f'{self.scores}/10', True, (255, 255, 255))
|
||||||
|
screen.blit(text, (70, 340))
|
||||||
|
|
||||||
|
if self.lose:
|
||||||
|
Lose.text(self)
|
||||||
|
elif self.win:
|
||||||
|
Win.text(self)
|
||||||
|
|
||||||
|
def side_change(self): # Изменение стороны
|
||||||
|
if not self.right:
|
||||||
|
self.right = True
|
||||||
|
elif self.right:
|
||||||
|
self.right = False
|
||||||
|
if color_change:
|
||||||
|
self.old_color = self.line_color
|
||||||
|
while self.old_color == self.line_color:
|
||||||
|
self.line_color = choice(self.colors)
|
||||||
|
|
||||||
|
def animation(self): # анимация (изменение координат)
|
||||||
|
if self.right:
|
||||||
|
sleep(0.4)
|
||||||
|
self.color = self.colors[0]
|
||||||
|
del self.colors[0]
|
||||||
|
self.colors.append(self.color)
|
||||||
|
else:
|
||||||
|
sleep(0.4)
|
||||||
|
self.colors.reverse()
|
||||||
|
self.color = self.colors[0]
|
||||||
|
del self.colors[0]
|
||||||
|
self.colors.append(self.color)
|
||||||
|
self.colors.reverse()
|
||||||
|
if self.scores == 10:
|
||||||
|
self.win = True
|
||||||
|
|
||||||
|
def check(self):
|
||||||
|
if self.line_color == self.colors[3] or self.line_color == self.colors[5] or self.line_color == self.colors[4]:
|
||||||
|
self.scores += 1
|
||||||
|
else:
|
||||||
|
self.lose = True
|
||||||
|
|
||||||
|
|
||||||
|
class Win:
|
||||||
|
def text(self):
|
||||||
|
pg.draw.rect(screen, (40, 40, 40), (0, 0, 599, 599))
|
||||||
|
font = pg.font.Font(None, 70)
|
||||||
|
text = font.render('Вы выиграли!', True, (255, 255, 255))
|
||||||
|
screen.blit(text, (120, 150))
|
||||||
|
|
||||||
|
|
||||||
|
class Lose:
|
||||||
|
def text(self):
|
||||||
|
pg.draw.rect(screen, (40, 40, 40), (0, 0, 599, 599))
|
||||||
|
font = pg.font.Font(None, 70)
|
||||||
|
text = font.render('Вы проиграли!', True, (255, 255, 255))
|
||||||
|
screen.blit(text, (120, 150))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pg.init()
|
||||||
|
size = 600, 400
|
||||||
|
screen = pg.display.set_mode(size)
|
||||||
|
game = Game()
|
||||||
|
animation = False
|
||||||
|
color_change = False
|
||||||
|
running = True
|
||||||
|
|
||||||
|
while running:
|
||||||
|
for event in pg.event.get():
|
||||||
|
if event.type == pg.QUIT:
|
||||||
|
running = False
|
||||||
|
if event.type == pg.MOUSEBUTTONDOWN: # Запуск игры
|
||||||
|
if color_change == False:
|
||||||
|
animation = True
|
||||||
|
game.side_change()
|
||||||
|
color_change = True
|
||||||
|
else:
|
||||||
|
game.side_change()
|
||||||
|
game.check()
|
||||||
|
if animation:
|
||||||
|
game.animation()
|
||||||
|
pg.display.update()
|
||||||
|
screen.fill((40, 40, 40))
|
||||||
|
game.render(screen)
|
||||||
|
pg.display.flip()
|
||||||
|
pg.display.quit()
|
||||||
|
|||||||
Reference in New Issue
Block a user