09.04.2022

Zuffals - Algotithmus geändert
This commit is contained in:
marcusferl@weifer.de 2022-04-09 23:36:27 +02:00
parent f294083a81
commit 3114bfe091
6 changed files with 24 additions and 40 deletions

View File

@ -26,7 +26,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Row="1"> <StackPanel Grid.Row="1">
<Button Content="Home" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="home_on_click" FontFamily="Tw Cen MT" /> <Button Content="Home" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="home_on_click" FontFamily="Tw Cen MT" />
<Button Content="Test" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="start_on_click" FontFamily="Tw Cen MT" ToolTip="Teste dein Wissen"/> <Button Content="Teste dich!" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="start_on_click" FontFamily="Tw Cen MT" ToolTip="Teste dein Wissen"/>
<Button Content="Datenbank" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="datenbank_on_click" FontFamily="Tw Cen MT" ToolTip="Eine Liste aller Fragaen auf einem Blick"/> <Button Content="Datenbank" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="datenbank_on_click" FontFamily="Tw Cen MT" ToolTip="Eine Liste aller Fragaen auf einem Blick"/>
<Button Content="Info" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="info_on_click" FontFamily="Tw Cen MT"/> <Button Content="Info" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="info_on_click" FontFamily="Tw Cen MT"/>
<Button Content="Quit" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="exit_on_click" FontFamily="Tw Cen MT"/> <Button Content="Quit" HorizontalAlignment="Center" VerticalAlignment="Top" Height="59" Width="198" BorderBrush="{x:Null}" Style="{StaticResource Button_Hover}" Click="exit_on_click" FontFamily="Tw Cen MT"/>

View File

