Skip to content

Commit

Permalink
Merge pull request #67 from cardeons/feature/add_reset_to_gameboard
Browse files Browse the repository at this point in the history
Feature/add reset to gameboard
  • Loading branch information
Moarales authored Feb 4, 2021
2 parents a041749 + 6d5e1ca commit 9bd00a5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 34 deletions.
68 changes: 34 additions & 34 deletions app/channels/game_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,40 @@ def attack()
broadcast_to(@gameboard, { type: BOARD_UPDATE, params: updated_board })
end

def play_card(params)
# add actions!

paramsObject = JSON.parse params
puts paramsObject

broadcast_to(@gameboard, { type: DEBUG, params: { message: 'You just used play_card with ', params: paramsObject } })

case paramsObject.to
when 'Inventory'
broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to inventory" } })
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
current_card.update_attribute(:cardable_type, 'Inventory')
when 'Monsterone'
broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to monsterone" } })
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
current_card.update_attribute(:cardable_type, 'Monsterone')
when 'Monstertwo'
broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to monstertwo" } })
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
current_card.update_attribute(:cardable_type, 'Monstertwo')
when 'Monsterthree'
broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to monsterthree" } })
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
current_card.update_attribute(:cardable_type, 'Monsterthree')
when 'center'
broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to center" } })
# TODO: currently not implemented
else
broadcast_to(@gameboard, { type: ERROR, params: { message: "Player #{current_user.email} just played to something i dont know" } })
end

broadcast_to(@gameboard, { type: BOARD_UPDATE, params: Gameboard.broadcast_game_board(@gameboard) })
end
# def play_card(params)
# # add actions!

# paramsObject = JSON.parse params
# puts paramsObject

# broadcast_to(@gameboard, { type: DEBUG, params: { message: 'You just used play_card with ', params: paramsObject } })

# case paramsObject.to
# when 'Inventory'
# broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to inventory" } })
# current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
# current_card.update_attribute(:cardable_type, 'Inventory')
# when 'Monsterone'
# broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to monsterone" } })
# current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
# current_card.update_attribute(:cardable_type, 'Monsterone')
# when 'Monstertwo'
# broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to monstertwo" } })
# current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
# current_card.update_attribute(:cardable_type, 'Monstertwo')
# when 'Monsterthree'
# broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to monsterthree" } })
# current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id)
# current_card.update_attribute(:cardable_type, 'Monsterthree')
# when 'center'
# broadcast_to(@gameboard, { type: DEBUG, params: { message: "Player #{current_user.email} just played to center" } })
# # TODO: currently not implemented
# else
# broadcast_to(@gameboard, { type: ERROR, params: { message: "Player #{current_user.email} just played to something i dont know" } })
# end

# broadcast_to(@gameboard, { type: BOARD_UPDATE, params: Gameboard.broadcast_game_board(@gameboard) })
# end

def move_card(params)
unique_card_id = params['unique_card_id']
Expand Down
28 changes: 28 additions & 0 deletions app/models/gameboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,32 @@ def self.attack(gameboard)

message
end



def self.reset_all_game_boards()
Ingamedeck.all.where(cardable_type: "Centercard").destroy_all

Gameboard.all.each do |gameboard|

player_id_current = gameboard.current_player


if player_id_current
current_player = Player.find(player_id_current)
current_player.handcard.ingamedecks.delete_all
current_player.inventory.ingamedecks.delete_all
current_player.monsterone.ingamedecks.delete_all
current_player.monstertwo.ingamedecks.delete_all
current_player.monsterthree.ingamedecks.delete_all

Handcard.draw_handcards(current_player.id, gameboard)

# updated_board = Gameboard.broadcast_game_board(gameboard)
# GameChannel.broadcast_to(gameboard, { type: "BOARD_UPDATE", params: updated_board })
# PlayerChannel.broadcast_to(current_player.user, { type: 'HANDCARD_UPDATE', params: { handcards: Gameboard.renderCardId(current_player.handcard.ingamedecks) } })
end
end

end
end

0 comments on commit 9bd00a5

Please sign in to comment.