initial commit
248
.gitignore
vendored
Normal file
@ -0,0 +1,248 @@
|
||||
Created by https://www.toptal.com/developers/gitignore/api/pycharm,python
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=pycharm,python
|
||||
|
||||
### PyCharm ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
.idea
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### PyCharm Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator-enh.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
.idea/codestream.xml
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
pytestdebug.log
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
doc/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
pythonenv*
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# profiling data
|
||||
.prof
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/pycharm,python
|
BIN
images/Tiles/grass_01.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
images/Tiles/grass_02.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
images/Tiles/grass_mine_01.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
images/Tiles/grass_mine_02.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
images/Tiles/grass_rock_01.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
images/Tiles/grass_rock_02.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
images/Tiles/mud_01.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
images/Tiles/mud_02.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
images/Tiles/silt_01.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
images/Tiles/silt_02.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
images/mine_icon.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
images/sapper_idle/cpt_bomba.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
images/sapper_idle/cpt_bomba_left.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
images/sapper_idle/cpt_bomba_right.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
images/sapper_idle/idle.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
images/sapper_run/sapper_run_01.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
images/sapper_run/sapper_run_02.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
images/sapper_run/sapper_run_03.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
images/sapper_run/sapper_run_04.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
images/sapper_run/sapper_run_05.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
images/sapper_run/sapper_run_06.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
images/sapper_run/sapper_run_07.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
images/sapper_run/sapper_run_08.png
Normal file
After Width: | Height: | Size: 13 KiB |
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
pygame==2.0.1
|
0
src/__init__.py
Normal file
10
src/agent.py
Normal file
@ -0,0 +1,10 @@
|
||||
from const import SAPPER_IDLE
|
||||
|
||||
|
||||
class Agent:
|
||||
def __init__(self, x: int = 0, y: int = 0, x_px: int = 0, y_px: int = 0):
|
||||
self.img = SAPPER_IDLE
|
||||
self.x_px = x_px
|
||||
self.y_px = y_px
|
||||
self.x = x
|
||||
self.y = y
|
41
src/const.py
Normal file
@ -0,0 +1,41 @@
|
||||
from pygame import image
|
||||
|
||||
WIDTH = 800
|
||||
HEIGHT = 800
|
||||
|
||||
IMAGES = []
|
||||
for img in ['grass_01', 'grass_02', 'grass_mine_01', 'grass_mine_02', 'grass_rock_01', 'grass_rock_02']:
|
||||
IMAGES.append(image.load('C:/Users/matix/Documents/Python/Saper/images/Tiles/' + img + ".png"))
|
||||
|
||||
ICON = 'C:/Users/matix/Documents/Python/Saper/images/mine_icon.png'
|
||||
SAPPER_IDLE = image.load('C:/Users/matix/Documents/Python/Saper/images/sapper_idle/cpt_bomba.png')
|
||||
|
||||
SAPPER_RUNNING = []
|
||||
"""for img in [
|
||||
'sapper_run_01',
|
||||
'sapper_run_02',
|
||||
'sapper_run_03',
|
||||
'sapper_run_04',
|
||||
'sapper_run_05',
|
||||
'sapper_run_06',
|
||||
'sapper_run_07',
|
||||
'sapper_run_08',
|
||||
]:"""
|
||||
for img in [
|
||||
'cpt_bomba_left',
|
||||
'cpt_bomba_right',
|
||||
]:
|
||||
SAPPER_RUNNING.append(image.load('C:/Users/matix/Documents/Python/Saper/images/sapper_idle/' + img + ".png"))
|
||||
|
||||
DEFAULT_FIELD = [
|
||||
[1, 3, 4, 5, 0, 1, 2, 3, 2, 0],
|
||||
[1, 5, 0, 2, 1, 0, 4, 1, 0, 0],
|
||||
[1, 0, 1, 1, 5, 4, 5, 1, 5, 4],
|
||||
[4, 1, 5, 1, 0, 2, 4, 0, 3, 3],
|
||||
[1, 5, 0, 1, 4, 4, 1, 1, 1, 5],
|
||||
[1, 4, 5, 4, 0, 5, 4, 0, 2, 1],
|
||||
[0, 2, 1, 3, 0, 3, 5, 5, 5, 4],
|
||||
[1, 2, 0, 2, 0, 4, 0, 2, 0, 0],
|
||||
[5, 2, 0, 1, 3, 1, 2, 1, 0, 0],
|
||||
[2, 5, 1, 4, 5, 1, 0, 5, 4, 0],
|
||||
]
|
10
src/environment.py
Normal file
@ -0,0 +1,10 @@
|
||||
from typing import List
|
||||
|
||||
from const import DEFAULT_FIELD
|
||||
|
||||
|
||||
class Environment:
|
||||
def __init__(self, field: List[List[int]] = DEFAULT_FIELD):
|
||||
self.field = field
|
||||
self.rows = len(field)
|
||||
self.cols = len(field[0])
|
30
src/game_ui.py
Normal file
@ -0,0 +1,30 @@
|
||||
import pygame
|
||||
|
||||
from agent import Agent
|
||||
from environment import Environment
|
||||
from const import WIDTH, HEIGHT, IMAGES, SAPPER_RUNNING, SAPPER_IDLE
|
||||
|
||||
|
||||
class GameUi:
|
||||
def __init__(self, agent: Agent, env: Environment):
|
||||
self.agent = agent
|
||||
self.env = env
|
||||
self.clock = pygame.time.Clock()
|
||||
self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
|
||||
def move(self, coord: str, shift: int):
|
||||
setattr(self.agent, coord, getattr(self.agent, coord) + shift)
|
||||
for x in range(8):
|
||||
setattr(self.agent, f'{coord}_px', getattr(self.agent, f'{coord}_px') + (shift * 10))
|
||||
self.agent.img = SAPPER_RUNNING[x % 2]
|
||||
self.update()
|
||||
self.clock.tick(15)
|
||||
self.agent.img = SAPPER_IDLE
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
for x in range(10):
|
||||
for y in range(10):
|
||||
self.screen.blit(IMAGES[self.env.field[y][x]], (x * 80, y * 80))
|
||||
self.screen.blit(self.agent.img, (self.agent.x_px, self.agent.y_px))
|
||||
pygame.display.update()
|
40
src/main.py
Normal file
@ -0,0 +1,40 @@
|
||||
import pygame
|
||||
|
||||
from const import ICON
|
||||
from agent import Agent
|
||||
from game_ui import GameUi
|
||||
from environment import Environment
|
||||
|
||||
|
||||
def main():
|
||||
pygame.init()
|
||||
pygame.display.set_caption('Super Saper')
|
||||
pygame.display.set_icon(pygame.image.load(ICON))
|
||||
|
||||
env = Environment()
|
||||
agent = Agent()
|
||||
game_ui = GameUi(agent, env)
|
||||
game_ui.update()
|
||||
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
elif event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_d and agent.x_px < 700:
|
||||
game_ui.move('x', 1)
|
||||
elif event.key == pygame.K_a and agent.x_px > 5:
|
||||
game_ui.move('x', -1)
|
||||
elif event.key == pygame.K_s and agent.y_px < 700:
|
||||
game_ui.move('y', 1)
|
||||
elif event.key == pygame.K_w and agent.y_px > 0:
|
||||
game_ui.move('y', -1)
|
||||
elif event.key == pygame.K_SPACE:
|
||||
if env.field[agent.y][agent.x] in [2, 3]:
|
||||
env.field[agent.y][agent.x] -= 2
|
||||
game_ui.update()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|