Skip to content

Commit

Permalink
Merge pull request barryclark#35 from chaelimee/main
Browse files Browse the repository at this point in the history
메인 화면, 배경 삽입, 게임 선택 버튼 생성
  • Loading branch information
ParkJeonghyeon1013 authored Nov 30, 2023
2 parents 08dff0e + b3a2177 commit 8e16a2f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 71 deletions.
Binary file added image/common.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 43 additions & 71 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,36 @@
# main_game.py

import pygame
import sys
import subprocess
import os
from pygame.locals import *

def G_snake():
pygame.init()

screen = pygame.display.set_mode((400, 300))
pygame.display.set_caption("G_snake")

font = pygame.font.Font(None, 36)
clock = pygame.time.Clock()

while True:
screen.fill((255, 255, 255))
text = font.render("G_snake", True, (0, 0, 0))
screen.blit(text, (150, 150))
pygame.display.flip()

for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
def G_snake():
game_path = os.path.abspath("G_snake.py")
subprocess.run([sys.executable, game_path])
print("Selected Game: G_snake")

clock.tick(30)

def G_avoid():
pygame.init()

screen = pygame.display.set_mode((400, 300))
pygame.display.set_caption("G_avoid")

font = pygame.font.Font(None, 36)
clock = pygame.time.Clock()

while True:
screen.fill((255, 255, 255))
text = font.render("G_avoid", True, (0, 0, 0))
screen.blit(text, (150, 150))
pygame.display.flip()
game_path = os.path.abspath("G_avoid.py")
subprocess.run([sys.executable, game_path])
print("Selected Game: G_avoid")

for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

clock.tick(30)

def G_memoryGame():
pygame.init()

screen = pygame.display.set_mode((400, 300))
pygame.display.set_caption("G_memoryGame")

font = pygame.font.Font(None, 36)
clock = pygame.time.Clock()

while True:
screen.fill((255, 255, 255))
text = font.render("G_memoryGame", True, (0, 0, 0))
screen.blit(text, (150, 150))
pygame.display.flip()

for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

clock.tick(30)
game_path = os.path.abspath("G_memoryGame.py")
try:
subprocess.run([sys.executable, game_path], check=True)
print("Selected Game: G_memoryGame")
except subprocess.CalledProcessError as e:
print(f"Error while running G_memoryGame: {e}")


def display_text(screen, font, text, x, y):
text_surface = font.render(text, True, (0, 0, 0))
text_rect = text_surface.get_rect(center=(x, y))
screen.blit(text_surface, text_rect)

def main():
pygame.init()
Expand All @@ -79,33 +39,45 @@ def main():
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Main Game")

# 배경 이미지 로드
background_image = pygame.image.load("image/common.jpeg")
background_rect = background_image.get_rect()

font = pygame.font.Font(None, 36)
clock = pygame.time.Clock()

games = [G_snake, G_avoid, G_memoryGame]
selected_game = 0
selected_game = None

while True:
screen.fill((255, 255, 255))
screen.blit(background_image, background_rect)

game_names = ["Snake Game", "Avoid Game", "Memory Game"]
for i, game_name in enumerate(game_names):
text = font.render(game_name, True, (0, 0, 0))
text_rect = text.get_rect(center=(width // 2, 50 + i * 50))
screen.blit(text, text_rect)

for i, game in enumerate(games):
text = font.render(f"Game {i + 1}", True, (0, 0, 0))
screen.blit(text, (width // 2 - 50, 50 + i * 50))
display_text(screen, font, f"Selected Game: {selected_game}", width // 2, height - 50)

pygame.display.flip()

for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
x, y = event.pos
for i, game in enumerate(games):
text_rect = font.render(game_names[i], True, (0, 0, 0)).get_rect(center=(width // 2, 50 + i * 50))
if text_rect.collidepoint(x, y):
selected_game = game_names[i]
games[i]()
break
elif event.type == KEYDOWN:
if event.key == K_UP:
selected_game = (selected_game - 1) % len(games)
elif event.key == K_DOWN:
selected_game = (selected_game + 1) % len(games)
elif event.key == K_RETURN:
# 선택된 게임 실행
games[selected_game]()
if event.key == K_q:
pygame.quit()
sys.exit()

clock.tick(30)

Expand Down

0 comments on commit 8e16a2f

Please sign in to comment.