Ejemplo n.º 1
0
        public Game()
        {
            settings = GetSettings();

            // Connect players
            if (settings.Players.Count(p => p == PlayerType.AI) > 0)
            {
                SocketForm socketForm = new SocketForm(settings);
                socketForm.Show();
                socketManager = socketForm.CreateSocketManager();
                socketForm.Close();
                if (socketManager == null)
                    return;
            }

            // Setup graphics
            graphics = new FormGraphics();
            graphics.Show();
            graphics.Closed += (sender, args) => Dispose();

            // Get keyboard control
            KeyboardHandler keyboardHandler = new KeyboardHandler(graphics);
            gameManager = new GameManager(settings, keyboardHandler, socketManager, graphics);

            // Start game
            gameManager.Start();
        }
Ejemplo n.º 2
0
        public SocketManager CreateSocketManager()
        {
            if (maxClients <= 0)
                return null;

            socketManager = new SocketManager(maxClients, settings.Port);
            socketManager.Start();
            backgroundWorker1.RunWorkerAsync();

            while (backgroundWorker1.IsBusy)
                Application.DoEvents();

            if (socketManager.CountClients < maxClients)
                return null;

            return socketManager;
        }
Ejemplo n.º 3
0
 private Bumpership CreateBumpership(PlayerType player, IInputHandler keyboardHandler, SocketManager socketManager, ref int countShip)
 {
     IInputHandler input;
     string name = "";
     switch (player)
     {
         case PlayerType.Human:
             input = keyboardHandler;
             name = "Human";
             break;
         case PlayerType.AI:
             input = socketManager.GetNetworkPlayer();
             break;
         default:
             input = new IdiotAi(); // Test
             break;
     }
     Vector startPosition = world.Map.StartPositions[countShip];
     countShip++;
     return new Bumpership(input, world, graphics.CreateShip(), name, startPosition);
 }
Ejemplo n.º 4
0
        public GameManager(
            GameSettings gameSettings,
            IInputHandler keyboardHandler,
            SocketManager socketManager,
            IGraphicsHandler graphics)
        {
            this.gameSettings = gameSettings;
            this.graphics = graphics;
            const int ticksPerSecond = 30;
            gameLoop = new GameLoop(5, ticksPerSecond);
            gameLoop.Update += Update;
            gameLoop.Render += Render;

            Map map = new Map(gameSettings.Map);
            world = new World(map);

            int countShip = 0;
            List<Bumpership> bumperships = gameSettings.Players.Take(world.Map.StartPositions.Count)
                .Select(p => CreateBumpership(p, keyboardHandler, socketManager, ref countShip))
                .ToList();
            world.AddShips(bumperships);
        }