1. 程式人生 > >c#day05

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(); } } }