Skip to content

Commit

Permalink
#4 rather efficient impl. using the json lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzt-ysmr committed Sep 17, 2016
1 parent 31851a1 commit 96082f8
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions data/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import json

class Player:
def __init__(self, id_, name_, position_, cash_):
Expand All @@ -8,11 +9,7 @@ def __init__(self, id_, name_, position_, cash_):
self.cash = cash_

def toJson(self):
id_str = "id : " + str(self.id)
name_str = "name : " + self.name
position_str = "position : " + str(self.position)
cash_str = "cash : " + str(self.cash)
return "{" + id_str + " , "+ name_str + " , "+ position_str + " , "+ cash_str + "}"
return json.dumps(self)

class Cell:
def __init__(self, id_, type_, owner_):
Expand All @@ -21,10 +18,7 @@ def __init__(self, id_, type_, owner_):
self.owner = owner_

def toJson(self):
id_str = "id : " + str(self.id)
type_str = "type : " + str(self.type)
owner_str = "owner : " + str(self.owner)
return "{" + id_str + " , " + type_str + " , " + owner_str + " , " + "}"
return json.dumps(self)


class Board:
Expand All @@ -38,5 +32,4 @@ def __new__(cls):
return cls._instance

def toJson(self):
cells_str = "cells_str : " + " , ".join( map( lambda c:c.toJson() , self.cells.toJson() ) )
return "{ " + cells_str + " }"
return json.dumps(self)

0 comments on commit 96082f8

Please sign in to comment.