728x90
SMALL

// RPGの冒者にMPを設定しよう

using System;

 

public class Practice

{

    public static void Main()

    {

        var adventurer = new Adventurer("", 120);

        var wizard = new Adventurer("ウィザ", 549);

        var crusader = new Adventurer("クルセイダ", 50);

        var priest = new Adventurer("プリスト", 480);

 

        Adventurer[] party = {adventurer, wizard, crusader, priest};

 

        foreach (Adventurer player in party)

        {

            player.Attack();

            Console.WriteLine("MP" + player.GetMP());

        }

    }

}

 

class Adventurer

{

    private string job;

    private int mp;

 

    public Adventurer(string job, int mp)

    {

        this.job = job;

        this.mp = mp;

    }

 

    public void Attack()

    {

        Console.WriteLine(job + "は魔王を攻した");

        mp -= 5;

    }

 

    // 現在のMPの値を返すGetMP()メソッドを装する

    public int GetMP()

    {

        return mp;

    }

   

   

 

}

//////////

///// 남은 MP 출력하기

 

////

// アクセス修飾子を理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

var player = new Player("yousha");

player.Walk();

 

 

 

    }

}

public class Player

{

    private string name;

    public Player(string name)

    {

        this.name = name;

    }

    public void Walk()

    {

        Console.WriteLine(name + "は荒野をいていた");

    }

    // public은 어디서나 억세스가 가능하다.

   

}

 

///////////

///

// アクセス修飾子を理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

var player = new Player("yousha");

player.Walk();

 

Console.WriteLine(player.name);

// 에러가 된다.

 

    }

}

public class Player

{

    //private string name; //여기가 private라서 안됨

    public string name;

    public Player(string name)

    {

        this.name = name;

    }

    public void Walk()

    {

        Console.WriteLine(name + "は荒野をいていた");

    }

    // public은 어디서나 억세스가 가능하다.

   

}

/////

////

728x90

설정

트랙백

댓글