除了排序之外,我已经完成了通用链接列表中的所有操作.而且我不知道如何使用IComparable或如何使用它,因为它是通用的.我不知道我甚至会比较或排序?
public class Node<T> : IComparable<T>
{
private Node<T> next;
private T item;
}
Run Code Online (Sandbox Code Playgroud)
所以
public int CompareTo( T other )
{
// TODO: Find out how to do it properly
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
它也反对将它转换为数组然后对其进行排序然后将其转换回来的指令.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.5*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Background="DarkCyan">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<ComboBox ItemsSource="{Binding Path=charList}" x:Name="comboBox" VerticalAlignment="Top" Width="Auto" Grid.ColumnSpan="2">
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="Pictures\bagi_warrior.jpg" Width="100" Height="150"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="6*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Path=Character.Name}" FontSize="30"/>
<Label Grid.Row="1" Content="{Binding Path=Character.Level}" FontSize="20"/>
</Grid>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="Pictures\azure_knight.jpg" Width="100" Height="130"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="6*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="Azure Knight" FontSize="30"/>
<Label Grid.Row="1" Content="Level 158" FontSize="20"/>
</Grid>
</StackPanel>
</ComboBoxItem>
</ComboBox>
<Label x:Name="strLabel" Grid.Column="0" …Run Code Online (Sandbox Code Playgroud) 这段代码是为了绘制塔.广场位置是广场的左上角.TILE_SIZE只是方形的尺寸.
SpriteBatch.Draw(TowerImage, new Rectangle(square.X * TILE_SIZE, square.Y * TILE_SIZE, TILE_SIZE, TILE_SIZE), null, Color.White, myTower.Rotation,
new Vector2(TILE_SIZE - 35, TILE_SIZE - 35), SpriteEffects.None, (float)0.0);
Run Code Online (Sandbox Code Playgroud)
这段代码是我确定旋转的方式
public void FaceTarget(Vector2 center, Vector2 enemyCenter)
{
Vector2 direction = center - enemyCenter;
direction.Normalize();
this.Rotation = (float)Math.Atan2(-direction.X, direction.Y);
}
Run Code Online (Sandbox Code Playgroud)
我这样做基于:
http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Rotation.php
http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Direction_to_Angle.php
旋转真的很奇怪,这是它看起来如何正常:

但是当它旋转时它会像这样:

最后,当它往下看时,它完全离开路径,它不是由它的中心旋转,但整个图像正在移动它为什么这样做?

只有第一张图像实际上是正确位置的塔
看起来它是左上角的旋转,我不知道为什么.有人可以帮忙吗?