-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- moved folder structure to scaffold libs
- moved example in folder - moved libs to their own folder - improved exporting for server and client libs
- Loading branch information
Showing
65 changed files
with
2,492 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
# ws-gamelib | ||
some tests with websockets games | ||
## Backend | ||
``` | ||
npm install | ||
``` | ||
# Strummulu | ||
a small fullstack library to serve web-browser games based on websockets communication | ||
# Docs | ||
coming soon... | ||
|
||
``` | ||
npm run dev | ||
``` | ||
## Examples | ||
|
||
you can fuind some examples in the `example/` folder. | ||
|
||
### Revorbaro | ||
Frontend developed in **React**. | ||
|
||
Revorbaro is like Rock, Paper, Scissor but with a gun. | ||
|
||
You can **shoot** only if you have a bullet loaded, you will have a bullet loaded if you **reload** and you can **defend**. | ||
|
||
- 2 x **shoot** is a draw | ||
- **shoot** can be blocked by **defend** | ||
- if you **shoot** while someone else **reload**, you win. | ||
|
||
it is running at [https://revorbaro-ws.surge.sh](https://revorbaro-ws.surge.sh) | ||
|
||
|
||
|
||
## Frontend | ||
``` | ||
npm install | ||
``` | ||
|
||
``` | ||
npm start | ||
``` |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as strummulu } from './strummulu'; | ||
export { default as messageHandler } from './messageHandler'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "strummulu-client", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"socket.io-client": "^2.3.0" | ||
}, | ||
"scripts": { | ||
"test": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import openSocket from 'socket.io-client'; | ||
|
||
const logger = msg => console.log(msg); | ||
const CLIENT_EVENTS = { | ||
CREATE_ROOM: 'createRoom', | ||
JOIN_ROOM: 'joinRoom', | ||
LEAVE_ROOM: 'leaveRoom', | ||
ACTION: 'action' | ||
}; | ||
|
||
const SERVER_EVENTS = { | ||
MESSAGE: 'message', | ||
ERROR: 'errorMessage', | ||
STATE_UPDATE: 'stateUpdate' | ||
}; | ||
|
||
const defaultConfig = { | ||
[SERVER_EVENTS.MESSAGE]: logger, | ||
[SERVER_EVENTS.ERROR]: logger, | ||
}; | ||
|
||
const strummulu = serverUrl => { | ||
return { | ||
EVENTS: SERVER_EVENTS, | ||
|
||
init(config = {}) { | ||
this.socket = openSocket(serverUrl); | ||
config = { ...defaultConfig, ...config } | ||
this.bindEvents(config); | ||
}, | ||
|
||
getId() { | ||
return this.socket ? this.socket.id : null; | ||
}, | ||
|
||
bindEvents(config) { | ||
for (const message in SERVER_EVENTS) { | ||
const event = SERVER_EVENTS[message]; | ||
const handler = config[event] || logger; | ||
this.socket.on(event, handler); | ||
} | ||
}, | ||
|
||
|
||
|
||
createRoom() { | ||
this.socket.emit(CLIENT_EVENTS.CREATE_ROOM, { me: this.getId() }); | ||
}, | ||
joinRoom(roomId) { | ||
this.socket.emit(CLIENT_EVENTS.JOIN_ROOM, { roomId }); | ||
}, | ||
leaveRoom(roomId) { | ||
this.socket.emit(CLIENT_EVENTS.LEAVE_ROOM, { roomId }); | ||
}, | ||
sendAction(type, roomId, payload = {}) { | ||
this.socket.emit(CLIENT_EVENTS.ACTION, { type, roomId, payload }) | ||
} | ||
|
||
} | ||
}; | ||
|
||
|
||
export default strummulu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
3 changes: 2 additions & 1 deletion
3
backend/example/revorbaro.js → ...t/backend/GameLogic/RevorbaroGameLogic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { strummuluServerFactory, GAME_TYPES, Server, gameRoomFactory } = require('strummulu-server'); | ||
const RevorbaroGameLogic = require('./GameLogic/RevorbaroGameLogic'); | ||
const port = process.env.PORT || 5000; | ||
|
||
const gameServer = new Server({ | ||
roomFactory: (client, data) => gameRoomFactory(GAME_TYPES.TWO_PLAYERS_TURN_BASED, new RevorbaroGameLogic(), client) | ||
}); | ||
|
||
const server = strummuluServerFactory(gameServer); | ||
|
||
|
||
server.listen(port); | ||
console.log('game server listening on ', port); |
Oops, something went wrong.