Untitled
unknown
plain_text
a year ago
1.2 kB
7
Indexable
public interface IGraphicLib { public void Init(int screenWidth, int screenHeight); public void DrawPixel(int x, int y, Color color); } public class CommandLineGraphicLib : IGraphicLib { public void Init(int screenWidth, int screenHeight) { // Initialize commande line } public void DrawPixel(int x, int y, Color color) { // Draw in command line } } public class NCurseGraphicLib : IGraphicLib { public void Init(int screenWidth, int screenHeight) { // Initialize ncurse } public void DrawPixel(int x, int y, Color color) { // Draw with ncurse } } public class LeProgramDeLouis { int screenWidth = 680; int screenHeight = 440; IGraphicLib _currentLib; void Update() { // j'ai plein de truc à dessiner à l'écran for (int x = 0; x < screenWidth; x++) { for (int Y = 0; Y < screenHeight; Y++) { _currentLib.DrawPixel(x, Y, new Color()); } } } public void UseCommandLine() { SetGraphicLib(new CommandLineGraphicLib()); } public void UseNCurse() { SetGraphicLib(new NCurseGraphicLib()); } public void SetGraphicLib(IGraphicLib lib) { _currentLib = lib; _currentLib.Init(screenWidth, screenHeight); } }
Editor is loading...
Leave a Comment