generated from mwc/project_game
I coded the introduction part of my game.
In this milestone I created necessary files such as Starfall, starfall_spawner, person, and questioner. I used smaple codes from Retro and adjusted them to suit my purposes. I am proud of the Questioner file. I was intimidated that I would drop the ball on the dialogue spawn but after frustrating few tries, I manges to make it look and spawn as I wanted it to. I am now worried about how to make the starfall_spawner launch and abort as intended (start after answers then pause once player collects 200 points.) I learned new skills with how to accept input answers. I was reading up on ways to sort the answers and I learned about strip and upper functions that help remove spaces and lowercase specifications!
This commit is contained in:
BIN
__pycache__/person.cpython-312.pyc
Normal file
BIN
__pycache__/person.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/player.cpython-312.pyc
Normal file
BIN
__pycache__/player.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/questioner.cpython-312.pyc
Normal file
BIN
__pycache__/questioner.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/starfall.cpython-312.pyc
Normal file
BIN
__pycache__/starfall.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/starfall_spawner.cpython-312.pyc
Normal file
BIN
__pycache__/starfall_spawner.cpython-312.pyc
Normal file
Binary file not shown.
23
person.py
Normal file
23
person.py
Normal file
@@ -0,0 +1,23 @@
|
||||
class Person:
|
||||
name = "Person"
|
||||
character = '^'
|
||||
|
||||
def __init__(self, board_size):
|
||||
board_width, board_height = board_size
|
||||
self.position = (board_width // 2, board_height - 1)
|
||||
|
||||
def handle_keystroke(self, keystroke, game):
|
||||
x, y = self.position
|
||||
if keystroke.name == "KEY_LEFT":
|
||||
new_position = (x - 1, y)
|
||||
elif keystroke.name == "KEY_RIGHT":
|
||||
new_position = (x + 1, y)
|
||||
elif keystroke.name == "KEY_UP":
|
||||
new_position = (x, y - 1)
|
||||
elif keystroke.name == "KEY_DOWN":
|
||||
new_position = (x, y + 1)
|
||||
else:
|
||||
return
|
||||
|
||||
if game.on_board(new_position) and game.is_empty(new_position):
|
||||
self.position = new_position
|
||||
25
player.py
Normal file
25
player.py
Normal file
@@ -0,0 +1,25 @@
|
||||
class Person:
|
||||
name = "Person"
|
||||
character = '^'
|
||||
|
||||
def __init__(self, board_size):
|
||||
board_width, board_height = board_size
|
||||
self.position = (board_width // 2, board_height - 1)
|
||||
|
||||
def handle_keystroke(self, keystroke, game):
|
||||
x, y = self.position
|
||||
if keystroke.name in ("KEY_LEFT", "KEY_RIGHT", "KEY_UP", "KEY_DOWN"):
|
||||
if keystroke.name == "KEY_LEFT":
|
||||
new_position = (x - 1, y)
|
||||
if keystroke.name == "KEY_RIGHT":
|
||||
new_position = (x + 1, y)
|
||||
if keystroke.name == "KEY_UP":
|
||||
new_position = (x, y + 1)
|
||||
if keystroke.name == "KEY_DOWN":
|
||||
new_position = (x, y -1)
|
||||
else:
|
||||
new_position =(x,y)
|
||||
|
||||
if game.on_board(new_position):
|
||||
if game.is_empty(new_position):
|
||||
self.position = new_position
|
||||
30
questioner.py
Normal file
30
questioner.py
Normal file
@@ -0,0 +1,30 @@
|
||||
class Questioner:
|
||||
name = "Questioner"
|
||||
character = '?'
|
||||
|
||||
def __init__(self, board_size):
|
||||
board_width, board_height = board_size
|
||||
self.position = (board_width // 2, board_height // 2)
|
||||
|
||||
def play_turn(self,game):
|
||||
person = game.get_agent_by_name('Person')
|
||||
if person:
|
||||
personx, persony = person.position
|
||||
questionerx, questionery = self.position
|
||||
if personx == questionerx and persony == questionery +1:
|
||||
prompt = input("Questioner: Are you ready to start the game? [[Y/N]] \n")
|
||||
if prompt.strip().upper() == "Y":
|
||||
print("Questioner: Well then, the rules are as follows... \n 1. You have 3 lives. \n 2. For every 200 points you accumulate during Starfall, you receive a question. \n 3. Each wrong answer costs you a life. You must answer 3 questions to escape this terminal. \n")
|
||||
|
||||
begin = input("Questioner: Shall we begin? [[Y/N]] \n" )
|
||||
if begin.strip().upper() == "Y":
|
||||
print("Questioner: Well then, good luck player! \n")
|
||||
game.state["begin"] = True
|
||||
|
||||
|
||||
elif prompt.strip().upper() == "N":
|
||||
print("Questioner: I'll be here when you're ready. \n")
|
||||
else:
|
||||
print("Questioner: What now?) \n")
|
||||
|
||||
|
||||
19
starfall.py
Normal file
19
starfall.py
Normal file
@@ -0,0 +1,19 @@
|
||||
class Star:
|
||||
character = '*'
|
||||
|
||||
def __init__(self, position):
|
||||
self.position = position
|
||||
|
||||
def play_turn(self, game):
|
||||
width, height = game.board_size
|
||||
if game.turn_number % 2 == 0:
|
||||
x, y = self.position
|
||||
if y == height - 1:
|
||||
game.remove_agent(self)
|
||||
else:
|
||||
person = game.get_agent_by_name('Person')
|
||||
new_position = (x, y + 1)
|
||||
if new_position == person.position:
|
||||
game.end()
|
||||
else:
|
||||
self.position = new_position
|
||||
11
starfall_game.py
Normal file
11
starfall_game.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from retro.game import Game
|
||||
from person import Person
|
||||
from questioner import Questioner
|
||||
from starfall_spawner import StarfallSpawner
|
||||
|
||||
board_size = (50, 30)
|
||||
player = Person(board_size)
|
||||
questioner = Questioner(board_size)
|
||||
spawner = StarfallSpawner()
|
||||
game = Game([player, questioner, spawner], {"score": 0, "begin": False}, board_size=board_size)
|
||||
game.play()
|
||||
17
starfall_spawner.py
Normal file
17
starfall_spawner.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from random import randint
|
||||
from starfall import Star
|
||||
|
||||
class StarfallSpawner:
|
||||
display = False
|
||||
|
||||
def play_turn(self, game):
|
||||
if not game.state.get("begin"):
|
||||
return
|
||||
width, height = game.board_size
|
||||
game.state['score'] += 1
|
||||
if self.should_spawn_star(game.turn_number):
|
||||
star = Star((randint(0, width - 1), 0))
|
||||
game.add_agent(star)
|
||||
|
||||
def should_spawn_star(self, turn_number):
|
||||
return randint(0, 1000) < turn_number
|
||||
Reference in New Issue
Block a user