generated from mwc/project_game
Compare commits
3 Commits
28274e7a09
...
d047592c5c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d047592c5c | ||
|
|
0247bdb16a | ||
|
|
45f45a428f |
BIN
__pycache__/path.cpython-312.pyc
Normal file
BIN
__pycache__/path.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/person.cpython-312.pyc
Normal file
BIN
__pycache__/person.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/spawner.cpython-312.pyc
Normal file
BIN
__pycache__/spawner.cpython-312.pyc
Normal file
Binary file not shown.
10
new.py
Normal file
10
new.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from retro.game import Game
|
||||
from person import Person
|
||||
from spawner import CarSpawner
|
||||
from path import Car
|
||||
|
||||
board_size = (25, 25)
|
||||
person = Person(board_size)
|
||||
spawner = CarSpawner()
|
||||
game = Game([person,spawner], {"score": 0,"lives":3}, board_size=board_size,color="black_on_white")
|
||||
game.play()
|
||||
53
path.py
Normal file
53
path.py
Normal file
@@ -0,0 +1,53 @@
|
||||
class Car:
|
||||
character = 'OO'
|
||||
|
||||
def __init__(self, position):
|
||||
self.position = position
|
||||
|
||||
#def play_turn(self, game):
|
||||
# lives = 5
|
||||
# width, height = game.board_size
|
||||
# if game.turn_number % 2 == 0:
|
||||
# x, y = self.position
|
||||
# if y == height - 1:
|
||||
# game.remove_agent(self)
|
||||
# else:
|
||||
# ship = game.get_agent_by_name('ship')
|
||||
# new_position = (x, y + 1)
|
||||
# if new_position == ship.position:
|
||||
# lives = lives-1
|
||||
# game.state["lives"] -=1
|
||||
# if game.state["lives"] == 0:
|
||||
# game.end()
|
||||
#else:
|
||||
# self.position = new_position
|
||||
|
||||
def play_turn(self, game):
|
||||
lives = 3
|
||||
width, height = game.board_size
|
||||
if game.turn_number % 2 == 0:
|
||||
x, y = self.position
|
||||
if x == width - 1:
|
||||
game.remove_agent(self)
|
||||
else:
|
||||
person = game.get_agent_by_name('person')
|
||||
new_position = (x+1, y)
|
||||
|
||||
# if game.turn_number % 2 == 1:
|
||||
# x, y = self.position
|
||||
#if x == width - 1:
|
||||
# game.remove_agent(self)
|
||||
# else:
|
||||
# person = game.get_agent_by_name('person')
|
||||
# new_position = (x-1, y)
|
||||
|
||||
|
||||
|
||||
|
||||
if new_position == person.position:
|
||||
lives = lives-1
|
||||
game.state["lives"] -=1
|
||||
if game.state["lives"] == 0:
|
||||
game.end()
|
||||
else:
|
||||
self.position = new_position
|
||||
24
person.py
Normal file
24
person.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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)
|
||||
if game.on_board(new_position):
|
||||
if game.is_empty(new_position):
|
||||
self.position = new_position
|
||||
else:
|
||||
game.end()
|
||||
16
spawner.py
Normal file
16
spawner.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from random import randint
|
||||
from path import Car
|
||||
|
||||
class CarSpawner:
|
||||
display = False
|
||||
|
||||
def play_turn(self, game):
|
||||
width, height = game.board_size
|
||||
game.state['score'] += 1
|
||||
if self.should_spawn_car(game.turn_number):
|
||||
#car = Car((randint(0, width - 1), 0))
|
||||
car = Car((0, randint(0, height - 1)))
|
||||
game.add_agent(car)
|
||||
|
||||
def should_spawn_car(self, turn_number):
|
||||
return randint(0, 1000) < turn_number
|
||||
Reference in New Issue
Block a user