Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public Clue RevealClue(int locationID, int gameID, int playerID)
        {
            Clue revealedClue = new Clue();

            using (ClueLessContext db = new ClueLessContext())
            {
                //Get the ClueLocation Object
                PositionToClue clue = db.PositionsToClues.Where(x => x.PositionID == locationID && x.GameID == gameID).FirstOrDefault();
                //Based on the clue type added the clue in the room to the player's  tracking table if it does not already exist
                int clueID = -1;
                switch (clue.ClueType)
                {
                case "Character":
                    //Look for the clue in the player's tracked character clues
                    clueID = db.PlayersToCharcters.Where(x => x.CharacterConfigurationID == clue.ClueID && x.PlayerID == playerID).Select(x => x.ID).FirstOrDefault();
                    //if it doesn't exist, add it to the player's tracker character clues
                    if (clueID <= 0)
                    {
                        db.PlayersToCharcters.Add(new PlayerToCharacter
                        {
                            PlayerID = playerID,
                            CharacterConfigurationID = clue.ClueID,
                        });
                        db.SaveChanges();
                    }
                    //Pull the information for the clue to be returned
                    CharacterConfiguration characterConfiguration = db.CharacterConfigurations.Where(x => x.ID == clue.ClueID).FirstOrDefault();
                    revealedClue = new Clue
                    {
                        ID   = characterConfiguration.ID,
                        Name = characterConfiguration.Character.Name,
                    };

                    break;

                case "Weapon":
                    //Look for the clue in the player's tracked weapon clues
                    clueID = db.PlayersToWeapons.Where(x => x.WeaponConfigurationID == clue.ClueID && x.PlayerID == playerID).Select(x => x.ID).FirstOrDefault();
                    //if it doesn't exist, add it to the player's tracked weapon clues
                    if (clueID <= 0)
                    {
                        db.PlayersToWeapons.Add(new PlayerToWeapon
                        {
                            PlayerID = playerID,
                            WeaponConfigurationID = clue.ClueID
                        });
                        db.SaveChanges();
                    }

                    //Pull the informaton for the clue to be returned
                    WeaponConfiguration weaponConfiguration = db.WeaponConfigurations.Where(x => x.ID == clue.ClueID).FirstOrDefault();
                    revealedClue = new Clue {
                        ID = weaponConfiguration.ID, Name = weaponConfiguration.Weapon.Name
                    };

                    break;

                case "Room":
                    clueID = db.PlayersToLocations.Where(x => x.PositionID == clue.ClueID && x.PlayerID == playerID).Select(x => x.ID).FirstOrDefault();
                    if (clueID > 0)
                    {
                        db.PlayersToLocations.Add(new PlayerToLocation
                        {
                            PlayerID   = playerID,
                            PositionID = clue.ClueID
                        });
                        db.SaveChanges();
                    }

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

                default:
                    throw new ArgumentException();
                }

                // return the clue object
                return(revealedClue);
            }
        }