Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into quinn
Browse files Browse the repository at this point in the history
  • Loading branch information
qastanley committed Aug 29, 2020
2 parents b8034a6 + 3cc3e8f commit 97aae8d
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 96 deletions.
48 changes: 48 additions & 0 deletions game/common/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from game.common.game_object import GameObject
from game.common.enums import *
from game.common.map import Map
import random
import json


class Contract(GameObject):
def __init__(self, name=None, region=None, cities=None):
super().__init__()
self.object_type = ObjectType.contract

# if no name is supplied it will generate a random one
self.name = self.generateName() if not name else name
# region is region enum
self.region = region

# cities is a list of strings representing the keys for the nodes within the graph
self.cities = cities

def to_json(self):
data = super().to_json()
data['name'] = self.name
data['region'] = self.region
data['cities'] = self.cities
return data

def from_json(self,data):
super().from_json(data)
self.name = data['name']
self.region = data['region']
self.cities = data['cities']

# generates a random name, has no effect on gameplay other than lols
def generateName(self):
verb = ["Deliver ", "Transport ", "Drop off ", "Ship "]
quantity = ["a lot ", "several ", "one ", "a few "]
adjective = ["big ", "small ", "happy ", "sad ", "angry "]
noun = ["lobsters", "cd players", "power converers sourced from Tosche station", "Patented Skinner Burgers"]
# Literally making code worse for a joke
index = random.randrange(len(noun))
if index == 3:
return random.choice(verb) + random.choice(quantity) + "of" + noun[index]
else:
return random.choice(verb) + random.choice(quantity) + "of " + random.choice(adjective) + noun[index]

def __eq__(self, other):
return isinstance(other, self.__class__) and self.name == other.name and self.region == other.region and self.cities == other.cities
6 changes: 4 additions & 2 deletions game/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ class ObjectType:
player = 2
node = 3
truck = 4
contract = 5

class ActionType:
none = 0
select_route = 1
choose_speed = 2
buy_gas = 3
upgrade = 4
select_contract = 5

class LocationType:
class Region:
none = 0
grass_lands = 1
mount_vroom = 2
Expand All @@ -31,4 +33,4 @@ class RoadType:
none = 0
rural = 1
street = 2
highway = 3
highway = 3
51 changes: 0 additions & 51 deletions game/common/location_types.py

This file was deleted.

5 changes: 4 additions & 1 deletion game/common/map.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#This needs to be a game object desperately
# STATIC METHODS BAAAAAAAAAAADDDDDDDDDDD
class Map():
#This needs work but oh well
cities = dict()
roads = dict()

# This part is probs obsolete
@staticmethod
def getRoadByName(name):
return roads[name]

# This part is probs obsolete
@staticmethod
def getCityByName(name):
return cities[name]
Expand Down
19 changes: 8 additions & 11 deletions game/common/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,33 @@
from game.common.map import Map

class Node(GameObject):


#Name is the key for this node in the graph it must be unique
def __init__(self, name):
super().__init__()
self.object_type = ObjectType.node
self.city_name = name
self.location_type = LocationType.none
self.region = Region.none
self.connections = list()
# registers this object to the graph with city_name as the key
Map.cities[self.city_name] = self

def to_json(self):
data = super().to_json()
data['location_type'] = self.location_type
data['region'] = self.region
data['city_name'] = self.city_name
data['connections'] = self.connections
return data

def from_json(self, data):
super().from_json(data)
self.location_type = data['location_type']
self.region = data['region']
self.city_name = data['city_name']
self.connections = data['connections']
Map.cities[self.city_name] = self

def Connect(self,cityToConnect, roadName):
# this method connects two cities together and generates a road object
def Connect(self, cityToConnect, roadName):
road = Road(roadName,self.city_name,cityToConnect.city_name)
self.connections.append(road.road_name)
return road






18 changes: 15 additions & 3 deletions game/common/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
from game.common.action import Action
from game.common.game_object import GameObject
from game.common.enums import *
from game.common.contract import Contract
from game.common.truck import Truck


