Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using Resource = Шахматы.Properties.Resources;
- using Bitmap = System.Drawing.Bitmap;
- using System.IO;
- namespace Шахматы
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public class imgs
- {
- public static class black
- {
- static public BitmapImage pawn = BitmapToImageSource(Resource.ЧПешка);
- static public BitmapImage bishop = BitmapToImageSource(Resource.ЧСлон);
- static public BitmapImage knight = BitmapToImageSource(Resource.ЧКонь);
- static public BitmapImage castle = BitmapToImageSource(Resource.ЧЛадья);
- static public BitmapImage queen = BitmapToImageSource(Resource.ЧФерзь);
- static public BitmapImage king = BitmapToImageSource(Resource.ЧКороль);
- }
- public static class white
- {
- static public BitmapImage pawn = BitmapToImageSource(Resource.БПешка);
- static public BitmapImage bishop = BitmapToImageSource(Resource.БСлон);
- static public BitmapImage knight = BitmapToImageSource(Resource.БКонь);
- static public BitmapImage castle = BitmapToImageSource(Resource.БЛадья);
- static public BitmapImage queen = BitmapToImageSource(Resource.БФерзь);
- static public BitmapImage king = BitmapToImageSource(Resource.БКороль);
- }
- static BitmapImage BitmapToImageSource(Bitmap bitmap)
- {
- using (MemoryStream memory = new MemoryStream())
- {
- bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
- memory.Position = 0;
- BitmapImage bitmapimage = new BitmapImage();
- bitmapimage.BeginInit();
- bitmapimage.StreamSource = memory;
- bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
- bitmapimage.EndInit();
- return bitmapimage;
- }
- }
- }
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void button_Click(object sender, RoutedEventArgs e)
- {
- new Game(true);
- this.Close();
- }
- }
- public class Game
- {
- Grid gr = null;
- public Game(bool White)
- {
- Window win = new Window();
- win.SizeToContent = SizeToContent.WidthAndHeight;
- //win.Show();
- gr = new Grid();
- gr.HorizontalAlignment = HorizontalAlignment.Left;
- gr.VerticalAlignment = VerticalAlignment.Top;
- char code = '\u0041';
- for(int i = 0; i<9; i++)
- {
- gr.RowDefinitions.Add(new RowDefinition());
- gr.ColumnDefinitions.Add(new ColumnDefinition());
- }
- bool tableColor = true;
- for (int i = 1; i<9; i++, code++)
- {
- TextBlock tbA = new TextBlock();
- tbA.Text = Convert.ToString(code);
- gr.Children.Add(tbA);
- tbA.VerticalAlignment = VerticalAlignment.Center;
- tbA.TextAlignment = TextAlignment.Center;
- //tbA.MaxHeight = 15;
- Grid.SetRow(tbA, 0);
- Grid.SetColumn(tbA, i);
- TextBlock tb1 = new TextBlock();
- tb1.VerticalAlignment = VerticalAlignment.Center;
- tb1.TextAlignment = TextAlignment.Center;
- tb1.MinWidth = 20;
- tb1.Text = Convert.ToString(i);
- gr.Children.Add(tb1);
- Grid.SetColumn(tb1, 0);
- Grid.SetRow(tb1, i);
- for (int j = 1; j < 9; j++)
- {
- Rectangle rect = new Rectangle();
- rect.Width = 80;
- rect.Height = 80;
- SolidColorBrush color = new SolidColorBrush();
- Panel.SetZIndex(rect, -1);
- Grid.SetColumn(rect, i);
- Grid.SetRow(rect, j);
- gr.Children.Add(rect);
- if (tableColor)
- {
- color.Color = Color.FromRgb(175, 119, 92);
- tableColor = false;
- }
- else
- {
- color.Color = Color.FromRgb(231, 189, 140);
- tableColor = true;
- }
- rect.Fill = color;
- }
- tableColor = !tableColor;
- }
- initGame(White);
- win.Content = gr;
- win.Show();
- }
- private void initGame(bool White)
- {
- for (int i = 1; i < 3; i++)
- {
- for(int j = 1; j< 9; j++)
- {
- Image img = new Image();
- img.Source = imgs.black.bishop;
- img.Height = 80;
- img.Width = 80;
- gr.Children.Add(img);
- Grid.SetColumn(img, j);
- Grid.SetRow(img, i);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement