Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // Create the server
  2. using (var game = new ExampleGame(new ServerNetworkManager()))
  3. {
  4. game.Run();
  5. }
  6.  
  7. // Create the client
  8. using (var game = new ExampleGame(new ClientNetworkManager()))
  9. {
  10. game.Run();
  11. }
  12.  
  13. // Network Manager type injected as appropriate.
  14. using (XNAGame game = new XNAGame(new ClientNetworkManager()))
  15. {
  16. game.Run();
  17. }
  18.  
  19. // Constructor accepts the "injected" type as below.
  20. public XnaGame(INetworkManager networkManager)
  21. {
  22. graphics = new GraphicsDeviceManager(this);
  23. Content.RootDirectory = "Content";
  24.  
  25. this.networkManager = networkManager;
  26. }
  27.  
  28. // RTTI / Polymorphism. Determine if this instance is a Server or a Client.
  29. public bool IsServer()
  30. {
  31. return this.networkManager is ServerNetworkManager ? true : false;
  32. }
  33.  
  34. // The Windows form within this project can then be run as follows.
  35. protected override void Initialize()
  36. {
  37. // TODO: Add your initialization logic here
  38.  
  39. // If this is the server, we need to create and show the management form.
  40. if (this.IsServer() == true)
  41. {
  42. Form = new MainServerForm();
  43. Form.Show();
  44. }
  45.  
  46. base.Initialize();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement