Exemplo n.º 1
0
        //public byte[,] handleLudoLogic(Room room)
        //{
        //}
        public int[,] initGame(Room room)
        {
            int[,] fields = new int[11, 11];

            for (int x = 0; x <= 10; x++)
            {
                for (int y = 0; y <= 10; y++)
                {
                    fields[x, y] = -1;
                }
            }

            if (room.Game.UserInGameIDs.Count() == 2)
            {
                fields = initPlayerOneStartFields(fields, room);
                fields = initPLayerTwoStartFields(fields, room);
            }
            else if (room.Game.UserInGameIDs.Count() == 3)
            {
                fields = initPlayerOneStartFields(fields, room);
                fields = initPLayerTwoStartFields(fields, room);
                fields = initPLayerThreeStartFields(fields, room);
            }
            else if (room.Game.UserInGameIDs.Count() == 4)
            {
                fields = initPlayerOneStartFields(fields, room);
                fields = initPLayerTwoStartFields(fields, room);
                fields = initPLayerThreeStartFields(fields, room);
                fields = initPLayerFourStartFields(fields, room);
            }
            return fields;
        }
Exemplo n.º 2
0
 private void createRoom(Room room)
 {
     room.RoomStatus = "Waiting";
     room.RoomID = Main.ludo.Rooms.Count; // get the room count and set it as as roomID
     room.RoomAction = "roomCreated";
     Main.ludo.Rooms.Add(room);
     sendUpdatedRoomList();
 }
Exemplo n.º 3
0
 private int[,] initPlayerOneStartFields(int[,] fields, Room room)
 {
     int playerOneID = room.Game.UserInGameIDs[0];
     fields[0, 0] = playerOneID;
     fields[0, 1] = playerOneID;
     fields[1, 0] = playerOneID;
     fields[1, 1] = playerOneID;
     return fields;
 }
Exemplo n.º 4
0
 private int[,] initPLayerFourStartFields(int[,] fields, Room room)
 {
     int playerFourID = room.Game.UserInGameIDs[3];
     fields[9, 9] = playerFourID;
     fields[9, 10] = playerFourID;
     fields[10, 9] = playerFourID;
     fields[10, 10] = playerFourID;
     return fields;
 }
Exemplo n.º 5
0
 private int[,] initPLayerThreeStartFields(int[,] fields, Room room)
 {
     int playerThreeID = room.Game.UserInGameIDs[2];
     fields[0, 9] = playerThreeID;
     fields[1, 9] = playerThreeID;
     fields[0, 10] = playerThreeID;
     fields[1, 10] = playerThreeID;
     return fields;
 }
Exemplo n.º 6
0
 private int[,] initPLayerTwoStartFields(int[,] fields, Room room)
 {
     int playerTwoID = room.Game.UserInGameIDs[1];
     fields[9, 0] = playerTwoID;
     fields[9, 1] = playerTwoID;
     fields[10, 0] = playerTwoID;
     fields[10, 1] = playerTwoID;
     return fields;
 }
Exemplo n.º 7
0
 private int getUsersTurnIndex(Room room)
 {
     foreach (var userID in room.Game.UserInGameIDs)
     {
         if (userID == room.Game.UsersTurnID)
         {
             return room.Game.UserInGameIDs.IndexOf(userID);
         }
     }
     return -1;
 }
