IntRect SelectLevelLandskape(TrackModel level)
        {
            var land      = AssetsCoordinates.Generic.Boxes.LevelBlocked;
            int landskape = level.Landskape;
            int completed = level.Completed;

            // TODO: set blocked levels
            //if (completed == 0 && counter > lastComplededRace + 1 && !(counter == lastComplededRace + 1)) {
            //    land = AssetsCoordinates.Generic.Boxes.LevelBlocked;
            //}
            //else {
            if (landskape == 0)
            {
                Random rnd = new Random();
                landskape = rnd.Next(1, 4);     // creates a number between 1 and 3
            }

            switch (landskape)
            {
            case 1:
                land = AssetsCoordinates.Generic.Boxes.LevelSnow;
                break;

            case 2:
                land = AssetsCoordinates.Generic.Boxes.LevelMoon;
                break;

            case 3:
                land = AssetsCoordinates.Generic.Boxes.LevelBeach;
                break;
            }
            //}

            return(land);
        }
Пример #2
0
        public ScenePostRace(Game game, bool randomLevel = false) : base(game)
        {
            dim        = GameInstance.ScreenInfo;
            root       = GameInstance.UI.Root;
            cache      = GameInstance.ResourceCache;
            font       = cache.GetFont(GameInstance.defaultFont);
            _levelInfo = TrackManager.Instance.SelectedTrackModel ?? null;

            // Update best time data if not random level
            if (!randomLevel)
            {
                UpdateLevelInfo();
            }

            CreateBackground();
            CreateTopBar();
            CreateScene();
        }
Пример #3
0
        async Task <bool> InitTrackManager()
        {
            try {
                // Get default level
                if (Tracks == null || Tracks.TrackModel.Count == 0)
                {
                    var model = new TracksContainerModel {
                        TrackModel = new List <TrackModel>()
                    };
                    model.TrackModel.Add(new TrackModel {
                        IdTrack         = 0,
                        GuidTrack       = new Guid(),
                        Name            = "Random track",
                        Difficulty      = 1,
                        TrackLength     = 3600,
                        Landskape       = 0,
                        Completed       = 0,
                        BestTime        = 0,
                        TotalOfPlays    = 0,
                        TotalOfFailures = 0,
                        TotalPoints     = 0,
                        PointsObtained  = 0
                    });
                    Tracks = model;
                }
                //Tracks = JsonReaderLevels.GetLevelsConfig();

                // Get SRS levels and convert data to game model
                var srsTracks = await DataStore.GetCollectedTracks(TimeOrdering.OldFirst);

                var currentTracks = Tracks;

                foreach (var t in srsTracks)
                {
                    // Don't import any tracks with null distance
                    if (t.RecordingDistance <= 0)
                    {
                        continue;
                    }

                    // Don't import any tracks that are shorter than
                    var points = await DataStore.GetTrackLength(t.Id);

                    Debug.WriteLine($"TRACK DATA: {t.Id}: {t.RecordedOn} - {t.RecordingDistance} - {t.RecordingLength}, {points} ppe points.");

                    if (points < 900)
                    {
                        continue;
                    }

                    // If track is longer than 3600 points, divide it into smaller tracks
                    int numTracks = 1;
                    if (points > _maxTrackLength)
                    {
                        Debug.WriteLine("Tracks over 3600 - dividing it");
                        var tracks = (double)points / _maxTrackLength;
                        numTracks = (int)Math.Truncate(tracks);
                        if ((double)points % _maxTrackLength >= _minTrackLength)
                        {
                            numTracks += 1;
                        }
                    }
                    var exists = currentTracks.TrackModel.Exists(track => track.GuidTrack == t.Id);
                    if (exists)
                    {
                        continue;
                    }

                    var landskape = _random.Next(1, 4);
                    for (var i = 0; i < numTracks; i++)
                    {
                        int trackLength = points;
                        if (numTracks > 1)
                        {
                            if (i < numTracks - 1)
                            {
                                trackLength = _maxTrackLength;
                            }
                            else
                            {
                                trackLength = points % _maxTrackLength;
                            }
                        }
                        var model = new TrackModel {
                            IdTrack         = currentTracks.TrackModel.Count,
                            GuidTrack       = t.Id,
                            Name            = "Track " + (currentTracks.TrackModel.Count + 1),
                            Difficulty      = CharacterManager.Instance.User.Level,
                            TrackLength     = trackLength,
                            Landskape       = landskape,
                            Completed       = 0,
                            BestTime        = 0,
                            TotalOfPlays    = 0,
                            TotalOfFailures = 0,
                            TotalPoints     = 0,
                            PointsObtained  = 0
                        };
                        currentTracks.TrackModel.Add(model);
                    }
                }

                Tracks = currentTracks;
                return(true);
            } catch (Exception e) {
                Debug.WriteLine("Error initializing tracks: " + e);
                return(false);
            }
        }