For our first EECS 581 project, we expanded upon an existing web service.
Overview of Initial Web Service:
Upon start of the service the user opens an html page (index.html) that initiates a connection with a web server (node server). All interaction between the Client and Server is accomplished utilizing the methods: GET, POST, PUT and DELETE. The JSON protocol is used on both ends to syntactically arrange the bi-directional communications.Our lab setup is on Linux workstations in the Senior Design Lab at the University of Kansas.
The commands to get started with the starter code package are:
//download the package from git hub (you will need a git account if you don't already have one)
$git clone https://github.com/ku-eecs-capstone/lab2.git
//navigate into the newly downloaded directory
$cd lab2
//install the local hosting package
$npm install express (so that we may install and run the node modules locally)
//start the server running
$node server.js
//start the user by opening Firefox (or Chrome) and in the browser bar type:
localhost:3000
Now the game will begin... you can roam around KU campus and interact in different locations - the ultimate goal is to help the basketball game begin by finding, picking up, and delivering the basketball to Allen Field House.
Adding Non-Interference
Non-Interference was defined by allowing more than one user in the game's universe (aka on KU Campus), where each user's actions were unique to themself. The starter code behaves poorly when two people are walking around and picking up items since the entire inventory list is maintained on the client-side in a local browser-based inventory. The server does not have the ability to distinguish one user from the other so when Player 1 picks up a Coffee - it also appears as Player 2 having picked up the Coffee. The implementation expansion to correct this was to create an array of users (much like the existing array model of the campus) indexed by randomly generated id's. Upon launch of the game on a browser, a function would be called to create a new cookie (we added the appropriate express module listed below to use cookies), assign it a randomly generated number as an ID, and add that new user to the array in the index of the id.
$npm install cookie-parser
$npm install cookie-parser
Adding Interaction
Interaction adds a level of users being aware of each other in the universe in order to interact. We create a unique personal inventory per id by referring to the appropriate user in the array when handling inventory anywhere in our program, initializing each user with an inventory containing their own laptop upon start of the game. This way if Player 1 picked up the Coffee at Strong Hall the Coffee would disappear from the view of Player 2. Our implementation of this idea was not perfect since the browser does not automatically refresh. This means that the player would have to refresh their browser or complete some sort of action in the game to see that the inventory available in a room was changed.
Adding Persistence
Persistence is the idea that when a user re-enters the game their "universe" is the same way it was when they left it. It persists! Our implementation of persistence was for the user to hold the same inventory and be in the same room as when they last left the game upon restarting. We approached this type of persistence by adding the layer of node - mySQL support and backing the server initialization with database records. The appropriate command to add the mySQL module is listed below. A user's data does NOT persist if the browser cache is deleted (a cookie is attached to the browser). The user does not have to explicitly define log on information; their "universe" is stored on the individual computer and browser that they initially accessed the game from. We realize that this does not yet address the possibility that a user could "leave" the game with all inventory (including the basketball required to win the game) so that any other user entering the game has no inventory to manipulate (except possibly their own laptop) or way to win the game.
$npm install mysql
$npm install mysql
No comments:
Post a Comment