Beispiel #1
0
        }                                  //To hold the amount of damage the enemy does



        public Enemies(string name, string description, int gold_reward, int maxdamage, Rooms currentlocation, int hp, int ac, bool isalive) : base(currentlocation, hp, ac, isalive, gold_reward)
        {
            Name        = name;
            Description = description;
            MaxDamage   = maxdamage;
        }
Beispiel #2
0
 public static string Look(Rooms currentLocation)
 {
     return($"You are in {currentLocation.Name} {currentLocation.Description}");
 }
Beispiel #3
0
        public static Tuple <bool, Player> createPlayer()
        {
            Tuple <bool, Player> loginPlayer;

            StandardMessages.getUsername();
            string username = Console.ReadLine();

            if (InputValidation.VerifyUsername(username) == true)
            {
                //if username is already used prompts user to try to login or select a new username
                StandardMessages.usernameTaken();
                Console.WriteLine("Would you like to try to login? (Y/N)");
                string login = Console.ReadLine().ToLower();

                char[] letter = login.ToCharArray();

                switch (letter[0])
                {
                case 'y':
                    loginPlayer = LoginMenu();
                    return(loginPlayer);

                case 'n':
                    loginPlayer = createPlayer();
                    return(loginPlayer);

                default:
                    Console.WriteLine("Invalid Input");
                    break;
                }

                return(null);
            }

            else
            {
                StandardMessages.createPassword();
                string password = Console.ReadLine();
                while (!InputValidation.ValidatePassword(password))
                {
                    //prompts user to keep trying password until reqs met
                    StandardMessages.createPassword();
                    password = Console.ReadLine();
                }
                StandardMessages.selectClass();
                string characterClass = Console.ReadLine();
                Tuple <string, int> characterClassTuple;

                while (!InputValidation.CharacterClassValidation(characterClass))
                {
                    //prompts user to enter a class choice that is given
                    StandardMessages.selectClass();
                    characterClass = Console.ReadLine();
                }

                characterClassTuple = Enums.getCharacterInfo(characterClass);

                StandardMessages.selectRace();
                string race = Console.ReadLine();
                Tuple <string, int> raceTuple;

                while (!InputValidation.characterRaceValidation(race))
                {
                    //prompts user to enter a race choice that is given
                    StandardMessages.selectRace();
                    race = Console.ReadLine();
                }

                raceTuple = Enums.getRaceInfo(race);

                Rooms         currentLocation = World.GetRoomByName("Troy");     //This defaults the player to Troy
                bool          isalive         = true;                            //defaults to alive
                int           gold_reward     = 0;
                Weapons       weapon          = World.GetWeaponByName("dagger"); //defaults to null
                List <IItems> inventory       = new List <IItems>();
                inventory.Add(World.GetWeaponByName("dagger"));
                //Create player object
                Player newPlayer = new Player(username, password, characterClassTuple.Item1, raceTuple.Item1, currentLocation, characterClassTuple.Item2, raceTuple.Item2, isalive, weapon, gold_reward, inventory);
                Player.sendToLoginFile(newPlayer);
                //Send the properties to the text file
                Player.sendToPlayerFile(newPlayer);
                loginPlayer = new Tuple <bool, Player>(true, newPlayer);
                return(loginPlayer);
            }
        }
Beispiel #4
0
        public static Player getPlayer(string username, string password)
        {
            List <IItems> inventory        = new List <IItems>();
            Player        player           = null;
            string        classOfCharacter = "";
            int           HP          = 0;
            string        race        = "";
            int           AC          = 0;
            Rooms         location    = null;
            int           gold_reward = 0;
            Weapons       weapon      = null;
            bool          isAlive     = true;
            string        enemy       = "";
            string        enemyAlive  = "";
            string        invent      = "";
            string        room        = "";
            string        questStat   = "";

            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                string sql = "select * from player where Name like @param1";
                cnn.Open();

                using (SQLiteCommand command = new SQLiteCommand(sql, cnn))
                {
                    command.Parameters.Add(new SQLiteParameter("@param1", username));

                    SQLiteDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        classOfCharacter = reader.GetString(1).ToLower();
                        HP          = reader.GetInt16(2);
                        race        = reader.GetString(3);
                        AC          = reader.GetInt16(4);
                        location    = World.GetRoomByName(reader.GetString(5));
                        gold_reward = reader.GetInt16(6);
                        weapon      = World.GetWeaponByName(reader.GetString(7));
                        isAlive     = true;
                        enemy       = reader.GetString(8).TrimEnd(',');
                        enemyAlive  = reader.GetString(9).ToLower().TrimEnd(',');
                        invent      = reader.GetString(10).TrimEnd(',');
                        room        = reader.GetString(11).TrimEnd(',');
                        questStat   = reader.GetString(12).TrimEnd(',');

                        string[] enemies    = enemy.Split(',');
                        string[] lives      = enemyAlive.Split(',');
                        string[] invents    = invent.Split(',');
                        string[] rooms      = room.Split(',');
                        string[] queststats = questStat.Split(',');

                        for (int i = 0; i < enemies.Count(); i++)
                        {
                            World.GetEnemyByName(enemies[i]).IsAlive = bool.Parse(lives[i]);
                        }
                        if (invents != null)
                        {
                            for (int i = 0; i < invents.Count(); i++)
                            {
                                inventory.Add(World.GetItemByName(invents[i]));
                            }
                        }
                        if (rooms != null && queststats != null)
                        {
                            for (int i = 0; i < rooms.Count(); i++)
                            {
                                World.GetRoomByName(rooms[i]).QuestCompleted = bool.Parse(queststats[i]);
                            }
                        }

                        player = new Player(username, password, classOfCharacter, race, location, HP, AC, isAlive, weapon, gold_reward, inventory);
                        return(player);
                    }

                    command.ExecuteNonQuery();
                    player = new Player(username, password, classOfCharacter, race, location, HP, AC, isAlive, weapon, gold_reward, inventory);
                    return(player);
                }
            }
        }
