本文整理汇总了C#中System.Windows.Controls.Canvas.DrawRect方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawRect方法的具体用法?C# Canvas.DrawRect怎么用?C# Canvas.DrawRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Canvas
的用法示例。
在下文中一共展示了Canvas.DrawRect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawShips
private void DrawShips(Canvas canvas, BattleShipsPlayer player)
{
var board = player.Board;
var size = Math.Min(canvas.ActualHeight, canvas.ActualWidth);
var rectSize = size / BORAD_SIZE;
for (var y = 0; y < board.GetLength(0); y++)
for (var x = 0; x < board.GetLength(1); x++)
{
if (board[y, x].HasFlag(FieldState.Water) && !board[y, x].HasFlag(FieldState.Unknown))
canvas.DrawMiss(x * rectSize, y * rectSize, (x+1) * rectSize, (y+1) * rectSize);
if (board[y, x].HasFlag(FieldState.Ship) && !board[y, x].HasFlag(FieldState.Unknown))
canvas.DrawRect(x * rectSize, y * rectSize, rectSize, rectSize, Config.SHIP_HIT_COLOR);
else if (board[y, x].HasFlag(FieldState.SankShip))
canvas.DrawRect(x * rectSize, y * rectSize, rectSize, rectSize, Config.SHIP_SANK_COLOR);
else if (board[y, x].HasFlag(FieldState.Ship))
canvas.DrawRect(x* rectSize, y* rectSize, rectSize, rectSize, Config.SHIP_OK_COLOR);
}
}