Implementiert das Speicherformat für Challenges.
Inheritance: IChallengeIO
 public void ChallengeMetaDataHighscore_Test()
 {
     ChallengeFileIO file = new ChallengeFileIO ();
     ChallengeMetaData meta = file.LoadMetaData (TestHelper.TestResourcesDirectory + "TestChallenge.challenge");
     Assert.AreEqual (meta.AvgTime, 7.666666f, 0.0001f);
     Assert.AreEqual (ChallengeMetaData.formatTime (1337f), "00h:22m:17s");
     Assert.AreEqual (meta.FormatedAvgTime, "00h:00m:07s");
     {
         string[] names = { "Erster", "Dritter", "Zweiter" };
         int[] times = { 1, 15, 7 };
         int position = 0;
         foreach (KeyValuePair<string, int> entry in meta.Highscore) {
             Assert.AreEqual (entry.Key, names [position]);
             Assert.AreEqual (entry.Value, times [position]);
             position++;
         }
     }
     meta.AddToHighscore ("Noob", 1337);
     {
         string[] names = { "Erster", "Dritter", "Zweiter", "Noob"};
         int[] times = { 1, 15, 7, 1337 };
         int position = 0;
         foreach (KeyValuePair<string, int> entry in meta.Highscore) {
             Assert.AreEqual (entry.Key, names [position]);
             Assert.AreEqual (entry.Value, times [position]);
             position++;
         }
     }
 }
 public void ChallengeFileIO_Test()
 {
     ChallengeFileIO fileIO = new ChallengeFileIO ();
     Assert.DoesNotThrow (() => { fileIO.Load (filename); });
     Assert.DoesNotThrow (() => { fileIO.LoadMetaData (filename); });
     Assert.Throws<FileNotFoundException>(() => { fileIO.Load (TestHelper.TestResourcesDirectory + "DoesNotExist.challenge"); });
     Assert.Throws<IOException>(() => { fileIO.Load (TestHelper.TestResourcesDirectory + "invalid.challenge"); });
     Challenge tempChallenge = fileIO.Load (filename);
     File.Delete (filename);
     tempChallenge.Save (true);
     Challenge tempChallenge2 = fileIO.Load (filename);
     Assert.AreEqual (tempChallenge.MetaData, tempChallenge2.MetaData);
 }
Exemple #3
0
 public void Challenge_Test()
 {
     ChallengeFileIO file = new ChallengeFileIO ();
     ChallengeMetaData meta = file.LoadMetaData (filename);
     Challenge challenge = file.Load (filename);
     Challenge secondChallenge = new Challenge (meta, challenge.Start, challenge.Target);
     challenge.Name = "other";
     Assert.AreEqual (challenge.Name, "other");
     Assert.AreNotEqual (secondChallenge.Name, "other");
     challenge.AddToHighscore ("Noob", 1337);
     string[] names = { "Erster", "Dritter", "Zweiter", "Noob" };
     int[] times = { 1, 15, 7, 1337 };
     int position = 0;
     foreach (KeyValuePair<string, int> entry in challenge.Highscore) {
         Assert.AreEqual (entry.Key, names [position]);
         Assert.AreEqual (entry.Value, times [position]);
         position++;
     }
 }
        /// <summary>
        /// Erstellt eine neue Instanz eines ChallengeStartScreen-Objekts und
        /// initialisiert diese mit einem Knot3Game-Objekt.
        /// </summary>
        public ChallengeStartScreen(GameCore game)
            : base(game)
        {
            savegameMenu = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            savegameMenu.Bounds.Position = ScreenContentBounds.Position;
            savegameMenu.Bounds.Size = new ScreenPoint (this, 0.300f, ScreenContentBounds.Size.Relative.Y);
            savegameMenu.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            savegameMenu.ItemAlignX = HorizontalAlignment.Left;
            savegameMenu.ItemAlignY = VerticalAlignment.Center;
            savegameMenu.ItemBackgroundColor = Design.ComboBoxItemBackgroundColorFunc;
            savegameMenu.ItemForegroundColor = Design.ComboBoxItemForegroundColorFunc;
            savegameMenu.RelativeItemHeight = Design.DataItemHeight;

            lines.AddPoints (.000f, .050f, .030f, .970f, .620f, .895f, .740f, .970f, .760f, .895f, .880f, .970f, .970f, .050f, 1.000f);

            title = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: "Start Challenge");
            title.Bounds.Position = ScreenTitleBounds.Position;
            title.Bounds.Size = ScreenTitleBounds.Size;
            title.ForegroundColorFunc = (s) => Color.White;

            infoTitle = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: "Challenge Info:");
            infoTitle.Bounds.Position = new ScreenPoint (this, 0.45f, 0.62f);
            infoTitle.Bounds.Size = new ScreenPoint (this, 0.900f, 0.050f);
            infoTitle.ForegroundColorFunc = (s) => Color.White;

            challengeInfo = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            challengeInfo.Bounds.Position = new ScreenPoint (this, 0.47f, 0.70f);
            challengeInfo.Bounds.Size = new ScreenPoint (this, 0.300f, 0.500f);
            challengeInfo.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            challengeInfo.ItemAlignX = HorizontalAlignment.Left;
            challengeInfo.ItemAlignY = VerticalAlignment.Center;

            // Erstelle einen Parser für das Dateiformat
            ChallengeFileIO fileFormat = new ChallengeFileIO ();
            // Erstelle einen Spielstand-Loader
            loader = new SavegameLoader<Challenge, ChallengeMetaData> (fileFormat, "index-challenges");

            // Preview
            Bounds previewBounds = new Bounds (this, 0.45f, 0.1f, 0.48f, 0.5f);
            previewWorld = new World (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.GameWorld,
                bounds: previewBounds
            );
            previewRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            previewWorld.Add (previewRenderer);
            previewBorder = new Border (
                screen: this,
                drawOrder: DisplayLayer.GameWorld,
                bounds: previewBounds,
                lineWidth: 2,
                padding: 0
            );
            previewInput = new KnotInputHandler (screen: this, world: previewWorld);
            previewMouseHandler = new ModelMouseHandler (screen: this, world: previewWorld);

            backButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Back",
                onClick: (time) => NextScreen = Game.Screens.Where ((s) => !(s is ChallengeStartScreen)).ElementAt (0)
            );
            backButton.AddKey (Keys.Escape);

            backButton.SetCoordinates (left: 0.770f, top: 0.910f, right: 0.870f, bottom: 0.960f);
            backButton.AlignX = HorizontalAlignment.Center;
            Action<GameTime> loadSelectedChallenge = (time) => {
                NextScreen = new ChallengeModeScreen (
                    game: Game,
                    challenge: loader.FileFormat.Load (previewChallenge.MetaData.Filename)
                );
            };
            startButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Start",
                onClick: loadSelectedChallenge
            );
            startButton.IsVisible = false;
            startButton.AddKey (Keys.Enter);
            startButton.SetCoordinates (left: 0.630f, top: 0.910f, right: 0.730f, bottom: 0.960f);

            startButton.AlignX = HorizontalAlignment.Center;
        }