C# /// /// Abstrakcyjna klasa wspólna dla wielu gier, w których /// gracze grają przeciwko sobie, ale tylko jeden z nich /// wykonuje w danej chwili ruch. /// public abstract class Gra { private int liczbaGraczy; protected abstract void InicjalizujGrę(); protected abstract void ZróbRuch(int gracz); protected abstract bool KoniecGry(); protected abstract void WyświetlZwycięzcę(); /// /// Metoda szablonu /// public void ZagrajRaz(int liczbaGraczy)
this.liczbaGraczy = liczbaGraczy; InicjalizujGrę(); int j = 0; while (!KoniecGry())
ZróbRuch(j); j = (j + 1) % liczbaGraczy;
WyświetlZwycięzcę();
public class Monopoly : Gra { #region Gra protected override void InicjalizujGrę()
throw new Exception("The method or operation is not implemented.");
protected override void ZróbRuch(int gracz)
throw new Exception("The method or operation is not implemented.");
protected override bool KoniecGry()
throw new Exception("The method or operation is not implemented.");
protected override void WyświetlZwycięzcę()
throw new Exception("The method or operation is not implemented.");
#endregion } public class Szachy : Gra { #region Gra protected override void InicjalizujGrę()
throw new Exception("The method or operation is not implemented.");
protected override void ZróbRuch(int gracz)
throw new Exception("The method or operation is not implemented.");
protected override bool KoniecGry()
throw new Exception("The method or operation is not implemented.");
protected override void WyświetlZwycięzcę()
throw new Exception("The method or operation is not implemented.");
#endregion }