Example #1
0
        /// <summary>
        /// Вызывается при приостановке выполнения приложения.  Состояние приложения сохраняется
        /// без учета информации о том, будет ли оно завершено или возобновлено с неизменным
        /// содержимым памяти.
        /// </summary>
        /// <param name="sender">Источник запроса приостановки.</param>
        /// <param name="e">Сведения о запросе приостановки.</param>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            //TODO: Сохранить состояние приложения и остановить все фоновые операции
            var audio = StaticContent.NowPlay;
            var file  = new LastPlay()
            {
                Playlist = StaticContent.NowPlayPlaylist,
                Track    = audio,
                Volume   = StaticContent.Volume
            };
            var json = JsonConvert.SerializeObject(file);

            try
            {
                var lastFile = await StaticContent.LocalFolder.GetFileAsync("LastPlay.json");

                await FileIO.WriteTextAsync(lastFile, json);
            }
            catch
            {
                var lastFile = await StaticContent.LocalFolder.CreateFileAsync("LastPlay.json");

                await FileIO.WriteTextAsync(lastFile, json);
            }

            //MemoryManager.

            deferral.Complete();
        }
Example #2
0
        public void Play()
        {
            _userInterface.RenderMessage("Please input your shoot coordinates (x, y) in format [Letter][Number], e.g. A5");
            _userInterface.RenderMessage("Board go from A to " + Position.GetLetterFromX(_board.Width + 64) + " and from 0 to " + (_board.Height - 1));

            while (true)
            {
                var coordinates = _userInterface.GetUserInput();

                if (!AreValidCoordinates(coordinates))
                {
                    _lastPlay = LastPlay.Error;
                    _userInterface.RenderMessage(GetLastPlayMessage());
                    _userInterface.RenderMessage("Your coordinates are invalid. Please make sure is in the format [Letter][Number], e.g A5");
                    _userInterface.RenderMessage("Board go from A to " + Position.GetLetterFromX(_board.Width + 64) + " and from 0 to " + (_board.Height - 1));
                    continue;
                }

                var shootPosition = new Position(coordinates);


                if (_board.IsCoordinateAlreadyUsed(shootPosition))
                {
                    _lastPlay = LastPlay.AlreadyHit;
                    _userInterface.RenderMessage(GetLastPlayMessage());
                    continue;
                }


                var cellStatus = _board.ProcessShipHit(shootPosition);

                switch (cellStatus)
                {
                case CellStatus.Hit:
                    this._lastPlay = LastPlay.Hit;
                    break;

                case CellStatus.Sunk:
                    this._lastPlay = LastPlay.Sunk;
                    break;

                case CellStatus.Miss:
                    this._lastPlay = LastPlay.Miss;
                    break;

                case CellStatus.Invalid:
                default:
                    this._lastPlay = LastPlay.Error;
                    break;
                }

                _userInterface.RenderMessage(GetLastPlayMessage());


                if (_board.AreAllShipsSunk())
                {
                    ProcessGameEnd();
                    break;
                }
            }
        }
