Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-section02 #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/gohandson/gacha-ja

go 1.18
5 changes: 4 additions & 1 deletion skeleton/section02/step01/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ func main() {
rand.Seed(time.Now().Unix())

// TODO: 長さ11の文字列型の配列を変数resultとして定義する
var result [11]string

for i := 0; /* TODO: 継続条件をiがresultの要素数より小さい場合にする */; i++ {
/* TODO: 継続条件をiがresultの要素数より小さい場合にする */
for i := 0; i < len(result); i++ {

// 0から99までの間で乱数を生成する
num := rand.Intn(100)
Expand All @@ -29,6 +31,7 @@ func main() {
result[i] = "ノーマル"
case num < 95:
// TODO: resultのi番目に"R"を代入する
result[i] = "R"
case num < 99:
result[i] = "SR"
default:
Expand Down
8 changes: 7 additions & 1 deletion skeleton/section02/step02/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ func main() {
fmt.Scanln(&n)

// TODO: nが0より大きい場合はforをbreakする
if n > 0 {
break
}

fmt.Println("もう一度入力してください")
}

// TODO: 長さnの文字列型のスライスを変数resultとして定義する
result := make([]string, n)

for i := 0;/* TODO: 継続条件をiがresultの要素数より小さい場合にする */; i++ {
/* TODO: 継続条件をiがresultの要素数より小さい場合にする */
for i := 0; i < len(result); i++ {

// 0から99までの間で乱数を生成する
num := rand.Intn(100)
Expand All @@ -41,6 +46,7 @@ func main() {
result[i] = "ノーマル"
case num < 95:
// TODO: resultのi番目に"R"を代入する
result[i] = "R"
case num < 99:
result[i] = "SR"
default:
Expand Down
2 changes: 1 addition & 1 deletion skeleton/section02/step03/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
}

// TODO: キーがstring型で値がint型のマップを定義する

result := make(map[string]int)

for i := 0; i < n; i++ {

Expand Down
4 changes: 2 additions & 2 deletions skeleton/section02/step04/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ func main() {
}

// TODO: 変数cardのrarityフィールドに"ノーマル"と代入

card.rarity = "ノーマル"

// TODO: 変数cardのnameフィールドに"スライム"と代入

card.name = "スライム"

fmt.Println(card)
}
5 changes: 3 additions & 2 deletions skeleton/section02/step05/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package main
import "fmt"

// TODO: string型をベースにしたrarity型を定義する

type rarity string

const (
rarityN rarity = "ノーマル"
Expand All @@ -17,13 +17,14 @@ const (
type card struct {
rarity rarity // レア度
// TODO: 文字列型のフィールドnameを設ける
name string
}

func main() {

// TODO: rarityフィールドがrarityNで
// nameフィールドが"スライム"の変数slimeを定義する

slime := card{rarity: rarityN, name: "スライム"}
fmt.Println(slime)

dragon := card{rarity: raritySR, name: "ドラゴン"}
Expand Down