Example #1
0
        public static ButtonStroked CreateDeviceButton(BluetoothConnectionActivity activity, BluetoothDevice device, TetrisColor color, int minHeight, int defaultText)
        {
            if(device == null)
            {
                return CreateDeviceButton(activity, device, color, minHeight, activity.Resources.GetString(defaultText));
            }

            return CreateDeviceButton(activity, device, color, minHeight, device.Name);
        }
Example #2
0
 public static Color getAndroidColor(TetrisColor color, ColorShade shade)
 {
     switch(shade)
     {
     case ColorShade.ReallyLight:
         return getAndroidReallyLightColor(color);
     case ColorShade.Light:
         return getAndroidLightColor(color);
     case ColorShade.Normal:
         return getAndroidColor(color);
     case ColorShade.Dark:
         return getAndroidDarkColor(color);
     case ColorShade.ReallyDark:
         return getAndroidReallyDarkColor(color);
     default:
         return Color.Black;
     };
 }
Example #3
0
        private void DrawTetrominoe(Shape shape)
        {
            switch (shape)
            {
            case Shape.T_Block:
                _shapeTemplate = Tetrominoes.T_Block;
                break;

            case Shape.S_Block:
                _shapeTemplate = Tetrominoes.S_Block;
                break;

            case Shape.Z_Block:
                _shapeTemplate = Tetrominoes.Z_Block;
                break;

            case Shape.I_Block:
                _shapeTemplate = Tetrominoes.I_Block;
                break;

            case Shape.L_Block:
                _shapeTemplate = Tetrominoes.L_Block;
                break;

            case Shape.J_Block:
                _shapeTemplate = Tetrominoes.J_Block;
                break;

            case Shape.O_Block:
                _shapeTemplate = Tetrominoes.O_Block;
                break;

            default:
                throw new Exception("Tetrominoe not exits.");
            }

            _shapeColor = (TetrisColor)((int)shape /* * _shapeLevel*/);

            Y += GetStartYPos();

            Render();
        }
Example #4
0
 public static ButtonStroked CreateDeviceButton(BluetoothConnectionActivity activity, BluetoothDevice device, TetrisColor color, int minHeight, string text)
 {
     ButtonStroked button = new ButtonStroked(activity);
     button.Settings = DeviceButtonUI.Clone();
     button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade);
     button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade);
     button.SetMinimumHeight(minHeight);
     int padding = Utils.GetPixelsFromDP(activity, button.Settings.Padding);
     button.SetPadding(padding, padding, padding, padding);
     button.Text = text;
     if(device != null)
     {
         button.Tag = device.Address;
         button.Click += delegate {
             activity.DeviceListClick(button);
         };
     }
     else
     {
         button.Enabled = false;
     }
     return button;
 }
Example #5
0
 public static Color getAndroidReallyDarkColor(TetrisColor color)
 {
     switch (color)
     {
     case TetrisColor.Red:
         return Color.ParseColor("#ff1a0000");
     case TetrisColor.Orange:
         return Color.ParseColor("#ff1a0d00");
     case TetrisColor.Yellow:
         return Color.ParseColor("#ff1a1a00");
     case TetrisColor.Green:
         return Color.ParseColor("#ff001a00");
     case TetrisColor.Cyan:
         return Color.ParseColor("#ff001a1a");
     case TetrisColor.Blue:
         return Color.ParseColor("#ff00001a");
     case TetrisColor.Magenta:
         return Color.ParseColor("#ff1a001a");
     default:
         return Color.ParseColor("#ff000000");
     }
 }
Example #6
0
 public static void SetDeviceMenuButton(Activity activity, ref ButtonStroked button, int id, TetrisColor color)
 {
     button = activity.FindViewById<ButtonStroked>(id);
     button.Settings = DeviceMenuButtonUI.Clone();
     button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade);
     button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade);
 }
Example #7
0
        public static ConsoleColor GetColorByIndex(int index)
        {
            TetrisColor name = (TetrisColor)index;

            return(FromColor(Color.FromName(name.ToString())));
        }
Example #8
0
 // Turn a color name into an Android Color
 public static Color getAndroidColor(TetrisColor color)
 {
     switch (color)
     {
     case TetrisColor.Red:
         return Color.ParseColor("#ffff0000");
     case TetrisColor.Orange:
         return Color.ParseColor("#ffff8000");
     case TetrisColor.Yellow:
         return Color.ParseColor("#ffffff00");
     case TetrisColor.Green:
         return Color.ParseColor("#ff00ff00");
     case TetrisColor.Cyan:
         return Color.ParseColor("#ff00ffff");
     case TetrisColor.Blue:
         return Color.ParseColor("#ff0000ff");
     case TetrisColor.Magenta:
         return Color.ParseColor("#ffff00ff");
     default:
         return Color.ParseColor("#ff808080");
     }
 }
