Git Product home page Git Product logo

onenightultimate's People

Contributors

andimeo avatar zhangchee avatar

Watchers

 avatar  avatar  avatar

onenightultimate's Issues

Design Doc v1

长连接 vs 短链接

  • 出于游戏考虑,游戏过程中,后端需要不断地向前端发送通知消息,所以暂时使用长连接 (web socket)。

登录、注册、房间等功能

  • 打开网页,输入昵称,直接登录到默认房间
  • 暂不支持创建房间的功能,只提供唯一默认房间
  • 前端直接发起建立web socket。初始化消息为昵称

游戏准备过程

  • 首个连接的玩家为房主,可以在所有玩家准备就绪状态下,开始游戏
  • 前端显示玩家数目以及就绪状态
  • 前端提供按钮,方便玩家更改就绪状态。状态改变请求通过web socket发送。后端需要向每一个接入的玩家发送通知。各个收到通知的玩家的前端进行相应更新

游戏进行过程

  • 行动开始:
    • 后端在每个角色行动前,向前端对应角色发送开始消息。
    • 前端接收到消息后,提示玩家,并允许该玩家进行操作。
  • 行动过程:
    • 看牌操作(化身幽灵看牌,狼人互相确认,独狼看底牌,爪牙确认狼人,预言家看牌,强盗看牌,失眠者看牌)
      • 后端将对应身份信息以消息的形式返回给前端
      • 前端将信息正确显示
    • 选择操作(化身幽灵选牌,预言家选牌,强盗选牌,捣蛋鬼选牌,酒鬼选牌,猎人选牌)
      • 前端提供选择界面,并将选择结果以消息方式发送给后端进行处理。
      • 后端根据选择卡牌已经所处行动,队卡牌进行处理。如果需要向前端反馈,则发送消息予以通知。
    • 换牌操作
      • 后端默默进行
      • 前端可以动画显示
      • 前后端无须通信
  • 行动结束:
    • 后端在认为前端行动结束后,向前端发送结束消息。并等待反馈。
    • 前端在接收到结束消息后,弹出通知框。确认后向后端发送消息。
  • 下一轮行动:
    • 后端收到所有前端行动结束的消息确认后,发起下一轮行动。
    • 如果是最后一轮结束,后端向前端发送行动全部完成的通知消息。

撕逼过程

  • 整个过程前端提供投票界面,并随时可以进行投票。
  • 前端提供投票确认按钮,一旦点击,则向后端发送投票结果。
  • 所有人均投票结束,后端统计。
  • 如果投死的是猎人,后端额外发起一轮行动,如上。
  • 猎人通过前端确认了带走的人之后,后端再次统计投票结果,并向前端公布所有人的身份和游戏结果
  • 前端显示所有人身份,并显示游戏结果
  • 前端显示返回按钮,点击则返回至游戏准备过程

Backend module list

  1. CardDeck
    A CardDeck represents a scenario for the game.
    All the operations' target should be the CardDeck.
    CardDeck controls the whole process, like which role should operate.
    A static instance defining all the possible roles.
  2. RoleRegistry
    Which specified which roles are selected for this round.
  3. Role
    The base class for all roles which should define the interface for all possible roles.
    Each role will have its own implementation.
  4. Various inherited roles
    Like villager, robber, trouble maker and etc.
  5. History
    Which should be recorded in the CardDeck.
  6. Operation
    An abstraction of all operations.

Each API represents an operation.
In each API, we only convert the arguments into an instance of Operation and pass it to the CardDeck which maintains the current gaming status.
The function of the role to handle this operation should return a status, OPERATING or END (because a role like a witch has to interact with server twice during her round, see one of the center cards and swap it with another player).
Besides the status, the function should also return, if any, the information shown to the client.
Then, CardDeck will write the message to the corresponding websocket.
After the status of all roles in RoleRegistry hit END, the game ends and start voting.
When all votes received or the time limit is hit, show the final result to the client.

Communication between frontend and backend

用户输入完用户名

front->end:

{
    type: "DO_ENTER",
    name: "ZhangChee"
}

end->front:

{
    type: "CONFIRM_ENTER",
    isHost: true
}

用户选择结束

front->end:

{
    type: "FINISH_SELECTION",
    selectedIndexes: [1,3,5,6]
}

Host发起新的游戏

front->end:

{
    type: "RESTART_GAME"
}

后端通知所有前端开始

end->front:

{
    type: "GAME_START",
    players: [
        {name: "name1"},
        {name: "name2"},
        {name: "name3"},
        {name: "name4"},
        {name: "name5"},
        {name: "name6"},
        {name: "name7"},
        {name: "name8"},
    ],
    myInfo: {
        index: 3,
        role: "强盗"
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.