728x90
SMALL

// 生成されたオブジェクトのえられるようにしよう

 

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

        }

 

        Console.WriteLine("者の" + Adventurer.GetCount() + "");

    }

}

 

class Adventurer

{

    private string job;

    private int mp;

 

    // 外部からアクセスできないスタティックな変数を定義する

public static int count=0;

 

    public Adventurer(string job, int mp)

    {

        this.job = job;

        this.mp = mp;

        count++;

    }

 

    public void Attack()

    {

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

        mp -= 5;

    }

 

    public int GetMP()

    {

        return mp;

    }

 

    // 者のを返すstaticなメソッドを追加する

    public static int GetCount()

    {

        return count;

    }

 

}

///////////

/////

 

// プロパティを理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120, 15);

        var total = apple.GetTotalPrice();

        Console.WriteLine("合計金額は" + total + "円です");

        var orange = new Item(85, 32);

        Console.WriteLine("合計金額は" + orange.GetTotalPrice() + "円です");

        Console.WriteLine("アイテムは" + Item.GetCount() + "種類です");

    }

}

// 프로퍼티 요미카키 할 때 사용

public class Item

{

    private int price;

    private int quantity;

    private static int count = 0;

    // 관례적으로 프로퍼티의 앞을 대문자로. 소문자로 해도 됨.

    public static int Count

   

    {

        get

        {

            return count;

        }

        set

        {

            count = value;

        }

       

    }

//카운트 프로퍼티가 됐다.

 

    public Item (int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        count += 1;

    }

 

    public int GetTotalPrice()

    {

        return price * quantity;

    }

 

    public static int GetCount()

    {

        return count;

    }

}

/////////

 

////////////

////

// プロパティを理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120, 15);

        var total = apple.GetTotalPrice();

        Console.WriteLine("合計金額は" + total + "円です");

        var orange = new Item(85, 32);

        Console.WriteLine("合計金額は" + orange.GetTotalPrice() + "円です");

        Console.WriteLine("アイテムは" + Item.GetCount() + "種類です");

    }

}

// 프로퍼티 요미카키 할 때 사용

public class Item

{

    private int price;

    private int quantity;

    private static int count = 0;

    // 관례적으로 프로퍼티의 앞을 대문자로. 소문자로 해도 됨.

    public static int Count

   

    {

        get

        {

            return count;

        }

        set

        {

            count = value;

        }

       

    }

//카운트 프로퍼티가 됐다.

 

    public Item (int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        count += 1;

    }

 

    public int GetTotalPrice()

    {

        return price * quantity;

    }

 

    public static int GetCount()

    {

        return count;

    }

}

/////////

728x90

설정

트랙백

댓글

728x90
SMALL

// アクセス修飾子を省略しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var player = new Player("勇者");

        player.Walk();

 

        Console.WriteLine(player.name);

    }

}

 

public class Player

{

    public string name;

    // 필드의 억세스 수식자를 생략하면 private가 된다.

//string name;

 

    public Player(string name)

    {

        this.name = name;

    }

 

    public void Walk()

    {

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

    }

    // 메소드에서 억세스 수식자를 생략하면 private가 된다.

}

//////////////

// 필드, 콘스트럭터, 메소드에서 억세스 수식자를 생략하면 다 private가 된다.

// 인터널 억세스 수식자

// 그 안에서 사용할 수 있는 수식자

// 개발할 때 사용한다.

 

//

// staticを理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120, 15); //오브젝트 작성

        //카운트가 0에서 1이 된다.

        var total = apple.GetTotalPrice();

        Console.WriteLine("合計金額は" + total + "円です");

        var orange = new Item(85, 32); // 두 번째 오브젝트 작성

        //카운트가 1에서 2로 변환

        Console.WriteLine("合計金額は" + orange.GetTotalPrice() + "円です");

        Console.WriteLine("商品は" + Item.GetCount() + "種類です。");

       

       

       

    }

}

 

public class Item

{

    private int price;

    private int quantity;

    public static int count=0;

    //static이라고 하면 실행이 가능하다. 불러올 수 있네

    //static 앞에 클래스의 종류 private public을 입력

   

    public Item(int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        count++;

    }

 

    public int GetTotalPrice()

    {

        return price * quantity;

    }

    public static int GetCount()

    {

        return count;

    }

   

}

/////////////

static을 이해하자

////

728x90

설정

트랙백

댓글

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

설정

트랙백

댓글

728x90
SMALL

//// 사과의 금액 구하기

////////

///

// り値のあるメソッドを作ろう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120,15);

        Console.WriteLine("合計金額は" + apple.GetTotalPrice() + "円です。");

       

       

    }

}

public class Item

{

    private int price;

    private int quantity;

    public Item(int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        

    }

    public int GetTotalPrice()

    {

        return price * quantity;

    }

   

}

////

사과 금액은 120엔 * 15개 = 1800엔으로 출력된다.

/////

 

//////////

// り値のあるメソッドを作ろう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120,15);

        var total = apple.GetTotalPrice(); //戻り値를 변수에 대입한다.

        Console.WriteLine("合計金額は" + total + "円です。"); //그거를 출력

        var orange = new Item(85,32);

        Console.WriteLine("合計金額は" + orange.GetTotalPrice() + "円です。");

       

    }

}

public class Item

{

    private int price;

    private int quantity;

    public Item(int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        

    }

    public int GetTotalPrice()

    {

        return price * quantity;

    }

   

}

//////////////

////

인수와 戻り値

728x90

설정

트랙백

댓글

728x90
SMALL

// RPGの冒者クラスを作ろう

 

using System;

 

public class Practice

{

    public static void Main()

    {

        var adventurer = new Adventurer("");

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

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

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

 

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

 

        foreach (Adventurer player in party)

        {

            player.Attack();

        }

    }

}

 

