Skip to content

Implementation Document

Yiou Chen edited this page May 27, 2018 · 6 revisions

Technologies:

General:

  • prettier JavaScript code formatter
  • Jest JavaScript unit testing

Server:

  • Socket.io websocket implementation in nodeJS

Client

Not decided.

Data structures

Game board

  • an array of size n x m
  • Each element in the array represent a tile
  • Each road has reference to the next roads, each property has reference to the connected properties. Each road tile has reference to the property tie to this road. (roads cannot be properties)
  • Tiles can be accessed using the index or coordinates, each tile also stores its own index and coordinates
  • Starting position
  • Properties has base price

Game state:

  • Current player
  • Game state (started, finished)
  • Player has location in the board (x, y)
  • Player has direction that he is traveling
  • Player has last path travelled, denoted in an array of coordinates [(x1, y1), (x2, y2), (x3, y3)]
  • Player has cash value
  • Player has index, player can be accessed using index, player also stores its own index
  • Property has rent, initial rent is 0
  • Property has ownership, denoted by player’s index

Messages:

Messages:

General format

socket.emit(var1, var2)
client < - > server
var1: type, 
var2: data
socket.emit(“ACTION_TYPE”,  { DATA: ‘’});

Client messages for rooms

Client login

type: LOGIN
data: {username: 'zebra'}
// server will send back an clientId

Client request join room

type: JOIN
data: {
	roomId: ‘unique id’
}

Client leaving room

type: LEAVE
data: {}

Client ready

type: READY
data: {}

Host start

type: START
data: {}

Host kick another client

type: KICK
data: { userId: '12345' }

Client create room

type: CREATE_ROOM
data: {roomName: 'desert'}
// server send back room id

Client chat

type: CHAT
data: {message: 'Hello'}
// publicly visible in the current room

Server messages for rooms

Server sends message back to client upon client request

Client login

type: LOGIN_ACCEPT
data: {}

Client request join room

type: JOIN_ACCEPT
data: {}

type: JOIN_ERROR
data: {
    errorType: 'ROOM_NOT_FOUND' or ...
}

Send room information to client

// server will send this immediately to client when they join.
// Also when there is any update
type: ROOM_STATE
data: {...}

Client leaving room

type: LEAVE_ACCEPT
data: {}

Client ready

type: READY_ACCEPT
data: {}

Host start

// send to all client
type: GAME_START
data: {}

Client disconnect

// To be decided

Host kick another client

type: KICK_ACCEPT
data: {}

type KICK_ERROR
data: {
    errorType: 'USER_NOT_FOUND', 'NO_PERMISSION' ...
}

Client create room

type: CREATE_ROOM_ACCEPT
data: {roomId: '12345'}

type: CREAT_ROOM_ERROR
data: { errorType: 'TOO_MANY_ROOMS'}

Client chat

type: CHAT
data: {message: 'Hello', messageId: 1, username: "name", extra: {} }
// id increases when we have new message.
// publicly visible in the current room

Client messages for game

Client roll dice

type: DICE
data: {}

Passive response

type: RESPONSE
data: { response: 'yes', actionId: 1 }

Server messages for game

Game state update

type: GAME_STATE
data: {...}

Game state

{

    currentPlayerLastMove: [[x,y], [x, y], [x,y]],
    currentPlayer: id
    players: [
        {
            cash: 1000,
            position: [x, y],
            id: 1,
            direction: 'UP', 'DOWN', 'LEFT', 'RIGHT',
            status: 'LOST', 'JAIL'...
            currentActionID: [1, 2]
        }
    ],
    properties: {
        name{
            id1: {
                rent: 1000,
                position: [x, y],
                onwer: undefined or playerId
            },
            id2: {

            }
        }
        
    }
    
}


[ 4, 5,6,7]

Board state (static)

{ // TODO [0,1] { baseRent: 122 id: id123 neighborhood: name } }

currentActionArray = [buyHouseActionHandlers, buyStockActionHander]

var playerActions = []
playerActions[0].currentAction
client:
    socket.emit("yes", {answer: "yes"});
    
serer:
    gameState.client1.currentAction = buyStockActionHandler;
    socket.emit('do you want to buy');
    
    
    var buyHouseActionHandlers ={
        onYes: function() {
        
        },
        onNo: function() {
        
        }
    }
    var buyStockActionHander() {
        onYes: function() {
        
        }
    }
    
    socket.on("yes", function(){
        gameState.client1.currentAction.onYest();
    });

Hosting:

Naming convention

  • File/Folder name: camelCase
  • Function name: camelCase
  • Variable name: camelCase
  • Class name: CamelCase
  • Constants: SNAKE_CASE

Random things:

Update a rent: find the property tie to the road, traverse to left, and to right of the linked list, update the rent on all connected properties owned by the same owner before th update.

Clone this wiki locally