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>
<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="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="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"/>

View File

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

View File

@ -43,7 +43,7 @@ namespace Test_App.Views
catch
{
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" +
"Oder eine Email an:\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" +
"Bitcoin: 17ruVoy3NXooM5yRbva9Kz898hB75XYqtx\n";

View File

@ -8,7 +8,7 @@
d:DesignHeight="525" d:DesignWidth="852">
<Grid>
<Grid Focusable="True">
<Grid.RowDefinitions>
<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="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="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="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="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>
</Page>

View File

@ -24,15 +24,15 @@ namespace Test_App.Views
public partial class Start : Page
{
string json_url = ConfigurationManager.AppSettings.Get("JsonUrl"); // Json File
string get_questions = "";
string get_answer = "";
List<int> list = new List<int>();
List<Ressources.Datas> dataList = new List<Ressources.Datas>();
public Start()
{
InitializeComponent();
liste();
//liste();
get_jsonData(json_url);
}
// ### Buttons ###
@ -54,9 +54,8 @@ namespace Test_App.Views
answer_textbox.Text = get_answer;
}
// Convertiert Json von der Url
dynamic get_jsonData(string url)
// Convertiert Json von der Url in ein Listenobjekt
private void get_jsonData(string url)
{
string json = "";
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");
}
dynamic dynJson = JsonConvert.DeserializeObject(json);
return dynJson;
dataList = JsonConvert.DeserializeObject<List<Ressources.Datas>>(json);
}
// Erstellt die Zufallsfrage
public void get_question()
// Erstellt die Zufallsfrage, entfernt sie dann von der Liste
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
int random_number = list.ElementAt(random_number_counter); // Gibt die Zahl am Listindex aus
get_questions = dataList.ElementAt(random_number).Question;
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
if (!list.Any())
// Wenn alle Fragen durch sind
if (!dataList.Any())
{
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);
}
}
}
}