Ejemplo n.º 1
0
 public void Init(ServerApi api, Player player, GameState game, Map map)
 {
     this.api = api;
     this.player = player;
     this.game = game;
     this.map = map;
 }
Ejemplo n.º 2
0
        public GameStateProviderTests()
        {
            _dummyPlayer = GetDummyPlayer();
            _dummyMap = GetDummyMap();

            _gameStateRepository = Substitute.For<IGameStateRepository>();
            _playersProvider = Substitute.For<IPlayersProvider>();
            _playersProvider.Get(Guid.Empty).ReturnsForAnyArgs(_dummyPlayer);
            _mapProvider = Substitute.For<IMapProvider>();
            _mapProvider.GetRandomMap().ReturnsForAnyArgs(_dummyMap);
            _gameStateProvider = new GameStateProvider(_gameStateRepository, _playersProvider, _mapProvider);
        }
Ejemplo n.º 3
0
        public GamesControllerTests()
        {
            _dummyGameState = GetDummyGameState();
            _dummyPlayer = GetDummyPlayer();
            _dummyMap = GetDummyMap();

            _gameStateProvider = Substitute.For<IGameStateProvider>();
            _gameStateProvider.CreateGame(Arg.Any<string>()).ReturnsForAnyArgs(ValidationResult<GameState>.Success.WithData(_dummyGameState));
            _gameStateProvider.JoinGame(Arg.Any<Guid>(), Arg.Any<Guid>()).ReturnsForAnyArgs(ValidationResult<GameState>.Success.WithData(_dummyGameState));

            _playersProvider = Substitute.For<IPlayersProvider>();
            _playersProvider.Create(Arg.Any<string>()).ReturnsForAnyArgs(ValidationResult<Player>.Success.WithData(_dummyPlayer));

            _controller = new GamesController(_gameStateProvider, _playersProvider);
        }
Ejemplo n.º 4
0
        public static Map FromStringRepresentation(Guid id, string[] rows)
        {
            Map m = new Map();
            m.Id = id;
            m.Tiles = new TileType[rows[0].Length][];
            for (int x = 0; x < m.Tiles.Length; x++)
            {
                m.Tiles[x] = new TileType[rows.Length];
                for (int y = 0; y < rows.Length; y++)
                {
                    TileType t;
                    switch (rows[y][x])
                    {

                        case '.':
                            t = new Grass();
                            break;

                        case '@':
                            t = new Rock();
                            break;

                        case 'T':
                            t = new Tree();
                            break;

                        case '~':
                            t = new Water();
                            break;

                        default:
                            continue;
                    }
                    m.Tiles[x][y] = t;
                }
            }
            return m;
        }
Ejemplo n.º 5
0
        public void DrawMap(GraphicsDevice device, SpriteBatch sb, Map map, int xOffset, int yOffset)
        {
            if (sb == null || map == null)
                return;

            int xStart = xOffset % CellWidth;
            int yStart = yOffset % CellWidth;
            int width = Math.Min((xOffset / CellWidth) + (device.Viewport.Width / CellWidth) + 2, map.Tiles.Length);
            int height = Math.Min((yOffset / CellWidth) + (device.Viewport.Height / CellWidth) + 2, map.Tiles[0].Length); // All columns are of equal height

            drawRect.X = -xStart;
            for (int xIndex = xOffset / CellWidth; xIndex < width && xIndex >= 0; ++xIndex)
            {
                drawRect.Y = -yStart;
                for (int yIndex = yOffset / CellWidth; yIndex < height && yIndex >= 0; ++yIndex)
                {
                    var tex = GetTex(map.Tiles[xIndex][yIndex]);
                    if (tex != null)
                        sb.Draw(tex, drawRect, Color.White);
                    drawRect.Y += CellWidth;
                }
                drawRect.X += CellWidth;
            }
        }
Ejemplo n.º 6
0
 public Point GetMapSize(Map map)
 {
     var x = map.Tiles.Length;
     var y = map.Tiles[0].Length;
     return new Point(x * CellWidth, y * CellWidth);
 }