Skip to content

Commit bfcf806

Browse files
Merge pull request avinashkranjan#2852 from Shikhar9425/master-9
Zhed.py
2 parents 9dc224d + b4f78e8 commit bfcf806

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

Zhed/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Package/Script Name: Zhed Game in Python
2+
3+
Short description of package/script: This script is a basic implementation of the puzzle game "Zhed" using the Pygame library. Zhed is a puzzle game where players move blocks to reach a target block.
4+
5+
Functionalities/Scripts:
6+
7+
Display a grid with a simple pattern using Pygame.
8+
Setup Instructions:
9+
10+
Ensure you have Python installed on your system.
11+
Install the Pygame library using the following command:
12+
bash
13+
Copy code
14+
pip install pygame
15+
Copy and paste the provided code into a file named zhed_game.py.
16+
How to Run:
17+
18+
Open a terminal or command prompt.
19+
Navigate to the directory where zhed_game.py is located.
20+
Run the script using the command:
21+
bash
22+
Copy code
23+
python zhed_game.py
24+
Detailed Explanation:
25+
This script initializes a Pygame window and displays a grid pattern on the screen. The main() function contains the main game loop, which listens for the quit event to close the game window. The draw_grid() function draws the grid lines on the screen.
26+
27+
Output:
28+
The script will display a window with a grid pattern similar to a chessboard.
29+
30+
Author:
31+
Shikhar9425
32+

Zhed/Zhed.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pygame
2+
import sys
3+
4+
# Initialize Pygame
5+
pygame.init()
6+
7+
# Constants
8+
WIDTH, HEIGHT = 400, 400
9+
GRID_SIZE = 5
10+
CELL_SIZE = WIDTH // GRID_SIZE
11+
12+
# Colors
13+
WHITE = (255, 255, 255)
14+
BLACK = (0, 0, 0)
15+
RED = (255, 0, 0)
16+
17+
# Create the screen
18+
screen = pygame.display.set_mode((WIDTH, HEIGHT))
19+
pygame.display.set_caption("Zhed")
20+
21+
# Main loop
22+
def main():
23+
running = True
24+
25+
while running:
26+
for event in pygame.event.get():
27+
if event.type == pygame.QUIT:
28+
running = False
29+
30+
screen.fill(WHITE)
31+
draw_grid()
32+
33+
pygame.display.flip()
34+
35+
pygame.quit()
36+
sys.exit()
37+
38+
# Draw the grid
39+
def draw_grid():
40+
for x in range(0, WIDTH, CELL_SIZE):
41+
pygame.draw.line(screen, BLACK, (x, 0), (x, HEIGHT))
42+
for y in range(0, HEIGHT, CELL_SIZE):
43+
pygame.draw.line(screen, BLACK, (0, y), (WIDTH, y))
44+
45+
# Start the game
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)