コード例 #1
0
        void OnContentViewSizeChanged(object sender, EventArgs args)
        {
            ContentView contentView = (ContentView)sender;

            WindowWidth  = contentView.Width;
            WindowHeight = contentView.Height;

            if (WindowWidth <= 0 || WindowHeight <= 0)
            {
                return;
            }

            // Orient StackLayout based on portrait/landscape mode.
            stackLayout.Orientation = (WindowWidth < WindowHeight) ? StackOrientation.Vertical :
                                      StackOrientation.Horizontal;

            // Calculate tile size and position based on ContentView size.
            tileSize = Math.Min(WindowWidth, WindowHeight) / Math.Min(Rows, Cols);
            absoluteLayout.WidthRequest  = Cols * tileSize;
            absoluteLayout.HeightRequest = Rows * tileSize;

            foreach (View view in absoluteLayout.Children)
            {
                PhotoHalfPairTile tile = (PhotoHalfPairTile)view;
                tile.InvalidSurfaceState();
                // Set tile bounds.
                AbsoluteLayout.SetLayoutBounds(tile,
                                               new Rectangle(tile.Col * tileSize, tile.Row * tileSize, tileSize, tileSize));
            }
        }
コード例 #2
0
        private async void ExecuteRotation(PhotoHalfPairTile tmp)
        {
            const float degreeStep       = 15.0f;
            const int   delayMicrosecond = 15;

            _Busy.Take(tmp);
            tmp.IsRotating = true;
            tmp.Flipped    = true;
            while (tmp.Deg <= 90 - degreeStep)
            {
                await Task.Delay(delayMicrosecond);

                await Device.InvokeOnMainThreadAsync(() => tmp.Deg = tmp.Deg + degreeStep);
            }
            while (tmp.Deg >= 0 + degreeStep)
            {
                await Task.Delay(delayMicrosecond);

                await Device.InvokeOnMainThreadAsync(() => tmp.Deg = tmp.Deg - degreeStep);
            }

            tmp.Deg        = 0;
            tmp.IsRotating = false;


            if (_Busy.State.Equals(BusyStates.Filled) || _Busy.State.Equals(BusyStates.Right))
            {
                int SRow = _Busy.Second.Row;
                int SCol = _Busy.Second.Col;
                while (tmp.IsRotating || tiles[SRow][SCol].IsRotating)
                {
                    continue;
                }
            }
            if (_Busy.State.Equals(BusyStates.Right))
            {
                ConfigEventArgs args = new ConfigEventArgs
                {
                    FRow = _Busy.First.Row,
                    FCol = _Busy.First.Col,
                    SRow = _Busy.Second.Row,
                    SCol = _Busy.Second.Col
                };
                RightConfiguration?.Invoke(this, args);
            }
            if (_Busy.State.Equals(BusyStates.Filled))
            {
                ConfigEventArgs args = new ConfigEventArgs
                {
                    FRow = _Busy.First.Row,
                    FCol = _Busy.First.Col,
                    SRow = _Busy.Second.Row,
                    SCol = _Busy.Second.Col
                };
                WrongConfiguration?.Invoke(this, args);
            }
        }
コード例 #3
0
 public PairCardsPage(int row, int col)
 {
     InitializeComponent();
     Rows  = row;
     Cols  = col;
     tiles = new PhotoHalfPairTile[row][];
     _Busy = new BusyBehavior();
     RightConfiguration += OnRightConfiguration;
     WrongConfiguration += OnWrongConfiguration;
     BackG.Source        = ImageSource.FromResource(App.PathToImages + "Pair.pair_background.png");
     Init();
 }
コード例 #4
0
        private void Init()
        {
            ImInfo = new SKImageInfo(150, 150);
            rnd    = new Random(DateTime.Now.Millisecond);
            List <string> faceImages = new List <string>();

            string[] folders        = new string[] { "lightblue", "lightgreen", "violet" };
            Assembly assembly       = GetType().GetTypeInfo().Assembly;
            string   selected_color = "";

            InitSound();
            InitCover(assembly, out selected_color);
            InitCheckMark(assembly, selected_color);

            string frontFolder = "";

            if (selected_color == "blue")
            {
                frontFolder = "lightblue";
            }
            if (selected_color == "green")
            {
                frontFolder = "lightgreen";
            }
            if (selected_color == "violet")
            {
                frontFolder = "violet";
            }

            IEnumerable <string> faces = from _tmp_faces_ in assembly.GetManifestResourceNames()
                                         where _tmp_faces_.Contains(frontFolder) && _tmp_faces_.Contains("Faces")
                                         select _tmp_faces_;

            for (int i = 0; i < Rows * Cols / 2; i++)
            {
                faceImages.Add(faces.ElementAt(i));
                faceImages.Add(faces.ElementAt(i));
            }


            Stream frontStream = null;

            for (int i = 0; i < Rows; i++)
            {
                tiles[i] = new PhotoHalfPairTile[Cols];
                for (int j = 0; j < Cols; j++)
                {
                    int    elem = rnd.Next(faceImages.Count);
                    string name = faceImages[elem];
                    faceImages.RemoveAt(elem);
                    string fullPath = name;

                    frontStream = assembly.GetManifestResourceStream(fullPath);
                    SKBitmap front = SKBitmap.Decode(frontStream).Resize(ImInfo, SKFilterQuality.High);
                    tiles[i][j]     = new PhotoHalfPairTile(TileBitmap, front);
                    tiles[i][j].Row = i;
                    tiles[i][j].Col = j;

                    name = Path.GetFileNameWithoutExtension(name);
                    int lInd = name.LastIndexOf('.');
                    name = name.Substring(lInd + 1);

                    tiles[i][j].FrontBitmapName = name;
                    TapGestureRecognizer tgr = new TapGestureRecognizer();
                    tgr.CommandParameter = tiles[i][j];
                    tgr.Command          = new Command <PhotoHalfPairTile>(ExecuteRotation, CanExecuteRotation);
                    tiles[i][j].AddGestureRecognizer(tgr);
                    absoluteLayout.Children.Add(tiles[i][j]);
                    frontStream.Close();
                }
            }
        }