Skip to content

feat じゃんけんゲーム用のハンドラを作成#5

Open
Yosh8g wants to merge 6 commits into
mainfrom
yosh8g/janken
Open

feat じゃんけんゲーム用のハンドラを作成#5
Yosh8g wants to merge 6 commits into
mainfrom
yosh8g/janken

Conversation

@Yosh8g

@Yosh8g Yosh8g commented Jun 15, 2026

Copy link
Copy Markdown

関係するissue

やったこと

ユーザーの手を受け取り、CPUとの勝負結果とCPUの手を返すAPIを作った

具体的には...

  • ユーザーの手(rock, scissors, paperのいずれか)を受け取る
  • rock, scissors, paper以外を受け取った場合にエラーを出力
  • CPUの手をrand.Intn(3)を使用し、決定する
  • ユーザーの手とCPUの手に基づき、勝敗判定を行う
  • JSONで勝負結果とCPUの手を返す

@Yosh8g Yosh8g requested a review from masakichi41 June 15, 2026 07:48

@masakichi41 masakichi41 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いくつかコメントしました!
main.go の方は修正お願いします!

ロジックも正確で全体的に良いと思います!
make up でサーバー起動して動作チェックできるので自分で色々試してみるのもおすすめです!

Comment thread internal/handler/janken.go Outdated
Comment on lines +61 to +67
result := "lose"

if req.UserHand == cpuHand {
result = "draw"
} else if winningMap[req.UserHand] == cpuHand {
result = "win"
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もっと良くするのであれば、ここの「勝敗を判定する処理」を、別の関数に切り出すと動作テストとかがやりやすくなります!

Comment thread internal/server/server.go

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Janken を追加したけど、main.go でそれを作って渡す部分がまだないから、main.go の方で Health と同じようにJankenも追加してもらえると!

	s := server.New(cfg, server.Handlers{
		Health: handler.NewHealthHandler(database),
        // ここ
	})

現時点では特にDBとの接続とかはないけど、将来的に追加するときに必要になってくるのでお願いします!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants