在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:mykeels/whot-server开源软件地址:https://github.com/mykeels/whot-server开源编程语言:JavaScript 88.7%开源软件介绍:Whot ServerAn HTTP server serving a REST API for hosting Whot! games. Setup and Usagenpm install
npm start RoutesThe following routes are available:
Socket Signals
DockerThis project has been setup to use docker to create a development environment, so prepare to be dazzled. The readme assumes docker version >= 1.9.1 installed on your system. The project contains bash scripts to simplify the interaction with docker and enable dynamic code changes. These can be found in <project_root>/bin To start up disposable containers use: bin/start_disposable.sh The command will attempt to start up containers based on a specific image. If the image cannot be found, it will be downloaded automatically. If the project's image cannot be found, it will be built from the Dockerfile automatically. When all is complete, you will be taken directly to the shell of the container with the application started for you. At this point the app will be accessible with base url:
Thus your adventure begins... Test Mock ScriptCopy and paste this in your browser console: (() => {
const makeRandomPlay = (ws) => {
if (ws.canPlay()) {
const compatibles = ws.hand.filter(card => card.matches(ws.pile))
const compatibleCardIndex = ws.hand.indexOf(compatibles[Math.floor(Math.random() * compatibles.length)])
let iNeed = null
if (ws.hand[compatibleCardIndex].shape === 'Whot') {
const eligibleCards = ws.hand.filter(card => card.shape != 'Whot')
iNeed = (eligibleCards[Math.floor(Math.random() * eligibleCards.length)] || {}).shape || 'Circle'
}
ws.send(JSON.stringify({ message: 'player:play', index: compatibleCardIndex, card: ws.hand[compatibleCardIndex], iNeed }))
}
else {
ws.send(JSON.stringify({ message: 'market:pick' }))
}
}
const setupCard = (c) => {
c.matches = (card = new Card()) => {
return (c.shape === 'Whot') ||
(card.shape === 'Whot' && c.iNeed && (c.iNeed === card.shape)) || (card.shape === c.shape) || (card.value === c.value)
}
return c
}
var wss = [1, 2, 3, 4].map(function () {
const ws = new WebSocket('ws://localhost:8800/game/1')
ws.onmessage = (msg) => {
try {
const data = JSON.parse(msg.data)
switch(data.message) {
case 'player:hand':
ws.hand = data.hand.map(setupCard)
break;
case 'game:start':
ws.pile = setupCard(data.pile)
break;
case 'turn:switch':
makeRandomPlay(ws)
break;
case 'player:play':
case 'pile:top':
ws.pile = data.card
break;
}
}
catch (ex) {
console.error(ex)
}
}
ws.onerror = (err) => console.error(err)
ws.onopen = () => {
console.log('WebSocket connection opened')
ws.send(JSON.stringify({ message: 'hello' }))
}
ws.canPlay = () => (ws.hand.findIndex(card => card.matches(ws.pile)) >= 0)
return ws
})
return wss
})() |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论