Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,64 @@
' Game 21 in VB.NET - an example for Rosetta Code
Class MainWindow
Private Const GOAL As Integer = 21
Private total As Integer = 0
Private random As New Random
Private Sub Update(box As TextBox, player As String, move As Integer)
total = total + move
box.Text = move
boxTotal.Text = total
If total + 1 > GOAL Then button1.IsEnabled = False
If total + 2 > GOAL Then button2.IsEnabled = False
If total + 3 > GOAL Then button3.IsEnabled = False
If total = GOAL Then
winner.Content = $"The winner is {player}."
End If
End Sub
Private Sub Ai()
Dim move As Integer = 1
For i = 1 To 3
If (total + i - 1) Mod 4 = 0 Then move = i
Next i
For i = 1 To 3
If total + i = GOAL Then move = i
Next i
Update(boxAI, "AI", move)
End Sub
Private Sub Choice(sender As Object, e As RoutedEventArgs) _
Handles button1.Click, button2.Click, button3.Click
Update(boxHuman, "human", sender.Content)
If total < GOAL Then Ai()
End Sub
' StartGame method handles both OnLoad (WM_INIT?) event
' as well as the restart of the game after user press the 'restart' button.
'
Private Sub StartGame(sender As Object, e As RoutedEventArgs) Handles restart.Click
total = 0
boxAI.Text = ""
boxHuman.Text = ""
boxTotal.Text = ""
'first.Content = "" ' It is not necessary, see below.
winner.Content = ""
button1.IsEnabled = True
button2.IsEnabled = True
button3.IsEnabled = True
' The random.Next(2) return pseudorandomly either 0 or 1. Generally
' random.Next(n) Return a value from 0 (inclusive) To n - 1 (inclusive).
'
If random.Next(2) = 0 Then
first.Content = "First player is AI player."
Ai()
Else
first.Content = "First player is human player."
End If
End Sub
End Class

View file

@ -0,0 +1,29 @@
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Game21vb"
mc:Ignorable="d"
Title="Game 21" Height="292" Width="409" Loaded="StartGame">
<Grid>
<TextBlock
HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="64" Width="376">
Game 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total.
The game is won by the player whose chosen number causes the running total to reach exactly 21.
The running total starts at zero.
</TextBlock>
<Label Content="AI" HorizontalAlignment="Left" Margin="60,121,0,0" VerticalAlignment="Top" Width="49" HorizontalContentAlignment="Right"/>
<Label Content="Human" HorizontalAlignment="Left" Margin="60,152,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Right"/>
<Label Content="Total" HorizontalAlignment="Left" Margin="60,183,0,0" VerticalAlignment="Top" Width="49" HorizontalContentAlignment="Right"/>
<TextBox x:Name="boxAI" HorizontalAlignment="Left" Height="23" Margin="114,125,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsReadOnly="True"/>
<TextBox x:Name="boxHuman" HorizontalAlignment="Left" Height="23" Margin="114,156,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsReadOnly="True"/>
<TextBox x:Name="boxTotal" HorizontalAlignment="Left" Height="23" Margin="114,187,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsReadOnly="True"/>
<Button x:Name="button1" Content="1" HorizontalAlignment="Left" Margin="114,220,0,0" VerticalAlignment="Top" Width="25"/>
<Button x:Name="button2" Content="2" HorizontalAlignment="Left" Margin="144,220,0,0" VerticalAlignment="Top" Width="25"/>
<Button x:Name="button3" Content="3" HorizontalAlignment="Left" Margin="174,220,0,0" VerticalAlignment="Top" Width="25"/>
<Button x:Name="restart" Content="restart" HorizontalAlignment="Left" Margin="215,220,0,0" VerticalAlignment="Top" Width="75"/>
<Label x:Name="winner" HorizontalAlignment="Left" Margin="245,184,0,0" VerticalAlignment="Top" Width="133"/>
<Label x:Name="first" HorizontalAlignment="Left" Margin="10,79,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>