Domemo (vb 버전) Lv2
                                            
                                                
                                                
                                                
                                                
                                                
                                                 16338 단어  VB. 네 t
                    
학위도?
일부 보드 게임.
사내 연구회에서 작성하는 프로그램의 소재로서 선정.
Domemo에 대해 자세히 알아보기

왜 Domemo를 만들기로 결정했다면,
만들고 놀 수 있는 것을 소재로 하는 것이 동기 부여가 계속 쉽기 때문에.
규칙 등은 Lv1 기사을 참조.
향후 로드맵
Lv1 : 우선 합쳐 보자.
Lv2 : 플레이어의 처리를 함수로 정리해 보자 (now!)
Lv3: 플레이어 1을 조작할 수 있도록 하자
Lv4: CPU를 강하게 하자
Lv5: 플레이어를 클래스화해보자
Lv2 : 플레이어의 처리를 함수로 정리합시다.
Lv1의 기사의 프로그램을 보면, 플레이어 1~4의 처리가
비슷한 것을 쓰고 있어 보기 어렵습니다.
함수에 정리해, 깔끔하게 해 봅시다.
Module Module1
    ' Player2~4の手札を表示する
    Sub show(cards As List(Of Integer))
        For Each card In cards
            Console.Write(card)
        Next
        Console.WriteLine("")
    End Sub
    ' Player1の手札を伏せて表示する
    Sub showMask(cards As List(Of Integer))
        For Each card In cards
            Console.Write("X")
        Next
        Console.WriteLine("")
    End Sub
    ' 7: 各プレイヤーは自分が持っているカードを予想して、宣言する
    Sub declarationCard(declaration As Integer,
                        playerCards As List(Of Integer),
                        playerName As String,
                        openCards As List(Of Integer))
        Console.WriteLine(playerName & " -> " & declaration)
        ' 8: 予想があっていたら、手札からカードを場に移動して表にする
        If playerCards.Remove(declaration) Then
            Console.WriteLine("jackPot!")
            openCards.Add(declaration)
            ' 9: 最初に手札がなくなったプレイヤーが勝ち
            If playerCards.Count = 0 Then
                Console.WriteLine(playerName & " win!")
                ' 判定がループの外に移動したので何か入力されるまで待つ
                Console.ReadKey()
                ' ゲームを終了させる
                Environment.Exit(0)
            End If
        End If
    End Sub
    Sub Main()
        ' 1: 1~7までのカードを用意する
        Dim cards As List(Of Integer) = New List(Of Integer)
        For i As Integer = 1 To 7
            For j As Integer = 1 To i
                cards.Add(i)
            Next
        Next
        ' 2: カードをシャッフルする
        Dim shuffledCards As List(Of Integer) = 
            cards.OrderBy(Function(x) Guid.NewGuid()).ToList
        show(shuffledCards)
        ' 3: 場にカードを4枚表にする
        Dim openCards As List(Of Integer) = shuffledCards.GetRange(0, 4)
        ' 4: 4枚のカードを、内容を伏せたままゲームから除外する
        Dim closeCards As List(Of Integer) = shuffledCards.GetRange(4, 4)
        ' 5: カードを5枚ずつ4人のプレイヤーに配る
        Dim player1 As List(Of Integer) = shuffledCards.GetRange(8, 5)
        Dim player2 As List(Of Integer) = shuffledCards.GetRange(13, 5)
        Dim player3 As List(Of Integer) = shuffledCards.GetRange(18, 5)
        Dim player4 As List(Of Integer) = shuffledCards.GetRange(23, 5)
        Dim random As New Random()
        ' 6: 各プレイヤーは自分には見えないようにカードを表にする
        For i As Integer = 1 To 30
            Console.WriteLine("---------------------------------")
            ' 場のカードとプレイヤーの手札を表示する
            Console.Write("open->")
            show(openCards)
            Console.Write("player1->")
            showMask(player1)
            Console.Write("player2->")
            show(player2)
            Console.Write("player3->")
            show(player3)
            Console.Write("player4->")
            show(player4)
            ' 7: 各プレイヤーは他のプレイヤーのカードを見ながら、自分が持っているカードを予想して、宣言する
            ' Player1
            Dim declaration As Integer = random.Next(7) + 1
            declarationCard(declaration, player1, "player1", openCards)
            ' Player2
            declaration = random.Next(7) + 1
            declarationCard(declaration, player2, "player2", openCards)
            ' Player3
            declaration = random.Next(7) + 1
            declarationCard(declaration, player3, "player3", openCards)
            ' Player4
            declaration = random.Next(7) + 1
            declarationCard(declaration, player4, "player4", openCards)
            ' 何か入力したら次のターンにいくようにする
            Console.ReadKey()
        Next
    End Sub
End Module
그 밖에도 정리할 수 있는 곳이 있을지도?
생각해 봅시다.
Reference
이 문제에 관하여(Domemo (vb 버전) Lv2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/aoi_erimiya/items/0642177270222e5ebfeb텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)