Current Sprint: 3. 遊戲基本流程完成
repo: https://github.com/side-project-at-SPT/ithome-ironman-2024-san-juan
swagger docs: https://side-project-at-spt.github.io/ithome-ironman-2024-san-juan/
🆕 前端 repo: https://github.com/side-project-at-SPT/ithome-ironman-2024-san-juan-frontend-example
礦工
階段行動step
model 用來儲存遊戲(每一步)紀錄議員
階段行動建築
階段行動生產
階段行動交易
階段行動負責
LobbyChannel
的 加入房間、查詢房間有誰、開始遊戲 刪掉# app/channels/lobby_channel.rb
class LobbyChannel < ApplicationCable::Channel
# ...
# Deprecated
def join_room(params)
deprecated_notice = "This method is deprecated. Please use RoomChannel#subscribed instead."
message = { message: deprecated_notice }
ActionCable.server.broadcast "lobby_channel", message
end
# Deprecated
def show_room_info(params)
deprecated_notice = "This method is deprecated. Please use RoomChannel#info instead."
message = { message: deprecated_notice }
ActionCable.server.broadcast "lobby_channel", message
end
# Deprecated
def start_new_game(params)
deprecated_notice = "This method is deprecated. Please use RoomChannel#play instead."
message = { message: deprecated_notice }
ActionCable.server.broadcast "lobby_channel", message
end
end
RoomChannel
# app/channels/room_channel.rb
class RoomChannel < ApplicationCable::Channel
def subscribed
@room_id = params[:room_id]
reject and return if @room_id.blank?
@channel = "room_#{@room_id}_channel"
stream_from @channel
data = { message: "#{current_user.email} has joined the room" }
ActionCable.server.broadcast @channel, data
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
stop_all_streams
end
# - 加入房間 subscribed
# - 查詢房間有誰 info
# - 開始遊戲 play
# - 離開房間 unsubscribed
# - 關閉房間 if invoker is room creator, then close room
def info
room = Kredis.string "room:#{@room_id}"
room_owner = Kredis.string "room:#{@room_id}:owner"
room_participants = Kredis.set "room:#{@room_id}:participants"
message = {
message: "Room #{room.value} info: owner - #{room_owner.value}, participants - #{room_participants.members.to_sentence}",
owner: room_owner.value,
participants: room_participants.members
}
ActionCable.server.broadcast @channel, message
end
def play
room_owner = Kredis.string "room:#{@room_id}:owner"
case room_owner.value
when nil
# room does not exist
message = { message: "Room #{@room_id} does not exist" }
ActionCable.server.broadcast @channel, message
when current_user.email
# room owner
room_participants = Kredis.set "room:#{@room_id}:participants"
game = Game.start_new_game(players: room_participants.members)
message = { message: "Game started in room #{@room_id}", game_id: game.id }
ActionCable.server.broadcast @channel, message
else
message = { message: "Only the room owner can start the game" }
ActionCable.server.broadcast @channel, message
end
end
end
TBD...
以上不代表明天會做,如有雷同純屬巧合
SPT (Side Project Taiwan) 的宗旨是藉由Side Project開發來成就自我,透過持續學習和合作,共同推動技術和專業的發展。我們相信每一個參與者,無論是什麼專業,都能在這個社群中找到屬於自己的成長空間。
歡迎所有對Side Project開發有興趣的人加入我們,可以是有點子來找夥伴,也可以是來尋找有興趣的Side Project加入,邀請大家一同打造一個充滿活力且有意義的技術社群!
Discord頻道連結: https://sideproj.tw/dc