Example #9
0
 //--------------------------------------------------------------
 // BUTTONS INITIALIZATION
 //--------------------------------------------------------------
 public static void SetMenuButton(ButtonStroked button, TetrisColor color)
 {
     button.Settings = MenuButtonUI.Clone();
     button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade);
     button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade);
 }
Example #10
0
 public static void SetIconButtonWithHeight(ButtonStroked button, TetrisColor color)
 {
     button.Settings = IconButtonUI.Clone();
     button.LayoutParameters.Width = MenuButtonHeight*2/3;
     button.LayoutParameters.Height = MenuButtonHeight*2/3;
     SetBaseIconButton(button, color, button.LayoutParameters.Height, button.LayoutParameters.Height/2);
 }
Example #11
0
 public static void SetIconButton(ButtonStroked button, TetrisColor color, int difference)
 {
     button.Settings = IconButtonUI.Clone();
     SetBaseIconButton(button, color, button.MeasuredWidth + difference, (button.MeasuredWidth + difference)/2);
 }
Example #12
0
 public static void SetGamePlayerStatText(Activity activity, int id, bool me, bool isTitle, TetrisColor color)
 {
     TextView textView = activity.FindViewById<TextView>(id);
     textView.SetBackgroundColor(Utils.getAndroidColor(color));
     textView.SetTextColor(!isTitle ? (me ? UtilsUI.Player1Background : UtilsUI.Player2Background)
         : Utils.getAndroidDarkColor(color));
 }
Example #13
0
 public static void SetGamePlayerNameText(Activity activity, int id, TetrisColor color)
 {
     TextView textView = activity.FindViewById<TextView>(id);
     textView.SetTextColor(Utils.getAndroidColor(color));
 }
Example #14
0
 public static void SetDialogButton(DialogActivity activity, ButtonStroked button, EditText field, TetrisColor color, string text, EventHandler action, bool answer)
 {
     if(!String.IsNullOrEmpty(text))
     {
         button.Settings = DialogButtonUI.Clone();
         button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade);
         button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade);
         button.Text = text;
         button.Click += delegate {
             DialogBuilder.ReturnText = (DialogActivity.Builder.RequestCode == DialogBuilder.DialogRequestCode.Text ) ? field.Text : null;
         };
         button.Click += action;
         button.Click += delegate {
             Intent intent = new Intent();
             switch(DialogActivity.Builder.RequestCode)
             {
             case DialogBuilder.DialogRequestCode.PosOrNeg:
                 intent.PutExtra(DialogActivity.Builder.RequestCode.ToString(), answer);
                 activity.SetResult(Result.Ok, intent);
                 activity.Finish();
                 break;
             case DialogBuilder.DialogRequestCode.Text:
                 if(answer)
                 {
                     if(!String.IsNullOrWhiteSpace(field.Text))
                     {
                         intent.PutExtra(DialogActivity.Builder.RequestCode.ToString(), field.Text);
                         activity.SetResult(Result.Ok, intent);
                         activity.Finish();
                     }
                 }
                 else
                 {
                     activity.SetResult(Result.Canceled);
                     activity.Finish();
                 }
                 break;
             default:
                 break;
             }
         };
     }
 }
Example #15
0
 public static Color getAndroidReallyLightColor(TetrisColor color)
 {
     switch (color)
     {
     case TetrisColor.Red:
         return Color.ParseColor("#ffffe5e5");
     case TetrisColor.Orange:
         return Color.ParseColor("#fffff2e5");
     case TetrisColor.Yellow:
         return Color.ParseColor("#ffffffe5");
     case TetrisColor.Green:
         return Color.ParseColor("#ffe5ffe5");
     case TetrisColor.Cyan:
         return Color.ParseColor("#ffe5ffff");
     case TetrisColor.Blue:
         return Color.ParseColor("#ffe5e5ff");
     case TetrisColor.Magenta:
         return Color.ParseColor("#ffffe5ff");
     default:
         return Color.ParseColor("#ffffffff");
     }
 }
Example #16
0
 public static void SetMenuButtonWithHeight(ButtonStroked button, TetrisColor color)
 {
     SetMenuButton(button, color);
     button.LayoutParameters.Width = ViewGroup.LayoutParams.MatchParent;
     button.LayoutParameters.Height = MenuButtonHeight;
 }
Example #17
0
 //--------------------------------------------------------------
 // TEXT INITIALIZATION
 //--------------------------------------------------------------
 public static void SetTitleTextView(TextView titleTextView, TetrisColor color)
 {
     titleTextView.SetTypeface(UtilsUI.TitleFont, TypefaceStyle.Normal);
     titleTextView.SetTextColor(Utils.getAndroidColor(color));
 }