Example #3
0
 public GameProcessor(IBoardFactory boardFactory, IUserInterface userInterface)
 {
     this._board         = boardFactory.Get();
     this._userInterface = userInterface;
     _lastPlay           = LastPlay.Init;
 }
        public void Play()
        {
            _userInterface.RenderMessage("Please input your shoot coordinates (x, y) in format [Letter][Number], e.g. B3");
            _userInterface.RenderMessage("Board go from A to " + Position.GetLetterFromX(_board.Width + 64) + " and from 0 to " + (_board.Height - 1));

            while (true)
            {
                var coordinates = _userInterface.GetUserInput();

                if (!AreValidCoordinates(coordinates))
                {
                    _lastPlay = LastPlay.Error;
                    _userInterface.RenderMessage(GetLastPlayMessage());
                    _userInterface.RenderMessage("Your coordinates are invalid. Please make sure is in the format [Letter][Number], e.g A7");
                    _userInterface.RenderMessage("Board go from A to " + Position.GetLetterFromX(_board.Width + 64) + " and from 0 to " +  (_board.Height - 1));
                    continue;
                }

                var shootPosition = new Position(coordinates);


                if (_board.IsCoordinateAlreadyUsed(shootPosition))
                {
                    _lastPlay = LastPlay.AlreadyHit;
                    _userInterface.RenderMessage(GetLastPlayMessage());
                    continue;
                }


                var cellStatus = _board.ProcessShipHit(shootPosition);

                switch (cellStatus)
                {
                    case CellStatus.Hit:
                        this._lastPlay = LastPlay.Hit;
                        break;
                    case CellStatus.Sunk:
                        this._lastPlay = LastPlay.Sunk;
                        break;
                    case CellStatus.Miss:
                        this._lastPlay = LastPlay.Miss;
                        break;
                    case CellStatus.Invalid:
                    default:
                        this._lastPlay = LastPlay.Error;
                        break;
                }

                _userInterface.RenderMessage(GetLastPlayMessage());


                if (_board.AreAllShipsSunk())
                {
                    ProcessGameEnd();
                    break;
                }


            }

        }
 public GameProcessor(IBoardFactory boardFactory, IUserInterface userInterface)
 {
     this._board = boardFactory.Get();
     this._userInterface = userInterface;
     _lastPlay = LastPlay.Init;
 }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            ProgressRing.IsActive  = true;
            Start.Text             = "Music X выполняет первичную настройку. Пожалуйста, подождите...";
            ButtonStart.Visibility = Visibility.Collapsed;

            //создание папки с плейлистами.
            var localpath = ApplicationData.Current.LocalFolder;

            if (await localpath.TryGetItemAsync("Playlists") == null)
            {
                var pathPlaylists = await localpath.CreateFolderAsync("Playlists");

                StaticContent.PlaylistsFolder = pathPlaylists;
                var filePlaylistId1 = await pathPlaylists.CreateFileAsync("Id1.json");

                var filePlaylistId2 = await pathPlaylists.CreateFileAsync("Id2.json");

                var playlistLastPlay = new Models.PlaylistFile()
                {
                    Artist      = "Music X",
                    Cover       = "ms-appx:///Assets/Images/latest.png",
                    Id          = 1,
                    Name        = "Слушали недавно",
                    IsLocal     = true,
                    TracksFiles = new List <AudioFile>()
                };

                var playlistFavorite = new Models.PlaylistFile()
                {
                    Artist      = "Music X",
                    Cover       = "ms-appx:///Assets/Images/favorites.png",
                    Id          = 2,
                    Name        = "Избранное",
                    IsLocal     = true,
                    TracksFiles = new List <AudioFile>()
                };

                var jsonPlaylistId1 = JsonConvert.SerializeObject(playlistLastPlay);
                var jsonPlaylistId2 = JsonConvert.SerializeObject(playlistFavorite);
                await FileIO.WriteTextAsync(filePlaylistId1, jsonPlaylistId1);

                await FileIO.WriteTextAsync(filePlaylistId2, jsonPlaylistId2);
            }

            if (await localpath.TryGetItemAsync("Covers") == null)
            {
                StaticContent.CoversFolder = await localpath.CreateFolderAsync("Covers");
            }

            if (await localpath.TryGetItemAsync("MusicCollection.json") == null)
            {
                var musicFile = await localpath.CreateFileAsync("MusicCollection.json");

                var musicString = JsonConvert.SerializeObject(new MusicCollection()
                {
                    Music          = new List <AudioFile>(),
                    DateLastUpdate = "none"
                });
                await FileIO.WriteTextAsync(musicFile, musicString);
            }

            if (await localpath.TryGetItemAsync("LastPlay.json") == null)
            {
                var lastFile = await localpath.CreateFileAsync("LastPlay.json");

                var audio = new AudioFile()
                {
                    Artist          = "",
                    Cover           = "ms-appx:///Assets/Images/placeholder.png",
                    DurationMinutes = "00:00",
                    DurationSeconds = 0,
                    Id           = -2,
                    InternalId   = -2,
                    OwnerId      = -2,
                    PlaylistId   = 1,
                    SourceString = "ms-appx:///Assets/Audio/song.mp3",
                    Source       = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Audio/song.mp3")),
                    Title        = "Сейчас ничего не воспроизводится"
                };
                var lastplayModel = new LastPlay()
                {
                    Playlist = null,
                    Track    = audio,
                    Volume   = 1.0f,
                };
                var jsonLastFile = JsonConvert.SerializeObject(lastplayModel);
                await FileIO.WriteTextAsync(lastFile, jsonLastFile);
            }

            if (await localpath.TryGetItemAsync("ConfigApp.json") == null)
            {
                var configFile = await localpath.CreateFileAsync("ConfigApp.json");

                var config = new ConfigApp()
                {
                    FindInDocumentsLibrary = false,
                    FindInMusicLibrary     = true,
                    ThemeApp    = 0,
                    StreamMusic = true
                };
                var configString = JsonConvert.SerializeObject(config);
                await FileIO.WriteTextAsync(configFile, configString);

                StaticContent.Config = config;
            }

            var settings = ApplicationData.Current.LocalSettings;

            settings.Values["themeApp"] = 0;

            await LikedArtistsService.CreateLikedArtstsFile();

            await MusicFilesService.GetMusicLocal(true);

            var rootFrame = (Frame)Window.Current.Content;

            rootFrame.Navigate(typeof(Views.MainFrameView), null);
        }