Exemplo n.º 1
0
        public async Task <IActionResult> CreateRoom([FromBody] RoomCreation roomCreation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            short mapSize = 6;

            short[] shipList = new short[] { 0, 2, 0, 0 };


            if (roomCreation.MapSize != null && roomCreation.MapSize >= 3 && roomCreation.MapSize <= 8)
            {
                mapSize = roomCreation.MapSize;
            }

            bool flag = true;

            if (roomCreation.ShipsList.Length != 4)
            {
                flag = false;
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    if (roomCreation.ShipsList[i] < 0 || roomCreation.ShipsList[i] >= (6 - i))
                    {
                        flag = false;
                    }
                }
            }

            if (flag)
            {
                shipList = roomCreation.ShipsList;
            }


            GameRoom newGameRoom = new GameRoom(_gameRooms.GenerateRoomId(), roomCreation.RoomName, mapSize, shipList);

            Battleships_MBernackiUser user = await GetCurrentUserAsync();

            int playerRoomKey = newGameRoom.AddPlayer(user.UserName, user.Id);

            _gameRooms.GameRoomsList.Add(newGameRoom);


            return(Ok(new JoinedRoomInfo()
            {
                PlayerRoomKey = playerRoomKey,
                RoomID = newGameRoom.RoomID,
                OponentName = "",
                RoomName = newGameRoom.RoomName,
                ShipsList = shipList,
                MapSize = mapSize
            }));
        }
Exemplo n.º 2
0
        public int addRoom(String playerName, String roomName, int maxRoomSize)
        {
            RoomCreation room = new RoomCreation(playerName, roomName, maxRoomSize);

            factory.Request r = udp.SendRequest <RoomCreation>(room, serverPort);
            int             port;

            if (int.TryParse(r.responseMessage(), out port))
            {
                return(port);
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //

            AddPlayer    player     = new AddPlayer("rooooooms", null, "playerNaameab"); // port do komunikacji zwraca w resultMessage() jako string;
            RoomCreation room       = new RoomCreation("playeeerr", "rooooooms", 3);
            RoomStart    start      = new RoomStart("roomnaaamex", "token", "abs");
            PlayerMove   playerMove = new PlayerMove();

            //udpClient.SendRequest<RoomStart>(start, 38621);

            //########## PIERW TO
            //RoomManager rm = new RoomManager(38621);
            //rm.addRoom("abs", "roomnaaame", 3);

            //########## POTEM TO Z NAZWA POKOJU CO ADDROOM
            //PlayerManager pm = new PlayerManager(38621);
            //pm.addPlayer("roomnaaame", null, "playernameA");


            //####### POTEM TO I WSZYSTKO DZIAŁA
            UdpManager udpClient = new UdpManager();
            RoomStart  start1    = new RoomStart("roomnaaamex", "token", "abs");

            Console.WriteLine(udpClient.SendRequest <RoomStart>(start1, 38621).isRequestSuccess());

            //to jest odpowiedzialne za poruszanie graczem
            //wysylasz swoj ruch i konczysz polaczenie
            //udpClient.SendRequestPlayerMove(playerMove, 58278);
            //laczysz sie z serwerem i sluchasz wiadomosci
            while (true)
            {
                //udpClient.waitForMessages(58278);
                //jak jakas przyjdzie mozesz dac break i znow SendRequestPlayerMove z twoim ruchem
            }
            Console.Read();
        }
        public CreatedRoom AddRoom(RoomCreation values)
        {
            var createdRoom = roomService.Add(values.RoomName, this.userService.Get(values.UserId), this.deckService.Get(values.DeckId));

            return(new CreatedRoom(createdRoom.Id, createdRoom.Name));
        }