Commit 3c133925 authored by Kim Meiser's avatar Kim Meiser 💬
Browse files

Nachladen der Medien aus git, da Assets in git.hacksaar.de die benötigte Größe nicht zulässt.

parent f2a820b5
Pipeline #841 passed with stages
in 50 seconds
......@@ -55,6 +55,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Logic\Assets.cs" />
<Compile Include="Logic\BoardDefinition.cs" />
<Compile Include="Logic\Category.cs" />
<Compile Include="Logic\Game.cs" />
......@@ -138,7 +139,9 @@
<Resource Include="Todo.txt" />
</ItemGroup>
<ItemGroup>
<Resource Include="Media\wuerfel.PNG" />
<Resource Include="Media\wuerfel.PNG">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Kategroievorschlaege.txt" />
<Content Include="Media\Jeopardy_Theme_light.m4a">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
......
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
namespace Jeoparody.Logic
{
public class Assets
{
private Uri BaseUri = new Uri("https://git.hacksaar.de/hacksaar/jeoparody/-/raw/main/src/Jeoparody/Media/");
private string AssetFolder => "media";
private const string JeopardyThemeFilename = "Jeopardy_Theme_retro.wav";
private const string JeopardyLightFilename = "Jeopardy_Theme_light.wav";
private const string WuerfelImageFilename = "wuerfel.PNG";
public string JeopardyThemePath => Path.Combine(AssetFolder, JeopardyThemeFilename);
public string JeopardyLightPath => Path.Combine(AssetFolder, JeopardyLightFilename);
public string WuerfelImagePath => Path.Combine(AssetFolder, WuerfelImageFilename);
/// <summary>
/// Lädt Assets von git.hacksaar.de herunter
/// </summary>
public void LoadAssetsFromInternet()
{
if (!Directory.Exists(AssetFolder))
Directory.CreateDirectory(AssetFolder);
Task.WaitAll(
DownloadFile(JeopardyThemeFilename),
DownloadFile(JeopardyLightFilename),
DownloadFile(WuerfelImageFilename)
);
}
private Task DownloadFile(string filename)
{
return new WebClient().DownloadFileTaskAsync(new Uri(BaseUri, filename), Path.Combine(AssetFolder, filename));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace Jeoparody.Logic
......
......@@ -13,11 +13,15 @@ namespace Jeoparody
public partial class Board : Window
{
Game currentGame = null;
private Assets Assets { get; set; }
Random r = new Random(Guid.NewGuid().GetHashCode());
public Board(Game currentGame)
public Board(Game currentGame, Assets assets)
{
this.currentGame = currentGame;
this.Assets = assets;
InitializeComponent();
......@@ -89,7 +93,7 @@ namespace Jeoparody
QuestionView questionView = new QuestionView(
currentGame.board.categories[category], currentGame.board.categories[category].items[item].score,
currentGame.board.categories[category].items[item], currentGame);
currentGame.board.categories[category].items[item], currentGame, Assets);
questionView.ShowDialog();
currentGame.board.categories[category].items[item].playerAnswered = questionView.playerAnswered;
if (
......
......@@ -44,16 +44,20 @@ namespace Jeoparody
if (saveFileDialog.ShowDialog() == false)
return;
System.IO.TextWriter writer = new StreamWriter(saveFileDialog.FileName);
TextWriter writer = new StreamWriter(saveFileDialog.FileName);
for (int cat = 0; cat < 6; ++cat)
for (int categoryIndex = 0; categoryIndex < 6; ++categoryIndex)
{
writer.WriteLine(currentGame.board.categories[cat].title);
for (int item = 0; item < 5; ++item)
writer.WriteLine(currentGame.board.categories[cat].items[item].score.ToString() + ": " + currentGame.board.categories[cat].items[item].answer + " - " + currentGame.board.categories[cat].items[item].question);
var category = currentGame.board.categories[categoryIndex];
writer.WriteLine(category.title);
for (int itemIndex = 0; itemIndex < 5; ++itemIndex)
{
var item = category.items[itemIndex];
writer.WriteLine($"{item.score}: {item.answer} - {item.question}");
}
}
writer.Flush();
writer.Close();
}
......
......@@ -5,6 +5,7 @@ using Microsoft.Win32;
using Jeoparody.Logic;
using System.Reflection;
using System;
namespace Jeoparody
{
......@@ -18,12 +19,15 @@ namespace Jeoparody
Game currentGame = null;
SoundPlayer player = new SoundPlayer();
private Assets assets = new Assets();
public MainWindow()
{
InitializeComponent();
player.SoundLocation = "media/Jeopardy_Theme_retro.wav";
InitializeAssets();
player.SoundLocation = assets.JeopardyThemePath;
player.Load();
player.Play();
......@@ -65,6 +69,21 @@ namespace Jeoparody
LoadAndPrepareGame();
}
private void InitializeAssets()
{
if (File.Exists(assets.JeopardyThemePath))
return;
try
{
assets.LoadAssetsFromInternet();
}
catch (Exception ex)
{
MessageBox.Show("Beim Nachladen der Medien aus dem Internet ist ein Fehler aufgetreten: " + ex);
}
}
private void LoadAndPrepareGame()
{
currentGame = Game.Load(gameFileName);
......@@ -132,7 +151,7 @@ namespace Jeoparody
player.Stop();
Board board = new Board(currentGame);
Board board = new Board(currentGame, assets);
board.ShowDialog();
}
......
......@@ -6,7 +6,6 @@ using System.Windows.Media;
using System.Speech.Synthesis;
using System.Windows.Media.Imaging;
using System;
using System.Reflection;
using System.IO;
using System.Media;
......@@ -32,14 +31,14 @@ namespace Jeoparody
static SpeechSynthesizer synthesizer = new SpeechSynthesizer();
SoundPlayer player = new SoundPlayer();
public QuestionView(Category category, int score, QuizItem item, Game currentGame)
public QuestionView(Category category, int score, QuizItem item, Game currentGame, Assets assets)
{
this.item = item;
this.game = currentGame;
InitializeComponent();
player.SoundLocation = "media/Jeopardy_Theme_light.wav";
player.SoundLocation = assets.JeopardyLightPath;
player.Load();
player.Play();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment