コード例 #1
0
ファイル: Piece.cs プロジェクト: Maskl/Checkers
        public void SetPosition(bool animable, Field field, Piece toDestroy, double? x = null, double? y = null)
        {
            var thicknessOld = new Point(Drawable.Margin.Left, Drawable.Margin.Top);
            Point thicknessNew;
            if (x != null && y != null)
                thicknessNew = new Point((double) x + Board.PieceMargin, (double) y + Board.PieceMargin);
            else
                thicknessNew = new Point(field.DisplayX + Board.PieceMargin, field.DisplayY + Board.PieceMargin);

            if (animable)
            {
                AnimableMove(thicknessOld, thicknessNew, toDestroy);
            }
            else
            {
                Drawable.Margin = new Thickness(thicknessNew.X, thicknessNew.Y, 0, 0);
                if (IsKing)
                    KingImage.Margin = Drawable.Margin;
            }

            Field = field;

            if (!IsKing && field.Y == FinishY)
            {
                IsKing = true;
                KingImage = new Image { Source = new BitmapImage(new Uri(KingUrlString)), Width = Drawable.Width, Height = Drawable.Height };
                Board.BoardCanvas.Children.Add(KingImage);
            }

            if (IsKing)
                KingImage.Margin = Drawable.Margin;
        }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: Maskl/Checkers
        static public void FieldTapped(Field field)
        {
            if (!field.IsUsableInGame())
                return;

            if (JumpableFields.Contains(field))
            {
                var enemy = Board.Fields[field.Y + (SelectedPiece.Field.Y - field.Y) / 2][field.X + (SelectedPiece.Field.X - field.X) / 2].GetPieceOnField();
                SelectedPiece.SetPosition(true, field, enemy);
                Board.Pieces.Remove(enemy);
                DrawIterator = 0;

                MovableFields.Clear();
                JumpableFields.Clear();
                CheckAllPossibleMoveAndJumpsForPiece(SelectedPiece, SelectedPiece.IsBlack);
                if (JumpableFields.Count == 0)
                {
                    NextTurn();
                    return;
                }

                Board.DehighlightFields();
                foreach (var jumpableField in JumpableFields)
                {
                    jumpableField.Highlight();
                }

                Board.SelectField(SelectedPiece.Field);
                return;
            }

            if (MovableFields.Contains(field) && JumpableFields.Count == 0)
            {
                SelectedPiece.SetPosition(true, field, null);
                NextTurn();
                return;
            }

            foreach (var piece in Board.Pieces.Where(piece => piece.Field == field && piece.IsBlack == BlackTurn && SelectableFields.Contains(piece.Field)))
            {
                SelectPiece(piece);
            }
        }
コード例 #3
0
ファイル: Board.cs プロジェクト: Maskl/Checkers
        public static void SelectField(Field fieldToSelect)
        {
            for (var y = 0; y < 8; y++)
            {
                for (var x = 0; x < 8; x++)
                {
                    var field = Fields[y][x];
                    field.Deselect();
                }
            }

            fieldToSelect.Select();
        }
コード例 #4
0
ファイル: Board.cs プロジェクト: Maskl/Checkers
        public static void NewBoard()
        {
            Fields = new Field[8][];
            for (var y = 0; y < 8; y++)
            {
                Fields[y] = new Field[8];
                for (var x = 0; x < 8; x++)
                {
                    Fields[y][x] = new Field(x, y);
                }
            }

            Pieces = new List<Piece>();
            for (var i = 0; i < 12; ++i)
            {
                Pieces.Add(new Piece(true, (i % 4) * 2 + (i / 4) % 2, (i / 4) + 5));
            }

            for (var i = 12; i < 24; ++i)
            {
                Pieces.Add(new Piece(false, (i % 4) * 2 + (i / 4) % 2, (i / 4) - 3));
            }

            DrawBoard(false);
        }
コード例 #5
0
ファイル: GameManager.cs プロジェクト: Maskl/Checkers
        private static void CheckPossibleMoveOrJump(Field moveField, Field jumpField, bool isBlack)
        {
            if (moveField == null)
                return;

            var pieceOnMoveField = moveField.GetPieceOnField();
            if (pieceOnMoveField == null)
            {
                MovableFields.Add(moveField);
                return;
            }

            if (jumpField == null)
                return;

            var pieceOnJumpField = jumpField.GetPieceOnField();
            if (pieceOnJumpField == null && pieceOnMoveField.IsBlack != isBlack)
            {
                JumpableFields.Add(jumpField);
            }
        }