Beispiel #1
0
        private void DrawBoard()
        {
            bool clight = true;
            bool sWhite = MainColor == PieceColor.BLACK;
            int left = 0;
            int top = 0;

            // reset
            canvas1.Reset();
            Board.whites = true;
            GameOver = false;

            uimoves.Text = "";
            gameoverGrid.Visibility = Visibility.Collapsed;

            for (int row = 0; row < 8; row++)
            {
                left = 0;
                if (row == 6)
                    sWhite = !sWhite;

                for (int col = 0; col < 8; col++)
                {
                    Image m = new Image();
                    m.Source = tiles[(clight ? 0 : 1)] as BitmapImage;

                    canvas1.Children.Add(m);
                    Canvas.SetLeft(m, left);
                    Canvas.SetTop(m, top);
                    left += TILESIZE;
                    clight = !clight;
                    PieceType type = PieceType.KING;
                    bool pb = false;

                    //
                    if (row == 0 || row == 7)
                    {
                        switch (col)
                        {
                            case 0:
                            case 7:
                                type = PieceType.ROOK;
                                break;
                            case 1:
                            case 6:
                                type = PieceType.KNIGHT;
                                break;
                            case 2:
                            case 5:
                                type = PieceType.BISHOP;
                                break;
                            default:
                                if (col == (MainColor == PieceColor.WHITE ? 3 : 4))
                                    type = PieceType.QUEEN;
                                break;
                        }
                        pb = true;
                    }
                    else if (row == 1 || row == 6)
                    {
                        type = PieceType.PAWN;
                        pb = true;
                    }

                    if (pb && Type != GameType.UNSTARTED)
                    {
                        Piece pc = new Piece(type, (sWhite ? PieceColor.WHITE : PieceColor.BLACK), col, row, canvas1);
                        canvas1.Children.Add(pc);
                        pc.SetPosition();
                        Canvas.SetZIndex(pc, 100);
                        Board.Register(pc.Col, pc.Row, pc);
                    }
                }

                clight = !clight;
                top += TILESIZE;
            }
        }
Beispiel #2
0
 public void OnPromote(Piece piece)
 {
     if (IsConnected)
     {
         string com = "PRM " + piece.Col + "x" + piece.Row + ":" + (int)piece.Type;
         if (IsServer)
             Server.SendMessage(com);
         else
             Client.SendMessage(com);
     }
 }
Beispiel #3
0
        public void Capture(Piece cpiece)
        {
            cpiece.Capture = true;
            Children.Remove(cpiece);

            if (cpiece.Type == PieceType.KING)
            {
                Game.GameOver = true;
                if (OnGameOver != null)
                    OnGameOver(cpiece.Color);
            }
        }
 public Promote(Piece piece)
     : this()
 {
     this.Piece = piece;
 }
Beispiel #5
0
 public static void Register(int col, int row, Piece pc)
 {
     string hs = col + "x" + row;
     _pieces.Remove(hs);
     _pieces.Add(hs, pc);
     char p = ids[(int)pc.Type];
     pieces[col, row] = pc.Color == PieceColor.BLACK ? char.ToUpper(p) : p;
 }