Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // IAttackAction.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace interface_demo
- {
- interface IAttackAction
- {
- void attack();
- }
- }
- // ===============================================
- // Archer.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace interface_demo
- {
- class Archer: IAttackAction
- {
- public void attack()
- {
- Console.Out.WriteLine("Archer: shoots arrows.");
- }
- }
- }
- // =========================================
- // Rifleman.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace interface_demo
- {
- class Rifleman: IAttackAction
- {
- public void attack()
- {
- Console.Out.WriteLine("Rifleman: starts shooting.");
- }
- }
- }
- // ==================================
- // Swordsman.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace interface_demo
- {
- class Swordsman: IAttackAction
- {
- public void attack()
- {
- Console.Out.WriteLine("Swordsman: swings battlesword.");
- }
- }
- }
- // ================================
- // Main.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace interface_demo
- {
- class Program
- {
- public static void Controller(IAttackAction Unit)
- {
- Unit.attack();
- }
- static void Main(string[] args)
- {
- Controller(new Archer());
- Controller(new Swordsman());
- Controller(new Rifleman());
- Console.Out.WriteLine("Press any key to quit...");
- Console.ReadKey(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement