Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events #36

Merged
merged 19 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions game/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ class Region:

class RoadType:
none = 0
rural = 1
street = 2
highway = 3
mountain_road = 1
forest_road = 2
tundra_road = 3
highway = 4
city_road = 5
interstate = 6

class EventType:
none = 0
rock_slide = 1
icy_road = 2
animal_in_road = 3
bandits = 4
police = 5
traffic = 6

class NodeType:
none = 0
Expand Down
7 changes: 3 additions & 4 deletions game/common/road.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
class Road(GameObject):
# name is the key for this edge, it must always be unique
# city1 and city2 are strings representing the keys of the connected cities
def __init__(self, name ,city1=None, city2=None, length=GameStats.default_road_length):
def __init__(self, name, road_type=RoadType.none, city1=None, city2=None, length=GameStats.default_road_length):
super().__init__()
self.object_type = ObjectType.node
self.road_name = name
self.road_type = RoadType.none
self.road_distance = length
self.road_type = road_type
self.city_1 = city1
self.city_2 = city2
self.length = length
self.length = length * GameStats.road_type_length_modifier[self.road_type]
# upon finishing up it adds itself to the graph. could add some errors if the key isn't unique
Map.roads[self.road_name] = self

Expand Down
41 changes: 39 additions & 2 deletions game/common/stats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from game.common.enums import Region

from game.common.enums import *

class GameStats:
default_road_length = 100
Expand All @@ -22,10 +21,48 @@ class GameStats:
Region.tropical_cop_land: .9,
}

road_type_length_modifier = {
RoadType.mountain_road: 1,
RoadType.forest_road: 1,
RoadType.tundra_road: 1.5,
RoadType.city_road: 1.5,
RoadType.highway: 2,
RoadType.interstate: 2
}

possible_event_types = {
RoadType.mountain_road: [EventType.rock_slide, EventType.animal_in_road, EventType.icy_road, EventType.police],
RoadType.forest_road: [EventType.animal_in_road, EventType.police, EventType.rock_slide, EventType.icy_road],
RoadType.tundra_road: [EventType.icy_road, EventType.police, EventType.rock_slide],
RoadType.city_road: [EventType.bandits, EventType.police, EventType.traffic],
RoadType.highway: [EventType.police, EventType.traffic],
RoadType.interstate: [EventType.traffic, EventType.police]
}

event_type_damage = {
EventType.animal_in_road: 10,
EventType.bandits: 20,
EventType.icy_road: 5,
EventType.police: 5,
EventType.rock_slide: 5,
EventType.traffic: 5
}

event_type_time = {
EventType.animal_in_road: 5,
EventType.bandits: 5,
EventType.icy_road: 10,
EventType.police: 20,
EventType.rock_slide: 10,
EventType.traffic: 20
}

game_max_time = 10000

player_starting_money = 1000

truck_starting_gas = 1

truck_starting_max_gas = 1

truck_starting_health = 50
4 changes: 3 additions & 1 deletion game/common/truck.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, node = None):
self.gas = GameStats.truck_starting_gas
self.max_gas = GameStats.truck_starting_max_gas
self.speed = 50
self.health = GameStats.truck_starting_health

def get_city_contracts(self):
return self.contract_list
Expand All @@ -34,7 +35,8 @@ def set_current_speed(self, speed):

def to_json(self):
data = super().to_json()
data['current_node'] = self.current_node
node = self.current_node.to_json()
data['current_node'] = node
data['gas'] = self.gas
data['max_gas'] = self.max_gas
data['speed'] = self.speed
Expand Down
21 changes: 21 additions & 0 deletions game/controllers/event_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from game.common.stats import GameStats
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event_controller needs a method that determines if an event happens.

from game.common.enums import EventType
import random

def trigger_event(road, player):
# Picks random event type from those possible on given road
possible_event_type_count = len(GameStats.possible_event_types[road.road_type])
chosen_event_type = EventType.none
if possible_event_type_count == 4:
chosen_event_type = random.choices(GameStats.possible_event_types[road.road_type], weights=[4,3,2,1], k=1)
if possible_event_type_count == 3:
chosen_event_type = random.choices(GameStats.possible_event_types[road.road_type], weights=[3,2,1], k=1)
if possible_event_type_count == 2:
chosen_event_type = random.choices(GameStats.possible_event_types[road.road_type], weights=[2,1], k=1)
# Deal damage based on event
player.truck.health -= GameStats.event_type_damage[chosen_event_type]
# Reduce remaining time based on event
player.time -= GameStats.event_type_time[chosen_event_type]



4 changes: 3 additions & 1 deletion game/controllers/master_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def __init__(self):

# Receives all clients for the purpose of giving them the objects they will control
def give_clients_objects(self, client):
client.truck = Truck("HUB")
start_node = Node('Start Node')
start_node.region = Region.nord_dakotia
client.truck = Truck(start_node)
pass

# Generator function. Given a key:value pair where the key is the identifier for the current world and the value is
Expand Down
20 changes: 10 additions & 10 deletions game/utils/CreateMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
# STATIC METHOD BAAADDDD
def generateMap():
start = Node("HUB")
a = Node("CityA")
b = Node("CityB")
c = Node("CityC")
d = Node("CityD")
# a = Node("CityA")
# b = Node("CityB")
# c = Node("CityC")
# d = Node("CityD")

start.Connect(a,"RA")
start.Connect(b,"RB")
start.Connect(c,"RC")
start.Connect(d,"RD")
a.Connect(b,"RE")
d.Connect(c,"RF")
# start.Connect(a,"RA")
# start.Connect(b,"RB")
# start.Connect(c,"RC")
# start.Connect(d,"RD")
# a.Connect(b,"RE")
# d.Connect(c,"RF")
10 changes: 5 additions & 5 deletions game/utils/contract_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def generate_contracts(client):
city_list = []
hub = None
for city in Map.cities.values():
if city.region == Map.getCityByName(client.truck.current_node).region:
if city.region == Map.getCityByName(client.truck.current_node.city_name).region:
city_list.append(city)
for city in Map.cities.values():
if 'hub' in city.city_name.lower():
hub = city

# Placeholder contract generation
contract_list = [
Contract(None, Map.getCityByName(client.truck.current_node).region, [hub, random.choice(city_list)]),
Contract(None, Map.getCityByName(client.truck.current_node).region, [hub, random.choice(city_list)]),
Contract(None, Map.getCityByName(client.truck.current_node).region, [hub, random.choice(city_list)])]
Contract(None, Map.getCityByName(client.truck.current_node.city_name).region, [hub, random.choice(city_list)]),
Contract(None, Map.getCityByName(client.truck.current_node.city_name).region, [hub, random.choice(city_list)]),
Contract(None, Map.getCityByName(client.truck.current_node.city_name).region, [hub, random.choice(city_list)])]

return contract_list
return contract_list