Exemple #1
0
        public void Save()
        {
            using (ClueLessContext db = new ClueLessContext())
            {
                Database.DataModels.Suggestion suggestion = new Database.DataModels.Suggestion
                {
                    LocationID            = LocationID,
                    PlayerID              = playerID,
                    ConfiguredCharacterID = characterID,
                    ConfiguredWeaponID    = weaponID,
                    IsAccusation          = IsAccusastion
                };
                db.Suggestions.Add(suggestion);

                db.SaveChanges();

                //set the player to be the current responding player
                Database.DataModels.Player author = db.Players.Where(x => x.ID == suggestion.PlayerID).FirstOrDefault();
                author.IsCurrentRespondingPlayer = true;
                db.SaveChanges();

                int firstResponderID = FindNextResponder(suggestion.ID);
                Database.DataModels.Player firstResponder = db.Players.Where(x => x.ID == firstResponderID).FirstOrDefault();
                firstResponder.IsCurrentRespondingPlayer = true;
                author.IsCurrentRespondingPlayer         = false;
                db.SaveChanges();
            }
        }
Exemple #2
0
        public bool ValidateAccusation()
        {
            bool isValid = false;

            try
            {
                using (ClueLessContext db = new ClueLessContext())
                {
                    //Get the datbase suggestion object
                    Database.DataModels.Suggestion suggestion = db.Suggestions.Where(x => x.ID == ID).FirstOrDefault();

                    //Get the gameID
                    int gameID = db.Players.Where(x => x.ID == suggestion.PlayerID).Select(x => x.GameID).FirstOrDefault();

                    //Pull the game's solution
                    Database.DataModels.GameSolution solution = db.GameSolutions.Where(x => x.GameID == gameID).FirstOrDefault();

                    if (solution.ConfiguredCharacterID == suggestion.ConfiguredCharacterID &&
                        solution.ConfiguredWeaponID == suggestion.ConfiguredWeaponID &&
                        solution.PositionID == suggestion.LocationID)
                    {
                        isValid = true;
                        //End the Game
                        solution.SolvedByPlayerID = suggestion.PlayerID;
                        db.SaveChanges();

                        Game.ChangeGameStatus(gameID, Database.DataModels.Status.Completed_Solved);
                    }
                    else
                    {
                        //determine the number of active players
                        int activePlayers = db.Players.Where(x => x.GameID == gameID && x.IsActive).Count();
                        if (activePlayers > 2)
                        {
                            //deactivate the player
                            Database.DataModels.Player player = db.Players.Where(x => x.ID == playerID).FirstOrDefault();
                            player.IsActive = false;
                            db.SaveChanges();
                        }
                        else
                        {
                            //end the game
                            Game.ChangeGameStatus(gameID, Database.DataModels.Status.Completed_Unsolved);
                        }
                    }
                }
            }catch (Exception e)
            {
                Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
            }
            return(isValid);
        }
Exemple #3
0
        public static Clue RespondToSuggestion(int playerId, int suggestionID, int clueID = -1, string ClueType = "")
        {
            Clue responseClue = new Clue();
            SuggestionResponse response;
            ClueLessContext    db = new ClueLessContext();

            if (clueID > 0)
            {
                responseClue = RevealClue(playerId, clueID, ClueType, suggestionID);
                response     = new SuggestionResponse
                {
                    SuggestionID      = suggestionID,
                    Response          = "Revealed Clue",
                    RevealedClueID    = clueID,
                    RevealedClueTable = ClueType
                };
                db.SaveChanges();
            }
            else
            {
                response = new SuggestionResponse
                {
                    SuggestionID = suggestionID,
                    Response     = "Pass"
                };
                db.SaveChanges();

                Database.DataModels.Suggestion suggestion = db.Suggestions.Where(x => x.ID == suggestionID).FirstOrDefault();
                int nextPlayerID = FindNextResponder(suggestionID);
                Database.DataModels.Player currentResponder = db.Players.Where(x => x.ID == suggestion.PlayerID).FirstOrDefault();
                currentResponder.IsCurrentRespondingPlayer = false;
                db.SaveChanges();
                if (nextPlayerID != suggestion.PlayerID)
                {
                    Database.DataModels.Player nextResponder = db.Players.Where(x => x.ID == nextPlayerID).FirstOrDefault();
                    nextResponder.IsCurrentRespondingPlayer = true;
                    db.SaveChanges();
                }
            }

            return(responseClue);
        }
Exemple #4
0
        private static int FindNextResponder(int suggestionID)
        {
            ClueLessContext db = new ClueLessContext();

            Database.DataModels.Suggestion suggestion = db.Suggestions.Where(x => x.ID == suggestionID).FirstOrDefault();
            Database.DataModels.Player     author     = db.Players.Where(x => x.ID == suggestion.PlayerID).FirstOrDefault();
            int nextPlayerID;
            //Pull the list of all the players
            List <Database.DataModels.Player> players = db.Players.Where(x => x.GameID == author.GameID).OrderBy(x => x.ID).ToList();

            //Get the index of the current player
            int currentIndex = players.IndexOf(players.Where(x => x.IsCurrentRespondingPlayer).FirstOrDefault());

            if (currentIndex == players.Count - 1)
            {
                nextPlayerID = players.ElementAt(0).ID;
            }
            else
            {
                nextPlayerID = players.ElementAt(currentIndex + 1).ID;
            }

            return(nextPlayerID);
        }