Beispiel #5
0
 //The constructor takes no parameters, we will set them in the code after the object is first referenced (in the Login class)
 public Player(string username, string password, string classOfcharacter, string race, Rooms currentlocation, int hp, int ac, bool isalive, Weapons currentweapon, int gold_reward, List <IItems> inventory) :
     base(currentlocation, hp, ac, isalive, gold_reward)
 {
     Name             = username;
     Password         = password;
     Filename         = username + ".txt";
     ClassOfCharacter = classOfcharacter;
     Race             = race;
     CurrentWeapon    = currentweapon;
     Inventory        = inventory;
 }
Beispiel #6
0
        public static void Build()
        {
            //Create rooms objects
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from Rooms";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string name           = reader.GetString(0);
                    string description    = reader.GetString(1);
                    bool   questcompleted = bool.Parse(reader.GetString(2).ToLower());

                    World.rooms.Add(new Rooms(name, description, questcompleted));
                }
                reader.Close();
                cnn.Close();
            }

            //DB for room exits
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from RoomExits";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Rooms room = World.GetRoomByName(reader.GetString(0));
                    room.roomToNorth     = World.GetRoomByName(reader.GetString(1));
                    room.roomToSouth     = World.GetRoomByName(reader.GetString(2));
                    room.roomToEast      = World.GetRoomByName(reader.GetString(3));
                    room.roomToWest      = World.GetRoomByName(reader.GetString(4));
                    room.roomToNortheast = World.GetRoomByName(reader.GetString(5));
                    room.roomToNorthwest = World.GetRoomByName(reader.GetString(6));
                    room.roomToSoutheast = World.GetRoomByName(reader.GetString(7));
                    room.roomToSouthwest = World.GetRoomByName(reader.GetString(8));
                }



                reader.Close();
                cnn.Close();
            }

            //Create weapons objects
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from Weapons";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string name            = reader.GetString(0);
                    string description     = reader.GetString(1);
                    int    damage          = reader.GetInt16(2);
                    Rooms  currentLocation = World.GetRoomByName(reader.GetString(3));

                    World.weapons.Add(new Weapons(name, description, damage, currentLocation));
                    World.allItems.Add(new Weapons(name, description, damage, currentLocation));
                }
                reader.Close();
                cnn.Close();
            }

            //Create potions objects
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from Potions";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string name            = reader.GetString(0);
                    string description     = reader.GetString(1);
                    int    healthIncrease  = reader.GetInt16(2);
                    Rooms  currentLocation = World.GetRoomByName(reader.GetString(3));

                    World.potions.Add(new Potions(name, description, healthIncrease, currentLocation));
                    World.allItems.Add(new Potions(name, description, healthIncrease, currentLocation));
                }
                reader.Close();
                cnn.Close();
            }

            //Create treasure objects
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from Treasures";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string name            = reader.GetString(0);
                    string description     = reader.GetString(1);
                    int    value           = reader.GetInt16(2);
                    Rooms  currentLocation = World.GetRoomByName(reader.GetString(3));


                    World.treasures.Add(new Treasures(name, description, value, currentLocation));
                    World.allItems.Add(new Treasures(name, description, value, currentLocation));
                }
                reader.Close();
                cnn.Close();
            }


            //Create items objects
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from Items";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string name            = reader.GetString(0);
                    string description     = reader.GetString(1);
                    int    price           = reader.GetInt16(2);
                    Rooms  currentLocation = World.GetRoomByName(reader.GetString(3));

                    World.items.Add(new Items(name, description, price, currentLocation));
                    World.allItems.Add(new Items(name, description, price, currentLocation));
                }
                reader.Close();
                cnn.Close();
            }

            //DB for login
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from Logins";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string username = reader.GetString(0);
                    string password = reader.GetString(1);
                    string filename = reader.GetString(2);

                    World.logins.Add(new UserLogin(username, password));
                }
                reader.Close();
                cnn.Close();
            }

            //Create enemies objects
            using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Open();

                SQLiteCommand command = cnn.CreateCommand();

                command.CommandText = "select * from Enemies";

                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string name        = reader.GetString(0).ToLower();
                    string description = reader.GetString(1);
                    int    gold_reward = reader.GetInt16(2);
                    int    maxdamage   = reader.GetInt16(3);
                    int    HP          = reader.GetInt16(4);
                    int    AC          = reader.GetInt16(5);
                    bool   isAlive     = bool.Parse(reader.GetString(6).ToLower());
                    Rooms  location    = World.GetRoomByName(reader.GetString(7));

                    World.enemies.Add(new Enemies(name, description, gold_reward, maxdamage, location, HP, AC, isAlive));
                }
                reader.Close();
                cnn.Close();
            }
        }