Exemplo n.º 1
0
        public Bumpership(IInputHandler input, World world, object shape, string name, Vector spawnPosition)
        {
            this.input = input;
            this.world = world;
            Shape = shape;
            Name = name;
            this.spawnPosition = spawnPosition;

            Radius = 0.5;
            factor1 = 0.05;
            factor2 = 0.1;

            Spawn();
        }
Exemplo n.º 2
0
        public static string Create(Bumpership player, World world, int iteration)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine(BeginStateLine(iteration));
            builder.AppendLine(YouIndexLine(world, player));

            foreach (Bumpership bumpership in world.Bumperships)
                builder.AppendLine(BumpershipLine(bumpership));

            foreach (Cell cell in world.Map.Grid)
            {
                if (cell.CellType != CellType.Attractor)
                    continue;

                builder.AppendLine("STAR " + ConvertToString(cell.Position));
            }
            builder.AppendLine(EndStateLine());
            return builder.ToString();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private void SendMap(StringBuilder message, World world)
        {
            message.AppendFormat("BEGIN_MAP {0} {1}\n", world.Map.Width, world.Map.Height);
            for (int r = 0; r < world.Map.Height; r++)
            {
                for (int c = 0; c < world.Map.Width; c++)
                    message.Append(GetCellAsChar(world.Map.Grid[c, r].CellType));

                message.AppendLine();
            }

            message.AppendLine("END_MAP");
            SendMessage(message.ToString());
        }
Exemplo n.º 5
0
        public void Update(int iteration, World world, Bumpership bumpership)
        {
            if (!IsConnected())
            {
                Dispose();
                return;
            }

            bumpership.Name = playerName;

            state = new
            {
                player = bumpership,
                world,
                iteration
            };

            string messageReceived;
            while (commandQueue.TryDequeue(out messageReceived))
            {
                if(messageReceived == null)
                    continue;

                ParseMessage(messageReceived, bumpership);
            }
        }
Exemplo n.º 6
0
 public void Start(World world)
 {
     StringBuilder message = new StringBuilder();
     SendMap(message, world);
     SendMessage("START\n");
 }
Exemplo n.º 7
0
 private static string YouIndexLine(World world, Bumpership bumpership)
 {
     return "YOU {0}".Format(world.Bumperships.IndexOf(bumpership));
 }