コード例 #1
0
        public static Game2048Matrix GetGame2048Matrix()
        {
            _score     = 0;
            _maxNumber = 0;

            var game2048Matrix = new Game2048Matrix(6);

            game2048Matrix.Storage[GetExclusiveIndexes(game2048Matrix)] = GetTwoOrFour();
            game2048Matrix.Storage[GetExclusiveIndexes(game2048Matrix)] = GetTwoOrFour();

            game2048Matrix.Merged += (sender, args) =>
            {
                _score += args.MergedValue;
                if (args.MergedValue > _maxNumber)
                {
                    _maxNumber = args.MergedValue;
                }
            };

            game2048Matrix.Merged += (sender, args) => Trace.WriteLine(
                $"[GAME2048 MERGED] " +
                $"{args.Orientation}: " +
                $"({args.FromCell.X}, {args.FromCell.Y}) --> " +
                $"({args.ToCell.X}, {args.ToCell.Y}) = " +
                $"{args.MergedValue}");

            game2048Matrix.Moved += (sender, args) => Trace.WriteLine(
                $"[GAME2048 MOVED] " +
                $"{args.Orientation}: " +
                $"({args.FromCell.X}, {args.FromCell.Y}) --> " +
                $"({args.ToCell.X}, {args.ToCell.Y})");

            return(game2048Matrix);
        }
コード例 #2
0
        private static int GetExclusiveIndexes(Game2048Matrix matrix)
        {
            int result;

            do
            {
                result = Random.Next(0, matrix.Storage.Length);
            } while (matrix.Storage[result] != 0);

            return(result);
        }
コード例 #3
0
        public static void PrintMatrix(Game2048Matrix game2048Matrix)
        {
            var order = game2048Matrix.MatrixOrder;

            for (int i = 0; i < order; i++)
            {
                for (int j = 0; j < order; j++)
                {
                    var value = game2048Matrix[j, i];
                    Console.Write($"{(value == 0 ? "." : value.ToString()),-5} ");
                }
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
            }
        }