Example #18
0
        //--------------------------------------------------------------
        // STATIC METHODS
        //--------------------------------------------------------------
        public static Bitmap CreateImage(int blockSize, TetrisColor color)
        {
            if(color == TetrisColor.ColorMax)
                return null;

            // Create the image with its canvas to draw in it
            Bitmap image = Bitmap.CreateBitmap(blockSize, blockSize, Bitmap.Config.Argb8888);
            Canvas imageCanvas = new Canvas(image);

            // Calculate the width of the borders with a percentage of the size of the block
            float borderWidth = BorderWidth * blockSize;
            float borderWidth3D = BorderWidth3D * blockSize;

            // Calculate all the colors for the block based on its tetris color
            Color baseColor = adjustColor(Utils.getAndroidColor(color), SvBaseColor);
            Color topColor = adjustColor(baseColor, SvTopColor);
            Color leftColor = adjustColor(baseColor, SvLeftColor);
            Color rightColor = adjustColor(baseColor, SvRightColor);
            Color bottomColor = adjustColor(baseColor, SvBottomColor);
            Color borderColor = adjustColor(baseColor, SvBorderColor);

            // Draw the border
            Paint borderPaint = new Paint {AntiAlias = true, Color = borderColor};
            for(int i = 0 ; i < BorderWidth ; i++)
            {
                imageCanvas.DrawRect(i, blockSize - i, blockSize - i, i, borderPaint);
            }
            borderPaint.Dispose();

            // Define the corners of the big rectangle without the border
            PointF outerRectTopLeft = new PointF(
                borderWidth,
                borderWidth);
            PointF outerRectTopRight = new PointF(
                blockSize - borderWidth,
                borderWidth);
            PointF outerRectBottomRight = new PointF(
                blockSize - borderWidth,
                blockSize - borderWidth);
            PointF outerRectBottomLeft = new PointF(
                borderWidth,
                blockSize - borderWidth);

            // Define the corners of the small rectangle in the middle
            PointF innerRectTopLeft = new PointF(
                borderWidth + borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectTopRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectBottomRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                blockSize -borderWidth - borderWidth3D);
            PointF innerRectBottomLeft = new PointF(
                borderWidth + borderWidth3D,
                blockSize -borderWidth - borderWidth3D);

            // Draw inner square
            PointF[] innerSquare = new[]
            {
                innerRectTopLeft,
                innerRectTopRight,
                innerRectBottomRight,
                innerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, innerSquare, baseColor);

            // Draw top 3D border
            PointF[] top3dBorder = new[]
            {
                outerRectTopLeft,
                outerRectTopRight,
                innerRectTopRight,
                innerRectTopLeft
            };
            drawPolygonInCanvas(imageCanvas, top3dBorder, topColor);

            // Draw bottom 3D border
            PointF[] bottom3dBorder = new[]
            {
                innerRectBottomLeft,
                innerRectBottomRight,
                outerRectBottomRight,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, bottom3dBorder, bottomColor);

            // Draw left 3D border
            PointF[] left3dBorder = new[]
            {
                outerRectTopLeft,
                innerRectTopLeft,
                innerRectBottomLeft,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, left3dBorder, leftColor);

            // Draw right 3D border
            PointF[] right3dBorder = new[]
            {
                innerRectTopRight,
                outerRectTopRight,
                outerRectBottomRight,
                innerRectBottomRight
            };
            drawPolygonInCanvas(imageCanvas, right3dBorder, rightColor);

            imageCanvas.Dispose();

            return image;
        }
Example #19
0
 private static void SetBaseIconButton(ButtonStroked button, TetrisColor color, int height)
 {
     SetBaseIconButton(button, color, height, height);
 }
Example #20
0
 public static ConsoleColor GetColorByName(TetrisColor name)
 {
     return(FromColor(Color.FromName(name.ToString())));
 }
Example #21
0
 private static void SetBaseIconButton(ButtonStroked button, TetrisColor color, int height, int textsize)
 {
     button.Text = button.Tag.ToString();
     button.SetMaxHeight(height);
     button.SetMinimumHeight(height);
     button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade);
     button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade);
 }
Example #22
0
 //--------------------------------------------------------------
 // CONSTRUCTORS
 //--------------------------------------------------------------
 public Block(int x, int y, TetrisColor color)
 {
     _x = x;
     _y = y;
     _color = color;
 }
Example #23
0
 private static Intent CreateGameOverDialog(GameActivity activity, string message, TetrisColor messageColor)
 {
     string title = activity.Resources.GetString(Resource.String.gameOver);
     string posText = activity.Resources.GetString(Resource.String.playAgain);
     string negText = activity.Resources.GetString(Resource.String.menu);
     return DialogActivity.CreateYesNoDialog(activity, title, message, posText, negText,
         delegate {activity.NewGame();}, delegate {activity.Finish();});
 }