Skip to content

Commit

Permalink
feat(cogs.marble.dice): create player moving
Browse files Browse the repository at this point in the history
  • Loading branch information
snakeblanket committed Jul 31, 2022
1 parent aa1fab1 commit 4549ffa
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions cogs/marble/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,37 @@ async def on_interaction(self, interaction: discord.Interaction):
if interaction.is_component() and interaction.custom_id.startswith("dice_"):
if str(interaction.user.id) == interaction.custom_id.replace("dice_", ""):
con = str(random.randint(1, 6))
await send_response(interaction,
f"<@{interaction.user.id}>님의 주사위는 {con}입니다!", delete_after=5)
game_data = loadjson(f"./data/game/{interaction.channel_id}.json")
user_loc_num = 0
print(game_data)
print(game_data['province'])
for d in game_data['province']:
print(d['users'])
if interaction.user.id in d['users']:
if (user_loc_num + int(con)) >= len(game_data['province']):
user_now_loc_num = (user_loc_num + int(con)) - len(game_data['province'])
else:
user_now_loc_num = (user_loc_num + int(con))
print(game_data['province'][user_now_loc_num]['name'])
user_new_loc = game_data['province'][user_now_loc_num]['name']
user_pre_loc_num = user_loc_num
# print((list(game_data['province']).index(d['name'])) + int(con))
# print(game_data['province'][(list(game_data['province']).index(d['name'])) + int(con)])
user_loc_num += 1
await send_response(interaction,
f"<@{interaction.user.id}>님의 주사위는 {con}입니다! 현재 위치는 {user_new_loc}입니다.")

# 주사위 후 말 이동(json 파일 변경 우선)
print("말 이동")
data = loadjson(f"./data/game/{interaction.channel_id}.json")
province = data['province']
print(user_loc_num)
# print(province[user_now_loc_num]['users'])
province[user_pre_loc_num]['users'].remove(interaction.user.id)
province[user_now_loc_num]['users'].append(interaction.user.id)
savejson(f"./data/game/{interaction.channel_id}.json", data)

mydict = loadjson("./data/game.json")[game_data["game_owner"]]["players"]
# var = mydict[(list(mydict).index(interaction.user.id))+1]
print(interaction.custom_id)
# print(var)
this_turn = list(mydict).index(interaction.user.id)
print(this_turn)
print(mydict)
Expand Down

0 comments on commit 4549ffa

Please sign in to comment.