Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
239 commits
Select commit Hold shift + click to select a range
55b8aca
Update README.md with Hackiflette team description.
Hboni Apr 10, 2018
906cfe6
Class for cards
ldehaine Apr 11, 2018
bc099b8
Class for hands
ldehaine Apr 11, 2018
db01bfc
Class for deck
ldehaine Apr 11, 2018
c804d29
add __init__ to CardsAPI
ldehaine Apr 11, 2018
3d0897d
Add Type Hints (+PEP8)
ldehaine Apr 11, 2018
607e5ce
Merge pull request #2 from Cataboum/CardsAPI
Hboni Apr 11, 2018
044fa18
Merge pull request #3 from Cataboum/master
Hboni Apr 11, 2018
f59c4be
Make deck generation simpler
ldehaine Apr 12, 2018
f3acaab
Merge pull request #4 from Cataboum/CardsAPI
ldehaine Apr 12, 2018
dc3dca8
fix property value, used to mutate cardList attribute, not anymore
ldehaine Apr 12, 2018
a3a5fcf
Reorgansation of this project's structure and add some screens
deplanty Apr 12, 2018
d712d51
Merge branch 'bug_fix' of https://github.com/Cataboum/BlackJackProjec…
deplanty Apr 12, 2018
71db1e2
Add split method for Hand, + comments, docstrings
ldehaine Apr 12, 2018
32cb82a
Update image path
Hboni May 4, 2018
9edf0f8
Add split hand handling
ldehaine May 5, 2018
f67c52a
Merge pull request #5 from Cataboum/CardsAPI
ldehaine May 5, 2018
3ea0e62
PEP8 indent
Hboni May 19, 2018
8e87390
Add card tests
Hboni May 23, 2018
60753b8
Configure travis CI
Hboni May 23, 2018
d46d20b
Add build statut in README
Hboni May 23, 2018
66799dd
Merge pull request #6 from Hackiflette/travis_tests
Hboni May 23, 2018
de0f5cf
Update test_cards and add tests
Hboni Jun 2, 2018
879844a
Add tests of hand API
Hboni Jun 2, 2018
69293e2
Merge pull request #7 from Hackiflette/travis_tests
Hboni Jun 2, 2018
5b2eba0
Bug fixing: images load correctly
deplanty Jun 9, 2018
2a5e24a
Change menu background
Hboni Jun 9, 2018
5d69d2e
Bug fix: images load correctly v2
deplanty Jun 9, 2018
ff511df
Merge remote-tracking branch 'origin/bug_fix' into bug_fix
Hboni Jun 9, 2018
4c104cc
New files and folder organisation
deplanty Jun 9, 2018
a4a944b
add cards images
ldehaine Jun 9, 2018
8d80c8c
main.py is at root
deplanty Jun 9, 2018
0a3ada1
Merge branch 'bug_fix' of https://github.com/Cataboum/BlackJackProjec…
deplanty Jun 9, 2018
51bef11
change in naming convention
ldehaine Jun 9, 2018
442a56d
change in naming convention
ldehaine Jun 9, 2018
49d6b7b
Merge branch 'bug_fix' of https://github.com/Cataboum/BlackJackProjec…
ldehaine Jun 9, 2018
7c49bea
modify src/common
deplanty Jun 9, 2018
a629497
PEP8
Hboni Jun 9, 2018
2f65342
Create main of BlackJack to view menu
Hboni Jun 9, 2018
f587038
Fixes error build, change name
Hboni Jun 9, 2018
a6c2bf0
Update hand test PEP8
Hboni Jun 9, 2018
038bdb0
Update hand test PEP8
Hboni Jun 9, 2018
699b274
Create views directory and move view_menu
Hboni Jun 10, 2018
6cbd785
Update import view in main.py
Hboni Jun 10, 2018
328fced
Create LICENSE
Hboni Jun 10, 2018
a0ee49f
Update README with License badge
Hboni Jun 10, 2018
08e2141
Merge remote-tracking branch 'origin/bug_fix' into bug_fix
Hboni Jun 10, 2018
260461a
Remove old pictures directory
Hboni Jun 10, 2018
cf9492c
Add blackjack_table.png and create view_game.py
Hboni Jun 10, 2018
757c9e7
Add pygame import
Hboni Jun 10, 2018
72645b2
Update view_menu and add view_game in main
Hboni Jun 10, 2018
8e5c557
Change to more appropriate exception type
ldehaine Jun 13, 2018
f6ae66e
Create enum for states and update views
Hboni Jun 17, 2018
6505d1a
Merge branch 'bug_fix' into dev_views
Hboni Jun 17, 2018
6ad08ec
Merge pull request #8 from Hackiflette/dev_views
Hboni Jun 17, 2018
23e22c8
Update README
Hboni Jun 18, 2018
6cf9086
Change function name toRegexp->cardColorToRegexp
ldehaine Jun 27, 2018
3d25c54
rename, spaces are evil
ldehaine Jul 14, 2018
c6d0f0b
Player and Dealer classes, WIP
ldehaine Jul 14, 2018
14c8930
Button class creation
deplanty Jul 14, 2018
689e517
option button
GeoffreyE Jul 14, 2018
0aa0095
option button + path to view_option
GeoffreyE Jul 14, 2018
643f67c
option button + path to view_option
GeoffreyE Jul 14, 2018
bdbc27b
remove .pyc
ldehaine Jul 14, 2018
27988c5
remove .pyc
ldehaine Jul 14, 2018
48405b7
Add files via upload
GeoffreyE Jul 14, 2018
62f13e4
Delete __init__.cpython-36.pyc
GeoffreyE Jul 14, 2018
06b6fe6
Delete __init__.cpython-36.pyc
GeoffreyE Jul 14, 2018
af2bcad
Delete constants.cpython-36.pyc
GeoffreyE Jul 14, 2018
64029aa
Delete func_pictures.cpython-36.pyc
GeoffreyE Jul 14, 2018
78b14fc
Merge branch 'bug_fix' of https://github.com/Cataboum/BlackJackProjec…
ldehaine Jul 14, 2018
3e4b435
Merge branch 'bug_fix' of https://github.com/Cataboum/BlackJackProjec…
ldehaine Jul 14, 2018
846b9b8
Merge branch 'bug_fix' of https://github.com/Hackiflette/BlackJackPro…
GeoffreyE Jul 14, 2018
0dc042d
changed to standard python .gitignore
ldehaine Jul 14, 2018
0a10192
remove .pyc
ldehaine Jul 14, 2018
a694da6
option button + path to view_option
GeoffreyE Jul 14, 2018
54ca093
Merge branch 'bug_fix' of https://github.com/Hackiflette/BlackJackPro…
GeoffreyE Jul 14, 2018
9f79852
Test for deck
Jul 14, 2018
8ea757d
Update view_menu with text "quit" and "start"
GeoffreyE Jul 14, 2018
b80c711
Merge remote-tracking branch 'origin/bug_fix' into bug_fix
GeoffreyE Jul 14, 2018
255e129
Update button code
deplanty Jul 14, 2018
14726e2
Another update for the button (it works now)
deplanty Jul 14, 2018
0299cc7
Create Button tests
Hboni Jul 14, 2018
8a07040
New line
Hboni Jul 14, 2018
f57f173
Update Travis to use pygame
Hboni Jul 14, 2018
c681d8d
Update Travis to use pygame
Hboni Jul 14, 2018
b1e4a0c
Update Travis to use pygame
Hboni Jul 14, 2018
63da5f0
Use ui.cfg.json for buttons position
Hboni Jul 21, 2018
c4193e2
Delete helloWorld.py
Hboni Jul 21, 2018
61026a1
Modify the way our constants are used in the code: c.constant
deplanty Jul 21, 2018
7cf3bad
Merge branch 'bug_fix' of https://github.com/Hackiflette/BlackJackPro…
deplanty Jul 21, 2018
a4b2fd2
Changed import xx as c to import xx as cst
ldehaine Sep 9, 2018
48749b0
First version of Dealer class
ldehaine Sep 9, 2018
cf5dd2b
Ass Decision enumeration
ldehaine Sep 9, 2018
36fae2e
Revert "Ass Decision enumeration"
ldehaine Sep 9, 2018
524cf22
replace button in menu
GeoffreyE Sep 9, 2018
3ed79b2
Add Decision enumeration
ldehaine Sep 9, 2018
5eb613f
Merge remote-tracking branch 'origin/bug_fix' into bug_fix
GeoffreyE Sep 9, 2018
3272026
update button start options and quit
GeoffreyE Sep 9, 2018
a842e5b
Code reviewing and reformating
deplanty Sep 9, 2018
4d0b274
Code reviewing and reformating for pytest
deplanty Sep 9, 2018
0737ed3
Add borders and text color to Buttons
deplanty Sep 9, 2018
fa457e9
Add mode to use "Dealer hits on soft 17" rule, still defaults to "Dea…
ldehaine Sep 10, 2018
d27f3d9
Initiate game_manager as the main controler for the game
Hboni Sep 15, 2018
9528d3a
Separate the init of the game window of the init og the controler
Hboni Sep 15, 2018
7fec7b0
Create a class for view_game
Hboni Sep 15, 2018
ca3ff2f
Import and use the game_manager in main.py
Hboni Sep 15, 2018
bb81237
Use config file and data for button pos
Hboni Sep 15, 2018
0c03f11
Add a gameLoop function in main
Hboni Sep 29, 2018
ec72e1f
Update README
Hboni Sep 29, 2018
3d756ff
Test the add of a card on the window
Hboni Sep 30, 2018
811d63d
Update the display of the test card and add pictures config
Hboni Sep 30, 2018
f31cf27
Create a function to find the picture name of a Card object
Hboni Sep 30, 2018
545f9ea
Rename Game_manager in Game_controller and correct controller typo
Hboni Sep 30, 2018
cc0bd8d
Update card picture path
Hboni Sep 30, 2018
b9acb88
Update card add on window
Hboni Sep 30, 2018
ba13ae6
Merge pull request #9 from Hackiflette/dev_controler
Hboni Sep 30, 2018
d5125ed
Merge remote-tracking branch 'origin/bug_fix' into bug_fix
Hboni Sep 30, 2018
ae975ef
Create requirement.txt
Hboni May 19, 2019
f3022db
add pycharm project in .gitignore
Hboni May 19, 2019
d5e226a
update first card view on game window
Hboni May 19, 2019
0ec140d
pep8
ldehaine May 25, 2019
cfaeb34
Clean up
ldehaine May 25, 2019
4458861
refactor imports
ldehaine May 25, 2019
9b8edbe
Adding name for the Dealer
ChretienCml May 25, 2019
4fe4387
Merge branch 'bug_fix' of https://github.com/Hackiflette/BlackJackPro…
ChretienCml May 25, 2019
ee72532
controller : gestion des joueurs, appel du choix des joueurs
LAxelle May 25, 2019
1412364
Merge pull request #10 from Hackiflette/dev_controller
LAxelle May 25, 2019
acbf610
Adding new feature for the player double split and bet
ChretienCml May 25, 2019
69abb7e
Fixing synthax error
ChretienCml May 25, 2019
e89acee
Adding PLayer class testing. Fixing Deck method changing and testing
ChretienCml May 25, 2019
04e5be4
Adding splitting test and check for Hand and Player
ChretienCml May 25, 2019
6b68066
Various fixes, simplifications and pep8-ing
ldehaine May 25, 2019
72fd7cc
fix import
ldehaine May 25, 2019
1beaeea
fix import, again
ldehaine May 25, 2019
0065e5a
Fixes, mutable default args are bad
ldehaine May 26, 2019
f3b9da1
typo
ldehaine May 26, 2019
935531c
improve view management
ldehaine May 25, 2019
ca48071
fix
ldehaine May 30, 2019
d494175
fix
ldehaine May 30, 2019
e28d846
update tests
ldehaine May 30, 2019
dab0619
Merge pull request #13 from Hackiflette/fixes_improvements
Hboni May 30, 2019
89d89e4
Add Enum for menu cursor actions
Hboni Jun 1, 2019
30eb74b
Add value parameter for Button
Hboni Jun 1, 2019
611ef76
Add the use of arrow to move a cursor on menu & typo
Hboni Jun 1, 2019
04c0616
Deck shuffling update (#17)
ldehaine Jun 22, 2019
9a22411
Merge pull request #18 from Hackiflette/dev_menu
Hboni Jun 23, 2019
0f1d82e
Fix behavior of Hand's __iadd__ method
ldehaine Jun 22, 2019
c7c94d9
Update docstring in Hand __add__ and black-ing files
ldehaine Jun 22, 2019
91f6855
fix bug in Hand's __iadd__ method and update tests
ldehaine Jun 22, 2019
c158834
cosmetic changes + add some typehints
ldehaine Jun 28, 2019
c6c66f5
Add vscode project folder
deplanty Jul 6, 2019
8013df0
Load the path file as a class
deplanty Jul 6, 2019
e135ed3
add button area and quit button on game
Hboni Jul 6, 2019
43696cb
link the quit button to really quit game
Hboni Jul 6, 2019
2509866
Use ConfigPath class
deplanty Jul 6, 2019
e1e75cd
Add test for the ConfigPath class
deplanty Jul 6, 2019
5ee1415
Move game_buttons in game config
Hboni Jul 6, 2019
bcf22de
Update pytest
deplanty Jul 6, 2019
b9eee11
Use moussebuttonup instead moussebuttondown
Hboni Jul 6, 2019
c97a5c4
Merge pull request #20 from Hackiflette/config_parser
deplanty Jul 6, 2019
99da207
Merge pull request #21 from Hackiflette/dev_game_buttons
Hboni Jul 6, 2019
c552739
delete tests in code
Hboni Jul 6, 2019
3f43a54
View refactoring (#22)
ldehaine Jul 15, 2019
59b80dd
quick fix for autocompletion (#23)
ldehaine Jul 16, 2019
0790780
five new buttons
LAxelle Jul 27, 2019
d45a43d
Add tokens in the project
deplanty Jul 27, 2019
19b05d9
add functionality to button
LAxelle Jul 27, 2019
ce12945
correction for buttons
LAxelle Jul 27, 2019
45270c7
correction for pull request
LAxelle Jul 27, 2019
63021ce
correction for pull request 2
LAxelle Jul 27, 2019
3b944b0
Merge pull request #24 from Hackiflette/newbuttons
Hboni Jul 27, 2019
92196da
Implement a class to use the tokens
deplanty Jul 27, 2019
783bcb1
Create a first round to initialize the game. Initialize the name of t…
ChretienCml Jul 27, 2019
8508ec3
Merge branch 'bug_fix' into initialize_player
ChretienCml Jul 27, 2019
269ec0c
Translate to english
deplanty Jul 27, 2019
b74f187
Update to use configuration files
deplanty Jul 27, 2019
b4c2a48
Update folder usage with the ConfigPath class
deplanty Jul 27, 2019
4b2e622
Initialize Tokens in main
deplanty Jul 27, 2019
68df352
Create a first round to initialize the game. Initialize the name of t…
ChretienCml Jul 27, 2019
0a259ac
Call initializePlayers in gameLoop
ChretienCml Jul 27, 2019
d280026
Blit a token on the game view
deplanty Jul 27, 2019
3d9d53c
Merge branch 'initialize_player' of https://github.com/Hackiflette/Bl…
ChretienCml Jul 27, 2019
b9e34aa
Update game_controller.py
ChretienCml Jul 27, 2019
6d864e2
Merge pull request #25 from Hackiflette/initialize_player
ChretienCml Jul 27, 2019
99d1d3c
Update test to use abspath
deplanty Jul 27, 2019
d8fc3cb
Iterate directly through values
deplanty Jul 27, 2019
25c2730
Add newline at EOL for PEP8 purpose
deplanty Jul 27, 2019
9e863f4
Comment correction
deplanty Jul 27, 2019
ba76de2
Merge conflict resolution
deplanty Jul 27, 2019
c78a79f
Merge pull request #26 from Hackiflette/tokens-init
deplanty Jul 27, 2019
899bcd7
rename Card file into card
Hboni Jul 28, 2019
d03c40f
rename Deck file into deck
Hboni Jul 28, 2019
468f8c4
rename Exception file into exception
Hboni Jul 28, 2019
85f459d
rename Hand file into hand
Hboni Jul 28, 2019
e82c1ee
Rename CardsAPI directory
Hboni Aug 3, 2019
451649c
update tests for new module names
Hboni Aug 3, 2019
5b8f0f4
Merge pull request #27 from Hackiflette/rename_file_snake
Hboni Aug 3, 2019
9c8b1dc
Rename Button folder
Hboni Sep 1, 2019
ad821bf
Rename humans files folder
Hboni Sep 1, 2019
caf4d2f
fixes errors in tests
Hboni Sep 1, 2019
885b376
rename button in comment
Hboni Sep 1, 2019
c42b9c9
Merge pull request #28 from Hackiflette/rename_file_snake
Hboni Sep 1, 2019
16afa9c
resize tokens and add alpha (#29)
ldehaine Sep 1, 2019
0710546
update readme
LAxelle Sep 1, 2019
5fc89c3
Merge pull request #30 from Hackiflette/update_read_me
LAxelle Sep 1, 2019
bcdb1ca
Remove useless imports
deplanty Sep 1, 2019
df7957d
Manage several hands during rounds
Hboni Sep 29, 2019
916a460
Empty hands at the end of turn
Hboni Sep 29, 2019
4112b1e
Manage dealer decision in game controller
Hboni Sep 29, 2019
430d5b2
Add manage of win
Hboni Sep 29, 2019
5b30c2b
fixes split
Hboni Sep 29, 2019
1b887d7
Merge pull request #33 from Hackiflette/player_round
Hboni Sep 29, 2019
9c539ea
Load Images (#32)
ldehaine Sep 29, 2019
b86cadf
Buttons event (#34)
deplanty Sep 29, 2019
0407809
Fix merge problem on buttons_event
deplanty Sep 29, 2019
fa86504
Can disable a button
deplanty Sep 29, 2019
583060c
Button update itself in the window when drawn
deplanty Sep 30, 2019
50c867c
Update view and control to use the disabled button
deplanty Sep 30, 2019
d5a80c0
Set correct button size and position
deplanty Oct 1, 2019
0c67e40
Set the button actions in the button methods
deplanty Oct 1, 2019
45ca527
Set enabled/disabled as an attribute
deplanty Oct 2, 2019
410dbb7
Add a missing parentesis
deplanty Oct 2, 2019
6c81d2c
Merge pull request #35 from Hackiflette/buttons_state
deplanty Oct 2, 2019
3d27eff
Merge branch 'bug_fix' into game_buttons_actions_positions
deplanty Oct 2, 2019
ff26228
Merge pull request #39 from Hackiflette/game_buttons_actions_positions
deplanty Oct 2, 2019
51b779b
Redraw the button when changing its state
deplanty Oct 2, 2019
b1cadca
Fix the first round actions
deplanty Oct 2, 2019
6f1ccc8
Set a color when button is pressed
deplanty Oct 27, 2019
e7518ea
Enable and disable buttons easily
deplanty Oct 27, 2019
e700d87
PEP8 fix : too much whitesapces
deplanty Oct 27, 2019
1a62915
Fix bug of brain
deplanty Oct 27, 2019
a975387
Merge pull request #44 from Hackiflette/game_play_loops
deplanty Oct 27, 2019
0370c1c
Set game view buttons in config file
deplanty Oct 27, 2019
3e36c6f
Remove useless import and whitespace
deplanty Oct 27, 2019
513b885
Manage bet turn to allow the player to bet multiple time (5 by 5) (#45)
Hboni Oct 27, 2019
7728b38
Merge pull request #46 from Hackiflette/buttons_in_config
deplanty Oct 27, 2019
96e91c4
config_game_view is a dict
deplanty Oct 27, 2019
00f827b
Add codecoverage! (#49)
Hboni Oct 31, 2019
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
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = */tests/*
110 changes: 110 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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/
*.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/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Pycharm project
.idea/

# VSCode project
.vscode/
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: python
python:
- "3.6"

# Command to run tests
install:
- pip3 install -r requirements.txt
script:
- python -m pytest --cov=src
after_success:
- coveralls
42 changes: 42 additions & 0 deletions ExamplePygame/Stars/class_enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Enum:
"""
A C++ like enum

:param args: a list of strings

:Example:

enum = Enum(
"splash",
"mainMenu",
"quit"
)

state = enum.splash

if state == enum.splash:
state = enum.mainMenu
else:
state = enum.quit

enum.print(state)
"""

def __init__(self, *args):

self.__i = 0
self.__names = args

for name in args:
setattr(self, name, self.__i)
self.__i += 1

def print(self, i: int, **kwargs):
"""
Print the name of the enum

:param i: the value of the Enum
:param kwargs: the common keyword arguments for the print function
"""

print(self.__names[i], **kwargs)
28 changes: 28 additions & 0 deletions ExamplePygame/Stars/class_star.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pygame


class Star(pygame.sprite.Sprite):
"""
A shooting star

kwargs is used to define where the rect is placed
"""

speed = 2
images = list()
screenRect = None

def __init__(self, **kwargs):
pygame.sprite.Sprite.__init__(self, self.containers)

self.image = self.images[0]
self.rect = self.image.get_rect(**kwargs)

def update(self):
"""
Update the star at each iteration
"""

self.rect.move_ip(self.speed, 0)
if not self.screenRect.contains(self.rect):
self.kill()
17 changes: 17 additions & 0 deletions ExamplePygame/Stars/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

from class_enum import Enum


DIRMAIN = os.path.dirname(__file__)
DIRFILES = os.path.join(DIRMAIN, "files")
DIRIMAGES = os.path.join(DIRMAIN, "images")
DIRSOUNDS = os.path.join(DIRMAIN, "sounds")


ENUM = Enum(
"splash",
"mainmenu",
"play",
"quit"
)
22 changes: 22 additions & 0 deletions ExamplePygame/Stars/func_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

import pygame

from constants import DIRIMAGES


def load_image(filename: str) -> pygame.Surface:
"""
Loads an image and prepares it

:param filename: the path to the image
:return: the image converted
"""

try:
surface = pygame.image.load(os.path.join(DIRIMAGES, filename))
except pygame.error:
error = "Could not load image \"%s\" %s" % (filename, pygame.get_error())
raise SystemExit(error)

return surface.convert()
77 changes: 77 additions & 0 deletions ExamplePygame/Stars/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
import json

import pygame
from pygame.locals import *

from constants import *
from screen_splash import screen_splash
from screen_mainmenu import screen_mainmenu
from screen_play import screen_play


class Main:
"""
The main application
"""

def __init__(self):

# Configuration
self.load_config()

# Init pygame
self.init_pygame()

# mainloop
self.mainloop()

def load_config(self):
"""
Load the configuration file
"""

fileConfig = os.path.join(DIRFILES, "config.json")
with open(fileConfig, "r", encoding="utf-8") as f:
self.config = json.load(f)

def init_pygame(self):
"""
Intialize the main screen
"""

size = self.config["screen"]["size"]
self.screenRect = Rect(0, 0, *size)

pygame.init()
pygame.font.init()

self.window = pygame.display.set_mode(self.screenRect.size)

def mainloop(self):
"""
The mainloop the launch the game
"""

state, param = screen_splash(self.window)

while state != ENUM.quit:

ENUM.print(state)

if state == ENUM.mainmenu:
state, param = screen_mainmenu(self.window, param)

elif state == ENUM.play:
param["config"] = self.config
param["screenRect"] = self.screenRect
state, param = screen_play(self.window, param)

else:
state = ENUM.quit

pygame.quit()


if __name__ == '__main__':
Main()
37 changes: 37 additions & 0 deletions ExamplePygame/Stars/screen_mainmenu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pygame
from pygame.locals import *

from constants import *


def screen_mainmenu(window: pygame.Surface, param: dict = dict()) -> tuple:
"""
The splash screen

:param window: The main window where to display the game
:param param: Some parameters from another screen
:return: The state of the next screen and a dict with some parameters
"""

state = ENUM.mainmenu

font = pygame.font.SysFont('Comic Sans MS', 30)
textSurface = font.render('Main Menu', False, (0, 0, 0))

window.fill((0, 127, 127))
window.blit(textSurface, (0, 0))

while state == ENUM.mainmenu:

# Check for events
for event in pygame.event.get():
if event.type == QUIT:
state = ENUM.quit
elif (event.type == KEYDOWN and event.key == K_ESCAPE):
state = ENUM.quit
elif (event.type == KEYDOWN and event.key == K_RETURN):
state = ENUM.play

pygame.display.flip()

return state, dict()
Loading