From 8e5e10c734893945920ed62209afc4de141e4c83 Mon Sep 17 00:00:00 2001 From: Tashi Gyatso Date: Mon, 6 Nov 2023 17:29:17 -0500 Subject: [PATCH 01/19] Initial Commit, created player and world class and tables --- lib/debug.py | 5 +++- lib/helpers.py | 9 -------- lib/models/model_1.py | 0 lib/models/player.py | 54 +++++++++++++++++++++++++++++++++++++++++++ lib/models/world.py | 38 ++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 10 deletions(-) delete mode 100644 lib/helpers.py delete mode 100644 lib/models/model_1.py create mode 100644 lib/models/player.py create mode 100644 lib/models/world.py diff --git a/lib/debug.py b/lib/debug.py index 6fadf6e66..7f519a89d 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -1,8 +1,11 @@ #!/usr/bin/env python3 # lib/debug.py +from models.player import Player +from models.world import World from models.__init__ import CONN, CURSOR import ipdb - +player1 = Player('Matt') +world1 = World('Howling Castle') ipdb.set_trace() diff --git a/lib/helpers.py b/lib/helpers.py deleted file mode 100644 index f10df049c..000000000 --- a/lib/helpers.py +++ /dev/null @@ -1,9 +0,0 @@ -# lib/helpers.py - -def helper_1(): - print("Performing useful function#1.") - - -def exit_program(): - print("Goodbye!") - exit() diff --git a/lib/models/model_1.py b/lib/models/model_1.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/models/player.py b/lib/models/player.py new file mode 100644 index 000000000..5019839af --- /dev/null +++ b/lib/models/player.py @@ -0,0 +1,54 @@ +from models.__init__ import CONN, CURSOR +class Player: + def __init__(self, name, strength = 1, hp = 10, id=None ): + self.name = name + self.strength = strength + self.hp = hp + self.id = id + + @property + def name(self): + return self._name + @name.setter + def name(self, new_name): + if not hasattr(self, "_name"): + if isinstance(new_name, str) and 1 <= len(new_name) <= 10: + self._name = new_name + + + @classmethod + def create_table(cls): + sql= ''' + CREATE TABLE players( + id INTEGER PRIMARY KEY, + name TEXT, + strength INTEGER, + HP INTEGER + + ) + ''' + CURSOR.execute(sql) + + def save(self): + if self.id: + sql: f'UPDATE players SET name = ?, strength = ?, hp = ? WHERE id = ?' + param_tuples = (self.name, self.strength, self.hp, self.id) + CURSOR.execute(sql, param_tuples) + CONN.commit() + else: + sql = 'INSERT INTO players (name,strength,hp) VALUES (?, ?, ? )' + param_tuples = (self.name, self.strength, self.hp ) + CURSOR.execute(sql, param_tuples) + CONN.commit() + id_sql = 'SELECT LAST_INSERT_ROWID() FROM players' + new_id_tuple = CURSOR.execute( id_sql ).fetchone() + self.id = new_id_tuple[0] + + + + + + + + + diff --git a/lib/models/world.py b/lib/models/world.py new file mode 100644 index 000000000..eaf44acbd --- /dev/null +++ b/lib/models/world.py @@ -0,0 +1,38 @@ +from models.__init__ import CONN, CURSOR +class World: + def __init__(self, location,id=None): + self.location = location + self.id = id + + @property + def location(self): + return self._location + @location.setter + def location(self,new_location): + if not hasattr(self, '_location'): + if type(new_location) == str and 1 <= len(new_location) <= 15: + self._location = new_location + + @classmethod + def create_table(cls): + sql= ''' + CREATE TABLE worlds( + id INTEGER PRIMARY KEY, + location TEXT + ) + ''' + CURSOR.execute(sql) + def save(self): + if self.id: + sql: f'UPDATE worlds SET location = ? WHERE id = ?' + param_tuples = (self.location, self.id) + CURSOR.execute(sql, param_tuples) + CONN.commit() + else: + sql = 'INSERT INTO worlds (location) VALUES (?)' + param_tuples = (self.location, ) + CURSOR.execute(sql, param_tuples) + CONN.commit() + id_sql = 'SELECT LAST_INSERT_ROWID() FROM worlds' + new_id_tuple = CURSOR.execute( id_sql ).fetchone() + self.id = new_id_tuple[0] From 8b8d943d1a424ddf56201716cac9f25a562ab970 Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Tue, 7 Nov 2023 00:03:33 -0600 Subject: [PATCH 02/19] Touched some db stuff --- lib/debug.py | 6 +++--- lib/models/__init__.py | 2 +- lib/models/world.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/debug.py b/lib/debug.py index 7f519a89d..ddbc501d1 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -5,7 +5,7 @@ from models.__init__ import CONN, CURSOR import ipdb -player1 = Player('Matt') -world1 = World('Howling Castle') - +# player1 = Player('Matt') +# world1 = World('Howling Castle') +# world2 = World('Mt Everwood') ipdb.set_trace() diff --git a/lib/models/__init__.py b/lib/models/__init__.py index d5b061e1e..1098a2f26 100644 --- a/lib/models/__init__.py +++ b/lib/models/__init__.py @@ -1,4 +1,4 @@ import sqlite3 -CONN = sqlite3.connect('company.db') +CONN = sqlite3.connect('game.db') CURSOR = CONN.cursor() diff --git a/lib/models/world.py b/lib/models/world.py index eaf44acbd..f8223315f 100644 --- a/lib/models/world.py +++ b/lib/models/world.py @@ -36,3 +36,23 @@ def save(self): id_sql = 'SELECT LAST_INSERT_ROWID() FROM worlds' new_id_tuple = CURSOR.execute( id_sql ).fetchone() self.id = new_id_tuple[0] +# Deletes World from db + def shatter( self ): + sql = 'DELETE FROM worlds WHERE id = ?' + params_tuple = ( self.id, ) + CURSOR.execute( sql, params_tuple ) + CONN.commit() + self.id = None +# V makes database display , work to create a instance with menu + @classmethod + def all(cls): + sql = 'SELECT * FROM worlds' + list_of_tuples = CURSOR.execute( sql ).fetchall() + return [World.from_db(row) for row in list_of_tuples] + @classmethod + def from_db(cls,row_tuple): + world_instance = World( row_tuple[1]) + world_instance.id = row_tuple[0] + return world_instance + def __repr__(self): + return f'\n' \ No newline at end of file From 2dc8fcd09a2b3445f48ddd6e9131cdc0576ed799 Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Tue, 7 Nov 2023 00:17:42 -0600 Subject: [PATCH 03/19] played with menu a bit --- lib/cli.py | 9 +++------ lib/helpers.py | 9 +++++++++ lib/models/world.py | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 lib/helpers.py diff --git a/lib/cli.py b/lib/cli.py index edd1b62ad..aaee575a7 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1,8 +1,7 @@ # lib/cli.py - +from models.world import World from helpers import ( exit_program, - helper_1 ) @@ -13,7 +12,7 @@ def main(): if choice == "0": exit_program() elif choice == "1": - helper_1() + print(World.all()) else: print("Invalid choice") @@ -21,8 +20,6 @@ def main(): def menu(): print("Please select an option:") print("0. Exit the program") - print("1. Some useful function") - - + print("1. Select World") if __name__ == "__main__": main() diff --git a/lib/helpers.py b/lib/helpers.py new file mode 100644 index 000000000..f10df049c --- /dev/null +++ b/lib/helpers.py @@ -0,0 +1,9 @@ +# lib/helpers.py + +def helper_1(): + print("Performing useful function#1.") + + +def exit_program(): + print("Goodbye!") + exit() diff --git a/lib/models/world.py b/lib/models/world.py index f8223315f..0c1d642e9 100644 --- a/lib/models/world.py +++ b/lib/models/world.py @@ -43,7 +43,7 @@ def shatter( self ): CURSOR.execute( sql, params_tuple ) CONN.commit() self.id = None -# V makes database display , work to create a instance with menu +# V makes database display , work to create a instance with @classmethod def all(cls): sql = 'SELECT * FROM worlds' @@ -55,4 +55,4 @@ def from_db(cls,row_tuple): world_instance.id = row_tuple[0] return world_instance def __repr__(self): - return f'\n' \ No newline at end of file + return f'\n\n.' \ No newline at end of file From 615ce50c004a84386d7f668e2a767ed341cf4a88 Mon Sep 17 00:00:00 2001 From: Tashi Gyatso Date: Tue, 7 Nov 2023 11:14:16 -0500 Subject: [PATCH 04/19] find by id method --- lib/debug.py | 6 +++--- lib/models/player.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/debug.py b/lib/debug.py index ddbc501d1..a0c5b3651 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -5,7 +5,7 @@ from models.__init__ import CONN, CURSOR import ipdb -# player1 = Player('Matt') -# world1 = World('Howling Castle') -# world2 = World('Mt Everwood') +player1 = Player('Matt') +world1 = World('Howling Castle') +world2 = World('Mt Everwood') ipdb.set_trace() diff --git a/lib/models/player.py b/lib/models/player.py index 5019839af..49a28ac52 100644 --- a/lib/models/player.py +++ b/lib/models/player.py @@ -44,7 +44,35 @@ def save(self): new_id_tuple = CURSOR.execute( id_sql ).fetchone() self.id = new_id_tuple[0] - + #Deletes player from db + def deletes( self ): + sql = 'DELETE FROM players WHERE id = ?' + params_tuple = ( self.id, ) + CURSOR.execute( sql, params_tuple ) + CONN.commit() + self.id = None +# V makes database display , work to create a instance with + @classmethod + def all(cls): + sql = 'SELECT * FROM players' + list_of_tuples = CURSOR.execute( sql ).fetchall() + return [Player.from_db(row) for row in list_of_tuples] + @classmethod + def from_db(cls,row_tuple): + player_instance = Player( row_tuple[1],row_tuple[2],row_tuple[3]) + player_instance.id = row_tuple[0] + return player_instance + def __repr__(self): + return f'\n\n.' + @classmethod + def find_by_id(cls,id): + sql = ''' + SELECT * FROM players WHERE id = ? + ''' + row = CURSOR.execute(sql,(id,)).fetchone() + return cls.from_db(row) if row else None + + From 5b8937310e3d2f71653944b91d5a64a4a8dd8224 Mon Sep 17 00:00:00 2001 From: Nicole Casteel Date: Tue, 7 Nov 2023 13:20:48 -0600 Subject: [PATCH 05/19] added Players find_by_id --- lib/cli.py | 2 +- lib/debug.py | 6 +++--- lib/models/world.py | 10 +++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index aaee575a7..187fe5c3e 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -8,7 +8,7 @@ def main(): while True: menu() - choice = input("> ") + choice = input(">") if choice == "0": exit_program() elif choice == "1": diff --git a/lib/debug.py b/lib/debug.py index a0c5b3651..ddbc501d1 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -5,7 +5,7 @@ from models.__init__ import CONN, CURSOR import ipdb -player1 = Player('Matt') -world1 = World('Howling Castle') -world2 = World('Mt Everwood') +# player1 = Player('Matt') +# world1 = World('Howling Castle') +# world2 = World('Mt Everwood') ipdb.set_trace() diff --git a/lib/models/world.py b/lib/models/world.py index 0c1d642e9..e89ddbce8 100644 --- a/lib/models/world.py +++ b/lib/models/world.py @@ -55,4 +55,12 @@ def from_db(cls,row_tuple): world_instance.id = row_tuple[0] return world_instance def __repr__(self): - return f'\n\n.' \ No newline at end of file + return f'\n\n.' + + @classmethod + def find_by_id(cls, id): + sql = ''' + SELECT * FROM worlds WHERE id = ? + ''' + row = CURSOR.execute(sql, (id,)).fetchone() + return cls.from_db(row) if row else None \ No newline at end of file From 550f42c8d5aa8de9a5ed376a64fe32413a649bee Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Tue, 7 Nov 2023 14:43:43 -0600 Subject: [PATCH 06/19] Menu Stuff --- lib/cli.py | 32 +++++++++++++++++++++++++++++--- lib/models/player.py | 6 +++++- lib/models/world.py | 7 ++++++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 187fe5c3e..6a3183d1a 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1,5 +1,6 @@ # lib/cli.py from models.world import World +from models.player import Player from helpers import ( exit_program, ) @@ -10,16 +11,41 @@ def main(): menu() choice = input(">") if choice == "0": - exit_program() + print("What Is Your World Called Traveler?") + World.create(input("->")) elif choice == "1": print(World.all()) + elif choice == "2": + print("Select World Id to Delete") + id = input("->") + world = World.find_by_id(id) + world.shatter() + elif choice == "3": + print("What Is Your Name Traveler?") + Player.create(input("->")) + elif choice == "4": + print(Player.all()) + elif choice == "5": + print("Select Player Id to Delete") + id = input("->") + player = Player.find_by_id(id) + player.deletes() + elif choice == "6": + exit_program() else: print("Invalid choice") def menu(): print("Please select an option:") - print("0. Exit the program") - print("1. Select World") + print("0. Create World") + print("1. Display World's") + print("2. Delete World") + print("3. Create Player") + print("4. Display Player's") + print("5. Remove Player") + print("6. Exit the program") if __name__ == "__main__": main() + +# someint=World("Input") \ No newline at end of file diff --git a/lib/models/player.py b/lib/models/player.py index 49a28ac52..60e88c35d 100644 --- a/lib/models/player.py +++ b/lib/models/player.py @@ -71,7 +71,11 @@ def find_by_id(cls,id): ''' row = CURSOR.execute(sql,(id,)).fetchone() return cls.from_db(row) if row else None - + @classmethod + def create(cls,name): + player = cls(name) + player.save() + return player diff --git a/lib/models/world.py b/lib/models/world.py index e89ddbce8..758656ca4 100644 --- a/lib/models/world.py +++ b/lib/models/world.py @@ -63,4 +63,9 @@ def find_by_id(cls, id): SELECT * FROM worlds WHERE id = ? ''' row = CURSOR.execute(sql, (id,)).fetchone() - return cls.from_db(row) if row else None \ No newline at end of file + return cls.from_db(row) if row else None + @classmethod + def create(cls,location): + world = cls(location) + world.save() + return world From 1abe6c4f8b80d47f4b9e33276abe5c04c7e429e2 Mon Sep 17 00:00:00 2001 From: Tashi Gyatso Date: Tue, 7 Nov 2023 21:28:03 -0500 Subject: [PATCH 07/19] some changes --- lib/cli.py | 15 +++++++++++++-- lib/models/player.py | 11 +++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 6a3183d1a..ac6666a4d 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -13,25 +13,35 @@ def main(): if choice == "0": print("What Is Your World Called Traveler?") World.create(input("->")) + elif choice == "1": print(World.all()) + elif choice == "2": print("Select World Id to Delete") id = input("->") world = World.find_by_id(id) world.shatter() + elif choice == "3": print("What Is Your Name Traveler?") Player.create(input("->")) + elif choice == "4": print(Player.all()) + elif choice == "5": - print("Select Player Id to Delete") - id = input("->") + id = input("Select Player Id to Delete:") player = Player.find_by_id(id) player.deletes() + elif choice == "6": exit_program() + + elif choice == '7': + name = input('Find your character by their name: ') + player = Player.find_by_name(name) + print(player) else: print("Invalid choice") @@ -45,6 +55,7 @@ def menu(): print("4. Display Player's") print("5. Remove Player") print("6. Exit the program") + print('7. Find Player by name') if __name__ == "__main__": main() diff --git a/lib/models/player.py b/lib/models/player.py index 60e88c35d..d01e4a908 100644 --- a/lib/models/player.py +++ b/lib/models/player.py @@ -1,6 +1,6 @@ from models.__init__ import CONN, CURSOR class Player: - def __init__(self, name, strength = 1, hp = 10, id=None ): + def __init__(self, name, world_instance, strength = 1, hp = 10, id=None ): self.name = name self.strength = strength self.hp = hp @@ -63,7 +63,7 @@ def from_db(cls,row_tuple): player_instance.id = row_tuple[0] return player_instance def __repr__(self): - return f'\n\n.' + return f'\n\n.' @classmethod def find_by_id(cls,id): sql = ''' @@ -72,6 +72,13 @@ def find_by_id(cls,id): row = CURSOR.execute(sql,(id,)).fetchone() return cls.from_db(row) if row else None @classmethod + def find_by_name(cls, name): + sql = ''' + SELECT * FROM players WHERE name = ? + ''' + row = CURSOR.execute(sql,(name,)).fetchone() + return cls.from_db(row) if row else None + @classmethod def create(cls,name): player = cls(name) player.save() From f5e89ce49d24d8a7fada5a07f9c9a28e452f761f Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Tue, 7 Nov 2023 22:34:03 -0600 Subject: [PATCH 08/19] Menu Tweaks --- lib/cli.py | 83 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index ac6666a4d..616dd81ad 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1,62 +1,83 @@ # lib/cli.py from models.world import World from models.player import Player -from helpers import ( - exit_program, -) +from helpers import exit_program def main(): while True: menu() choice = input(">") - if choice == "0": - print("What Is Your World Called Traveler?") - World.create(input("->")) + if choice == "1": + world_options() + elif choice == "2": + player_options() + elif choice == "3": + exit_program() + else: + print("Please Make A Valid Choice") - elif choice == "1": - print(World.all()) +def menu(): + print("Please select an option:") + print("1. World Options") + print("2. Player Options") + print("3. Exit the program") +def world_options(): + while True: + world_menu() + choice = input(">") + if choice == "1": + print("What Is Your World Called Traveler?") + World.create(input("->")) elif choice == "2": + print(World.all()) + elif choice == "3": print("Select World Id to Delete") id = input("->") world = World.find_by_id(id) world.shatter() + elif choice == "4": + break + else: + print("Please Make A Valid Choice") - elif choice == "3": +def world_menu(): + print("World Menu:") + print("1. Create World") + print("2. Display Worlds") + print("3. Delete World") + print("4. Back to Main Menu") + +def player_options(): + while True: + player_menu() + choice = input(">") + if choice == "1": print("What Is Your Name Traveler?") Player.create(input("->")) - - elif choice == "4": + elif choice == "2": print(Player.all()) - - elif choice == "5": + elif choice == "3": id = input("Select Player Id to Delete:") player = Player.find_by_id(id) player.deletes() - - elif choice == "6": - exit_program() - - elif choice == '7': + elif choice == '4': name = input('Find your character by their name: ') player = Player.find_by_name(name) print(player) + elif choice == "5": + break else: - print("Invalid choice") + print("Please Make A Valid Choice") +def player_menu(): + print("Player Menu") + print("1. Create Player") + print("2. Display Player's") + print("3. Remove Player") + print('4. Find Player by name') + print("5. Back to Main Menu") -def menu(): - print("Please select an option:") - print("0. Create World") - print("1. Display World's") - print("2. Delete World") - print("3. Create Player") - print("4. Display Player's") - print("5. Remove Player") - print("6. Exit the program") - print('7. Find Player by name') if __name__ == "__main__": main() - -# someint=World("Input") \ No newline at end of file From c5c0a04799171cff1a3ee5ad22759f2db97e7109 Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Tue, 7 Nov 2023 23:13:29 -0600 Subject: [PATCH 09/19] Some minor Visuals --- lib/cli.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 616dd81ad..6b24dc549 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -18,7 +18,9 @@ def main(): print("Please Make A Valid Choice") def menu(): - print("Please select an option:") + print("________________________") + print("Please select an option") + print("------------------------") print("1. World Options") print("2. Player Options") print("3. Exit the program") @@ -31,7 +33,11 @@ def world_options(): print("What Is Your World Called Traveler?") World.create(input("->")) elif choice == "2": - print(World.all()) + if World.all() == []: + print("") + print("There Are No Worlds\n Please Create One") + else: + print(World.all()) elif choice == "3": print("Select World Id to Delete") id = input("->") @@ -43,7 +49,9 @@ def world_options(): print("Please Make A Valid Choice") def world_menu(): - print("World Menu:") + print("________________________") + print("World Menu") + print("------------------------") print("1. Create World") print("2. Display Worlds") print("3. Delete World") @@ -72,7 +80,9 @@ def player_options(): print("Please Make A Valid Choice") def player_menu(): + print("________________________") print("Player Menu") + print("------------------------") print("1. Create Player") print("2. Display Player's") print("3. Remove Player") From 1269fbfa48e5c907ccae98aacc5185f743611041 Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Wed, 8 Nov 2023 10:40:42 -0600 Subject: [PATCH 10/19] Worked with tashi on join's --- lib/models/player.py | 50 +++++++++++++++++++++++++++++++++++--------- lib/models/world.py | 5 +++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lib/models/player.py b/lib/models/player.py index d01e4a908..46c002ee9 100644 --- a/lib/models/player.py +++ b/lib/models/player.py @@ -1,6 +1,7 @@ from models.__init__ import CONN, CURSOR +from models.world import World class Player: - def __init__(self, name, world_instance, strength = 1, hp = 10, id=None ): + def __init__(self, name, strength = 1, hp = 10, id=None ): self.name = name self.strength = strength self.hp = hp @@ -15,7 +16,6 @@ def name(self, new_name): if isinstance(new_name, str) and 1 <= len(new_name) <= 10: self._name = new_name - @classmethod def create_table(cls): sql= ''' @@ -24,7 +24,6 @@ def create_table(cls): name TEXT, strength INTEGER, HP INTEGER - ) ''' CURSOR.execute(sql) @@ -57,13 +56,16 @@ def all(cls): sql = 'SELECT * FROM players' list_of_tuples = CURSOR.execute( sql ).fetchall() return [Player.from_db(row) for row in list_of_tuples] + @classmethod def from_db(cls,row_tuple): player_instance = Player( row_tuple[1],row_tuple[2],row_tuple[3]) player_instance.id = row_tuple[0] return player_instance + def __repr__(self): return f'\n\n.' + @classmethod def find_by_id(cls,id): sql = ''' @@ -71,6 +73,7 @@ def find_by_id(cls,id): ''' row = CURSOR.execute(sql,(id,)).fetchone() return cls.from_db(row) if row else None + @classmethod def find_by_name(cls, name): sql = ''' @@ -78,16 +81,43 @@ def find_by_name(cls, name): ''' row = CURSOR.execute(sql,(name,)).fetchone() return cls.from_db(row) if row else None + @classmethod def create(cls,name): player = cls(name) player.save() return player + + def login(self, world): + sql = 'INSERT INTO login (world_id, player_id) VALUES(?,?)' + params_tuple = (world.id, self.id) + CURSOR.execute(sql,params_tuple) + CONN.commit() + def worlds(self): + sql = ''' + SELECT DISTINCT worlds.* FROM WORLDS + JOIN login ON login.world_id = worlds.id + WHERE login.player_id = ? + ''' + params_tuple = (self.id,) + list_of_tuples = CURSOR.execute(sql,params_tuple).fetchall() + return [World.from_db(row) for row in list_of_tuples] - - - - - - - + #CREATE TABLE login(id INTEGER PRIMARY KEY,player_id INTEGER,world_id INTEGER); + @classmethod + def create_table2(cls): + sql = 'CREATE TABLE login(id INTEGER PRIMARY KEY,player_id INTEGER,world_id INTEGER)' + CURSOR.execute(sql) + # must create a table(will throw seed at project later) + # need a player instace, and a world instance to login. +# ipdb> player1 = Player("Test7") +# ipdb> world1 = World("test4") +# ipdb> player1.save() +# ipdb> world1.save() +# ipdb> player1.login_history(world1) +# *** AttributeError: 'Player' object has no attribute 'login_history' +# ipdb> player1.login(world1) +# ipdb> player1.worlds() +# [ +# +# .] \ No newline at end of file diff --git a/lib/models/world.py b/lib/models/world.py index 758656ca4..55867f1fc 100644 --- a/lib/models/world.py +++ b/lib/models/world.py @@ -7,6 +7,7 @@ def __init__(self, location,id=None): @property def location(self): return self._location + @location.setter def location(self,new_location): if not hasattr(self, '_location'): @@ -22,6 +23,7 @@ def create_table(cls): ) ''' CURSOR.execute(sql) + def save(self): if self.id: sql: f'UPDATE worlds SET location = ? WHERE id = ?' @@ -49,11 +51,13 @@ def all(cls): sql = 'SELECT * FROM worlds' list_of_tuples = CURSOR.execute( sql ).fetchall() return [World.from_db(row) for row in list_of_tuples] + @classmethod def from_db(cls,row_tuple): world_instance = World( row_tuple[1]) world_instance.id = row_tuple[0] return world_instance + def __repr__(self): return f'\n\n.' @@ -64,6 +68,7 @@ def find_by_id(cls, id): ''' row = CURSOR.execute(sql, (id,)).fetchone() return cls.from_db(row) if row else None + @classmethod def create(cls,location): world = cls(location) From a60c65a62bb9296c5b5e96b84b6b9a1e581de9ee Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Wed, 8 Nov 2023 13:37:25 -0600 Subject: [PATCH 11/19] Progress --- lib/cli.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/cli.py b/lib/cli.py index 6b24dc549..a324f6fe1 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -38,6 +38,7 @@ def world_options(): print("There Are No Worlds\n Please Create One") else: print(World.all()) + select_world() elif choice == "3": print("Select World Id to Delete") id = input("->") @@ -89,5 +90,15 @@ def player_menu(): print('4. Find Player by name') print("5. Back to Main Menu") +def select_world(): + while True: + selection = input("Select a world id or backout with 0") + if selection == "0": + break + elif int(selection) <= len(World.all()): + print(World.find_by_id(selection)) + else: + print("Please Select a valid world ID") + if __name__ == "__main__": main() From 8da1cd1c6802e30946d367b4d56a2da12be29d69 Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Wed, 8 Nov 2023 14:39:32 -0600 Subject: [PATCH 12/19] started adding errors --- lib/cli.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index a324f6fe1..ec874f489 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -3,7 +3,6 @@ from models.player import Player from helpers import exit_program - def main(): while True: menu() @@ -63,10 +62,13 @@ def player_options(): player_menu() choice = input(">") if choice == "1": - print("What Is Your Name Traveler?") - Player.create(input("->")) + create_player_menu() elif choice == "2": - print(Player.all()) + if Player.all() == []: + print("") + print("There Are No Players\n Please Create One") + else: + print(Player.all()) elif choice == "3": id = input("Select Player Id to Delete:") player = Player.find_by_id(id) @@ -80,6 +82,19 @@ def player_options(): else: print("Please Make A Valid Choice") + +def create_player_menu(): + while True: + print("Press 0 to go back") + choice = input("What Is Your Name Traveler?:>") + if choice == "0": + break + elif choice == "": + print("Please Name Yourself") + else: + print(Player.create(choice)) + break + def player_menu(): print("________________________") print("Player Menu") @@ -92,13 +107,14 @@ def player_menu(): def select_world(): while True: - selection = input("Select a world id or backout with 0") + selection = input("Select a world id or backout with 0: >") if selection == "0": break + elif selection == "": + print("Please Select a world ID or backout with 0: ") elif int(selection) <= len(World.all()): - print(World.find_by_id(selection)) + print(f'Selected\n{World.find_by_id(selection)}') else: print("Please Select a valid world ID") - if __name__ == "__main__": main() From 7858fae174e4ffab7aa4764484ed7beb59d2d441 Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Wed, 8 Nov 2023 16:12:01 -0600 Subject: [PATCH 13/19] Some touchups --- lib/cli.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index ec874f489..a7b89a351 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -29,8 +29,7 @@ def world_options(): world_menu() choice = input(">") if choice == "1": - print("What Is Your World Called Traveler?") - World.create(input("->")) + create_world_menu() elif choice == "2": if World.all() == []: print("") @@ -90,10 +89,30 @@ def create_player_menu(): if choice == "0": break elif choice == "": + print("____________________") print("Please Name Yourself") + elif len(choice) > 11: + print("___________________________") + print("Please Enter A Shorter Name") else: print(Player.create(choice)) break +def create_world_menu(): + while True: + print("____________________") + print("Press 0 to go back") + choice = input("What Is Your World Called Traveler? >") + if choice == "0": + break + elif choice == "": + print("________________________________________") + print("No Input Detected: Please Name The World") + elif len(choice) > 16: + print("___________________________") + print("Please Enter A Shorter Name") + else: + print(World.create(choice)) + break def player_menu(): print("________________________") @@ -111,7 +130,7 @@ def select_world(): if selection == "0": break elif selection == "": - print("Please Select a world ID or backout with 0: ") + print("Please Select a world ID or backout with 0: >") elif int(selection) <= len(World.all()): print(f'Selected\n{World.find_by_id(selection)}') else: From 1c65e2df57a945f52f8371c577d7f2862f72ee04 Mon Sep 17 00:00:00 2001 From: Tashi Gyatso Date: Wed, 8 Nov 2023 18:31:21 -0500 Subject: [PATCH 14/19] worked for login --- lib/cli.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/cli.py b/lib/cli.py index 6b24dc549..68533eb29 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -76,8 +76,22 @@ def player_options(): print(player) elif choice == "5": break + elif choice == '6': + id = input('Please input a id') + name= input('Please input a name') + player = Player.find_by_name(name) + world_instance = World.find_by_id(id) + player.login(world_instance) + player.worlds() + + + + + else: print("Please Make A Valid Choice") + + def player_menu(): print("________________________") From 487f4ea0a78fa26249af6df2dfc28764358610ab Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Wed, 8 Nov 2023 17:32:35 -0600 Subject: [PATCH 15/19] just some smalls tuff --- lib/cli.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index a7b89a351..586cef988 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -3,6 +3,8 @@ from models.player import Player from helpers import exit_program +selected_world = None +selected_player = None def main(): while True: menu() @@ -13,6 +15,8 @@ def main(): player_options() elif choice == "3": exit_program() + elif choice == "4": + login_menu() else: print("Please Make A Valid Choice") @@ -27,6 +31,7 @@ def menu(): def world_options(): while True: world_menu() + print(selected_world) choice = input(">") if choice == "1": create_world_menu() @@ -46,6 +51,10 @@ def world_options(): break else: print("Please Make A Valid Choice") + +def login_menu(): + print(f"World Selected:{selected_world}") + print(f"Player Selected:{selected_player}") def world_menu(): print("________________________") @@ -68,6 +77,7 @@ def player_options(): print("There Are No Players\n Please Create One") else: print(Player.all()) + select_player() elif choice == "3": id = input("Select Player Id to Delete:") player = Player.find_by_id(id) @@ -132,8 +142,23 @@ def select_world(): elif selection == "": print("Please Select a world ID or backout with 0: >") elif int(selection) <= len(World.all()): - print(f'Selected\n{World.find_by_id(selection)}') + global selected_world + selected_world = World.find_by_id(selection) + print(f'Selected\n{selected_world}') else: print("Please Select a valid world ID") +def select_player(): + while True: + selection = input("Select a player id or backout with 0: >") + if selection == "0": + break + elif selection == "": + print("Please Select a Player with ID or backout with 0") + elif int(selection) <= len(Player.all()): + global selected_player + selected_player = Player.find_by_id(selection) + print(f'Selected\n{selected_player}') + else: + print("Please Select a valid Player ID") if __name__ == "__main__": main() From ccbd269884a409aabb1a9c32cbcb1a38adae263c Mon Sep 17 00:00:00 2001 From: Tashi Gyatso Date: Wed, 8 Nov 2023 20:56:14 -0500 Subject: [PATCH 16/19] allows player to know which world he/she went --- lib/cli.py | 4 ++++ lib/debug.py | 2 +- lib/models/player.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index 68533eb29..b5a7272d1 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -83,6 +83,10 @@ def player_options(): world_instance = World.find_by_id(id) player.login(world_instance) player.worlds() + elif choice == '7': + name = input('please input player name ') + player = Player.find_by_name(name) + print(player.worlds()) diff --git a/lib/debug.py b/lib/debug.py index ddbc501d1..d42eaee6b 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -5,7 +5,7 @@ from models.__init__ import CONN, CURSOR import ipdb -# player1 = Player('Matt') +player1 = # world1 = World('Howling Castle') # world2 = World('Mt Everwood') ipdb.set_trace() diff --git a/lib/models/player.py b/lib/models/player.py index 46c002ee9..b7d5c997e 100644 --- a/lib/models/player.py +++ b/lib/models/player.py @@ -108,6 +108,19 @@ def worlds(self): def create_table2(cls): sql = 'CREATE TABLE login(id INTEGER PRIMARY KEY,player_id INTEGER,world_id INTEGER)' CURSOR.execute(sql) + + @classmethod + def all_player_login(cls): + sql = ''' + SELECT * FROM login WHERE player_id = ? + ''' + list_of_tuples = CURSOR.execute(sql).fetchone() + return [Player.login_db(row) for row in list_of_tuples] + @classmethod + def login_db(cls,row_tuple): + player_instance = ( row_tuple[1],) + player_instance.id = row_tuple[0] + return player_instance # must create a table(will throw seed at project later) # need a player instace, and a world instance to login. # ipdb> player1 = Player("Test7") From 12cceb69561bb4ece02626e8293a0de9d96a4f91 Mon Sep 17 00:00:00 2001 From: Tashi Gyatso Date: Wed, 8 Nov 2023 20:58:00 -0500 Subject: [PATCH 17/19] One change --- lib/cli.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index b5a7272d1..3baf2801a 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -86,12 +86,7 @@ def player_options(): elif choice == '7': name = input('please input player name ') player = Player.find_by_name(name) - print(player.worlds()) - - - - - + print(player.worlds()) else: print("Please Make A Valid Choice") From 778c2496968fd2b6dcb6a00763ba89db31c278fb Mon Sep 17 00:00:00 2001 From: Mateusz M Trybunia Date: Wed, 8 Nov 2023 20:24:46 -0600 Subject: [PATCH 18/19] whops --- lib/cli.py | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 030ce9cc4..5a157eeb4 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -14,19 +14,49 @@ def main(): elif choice == "2": player_options() elif choice == "3": - exit_program() - elif choice == "4": login_menu() + # Would be a menu() + # while True: + # login_menu() + # Choice == "1": + # select_player() + # choice == "2": + # select_world() + elif choice == "4": + exit_program() else: print("Please Make A Valid Choice") def menu(): + print(""" + .,-:;//;:=, + . :H@@@MM@M#H/.,+%;, + ,/X+ +M@@M@MM%=,-%HMMM@X/, + -+@MM; $M@@MH+-,;XMMMM@MMMM@+- + ;@M@@M- XM@X;. -+XXXXXHHH@M@M#@/. + ,%MM@@MH ,@%= .---=-=:=,. + -@#@@@MX ., -%HX$$%%%+; + =-./@M@M$ .;@MMMM@MM: + X@/ -$MM/ .+MM@@@M$ +,@M@H: :@: . -X#@@@@- +,@@@MMX, . /H- ;@M@M= +.H@@@@M@+, %MM+..%#$. + /MMMM@MMH/. XM@MH; -; + /%+%$XHH@$= , .H@@@@MX, + .=--------. -%H.,@@@@@MX, + .%MM@@@HHHXX$$$%+- .:$MMX -M@@MM%. + =XMMM@MM@MM#H;,-+HMM@M+ /MMMX= + =%@M@M#@$-.=$@MM@@@M; %M%= + ,:+$+-,/H#MMMMMMM@- -, + =++%%%%+/:-. +""") print("________________________") print("Please select an option") print("------------------------") print("1. World Options") print("2. Player Options") - print("3. Exit the program") + print("3. Login Screen?") + print("4. Exit the program") def world_options(): while True: @@ -53,6 +83,7 @@ def world_options(): print("Please Make A Valid Choice") def login_menu(): + print("Theres Nothing Here Right Now") print(f"World Selected:{selected_world}") print(f"Player Selected:{selected_player}") @@ -86,23 +117,21 @@ def player_options(): name = input('Find your character by their name: ') player = Player.find_by_name(name) print(player) - elif choice == "5": - break - elif choice == '6': + elif choice == '5': id = input('Please input a id') name= input('Please input a name') player = Player.find_by_name(name) world_instance = World.find_by_id(id) player.login(world_instance) player.worlds() - elif choice == '7': + elif choice == '6': name = input('please input player name ') player = Player.find_by_name(name) print(player.worlds()) + elif choice == "7": + break else: print("Please Make A Valid Choice") - - def create_player_menu(): @@ -145,7 +174,9 @@ def player_menu(): print("2. Display Player's") print("3. Remove Player") print('4. Find Player by name') - print("5. Back to Main Menu") + print("5. Login A player to a world") + print("6. Search a Player Worlds") + print("7. Back to Main Menu") def select_world(): while True: From d1cbab9285a5983c0009841851ea94c18f7972cf Mon Sep 17 00:00:00 2001 From: Tashi Gyatso Date: Wed, 8 Nov 2023 22:31:32 -0500 Subject: [PATCH 19/19] menue 2 => option 5-6 debuggers included, 1 test ascii art --- lib/cli.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 5a157eeb4..26d346597 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -118,16 +118,28 @@ def player_options(): player = Player.find_by_name(name) print(player) elif choice == '5': - id = input('Please input a id') - name= input('Please input a name') - player = Player.find_by_name(name) - world_instance = World.find_by_id(id) - player.login(world_instance) - player.worlds() + id = input('Please input a id: ') + name= input('Please input a name: ') + if id and name: + player = Player.find_by_name(name) + world_instance = World.find_by_id(id) + if player and world_instance: + player.login(world_instance) + else: + print('Player or world not found') + else: + print('Please enter a valid world id and player name') elif choice == '6': + print(Player.all()) name = input('please input player name ') - player = Player.find_by_name(name) - print(player.worlds()) + if name: + player = Player.find_by_name(name) + if player: + print(player.worlds()) + else: + print('Player not found') + else: + print(' please enter a valid name') elif choice == "7": break else: @@ -170,7 +182,11 @@ def player_menu(): print("________________________") print("Player Menu") print("------------------------") - print("1. Create Player") + print('''1. + / __|| |_ ___ ___ ___ ___ _ _ ___ _ _ _ _ / __|| |_ __ _ _ _ __ _ __ | |_ ___ _ _ + | (__ | ' \ / _ \/ _ \(_-