Synchronization of old projects

Part1
This commit is contained in:
2025-09-30 16:46:01 +08:00
parent 116b65164b
commit 4e1548abe2
167 changed files with 8668 additions and 43 deletions
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Lesson9_封装_拓展方法练习</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,67 @@
namespace Lesson9_封装_拓展方法练习
{
static class Tools
{
public static int IntSqrt(this int i)
{
return i*i;
}
public static void Suicide(this player p)
{
Console.WriteLine("{0}自杀了",p.name);
}
}
class player
{
public string name;
public int hp, atk, def;
public player()
{
name = "null";
hp = 0;
atk = 0;
def = 0;
}
public player(string name,int hp,int atk,int def)
{
this.name =name;
this.hp = hp;
this.atk = atk;
this.def = def;
}
public void Attack()
{
Console.WriteLine("{0}攻击了,攻击值{1}",name,atk);
}
public void Defense()
{
Console.WriteLine("{0}防御了,防御值{1}",name,def);
}
public void Move()
{
Console.WriteLine("{0}移动了",name);
}
public void GetHurt()
{
Console.WriteLine("{0}受伤了,剩余{1}hp",name,hp);
}
}
internal class Program
{
static void Main(string[] args)
{
player p = new player();
p.Attack();
p.Defense();
p.Move();
p.GetHurt();
p.Suicide();
player p2 = new player("HK",100,100,100);
p2.Attack();
p2.Defense();
p2.Move();
p2.GetHurt();
p2.Suicide();
}
}
}