示例#1
0
        //Finally we pass the player and room information in the player_status. Adding the playerStatus (external call)
        //83: gettting 5 levels for a specific room (room_levels table). The first one is set true.
        // We create a playerStatus for one person when is on a room. Every player_status on every room_level. He is assigned to all all the room_levels (98)
        //The first is starting point true and the rest is created for the player based on the room_levels.
        //Iterating over 5 times and the the room_level index is passed in the objects and the first element (level 1->unlocked) for a player is set to true because of the starting point.
        public void CreatePlayerStatusForARoom(Player player, Room room)
        {
            using (Player_statusRepository player_statusRepository = new Player_statusRepository("DefaultConnection"))
            {
                List <Room_levels> room_levels = Room_LevelsLogic.getRoomLevels(room.ID);

                for (int i = 0; i < room_levels.Count(); i++)

                {
                    Room_levels room_level = room_levels[i];

                    Player_Status player_status = new Player_Status();

                    if (i == 0)
                    {
                        player_status.IsUnlocked = true;
                    }


                    player_status.Player      = player;
                    player_status.Room_levels = room_level;

                    addPlayerStatus(player_status);
                }
            }
        }
示例#2
0
 //Adding a room_level's properties in the database.
 public void addRoomLevel(Room_levels room_level)
 {
     using (Room_LevelsRepository room_LevelsRepository = new Room_LevelsRepository("DefaultConnection"))
     {
         room_LevelsRepository.addRoomLevel(room_level);
     }
 }
示例#3
0
        //Getting the levels for a specific Section by the room's sectionid.
        //Assigning all the levels in the a specific room.
        // Creating a room based on the section, players, room_levels.
        //For each room_level in the list we add a room_level in the table.
        //By creating the room, we need to get all the levels based on that section is taken.
        //The method argument takes a room (section is choosen)

        public void createRoom(Room room)
        {
            var levels = levelLogic.getLevelsForASection(room.SectionID);

            List <Room_levels> Room_levels = new List <Room_levels>();

            foreach (var level in levels)
            {
                Room_levels room_Levels = new Room_levels();
                room_Levels.Level = level;
                room_Levels.Room  = room;
                Room_levels.Add(room_Levels);
            }


            using (RoomRepository roomRepository = new RoomRepository("DefaultConnection"))
            {
                roomRepository.createRoom(room);
            }
            //after creating the room its levels get passed in
            foreach (var room_level in Room_levels)
            {
                room_LevelsLogic.addRoomLevel(room_level);
            }
        }
示例#4
0
        //Finding a player_status based on the player and the room_levels.
        //Finding the player_status (current level u finished)
        //If the player_status is not null, the playerStatus is set to the specific room with its specific level and the player is also assigned as well.
        public Player_Status findPlayerStatus(Player player, Room_levels room_levels)

        {
            using (Player_statusRepository player_statusRepository = new Player_statusRepository("DefaultConnection"))
            {
                Player_Status playerStatus = player_statusRepository.findPlayerStatus(player.Id, room_levels.ID);


                if (playerStatus != null)
                {
                    playerStatus.Room_levels = room_levels;
                    playerStatus.Player      = player;
                }

                return(playerStatus);
            }
        }
示例#5
0
        public string submitQuiz(QuizViewModel model)

        {
            int userid     = int.Parse(User.Identity.GetUserId());
            var room_level = room_LevelsLogic.getRoom_level(model.RoomID, model.LevelID);

            int correctedAnswers = 0;

            foreach (var question in model.questions)
            {
                var isCorrect = questionLogic.isAnsweredCorrect(question.SelectedAnswerID);

                if (isCorrect)
                {
                    correctedAnswers++;
                }
            }
            Player        player       = UserLogic.findPLayer(userid);
            Player_Status playerStatus = player_StatusLogic.findPlayerStatus(player, room_level);

            playerStatus.SavedScore = correctedAnswers;
            if (playerStatus.SavedScore < room_level.Level.Score)
            {
                playerStatus.Warnings++;
            }
            player_StatusLogic.updatePlayerStatus(playerStatus);



            //Getting all the players in the room. The first room_level is open and looking at their results in a given level. If the player is done yet or the score is less than score, they are not carrying on.
            //If they have cope with the score, they go to the next level.
            //For all players we are looking at their room_levels (player_status) (player_room_levels). Still setting the same room_level.
            List <Player> players = RoomLogic.FindAllPlayerOneRoom(model.RoomID);

            bool isCompleted = true;

            foreach (Player roomPlayer in players)
            {
                Player_Status player_status = player_StatusLogic.findPlayerStatus(roomPlayer, room_level);

                if (player_status == null || player_status.SavedScore < room_level.Level.Score)
                {
                    isCompleted = false;
                }
            }
            //If completed we find the next room_level id and open it up for each players.
            if (isCompleted)
            {
                foreach (Player roomPlayer in players)
                {
                    Room_levels   nextRoomLevel    = room_LevelsLogic.getRoom_level(model.RoomID, room_level.Level.Next_level);
                    Player_Status nextPlayerStatus = player_StatusLogic.findPlayerStatus(roomPlayer, nextRoomLevel);
                    nextPlayerStatus.IsUnlocked = true;
                    player_StatusLogic.updatePlayerStatus(nextPlayerStatus);
                }
            }
            //Udpdating the current one u have played
            room_LevelsLogic.updateRoomLevel(room_level);

            questionLogic.deletePlayerQuestions(model.LevelID, model.RoomID);

            if (playerStatus.Warnings == 1)
            {
                //gult kort
                return("Du har svaret rigtigt på " + correctedAnswers.ToString() + "/10. Det er ikke nok. Du har fået et gult kort!");
            }
            else if (playerStatus.Warnings == 2)
            {
                //rødt kort

                return("Du har svaret rigtigt på " + correctedAnswers.ToString() + "/10. Det er ikke nok. Du har fået rødt kort og er blevet sparket af holdet!!");
            }

            return("Du har svaret rigtigt på " + correctedAnswers.ToString() + "/10");
        }
示例#6
0
        // Inserting values into Room_levels based on the room and level you are on.
        public void addRoomLevel(Room_levels roomLevel)
        {
            string sql = "INSERT INTO Room_levels VALUES (@isCompleted, @room_id, @level_id)";

            con.Execute(sql, new { isCompleted = roomLevel.IsCompleted, room_id = roomLevel.Room.ID, level_id = roomLevel.Level.ID });
        }
示例#7
0
        //Updating a room_level based on the room and level you are on. Pay attention isCompleted is not used at all, but other columns are used.

        public void updateRoomLevel(Room_levels roomLevel)
        {
            string sql = "UPDATE Room_Levels SET isCompleted = @isCompleted where room_id = @room_id AND level_id = @level_id ";

            con.Execute(sql, new { isCompleted = roomLevel.IsCompleted, room_id = roomLevel.Room.ID, level_id = roomLevel.Level.ID });
        }