Exemplo n.º 8
0
 private bool deleteRoomWhenEmpty(Room room)
 {
     if (room.UserInRoomIDs.Count == 0)
     {
         Main.ludo.Rooms.RemoveAt(room.RoomID);
         sendUpdatedRoomList();
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 9
0
 private Room getUsersTurnID(Room room)
 {
     if (room.Game.UsersTurnID > -1 && getUsersTurnIndex(room) < room.Game.UserInGameIDs.Count() -1)
     {
         room.Game.UsersTurnID = room.Game.UserInGameIDs[getUsersTurnIndex(room) + 1];
     }
     else
     {
         room.Game.UsersTurnID = room.Game.UserInGameIDs[0];
     }
     Main.ludo.Rooms[room.RoomID].Game.UsersTurnID = room.Game.UsersTurnID;
     return room;
 }
Exemplo n.º 10
0
 // Sets the Room Moderator to the first User in Room List
 private Room getRoomModerator(Room room)
 {
     room.ReadyUsersInRoomIDs.Clear(); // when the moderator changes clear the ready user list
     room.RoomModeratorUserID = room.UserInRoomIDs[0];
     return room;
 }
Exemplo n.º 11
0
        private void setStart(Room room)
        {
            room.RoomStatus = "Starting";
            Main.ludo.Rooms[room.RoomID] = room;

            for (int i = 5; i > 0; i--)
            {
                room.RoomAction = "Starting in " + i;
                Console.WriteLine(room.RoomAction + i);
                sendUpdatedRoomList();
                System.Threading.Thread.Sleep(1000);
            }

            // Adding all ready Users and the room moderator to the userInGame List
            Main.ludo.Rooms[room.RoomID].Game.UserInGameIDs.Add(room.RoomModeratorUserID);
            foreach (var userID in Main.ludo.Rooms[room.RoomID].ReadyUsersInRoomIDs)
            {
                Main.ludo.Rooms[room.RoomID].Game.UserInGameIDs.Add(userID);
            }

            room.RoomAction = "Starting now ...";
            sendUpdatedRoomList();
            room.RoomStatus = "Playing";
            sendUpdatedRoomList();
        }
Exemplo n.º 12
0
 private void setReady(Room room)
 {
     foreach (var userID in room.UserInRoomIDs)
     {
         // set the status to default false
         Main.ludo.Users[userID].StatusInRoom = false;
         foreach (var readyUserID in room.ReadyUsersInRoomIDs)
         {
             Console.WriteLine("Ready User in List: " + Main.ludo.Users[readyUserID].UserName);
             if (userID == readyUserID)
             {
                 // when the user is in readyUsersInRoomIDs List set status true
                 Console.WriteLine("User " + Main.ludo.Users[userID].UserName + " is ready");
                 Main.ludo.Users[userID].StatusInRoom = true;
             }
         }
     }
     Main.ludo.Rooms[room.RoomID].ReadyUsersInRoomIDs = room.ReadyUsersInRoomIDs;
     Console.WriteLine("Ready Users: " + Main.ludo.Rooms[room.RoomID].ReadyUsersInRoomIDs.Count);
     sendUpdatedRoomList();
 }
Exemplo n.º 13
0
 private void setLeavingUserCurrentRoomID(Room room)
 {
     List<int> leavingUserID = Main.ludo.Rooms[room.RoomID].UserInRoomIDs.Except(room.UserInRoomIDs).ToList();
     Console.WriteLine("Leaving User ID: " + leavingUserID[0]);
     if (leavingUserID.Count > 0 && Main.ludo.Users.Contains(Main.ludo.Users[leavingUserID[0]]))
     {
         Main.ludo.Users[leavingUserID[0]].CurrentRoomID = -1;
     }
 }
Exemplo n.º 14
0
 private void leaveRoom(Room room)
 {
     room.RoomAction = "roomLeft";
     setLeavingUserCurrentRoomID(room);
     if (!deleteRoomWhenEmpty(room)) // When the room still exists
     {
         room = getRoomModerator(room); // set the new room moderator when room isn't empty
         Main.ludo.Rooms[room.RoomID] = room;
     }
     sendUpdatedRoomList();
 }
Exemplo n.º 15
0
 private void joinRoom(Room room)
 {
     setUserCurrentRoomIDs(room);
     room.RoomAction = "roomJoined";
     room = getRoomModerator(room);
     // sometimes nullPointerException out of no where...
     Main.ludo.Rooms[room.RoomID] = room;
     sendUpdatedRoomList();
 }
Exemplo n.º 16
0
        private void setUserCurrentRoomIDs(Room room)
        {
            int currentRoomID = room.RoomID;

            foreach (var userID in room.UserInRoomIDs)
            {
                Main.ludo.Users[userID].CurrentRoomID = currentRoomID;
            }
        }
Exemplo n.º 17
0
        private void sendGame(Room room)
        {
            foreach (var s in gameSocketList.ToList())
            {
                s.Send(JsonConvert.SerializeObject(room));

            }
        }