本文整理汇总了C#中Piece.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Piece.SetValue方法的具体用法?C# Piece.SetValue怎么用?C# Piece.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piece
的用法示例。
在下文中一共展示了Piece.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetCurrentPiecePosition
private Point SetCurrentPiecePosition(Piece currentPiece, double newX, double newY)
{
double cellX = (int)((newX) / 100);
double cellY = (int)((newY) / 100);
var firstPiece = currentSelection[0];
var relativeCellX = currentPiece.X - firstPiece.X;
var relativeCellY = currentPiece.Y - firstPiece.Y;
double rotatedCellX = relativeCellX;
double rotatedCellY = relativeCellY;
currentPiece.X = cellX + rotatedCellX;
currentPiece.Y = cellY + rotatedCellY;
currentPiece.SetValue(Canvas.LeftProperty, currentPiece.X * 100);
currentPiece.SetValue(Canvas.TopProperty, currentPiece.Y * 100);
shadowPieces[currentPiece.Index].SetValue(Canvas.LeftProperty, currentPiece.X * 100);
shadowPieces[currentPiece.Index].SetValue(Canvas.TopProperty, currentPiece.Y * 100);
return new Point(cellX, cellY);
}
示例2: CreatePuzzle
private void CreatePuzzle(Stream streamSource)
{
Random rnd = new Random();
var connections = new int[] { (int)ConnectionType.Tab, (int)ConnectionType.Blank };
png = null;
imageSource = null;
var uri = new Uri(destFileName);
//We do this to avoid memory leaks
using (WrappingStream wrapper = new WrappingStream(streamSource))
using (BinaryReader reader = new BinaryReader(wrapper))
{
imageSource = new BitmapImage();
imageSource.BeginInit();
imageSource.CacheOption = BitmapCacheOption.OnLoad;
imageSource.StreamSource = reader.BaseStream; // streamSource;
imageSource.EndInit();
imageSource.Freeze();
}
imgShowImage.Source = imageSource;
scvImage.Visibility = Visibility.Hidden;
cnvPuzzle.Visibility = Visibility.Visible;
var angles = new int[] { 0, 90, 180, 270 };
int index = 0;
for (var y = 0; y < rows; y++)
{
for (var x = 0; x < columns; x++)
{
if (x != 1000)
{
int upperConnection = (int)ConnectionType.None;
int rightConnection = (int)ConnectionType.None;
int bottomConnection = (int)ConnectionType.None;
int leftConnection = (int)ConnectionType.None;
if (y != 0)
upperConnection = -1 * pieces[(y - 1) * columns + x].BottomConnection;
if (x != columns - 1)
rightConnection = connections[rnd.Next(2)];
if (y != rows - 1)
bottomConnection = connections[rnd.Next(2)];
if (x != 0)
leftConnection = -1 * pieces[y * columns + x - 1].RightConnection;
int angle = 0;
var piece = new Piece(imageSource, x, y, 0.1, 0.1, (int)upperConnection, (int)rightConnection, (int)bottomConnection, (int)leftConnection, false, index, scale);
piece.SetValue(Canvas.ZIndexProperty, 1000 + x * rows + y);
piece.MouseEnter += new MouseEventHandler(piece_MouseEnter);
piece.MouseLeftButtonUp += new MouseButtonEventHandler(piece_MouseLeftButtonUp);
piece.MouseRightButtonUp += new MouseButtonEventHandler(piece_MouseRightButtonUp);
piece.Rotate(piece, angle);
var shadowPiece = new Piece(imageSource, x, y, 0.1, 0.1, (int)upperConnection, (int)rightConnection, (int)bottomConnection, (int)leftConnection, true, shadowPieces.Count(), scale);
shadowPiece.SetValue(Canvas.ZIndexProperty, x * rows + y);
shadowPiece.Rotate(piece, angle);
pieces.Add(piece);
shadowPieces.Add(shadowPiece);
index++;
}
}
}
var tt = new TranslateTransform() { X = 20, Y = 20 };
foreach (var p in pieces)
{
Random random = new Random();
int i = random.Next(0, pnlPickUp.Children.Count);
p.ScaleTransform.ScaleX = 1.0;
p.ScaleTransform.ScaleY = 1.0;
p.RenderTransform = tt;
p.X = -1;
p.Y = -1;
p.IsSelected = false;
pnlPickUp.Children.Insert(i, p);
double angle = angles[rnd.Next(0, 4)];
p.Rotate(p, angle);
shadowPieces[p.Index].Rotate(p, angle);
}
rectSelection.SetValue(Canvas.ZIndexProperty, 5000);
//.........这里部分代码省略.........