本章所有的代码都放在
https://github.com/hikinazimi/head-first-Csharp
封装 被定义为"把一个或多个项目封闭在一个物理的或者逻辑的包中"。在面向对象程序设计方法论中,封装是为了防止对实现细节的访问。
抽象和封装是面向对象程序设计的相关特性。抽象允许相关信息可视化,封装则使开发者实现所需级别的抽象。
C# 封装根据具体的需要,设置使用者的访问权限,并通过 访问修饰符 来实现。
封装意味着对另一个类隐藏信息,但是封装中的信息可以使用反射拿出来
SwordDamage游戏
本项目是一个计算伤害的程序
第一版
<Window x:Class="SwordDamage_WPF_Part_1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SwordDamage_WPF_Part_1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<CheckBox x:Name="flaming" Content="Flaming"
HorizontalAlignment="Center" VerticalAlignment="Center"
Checked="Flaming_Checked" Unchecked="Flaming_Unchecked"/>
<CheckBox x:Name="magic" Content="Magic" Grid.Column="1"
HorizontalAlignment="Center" VerticalAlignment="Center"
Checked="Magic_Checked" Unchecked="Magic_Unchecked" />
<Button Grid.Row="1" Grid.ColumnSpan="2" Margin="20,10"
Content="Roll for damage