class Player(GameObject):
def __init__(self, code=None, team_name=None, action=None):
# truck initialized with placeholder
def __init__(self, code=None, team_name=None, action=None, contract=None, truck=Truck("HUB"):
super().__init__()
self.object_type = ObjectType.player

Expand All @@ -15,6 +18,8 @@ def __init__(self, code=None, team_name=None, action=None):
self.team_name = team_name
self.code = code
self.action = action
self.truck = truck
self.active_contract = contract

def to_json(self):
data = super().to_json()
Expand All @@ -23,6 +28,8 @@ def to_json(self):
data['error'] = self.error
data['team_name'] = self.team_name
data['action'] = self.action.to_json() if self.action is not None else None
data['truck'] = self.truck.to_json()
data['active_contract'] = self.active_contract.to_json()

return data

Expand All @@ -34,10 +41,15 @@ def from_json(self, data):
self.team_name = data['team_name']
act = Action()
self.action = act.from_json(data['action']) if data['action'] is not None else None

truck = Truck()
self.truck = truck.from_json(data['truck'])
contract = Contract()
self.active_contract = contract.from_json(data['active_contract'])

def __str__(self):
p = f"""ID: {self.id}
Team name: {self.team_name}
Action: {self.action}
Contracts: {self.active_contract}
"""
return p
return p
51 changes: 51 additions & 0 deletions game/common/region.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from game.common.node import Node
from game.common.enums import Region
from game.common.stats import GameStats


class Grass_Lands(Node):
def __init__(self):
super().__init__()
self.region = Region.grass_lands
self.reward_modifier = GameStats.region_reward_modifier[self.region]
self.difficulty_modifier = GameStats.node_difficulty_modifier[self.region]


class Nord_Dakotia(Node):
def __init__(self):
super().__init__()
self.region = Region.nord_dakotia
self.reward_modifier = GameStats.region_reward_modifier[self.region]
self.difficulty_modifier = GameStats.region_difficulty_modifier[self.region]


class Mobave_Desert(Node):
def __init__(self):
super().__init__()
self.region = Region.mobave_desert
self.reward_modifier = GameStats.region_reward_modifier[self.region]
self.difficulty_modifier = GameStats.region_difficulty_modifier[self.region]


class Mount_Vroom(Node):
def __init__(self):
super().__init__()
self.region = Region.mount_vroom
self.reward_modifier = GameStats.region_reward_modifier[self.region]
self.difficulty_modifier = GameStats.region_difficulty_modifier[self.region]


class Loblantis(Node):
def __init__(self):
super().__init__()
self.region = Region.loblantis
self.reward_modifier = GameStats.region_reward_modifier[self.region]
self.difficulty_modifier = GameStats.region_difficulty_modifier[self.region]


class Tropical_Cop_Land(Node):
def __init__(self):
super().__init__()
self.region = Region.tropical_cop_land
self.reward_modifier = GameStats.region_reward_modifier[self.region]
self.difficulty_modifier = GameStats.region_difficulty_modifier[self.region]
3 changes: 3 additions & 0 deletions game/common/road.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import json

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):
super().__init__()
self.object_type = ObjectType.node
self.road_name = name
self.road_type = RoadType.none
self.city_1 = city1
self.city_2 = city2
# 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

def to_json(self):
Expand Down
30 changes: 15 additions & 15 deletions game/common/stats.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from game.common.enums import LocationType
from game.common.enums import Region


class GameStats:
location_reward_modifier = {
LocationType.grass_lands: .5,
LocationType.nord_dakotia: .6,
LocationType.mobave_desert: .7,
LocationType.mount_vroom: .8,
LocationType.loblantis: .8,
LocationType.tropical_cop_land: .9,
region_reward_modifier = {
Region.grass_lands: .5,
Region.nord_dakotia: .6,
Region.mobave_desert: .7,
Region.mount_vroom: .8,
Region.loblantis: .8,
Region.tropical_cop_land: .9,
}

location_difficulty_modifier = {
LocationType.grass_lands: .5,
LocationType.nord_dakotia: .6,
LocationType.mobave_desert: .7,
LocationType.mount_vroom: .8,
LocationType.loblantis: .8,
LocationType.tropical_cop_land: .9,
region_difficulty_modifier = {
Region.grass_lands: .5,
Region.nord_dakotia: .6,
Region.mobave_desert: .7,
Region.mount_vroom: .8,
Region.loblantis: .8,
Region.tropical_cop_land: .9,
}
19 changes: 11 additions & 8 deletions game/common/truck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
from game.common.enums import *
from game.common.road import *
from game.common.map import Map
from game.common.node import Node

# Probably need to add some extra stuff
class Truck(GameObject):

def __init__(self, node = None):
super().__init__()
self.object_type = ObjectType.truck
self.current_node = node
self.contract_list = []
self.active_contract = None

def get_city_contracts(self):
return self.contract_list

def get_active_contract(self):
return self.active_contract

def to_json(self):
data = super().to_json()
Expand All @@ -19,11 +28,5 @@ def to_json(self):

def from_json(self, data):
super().from_json(data)
self.current_node = data['current_node']







node = Node()
self.current_node = node.from_json(data['current_node'])
Loading

0 comments on commit 97aae8d

Please sign in to comment.