Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Sub Main()
- ' 建立撲克牌
- Dim poke As New List(Of PokeCard)
- For Each color As String In New String() {"C", "D", "H", "S"}
- For i As Integer = 1 To 13 Step 1
- poke.Add(New PokeCard(color, i))
- Next
- Next
- ' 洗牌
- Dim ran As New Random
- For i As Integer = 0 To 100 Step 1
- Dim indexA As Integer = ran.Next(1, poke.Count),
- indexB As Integer = ran.Next(1, poke.Count)
- Dim temp As PokeCard = poke(indexA)
- poke(indexA) = poke(indexB)
- poke(indexB) = temp
- Next
- ' 發牌
- Dim players As New Dictionary(Of String, List(Of PokeCard)) From {
- {"Player A", New List(Of PokeCard)},
- {"Player B", New List(Of PokeCard)},
- {"Player C", New List(Of PokeCard)},
- {"Player D", New List(Of PokeCard)}}
- For Each key As String In players.Keys
- For i As Integer = 0 To 12 Step 1
- players(key).Add(poke.First)
- poke.Remove(poke.First)
- Next
- Next
- ' 排序
- For Each key As String In players.Keys.ToArray
- players(key) = players(key).OrderBy(Function(x) x.color).ThenBy(Function(x) x.number).ToList
- Next
- ' 輸出
- For Each key As String In players.Keys
- Console.ForegroundColor = ConsoleColor.Green
- Console.WriteLine(key)
- For Each card As PokeCard In players(key)
- Console.ForegroundColor = If(card.color.Equals("D") Or card.color.Equals("H"), ConsoleColor.Red, ConsoleColor.White)
- Console.Write(card.color + If(card.number = 1, "A",
- If(card.number = 11, "J",
- If(card.number = 12, "Q",
- If(card.number = 13, "K",
- card.number.ToString)))) + vbTab)
- Next : Console.WriteLine(vbNewLine)
- Next : Console.ReadKey()
- End Sub
- Public Class PokeCard
- Public color As String
- Public number As Integer
- Sub New(ByVal color As String, ByVal number As Integer)
- Me.color = color
- Me.number = number
- End Sub
- End Class
- End Module
Advertisement
Add Comment
Please, Sign In to add comment