Ein Objekt dieser Klasse repräsentiert eine Challenge.
Exemplo n.º 1
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++;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Versucht ein Challenge-Objekt zu erstellen.
        /// </summary>
        private bool TryConstructChallenge()
        {
            bool can = createButton.IsEnabled = createButtonBorder.IsEnabled = CanCreateChallenge;

            if (can) {
                ChallengeMetaData challengeMeta = new ChallengeMetaData (
                    name: challengeName.InputText,
                    start: selectedStartKnot.MetaData,
                    target: selectedTargetKnot.MetaData,
                    filename: null,
                    format: new ChallengeFileIO (),
                    highscore: new List<KeyValuePair<string,int>> ()
                );
                selectedChallenge = new Challenge (
                    meta: challengeMeta,
                    start: selectedStartKnot,
                    target: selectedTargetKnot
                );
            }
            else {
                selectedChallenge = null;
            }

            return can;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines ChallengeModeScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt, einem Spielerknoten playerKnot und dem Knoten challengeKnot, den der Spieler nachbauen soll.
        /// </summary>
        public ChallengeModeScreen(GameCore game, Challenge challenge)
            : base(game)
        {
            // world
            PlayerWorld = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromRight (percent: 0.5f));
            ChallengeWorld = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromLeft (percent: 0.5f));
            ChallengeWorld.Camera = PlayerWorld.Camera;
            PlayerWorld.OnRedraw += () => ChallengeWorld.Redraw = true;
            ChallengeWorld.OnRedraw += () => PlayerWorld.Redraw = true;
            // input
            playerKnotInput = new KnotInputHandler (screen: this, world: PlayerWorld);
            challengeKnotInput = new KnotInputHandler (screen: this, world: ChallengeWorld);
            // overlay
            overlay = new Overlay (screen: this, world: PlayerWorld);
            // pointer
            pointer = new MousePointer (screen: this);
            // model mouse handler
            playerModelMouseHandler = new ModelMouseHandler (screen: this, world: PlayerWorld);
            challengeModelMouseHandler = new ModelMouseHandler (screen: this, world: ChallengeWorld);

            // knot renderer
            PlayerKnotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            PlayerWorld.Add (PlayerKnotRenderer);
            ChallengeKnotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            ChallengeWorld.Add (ChallengeKnotRenderer);

            // debug displays
            debugBoundings = new DebugBoundings (screen: this, position: Vector3.Zero);

            // edge movements
            PlayerEdgeMovement = new EdgeMovement (screen: this, world: PlayerWorld, knotRenderer: PlayerKnotRenderer, position: Vector3.Zero);
            PlayerEdgeMovement.KnotMoved = OnKnotMoved;

            // assign the specified challenge
            Challenge = challenge;
            // assign the specified player knot
            PlayerKnot = challenge.Start.Clone () as Knot;
            // assign the specified target knot
            ChallengeKnotRenderer.RenderKnot (challenge.Target);
            // assign the specified start knot
            PlayerKnotRenderer.RenderKnot (PlayerKnot);

            SkyCube playerSkyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: 10000);
            PlayerWorld.Add (playerSkyCube);
            SkyCube challengeSkyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: 10000);
            ChallengeWorld.Add (challengeSkyCube);

            // Die Spielzeit-Anzeige
            playTimeDisplay = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: String.Empty);
            playTimeDisplay.Bounds.Position = new ScreenPoint (this, 0.800f, 0.01f);
            playTimeDisplay.Bounds.Size = new ScreenPoint (this, 0.15f, 0.04f);
            playTimeDisplay.BackgroundColorFunc = (s) => Design.WidgetBackground;
            playTimeDisplay.ForegroundColorFunc = (s) => Design.WidgetForeground;
            playTimeDisplay.AlignX = HorizontalAlignment.Center;
            playTimeBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                         widget: playTimeDisplay, lineWidth: 2, padding: 0);
            //Undo-Button
            undoButton = new Button (screen: this,
                                     drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                     name: "Undo",
                                     onClick: (time) => OnUndo ());
            undoButton.SetCoordinates (left: 0.55f, top: 0.900f, right: 0.65f, bottom: 0.95f);

            undoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: undoButton, lineWidth: 2, padding: 0);
            undoButton.AlignX = HorizontalAlignment.Center;
            undoButton.IsVisible = false;

            // Redo-Button
            redoButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Redo",
                onClick: (time) => OnRedo ()
            );
            redoButton.SetCoordinates (left: 0.70f, top: 0.900f, right: 0.80f, bottom: 0.95f);

            redoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: redoButton, lineWidth: 2, padding: 0);
            redoButton.AlignX = HorizontalAlignment.Center;
            redoButton.IsVisible = false;

            // die Linien
            lines = new Lines (screen: this, drawOrder: DisplayLayer.Dialog, lineWidth: 2);
            lines.AddPoints (0.500f, 0.000f, 0.500f, 1.000f);

            // Status
            state = ChallengeModeState.Start;
        }
 public TutorialChallengeModeScreen(Knot3Game game, Challenge challenge)
     : base(game, challenge)
 {
     throw new System.NotImplementedException ();
 }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        public HighscoreDialog(IScreen screen, DisplayLayer drawOrder, Challenge challenge)
            : base(screen, drawOrder, "Highscores")
        {
            // Der Titel-Text ist mittig ausgerichtet
            AlignX = HorizontalAlignment.Center;
            Bounds.Size = new ScreenPoint (screen, 0.60f, 0.5f);

            // Erstelle das Highscore-Menü
            highscoreList = new Menu (Screen, Index + DisplayLayer.Menu);
            highscoreList.Bounds = ContentBounds;
            highscoreList.ItemAlignX = HorizontalAlignment.Left;
            highscoreList.ItemAlignY = VerticalAlignment.Center;

            if (challenge.Highscore != null) {
                //sotiert die Highscoreliste wird nach der Zeit sotiert
                int highscoreCounter = 0;
                foreach (KeyValuePair<string, int> entry in challenge.Highscore.OrderBy (key => key.Value)) {
                    TimeSpan playTime = TimeSpan.FromSeconds (entry.Value);
                    string formattedPlayTime = (playTime.Hours * 60 + playTime.Minutes).ToString ("D2") + "m " + playTime.Seconds.ToString ("D2") + "s";

                    TextItem firstScore = new TextItem (screen, drawOrder, formattedPlayTime + "    " + entry.Key);
                    highscoreList.Add (firstScore);
                    highscoreCounter++;
                    if (highscoreCounter > 8) {
                        break;
                    }
                }
            }

            buttons = new Container (screen, Index + DisplayLayer.Menu);
            buttons.ItemBackgroundColor =(s) => Design.DialogBackground;
            buttons.ItemAlignX = HorizontalAlignment.Center;

            // Button zum Neustarten der Challenge
            Action<GameTime> restartAction = (time) => {
                Close (time);
                Screen.NextScreen = new ChallengeModeScreen (Screen.Game, challenge);
            };
            MenuEntry restartButton = new MenuEntry (
                screen: Screen,
                drawOrder: Index + DisplayLayer.MenuItem,
                name: "Restart challenge",
                onClick: restartAction
            );
            restartButton.Bounds.Size = new ScreenPoint (screen, ContentBounds.Size.Relative.X / 2, 0.05f);
            restartButton.Bounds.Position = ContentBounds.Position + ContentBounds.Size.OnlyY
                                            - restartButton.Bounds.Size.OnlyY;
            buttons.Add (restartButton);

            // Button für die Rückkehr zum StartScreen
            Action<GameTime> returnAction = (time) => {
                Close (time);
                Screen.NextScreen = new StartScreen (Screen.Game);
            };
            MenuEntry returnButton = new MenuEntry (
                screen: Screen,
                drawOrder: Index + DisplayLayer.MenuItem,
                name: "Return to menu",
                onClick: returnAction
            );
            returnButton.Bounds.Size = new ScreenPoint (screen, ContentBounds.Size.Relative.X / 2, 0.05f);
            returnButton.Bounds.Position = ContentBounds.Position + ContentBounds.Size.OnlyY
                                           - returnButton.Bounds.Size.OnlyY + ContentBounds.Size.OnlyX / 2;
            buttons.Add (returnButton);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Diese Methode wird für jede gefundene Spielstanddatei aufgerufen
        /// </summary>
        private void AddSavegameToList(string filename, ChallengeMetaData meta)
        {
            // Erstelle eine Lamdafunktion, die beim Auswählen des Menüeintrags ausgeführt wird
            Action<GameTime> LoadFile = (time) => {
                if (previewChallenge == null || previewChallenge.MetaData != meta) {
                    RemoveGameComponents (time, challengeInfo);
                    challengeInfo.Clear ();

                    previewChallenge = loader.FileFormat.Load (filename);
                    previewRenderer.RenderKnot (previewChallenge.Target);
                    previewWorld.Camera.ResetCamera ();
                    startButton.IsVisible = true;

                    MenuEntry countEntry = new MenuEntry (
                        screen: this,
                        drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                        name: Localizer.Localize ("Edge Count: ") + meta.Target.CountEdges,
                    onClick: (t) => {}
                    );
                    countEntry.Enabled = false;
                    challengeInfo.Add (countEntry);

                    MenuEntry avgtimeEntry = new MenuEntry (
                        screen: this,
                        drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                        name: ("Avg Time: ").Localize () + (meta.FormatedAvgTime).Localize (),
                    onClick: (t) => {}
                    );
                    avgtimeEntry.IsLocalized = false;
                    avgtimeEntry.Enabled = false;
                    challengeInfo.Add (avgtimeEntry);

                    if (filename.Contains (SystemInfo.SavegameDirectory)) {
                        MenuEntry deleteEntry = new MenuEntry (
                            screen: this,
                            drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                            name: "Delete",
                            onClick: (t) => deleteSavegame (filename, t)
                        );
                        deleteEntry.AddKey (Keys.Delete);
                        challengeInfo.Add (deleteEntry);
                    }

                    AddGameComponents (time, challengeInfo);
                }
            };

            // Finde den Namen der Challenge
            string name = meta.Name.Length > 0 ? meta.Name : filename;

            // Erstelle den Menüeintrag
            MenuEntry button = new MenuEntry (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: name,
                onClick: LoadFile
            );
            button.IsSelectable = true;
            button.IsLocalized = false;
            savegameMenu.Add (button);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Speichert eine Challenge in dem Dateinamen, der in dem Challenge-Objekt enthalten ist.
 /// </summary>
 public void Save(Challenge challenge, bool force)
 {
     if (!force && File.Exists (challenge.MetaData.Filename)) {
         throw new FileAlreadyExistsException ("Error! Challenge already exists!");
     }
     else {
         using (ZipFile zip = new ZipFile ()) {
             // Namen
             zip.AddEntry ("name.txt", challenge.Name);
             // Startknoten
             KnotStringIO parser = new KnotStringIO (challenge.Start);
             zip.AddEntry ("start.knot", parser.Content);
             // Zielknoten
             parser = new KnotStringIO (challenge.Target);
             zip.AddEntry ("target.knot", parser.Content);
             // Highscore
             zip.AddEntry ("highscore.txt", string.Join ("\n", printHighscore (challenge.Highscore)));
             // ZIP-Datei speichern
             zip.Save (challenge.MetaData.Filename);
         }
     }
 }