@ -36,9 +36,6 @@ namespace Test_App
} }
// Buttons // Buttons
private void home_on_click(object sender, RoutedEventArgs e) private void home_on_click(object sender, RoutedEventArgs e)
{ {
@ -71,6 +68,8 @@ namespace Test_App
this.DragMove(); this.DragMove();
} }
// Networkcheck
private void Ping_Url() private void Ping_Url()
{ {
var hostUrl = "www.google.de"; var hostUrl = "www.google.de";

View File

@ -43,7 +43,7 @@ namespace Test_App.Views
catch catch
{ {
MainWindow.status.Fill = Brushes.Red; MainWindow.status.Fill = Brushes.Red;
MessageBox.Show("Server nicht erreichbar"); MessageBox.Show("Server nicht erreichbar!");
} }

View File

@ -32,7 +32,7 @@ namespace Test_App.Views
"Marcus Ferl\n\n" + "Marcus Ferl\n\n" +
"Oder eine Email an:\n" + "Oder eine Email an:\n" +
"support@weifer.de\n" + "support@weifer.de\n" +
"\nFalls jemand meine Arbeit unterstützen will, (die Fragen waren nicht kostenlis):\n\n" + "\nFalls jemand meine Arbeit unterstützen will, (die Fragen waren nicht kostenlos):\n\n" +
"Paypal: marcus@weifer.de\n" + "Paypal: marcus@weifer.de\n" +
"Bitcoin: 17ruVoy3NXooM5yRbva9Kz898hB75XYqtx\n"; "Bitcoin: 17ruVoy3NXooM5yRbva9Kz898hB75XYqtx\n";

View File

@ -8,7 +8,7 @@
d:DesignHeight="525" d:DesignWidth="852"> d:DesignHeight="525" d:DesignWidth="852">
<Grid> <Grid Focusable="True">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition/> <RowDefinition/>
<RowDefinition/> <RowDefinition/>
@ -20,8 +20,8 @@
<TextBox x:Name="question_textbox" Style="{StaticResource Textbox_Round_Corners}" Grid.Row="0" Background="#FF9A9494" TextWrapping="Wrap" Foreground="White" SelectionBrush="{x:Null}" FontSize="22" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{x:Null}" Focusable="False" Cursor="None" IsEnabled="False" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="719" Height="205"/> <TextBox x:Name="question_textbox" Style="{StaticResource Textbox_Round_Corners}" Grid.Row="0" Background="#FF9A9494" TextWrapping="Wrap" Foreground="White" SelectionBrush="{x:Null}" FontSize="22" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{x:Null}" Focusable="False" Cursor="None" IsEnabled="False" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="719" Height="205"/>
<TextBox x:Name="answer_textbox" Style="{StaticResource Textbox_Round_Corners}" Grid.Row="1" Background="#FF6C74F1" TextWrapping="Wrap" Foreground="Black" SelectionBrush="{x:Null}" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{x:Null}" Focusable="False" Cursor="None" IsEnabled="False" Width="720" Height="188" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0,0,0,50"/> <TextBox x:Name="answer_textbox" Style="{StaticResource Textbox_Round_Corners}" Grid.Row="1" Background="#FF6C74F1" TextWrapping="Wrap" Foreground="Black" SelectionBrush="{x:Null}" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{x:Null}" Focusable="False" Cursor="None" IsEnabled="False" Width="720" Height="188" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0,0,0,50"/>
<Button Content="Answer" Background="#232041" FontSize="30px" HorizontalAlignment="Left" Margin="113,214,0,0" Grid.Row="1" VerticalAlignment="Top" Height="40" Width="109" Style="{StaticResource Button_Hover}" Click="Get_Answer_Button"/> <Button Content="Lösung" FontSize="30px" HorizontalAlignment="Left" Margin="285,212,0,0" Grid.Row="1" VerticalAlignment="Top" Height="40" Width="109" Style="{StaticResource Button_Hover}" Click="Get_Answer_Button"/>
<Button Content="Next" Background="#232041" FontSize="30px" HorizontalAlignment="Left" Margin="624,214,0,0" Grid.Row="1" VerticalAlignment="Top" Height="40" Width="106" Style="{StaticResource Button_Hover}" Click="Next_Button_Click"/> <Button Content="Weiter" FontSize="30px" HorizontalAlignment="Left" Margin="463,212,0,0" Grid.Row="1" VerticalAlignment="Top" Height="40" Width="109" Style="{StaticResource Button_Hover}" Click="Next_Button_Click"/>
</Grid> </Grid>
</Page> </Page>

View File

@ -24,15 +24,15 @@ namespace Test_App.Views
public partial class Start : Page public partial class Start : Page
{ {
string json_url = ConfigurationManager.AppSettings.Get("JsonUrl"); // Json File string json_url = ConfigurationManager.AppSettings.Get("JsonUrl"); // Json File
string get_questions = ""; string get_questions = "";
string get_answer = ""; string get_answer = "";
List<int> list = new List<int>();
List<Ressources.Datas> dataList = new List<Ressources.Datas>();
public Start() public Start()
{ {
InitializeComponent(); InitializeComponent();
liste(); //liste();
get_jsonData(json_url);
} }
// ### Buttons ### // ### Buttons ###
@ -54,9 +54,8 @@ namespace Test_App.Views
answer_textbox.Text = get_answer; answer_textbox.Text = get_answer;
} }
// Convertiert Json von der Url in ein Listenobjekt
// Convertiert Json von der Url private void get_jsonData(string url)
dynamic get_jsonData(string url)
{ {
string json = ""; string json = "";
var webclient = new System.Net.WebClient(); var webclient = new System.Net.WebClient();
@ -72,39 +71,25 @@ namespace Test_App.Views
MessageBox.Show("Keine Verbindung zum Server möglich. Versuche es Später nocheinmal"); MessageBox.Show("Keine Verbindung zum Server möglich. Versuche es Später nocheinmal");
} }
dynamic dynJson = JsonConvert.DeserializeObject(json); dataList = JsonConvert.DeserializeObject<List<Ressources.Datas>>(json);
return dynJson;
} }
// Erstellt die Zufallsfrage // Erstellt die Zufallsfrage, entfernt sie dann von der Liste
public void get_question() private void get_question()
{ {
int random_number = new Random().Next(0, dataList.Count); // Generiert eine Zufallsindex
dynamic json_data = get_jsonData(json_url);
int random_number_counter = new Random().Next(0, list.Count); // Generiert eine Zufallsindex get_questions = dataList.ElementAt(random_number).Question;
int random_number = list.ElementAt(random_number_counter); // Gibt die Zahl am Listindex aus get_answer = dataList.ElementAt(random_number).Answer;
dataList.RemoveAt(random_number);
get_questions = json_data[random_number]["Question"];
get_answer = json_data[random_number]["Answer"];
list.RemoveAt(random_number_counter); // Entfernt die Zahl aus der Liste um Wiederholungen zu vermeiden // Wenn alle Fragen durch sind
if (!dataList.Any())
if (!list.Any())
{ {
MessageBox.Show("Alle Fragen erreicht!"); MessageBox.Show("Alle Fragen erreicht!");
} }
} }
// Erstellen der Zahlen Liste für die Zufallszahl
public void liste()
{
dynamic json_data = get_jsonData(json_url);
int count = json_data.Count;
for (int i = 0; i < count; i++)
{
list.Add(i);
}
}
} }
} }