generated from mwc/project_game
I made it so the cars go from left to right instead of top to bottom. I also added that players get 3 lives and changed the color of the background to black on white. I also made the cars 2 wide.
At first it was tough for me to figure out how to get the cars to move from left to right. I was able to figure this out by emailing you and also thinking about where it was telling the cars to spawn in the retro lab and changing that part of the code. I had to change a few lines of code where it used the height parameter and changed it to width. I was able to overcome this by thinking about what each individual line of code did and what I needed to change to fix it. I have gotten a lot better at debugging code and understanding what each line of code is doing throughout the semester. I would tell a future student to really think about what each line of code is doing and try to follow along and you should find many of your mistakes.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
new.py
11
new.py
@@ -1,9 +1,10 @@
|
||||
from retro.game import Game
|
||||
from person import Spaceship
|
||||
from spawner import AsteroidSpawner
|
||||
from person import Person
|
||||
from spawner import CarSpawner
|
||||
from path import Car
|
||||
|
||||
board_size = (25, 25)
|
||||
ship = Spaceship(board_size)
|
||||
spawner = AsteroidSpawner()
|
||||
game = Game([ship, spawner], {"score": 0,"lives":5}, board_size=board_size)
|
||||
person = Person(board_size)
|
||||
spawner = CarSpawner()
|
||||
game = Game([person,spawner], {"score": 0,"lives":3}, board_size=board_size,color="black_on_white")
|
||||
game.play()
|
||||
26
path.py
26
path.py
@@ -1,5 +1,5 @@
|
||||
class Asteroid:
|
||||
character = 'O'
|
||||
class Car:
|
||||
character = 'OO'
|
||||
|
||||
def __init__(self, position):
|
||||
self.position = position
|
||||
@@ -23,16 +23,28 @@ class Asteroid:
|
||||
# self.position = new_position
|
||||
|
||||
def play_turn(self, game):
|
||||
lives = 5
|
||||
lives = 3
|
||||
width, height = game.board_size
|
||||
if game.turn_number % 2 == 0:
|
||||
x, y = self.position
|
||||
if y == height - 1:
|
||||
if x == width - 1:
|
||||
game.remove_agent(self)
|
||||
else:
|
||||
ship = game.get_agent_by_name('ship')
|
||||
new_position = (x, y + 1)
|
||||
if new_position == ship.position:
|
||||
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:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Spaceship:
|
||||
name = "ship"
|
||||
class Person:
|
||||
name = "person"
|
||||
character = '^'
|
||||
|
||||
def __init__(self, board_size):
|
||||
|
||||
13
spawner.py
13
spawner.py
@@ -1,15 +1,16 @@
|
||||
from random import randint
|
||||
from path import Asteroid
|
||||
from path import Car
|
||||
|
||||
class AsteroidSpawner:
|
||||
class CarSpawner:
|
||||
display = False
|
||||
|
||||
def play_turn(self, game):
|
||||
width, height = game.board_size
|
||||
game.state['score'] += 1
|
||||
if self.should_spawn_asteroid(game.turn_number):
|
||||
asteroid = Asteroid((randint(0, width - 1), 0))
|
||||
game.add_agent(asteroid)
|
||||
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_asteroid(self, turn_number):
|
||||
def should_spawn_car(self, turn_number):
|
||||
return randint(0, 1000) < turn_number
|
||||
Reference in New Issue
Block a user