Compare commits

...

13 Commits

Author SHA1 Message Date
fecf047a5f simple window test 2022-08-11 14:30:13 +02:00
6555ed56b8 Add future games 2022-08-11 09:57:47 +02:00
4a8d02efd2 Add Chess 2022-08-11 09:53:41 +02:00
232bb211ee Delete Chess 2022-08-11 09:53:09 +02:00
d1f6110b10 Create Chess 2022-08-11 09:53:00 +02:00
cd50022bef Update README 2022-08-06 11:52:18 +02:00
aa6c9e907f Add img 2022-08-06 11:48:57 +02:00
142a684fd6 Merge pull request #1 from d3vyce/beta
Beta
2022-08-06 11:46:54 +02:00
9a681d7618 Adjustment of the level difficulty 2022-08-06 11:42:56 +02:00
b98cff34e3 Add score 2022-08-06 11:42:29 +02:00
bd8d9fc2fb Add img 2022-08-06 11:42:13 +02:00
e46fe34ea0 add FPS to draw_level function 2022-08-06 11:20:38 +02:00
fdeff9e17f Add info text on screen 2022-08-06 11:19:26 +02:00
11 changed files with 53 additions and 12 deletions

1
Chess/README.md Normal file
View File

@ -0,0 +1 @@

0
Chess/main.py Normal file
View File

2
Chess/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pygame
numpy

4
Chess/src/board.py Normal file
View File

@ -0,0 +1,4 @@
import src.board, src.board
import pygame
from pygame.locals import *

0
Chess/src/pieces.py Normal file
View File

View File

@ -1,3 +1,13 @@
Python Game
# Python Game
Here are the different games I've made so far in python.
- Snake [Current Project]
- Snake
<p>
<img src="Snake/img/Snake.png" width="500" title="hover text">
</p>
- Chess [WIP]
- Sudoku [SOON]
- Pandemic [SOON]

View File

@ -1,4 +1,6 @@
Snake in Python using pygame
# Snake in Python using pygame
![plot](./img/Snake.png)
## Install
```
@ -11,4 +13,4 @@ pip install -r .\requirements.txt
## Start Application
```
python .\main.py
```
```

BIN
Snake/img/Snake.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -18,14 +18,15 @@ def main():
Running = True
Direction = 'right'
Direction_prev = 'right'
Move_loop = 30
Move_loop = 10
Score = 0
Difficulty = 10
Difficulty = 1
Fruit = False
# Spawn snake head
L_snake = snake.List((5, 5), None)
# Spawn first apple
level.spawn_apple(Matrix, HEIGH, WIDTH)
while Running:
@ -48,7 +49,7 @@ def main():
Direction = Direction_prev
try:
L_snake, Matrix, Fruit = snake.Snake_move(Matrix, L_snake, Direction, HEIGH, WIDTH)
L_snake, Matrix, Fruit, Score = snake.Snake_move(Matrix, L_snake, Direction, Score, HEIGH, WIDTH)
except ValueError as Error:
if Error.args[0] == 1:
print("You take a wall !")
@ -60,12 +61,14 @@ def main():
level.spawn_apple(Matrix, HEIGH, WIDTH)
Direction_prev = Direction
Move_loop = 30 - Difficulty*2
if(Score > 1000):
Difficulty = int(Score/1000) + 1
Move_loop = 11 - Difficulty
Move_loop -= 1
# Draw Scene
Screen = window.draw_level(Screen, Matrix, Difficulty, Score, HEIGH, WIDTH)
Screen = window.draw_level(Screen, Matrix, Difficulty, Score, int(clock.get_fps()), HEIGH, WIDTH)
pygame.display.flip()
# Print current fps

View File

@ -29,7 +29,7 @@ class List:
return i
def Snake_move(M, L, dir, heigh, width):
def Snake_move(M, L, dir, score, heigh, width):
Fruit = False
List_save = L
Save_Value = L.val
@ -71,7 +71,8 @@ def Snake_move(M, L, dir, heigh, width):
# If snake eat fruit -> spawn new segment at the end of the snake
if Fruit:
List_save = List.List_add(List_save, Save_Value)
score += 50
else:
M[Save_Value[0]][Save_Value[1]] = 0
return List_save, M, Fruit
return List_save, M, Fruit, score

View File

@ -3,17 +3,35 @@ from pygame.locals import *
def init_game():
pygame.init()
pygame.font.init()
screen = pygame.display.set_mode((1000, 525), pygame.SCALED)
pygame.display.set_caption("Snake")
return screen
def draw_level(S, M, difficulty, score, heigh, width):
def draw_level(S, M, difficulty, score, fps, heigh, width):
WHITE = (255, 255, 255) # AIR
GREEN = (0, 255, 0) # SNAKE
BROWN = (255,248,220) # WALL
RED = (255, 0, 0) # APPLE
# Reset screen
pygame.draw.rect(S, (0, 0, 0), pygame.Rect(0, 0, 1000, 525))
my_font = pygame.font.SysFont('Comic Sans MS', 18)
# Add FPS counter
text_fps = my_font.render(str(fps) + ' fps', False, (255, 255, 255))
S.blit(text_fps, (10, 0))
# Add Score
text_score = my_font.render('Score : '+ str(score), False, (255, 255, 255))
S.blit(text_score, (400, 0))
# Add Diffucilty
text_difficulty = my_font.render('Difficulty : '+ str(difficulty), False, (255, 255, 255))
S.blit(text_difficulty, (850, 0))
Color = WHITE
for j in range(heigh):