///

 

모험자, 위자드, 크루세이더, 프리스트 출력

 

///

// Adventurerクラスを定義する

public class Adventurer

{

    private string name;

    public Adventurer(string name)

    {

        this.name = name;

    }

 

    public void Attack()

    {

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

       

    }

}

/////////////

////

728x90

설정

트랙백

댓글

728x90
SMALL

/////////

/////////

///////

// 키리시마 클래스 쿄코 출력

// オブジェクト生成時にフィルドを初期化しよう1

 

using System;

 

public class Practice

{

    public static void Main()

    {

        // オブジェクト生成時にコンストラクタに値を渡し、nameフィルドを初期化する

var kyo = new Human("霧島京子");

kyo.Greet();

    }

}

 

class Human

{

    private string name;

 

    public Human(string name)

    {

        this.name = name;

    }

 

    public void Greet()

    {

        Console.WriteLine("みなさんこんにちは" + name + "です");

    }

}

/////

///みなさんこんにちは霧島京子です

///

 

///

// RPGの敵クラスを作ろう

using System;

 

public class Lesson07

{

    public static void Main()

    {

Attack("슬라임");

 

    }

   

    public static void Attack(string enemy)

    {

        Console.WriteLine(enemy + "は勇者を攻した。");

    }

}

//// attack 슬라임

////

///

 

// RPGの敵クラスを作ろう

using System;

 

public class Lesson07

{

    public static void Main()

    {

//Attack("슬라임");

var enemy = new Enemy("몬스터");

enemy.Attack();

 

    }

   

   

}

public class Enemy

{

    private string name;

    public Enemy(string name)

    {

        this.name = name;

    }

     public void Attack()

    {

        Console.WriteLine(name + "は勇者を攻した。");

    }

   

}

///////////////

//////

 

// RPGの敵クラスを作ろう

using System;

 

public class Lesson07

{

    public static void Main()

    {

    Enemy[] enemies =

    {

        new Enemy("スライム"),

        new Enemy("モンスタ"),

        new Enemy("ドラゴン")

    };

   

foreach(var enemy in enemies)

{

enemy.Attack();

}

 

}

}

public class Enemy

{

    private string name;

    public Enemy(string name)

    {

        this.name = name;

    }

     public void Attack()

    {

        Console.WriteLine(name + "は勇者を攻した。");

    }

   

}

/////////////

///////영어의 instance의 의미에는 実例라는 의미가 있다.

728x90

설정

트랙백

댓글

728x90
SMALL

// 変数をクラスで管理しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

var player1 = new Player("전사");

player1.Walk();

 

 

    }

    public class Player

    {

        private string name;

        public Player(string name)

        {

            this.name = name;

        }

        public void Walk()

        {

            Console.WriteLine(name + "는 황야를 걸었다");

        }

       

    }

   

}

//

////////////

///////

// this없이

//////

// 変数をクラスで管理しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

var player1 = new Player("전사");

player1.Walk();

 

 

    }

    public class Player

    {

        private string name; //name을 대입한다. This가 없어서

// 필드, 클래스에 정의되어 있는 변수이다.

        public Player(string name)

        {

            name = name;

//constructor에서 사용하는 name을 그냥 대입해서 전사가 안 뜬다.

        }

        public void Walk()

        {

            Console.WriteLine(name + "는 황야를 걸었다");

        }

       

    }

   

}

////

///

// 変数をクラスで管理しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

var player1 = new Player("전사");

player1.Walk();

var player2 = new Player("魔法使い");

player2.Walk();

player1.Walk();

 

    }

    public class Player

    {

        private string name;

        public Player(string name)

        {

            this.name = name;

        }

        public void Walk()

        {

            Console.WriteLine(name + "는 황야를 걸었다");

        }

       

    }

   

}

 

728x90

설정

트랙백

댓글

728x90
SMALL

///////////

//////////

////////

7장 오브젝트: 변수와 메소드의 합

보통 오브젝트 지향의 프로그램이다.

클래스: 오브젝트의 설계도, 오브젝트: 클래스로부터 만들어짐

클래스(player) > 플레이어 오브젝트(paiza 공격, wizard 공격, dragon 공격)

오브젝트 = 인스턴스

1. 클래스를 작성한다.

2. 변수를 클래스에서 관리한다.

3. 구체적인 예: RPG의 적 클래스를 만든다.

4. 클래스에서, 인수와 인 메소드를 만든다.

5. 문자열이나 배열도 오브젝트로 되어 있다.

6. 억세스 수식자에 대해서 이해한다.

 

//

/////////

//

// クラスを作成しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var player1 = new Player(); //불러온다.

     Walk(); //static이 있는 Walk

     player1.Walk(); //출력

    }

   

    public static void Walk()

    {

        Console.WriteLine("勇者は荒野をいていた");

    }

}

public class Player

{

    public void Walk()

    {

        Console.WriteLine("勇者は");

    }

}

 

////

////

////

// クラスとメソッドを定義しよう

 

using System;

 

public class Practice

{

    public static void Main()

    {

        // Humanクラスのオブジェクトを生成してGreet()メソッドを呼び出す

var man = new Human(); //Human 클래스를 불러온다.

man.Greet(); //Greet의 명령어를 불러온다. 

    }

}

 

class Human

{

    public void Greet()

    {

        Console.WriteLine("こんにちは世界");

    }

}

/////

///

 

//////

// クラスとメソッドを定義しよう

 

using System;

 

public class Practice

{

    public static void Main()

    {

        var human = new Human();

        human.Greet();

    }

}

 

// Human クラスを定義する

class Human

{

    public void Greet()

    {

        Console.WriteLine("さようなら世界");

    }

   

}

///

 

728x90

설정

트랙백

댓글