c#day05

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ccc
{
    class Sort
    {
        //写一个方法判断用户输入是否正确,正确返回用户名,密码,用户信息
        public void sorts()
        {
            Console.WriteLine("请输入您的密保");
            string pas = Console.ReadLine();

            if(pas =="admin")
            {
                Console.WriteLine("admin,888,man");
            }
            
        }

        //写一个Fight结构体,给其添加成员health ,给其添加一个Attack方法,使其攻击另一个Fight,可以掉血。

        struct Health
        {
            public    int atk, hp;


        }


        struct Fight
        {
            public Health health;

             public void Attack(ref Fight f)
                {
                    f.health.hp = f.health.hp - this.health.atk;

                }
        }

        public void Diao()
        {
            Fight xiaohua = new Fight();
            xiaohua.health.hp = 100;
            xiaohua.health.atk = 20;
            Fight xiaoming = new Fight();
            xiaoming.health.hp = 200;
            xiaoming.health.atk = 20;

            xiaoming.Attack( ref xiaohua);
            Console.WriteLine("小花hp:{0},   小明hp{1}",xiaohua.health.hp, xiaoming.health.hp);
        }
        

    }
    class Program
    {
        static void Main(string[] args)
        {
            Sort sort = new Sort();
            sort.Diao();
        }
    }
}

 

posted @ 2019-01-05 19:12  D个人笔记  阅读(92)  评论(0编辑  收藏  举报