Exemple #5
0
        private static string GetEmailBody(NotificationType notification, int userID = -1, int suggestionID = -1, int gameID = -1)
        {
            string message           = "";
            string opening           = "Dear User,";
            string closingStatetment = "This is an automated email, responses sent to this address will not be recieved.\n\n" +
                                       "Sincerely,\nIconic Alliance";
            string playerName = "";
            string murderer   = "";
            string location   = "";
            string weapon     = "";

            try
            {
                if (suggestionID > 0)
                {
                    using (ClueLessContext db = new ClueLessContext())
                    {
                        playerName = db.Users.Where(x => x.ID == userID).Select(x => x.FirstName + " " + x.LastName).FirstOrDefault();
                        //Get the suggestion
                        Database.DataModels.Suggestion suggestion = db.Suggestions.Where(x => x.ID == suggestionID).FirstOrDefault();

                        murderer = suggestion.Character.Character.Name;
                        location = suggestion.Location.Location.LocationName;
                        weapon   = suggestion.Weapon.Weapon.Name;
                    }
                }
                if (userID > 0)
                {
                    using (ClueLessContext db = new ClueLessContext())
                    {
                        playerName = db.Users.Where(x => x.ID == userID).Select(x => x.FirstName + " " + x.LastName).FirstOrDefault();
                    }
                }
                switch (notification)
                {
                case NotificationType.UserNameReminder:
                    string Username = "";
                    using (ClueLessContext db = new ClueLessContext())
                    {
                        Username = db.Users.Where(x => x.ID == userID).Select(x => x.Username).FirstOrDefault();
                    }
                    message = "Your username for ClueLess is: " + Username + ". If you did not request this information, please check your account.";
                    break;

                case NotificationType.PasswordReset:
                    message = "Your password has been successfully reset. If you did not request a password reset, please check your account.";
                    break;

                case NotificationType.GameInvite:
                    message = "You have been invited by " + playerName + " to join them in a game of ClueLess. To accept the invitation, sign in to your ClueLess account. If you do not have an account and wish to join the game, create an account and search for the game to join.";
                    break;

                case NotificationType.NewSuggestion:
                    message = String.Format("A new suggestion has been made by: {0}. {0} suggested that is was {1} in the {2} with the {3}.", playerName, murderer, location, weapon);
                    break;

                case NotificationType.SuggestionResponse:
                    message = String.Format("{0} has responded to the suggestion: {1} in the {2} with the {3}. To see thier response, sign in to your ClueLess account and re-join your game.", playerName, murderer, location, weapon);
                    break;

                case NotificationType.AccusationMade:
                    message = String.Format("{0} has accused {1} of killing Mr.Boddy in the {2} with the {3}.", playerName, murderer, location, weapon);
                    break;

                case NotificationType.GameOver:

                    using (ClueLessContext db = new ClueLessContext())
                    {
                        Database.DataModels.Game game = db.Games.Where(x => x.ID == gameID).FirstOrDefault();
                        if (game != null)
                        {
                            if (game.Status == Database.DataModels.Status.Completed_Solved)
                            {
                                message = String.Format(" Your ClueLess Game {0} has completed. The murderer was commited by {1} in the {2} with the {3}.", game.Name, murderer, location, weapon);
                            }

                            if (game.Status == Database.DataModels.Status.Completed_Unsolved)
                            {
                                message = String.Format(" Your ClueLess Game {0} has completed. The murder was unsolved.", game.Name);
                            }
                        }
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error creating email message");
            }


            string body = opening + Environment.NewLine + message + Environment.NewLine + Environment.NewLine + closingStatetment;

            return(body);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="playerID">the ID of the player revealing the clue</param>
        /// <param name="clueID">The ID of the clue being revealed</param>
        /// <param name="ClueType">The Type of clue being revealed: Character, Weapon, Room</param>
        public static Clue RevealClue(int playerID, int clueID, string ClueType, int suggestionID)
        {
            Clue revealedClue = new Clue();

            try
            {
                using (ClueLessContext db = new ClueLessContext())
                {
                    //Get the database suggestion object
                    Database.DataModels.Suggestion suggestion = db.Suggestions.Where(x => x.ID == suggestionID).FirstOrDefault();

                    //Update the suggestion's author's clue tracker based on the clue type
                    switch (ClueType)
                    {
                    case "Character":
                        db.PlayersToCharcters.Add(new Database.DataModels.PlayerToCharacter
                        {
                            PlayerID = suggestion.PlayerID,
                            CharacterConfigurationID = clueID,
                        });
                        db.SaveChanges();

                        //Pull the information for the clue to be returned
                        CharacterConfiguration characterConfiguration = db.CharacterConfigurations.Where(x => x.ID == clueID).FirstOrDefault();
                        revealedClue = new Clue
                        {
                            ID   = characterConfiguration.ID,
                            Name = characterConfiguration.Character.Name,
                        };

                        break;

                    case "Weapon":
                        db.PlayersToWeapons.Add(new Database.DataModels.PlayerToWeapon
                        {
                            PlayerID = suggestion.PlayerID,
                            WeaponConfigurationID = clueID
                        });
                        db.SaveChanges();

                        WeaponConfiguration weaponConfiguration = db.WeaponConfigurations.Where(x => x.ID == clueID).FirstOrDefault();
                        revealedClue = new Clue {
                            ID = weaponConfiguration.ID, Name = weaponConfiguration.Weapon.Name
                        };

                        break;

                    case "Room":
                        db.PlayersToLocations.Add(new Database.DataModels.PlayerToLocation
                        {
                            PlayerID   = suggestion.PlayerID,
                            PositionID = clueID
                        });
                        db.SaveChanges();

                        //Pull the information for the clue to be returned
                        Position position = db.Positions.Where(x => x.ID == clueID).FirstOrDefault();
                        revealedClue = new Clue {
                            ID = position.ID, Name = position.Location.LocationName
                        };

                        break;

                    default:
                        throw new ArgumentException();
                    }
                }
            }catch (Exception e)
            {
                Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
            }

            return(revealedClue);
        }