trying a new template indisn guy

This commit is contained in:
Stephen Deaton 2024-07-03 17:42:42 -04:00
parent 4c9336cd3b
commit 721f2939e2
6 changed files with 182 additions and 25 deletions

View File

@ -0,0 +1,32 @@
import pygame
pygame.init()
SCREEN_WIDTH = 800
SCREEN_HEIGTH = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGTH))
player = pygame.Rect((300,250,50,50))
run = True
while run:
screen.fill((0, 0, 0))
pygame.draw.rect(screen, (255, 0, 0), player)
key = pygame.key.get_pressed()
if key[pygame.K_a] == True:
player.move_ip(-1, 0)
elif key[pygame.K_d] == True:
player.move_ip(1, 0)
elif key[pygame.K_w] == True:
player.move_ip(0, -1)
elif key[pygame.K_s] == True:
player.move_ip(0, 1)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()

View File

@ -0,0 +1,56 @@
import pygame
import random
import os
WIDTH = 360
HEIGHT = 480
WINDOW_SIZE = (WIDTH, HEIGHT)
FPS = 30
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.surface((50, 50))
self.image.fill(GREEN)
self.rect = self.image.get_rect()
self.rect.center = (WIDTH /2, HEIGHT /2)
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()
all_sprites = pygame.sprite.group()
player = Player()
all_sprites.add(player)
running = True
while running:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
all_sprites.update()
screen.fill(BLACK)
all_sprites.draw(screen)
pygame.display.flip()
pygame.quit()

View File

@ -1,8 +1,11 @@
import pygame
import random
import os
WIDTH = 360
HEIGHT = 480
WINDOW_SIZE = (WIDTH, HEIGHT)
FPS = 30
WHITE = (255, 255, 255)
@ -13,10 +16,10 @@ BLUE = (0, 0, 255)
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode(360, 480)
screen = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
running = True
while running:
clock.tick(FPS)
@ -28,5 +31,5 @@ while running:
pygame.QUIT()
pygame.quit()

View File

@ -1,4 +1,33 @@
{
"title": "The Portents of Doom",
"description": "You have ventured into blah blah blah..."
"description": "You have ventured into blah blah blah...",
"rooms": [
{
"id": 0,
"name": "The Starting Room" ,
"discription": "The room is made up of stones worn smoth from age. It is 20 fett by 20 feet big.",
"action":"You awakin laying on the floor, there is a door on the North wall and on the East Wall",
"player": "What door do you choose.",
"directions": {"North": 2, "East": 1}
},
{
"id": 1,
"name" : "Second Room" ,
"discription" : "This room is boring as taxes.",
"action" :"You sell your soul to the devil",
"player" : "What door do you choose.",
"directions": {"West": 0}
},
{
"id": 2,
"name" : "Third Room" ,
"discription" : "This room is boring as taxes.",
"action" :"You sell your soul to the devil",
"player" : "What door do you choose.",
"directions": {"South": 0}
}
]
}

View File

@ -1,26 +1,64 @@
import json
import os
import sys
from pathlib import Path
from typing import List, Dict, Tuple
def game():
MAPDATA_FILE = os.path.join("mapdata.json")
VALID_DIRECTIONS = {
"n": "North",
"s": "South",
"e": "East",
"w": "West"
}
mapdata_raw = Path(MAPDATA_FILE).read_text()
mapdata = json.loads(mapdata_raw)
def get_room(data, room_id) -> Dict:
for room in data["rooms"]:
if room["id"] == room_id:
return room
answer = input('Would you like to play a game?(y/n)')
if answer.lower() == 'n':
print( 'Ok Maybe Some other time' )
sys.exit()
if answer.lower() =='y':
print('Welcome to the Adventure')
start = True
inventory = []
else:
print( 'Ok Maybe Some other time' )
player_room = 0
name = input("Enter Your Name : ")
print("Greetings, " + name + "\n###Let's Start the Game###")
print("""\nAs you slowly regained consciousness, you found yourself in a strange room bathed in an eerie glow.
There are three imposing doors, each beckoning you towards a different path.
Which door would you choose---1, 2 or 3???""")
#print("""\nAs you slowly regained consciousness, you found yourself in a strange room bathed in an eerie glow.
#There are three imposing doors, each beckoning you towards a different path.
#Which door would you choose---1, 2 or 3???""")
current_room_data = get_room(mapdata, player_room)
print(f"You wake up in {current_room_data['name']}")
print(f"\n{current_room_data['discription']}")
print(f"{current_room_data['action']}")
print(f"\n{current_room_data['player']}")
door = ""
while door not in current_room_data["directions"].keys():
print("Available directions to travel: ", end='')
for direction, room_id in current_room_data['directions'].items():
print(f" {direction}", end='')
print()
door = input(">")
door = door.lower()[0:1]
if door not in VALID_DIRECTIONS.keys():
print(" You bump into a wall of your own incompetence.")
door = ""
else:
door = VALID_DIRECTIONS[door]
player_room = current_room_data["directions"][VALID_DIRECTIONS[door.lower()[0:1]]]
current_room_data = get_room(mapdata, player_room)
if(door == "1"):
print("You entered the First room and through time travelling you found yourself in a an ancient Battle")
@ -82,4 +120,3 @@ if (door == "3"):
else:
print("Type a Number!!!\nGAME OVER\nPLEASE RESTART the GAME")
game()