diff --git a/Pipfile b/Pipfile index 0ebe435..4df1490 100644 --- a/Pipfile +++ b/Pipfile @@ -9,7 +9,7 @@ faker = "*" pytest = "7.1.3" rich = "13.7.1" pick = "2.3.2" -sqlite3 = "*" + [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 6538411..12ba6ee 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "5c9ab3d3df05028a37934f5beef7b9fd83f4720c871befa2abcbf7363aa550a4" + "sha256": "a2eca7394da973551f69b3e70f67400316eabf39108e900bef63964817dccb65" }, "pipfile-spec": 6, "requires": { @@ -18,18 +18,26 @@ "default": { "appnope": { "hashes": [ - "sha256:02bd91c4de869fbb1e1c50aafc4098827a7a54ab2f39d9dcba6c9547ed920e24", - "sha256:265a455292d0bd8a72453494fa24df5a11eb18373a60c7c0430889f22548605e" + "sha256:1de3860566df9caf38f01f86f65e0e13e379af54f9e4bee1e66b48f2efffd1ee", + "sha256:502575ee11cd7a28c0205f379b525beefebab9d161b7c964670864014ed7213c" ], "markers": "sys_platform == 'darwin'", - "version": "==0.1.3" + "version": "==0.1.4" }, "asttokens": { "hashes": [ - "sha256:4622110b2a6f30b77e1473affaa97e711bc2f07d3f10848420ff1898edbe94f3", - "sha256:6b0ac9e93fb0335014d382b8fa9b3afa7df546984258005da0b9e7095b3deb1c" + "sha256:051ed49c3dcae8913ea7cd08e46a606dba30b79993209636c4875bc1d637bc24", + "sha256:b03869718ba9a6eb027e134bfdf69f38a236d681c83c160d510768af11254ba0" ], - "version": "==2.2.1" + "version": "==2.4.1" + }, + "attrs": { + "hashes": [ + "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30", + "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1" + ], + "markers": "python_version >= '3.7'", + "version": "==23.2.0" }, "backcall": { "hashes": [ @@ -43,31 +51,25 @@ "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330", "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186" ], - "markers": "python_version > '3.6' and python_version < '3.11'", + "markers": "python_version < '3.11' and python_version >= '3.7'", "version": "==5.1.1" }, - "exceptiongroup": { - "hashes": [ - "sha256:12c3e887d6485d16943a309616de20ae5582633e0a2eda17f4e10fd61c1e8af5", - "sha256:e346e69d186172ca7cf029c8c1d16235aa0e04035e5750b4b95039e65204328f" - ], - "markers": "python_version < '3.11'", - "version": "==1.1.2" - }, "executing": { "hashes": [ - "sha256:0314a69e37426e3608aada02473b4161d4caf5a4b244d1d0c48072b8fee7bacc", - "sha256:19da64c18d2d851112f09c287f8d3dbbdf725ab0e569077efb6cdcbd3497c107" + "sha256:35afe2ce3affba8ee97f2d69927fa823b08b472b7b994e36a52a964b93d16147", + "sha256:eac49ca94516ccc753f9fb5ce82603156e590b27525a8bc32cce8ae302eb61bc" ], - "version": "==1.2.0" + "markers": "python_version >= '3.5'", + "version": "==2.0.1" }, "faker": { "hashes": [ - "sha256:4b7d5cd0c898f0b64f88fbf0a35aac66762f2273446ba4a4e459985a2e5c8f8c", - "sha256:d1eb772faf4a7c458c90b19d3626c40ae3460bd665ad7f5fb7b089e31d1a6dcf" + "sha256:4c40b34a9c569018d4f9d6366d71a4da8a883d5ddf2b23197be5370f29b7e1b6", + "sha256:bdec5f2fb057d244ebef6e0ed318fea4dcbdf32c3a1a010766fc45f5d68fc68d" ], "index": "pypi", - "version": "==19.1.0" + "markers": "python_version >= '3.8'", + "version": "==25.8.0" }, "iniconfig": { "hashes": [ @@ -83,55 +85,81 @@ "sha256:e3ac6018ef05126d442af680aad863006ec19d02290561ac88b8b1c0b0cfc726" ], "index": "pypi", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.13.13" }, "ipython": { "hashes": [ - "sha256:c7b80eb7f5a855a88efc971fda506ff7a91c280b42cdae26643e0f601ea281ea", - "sha256:ea8801f15dfe4ffb76dea1b09b847430ffd70d827b41735c64a0638a04103bfc" + "sha256:3910c4b54543c2ad73d06579aa771041b7d5707b033bd488669b4cf544e3b363", + "sha256:b0340d46a933d27c657b211a329d0be23793c36595acf9e6ef4164bc01a1804c" ], - "markers": "python_version > '3.6' and python_version < '3.11'", - "version": "==8.12.2" + "markers": "python_version < '3.11' and python_version >= '3.7'", + "version": "==8.12.3" }, "jedi": { "hashes": [ - "sha256:203c1fd9d969ab8f2119ec0a3342e0b49910045abe6af0a3ae83a5764d54639e", - "sha256:bae794c30d07f6d910d32a7048af09b5a39ed740918da923c6b780790ebac612" + "sha256:cf0496f3651bc65d7174ac1b7d043eff454892c708a87d1b683e57b569927ffd", + "sha256:e983c654fe5c02867aef4cdfce5a2fbb4a50adc0af145f70504238f18ef5e7e0" ], "markers": "python_version >= '3.6'", - "version": "==0.18.2" + "version": "==0.19.1" + }, + "markdown-it-py": { + "hashes": [ + "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1", + "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb" + ], + "markers": "python_version >= '3.8'", + "version": "==3.0.0" }, "matplotlib-inline": { "hashes": [ - "sha256:f1f41aab5328aa5aaea9b16d083b128102f8712542f819fe7e6a420ff581b311", - "sha256:f887e5f10ba98e8d2b150ddcf4702c1e5f8b3a20005eb0f74bfdbd360ee6f304" + "sha256:8423b23ec666be3d16e16b60bdd8ac4e86e840ebd1dd11a30b9f117f2fa0ab90", + "sha256:df192d39a4ff8f21b1895d72e6a13f5fcc5099f00fa84384e0ea28c2cc0653ca" ], - "markers": "python_version >= '3.5'", - "version": "==0.1.6" + "markers": "python_version >= '3.8'", + "version": "==0.1.7" }, - "packaging": { + "mdurl": { "hashes": [ - "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61", - "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f" + "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", + "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba" ], "markers": "python_version >= '3.7'", - "version": "==23.1" + "version": "==0.1.2" + }, + "packaging": { + "hashes": [ + "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002", + "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124" + ], + "markers": "python_version >= '3.8'", + "version": "==24.1" }, "parso": { "hashes": [ - "sha256:8c07be290bb59f03588915921e29e8a50002acaf2cdc5fa0e0114f91709fafa0", - "sha256:c001d4636cd3aecdaf33cbb40aebb59b094be2a74c556778ef5576c175e19e75" + "sha256:a418670a20291dacd2dddc80c377c5c3791378ee1e8d12bffc35420643d43f18", + "sha256:eb3a7b58240fb99099a345571deecc0f9540ea5f4dd2fe14c2a99d6b281ab92d" ], "markers": "python_version >= '3.6'", - "version": "==0.8.3" + "version": "==0.8.4" }, "pexpect": { "hashes": [ - "sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937", - "sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c" + "sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523", + "sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f" ], "markers": "sys_platform != 'win32'", - "version": "==4.8.0" + "version": "==4.9.0" + }, + "pick": { + "hashes": [ + "sha256:78006b6c6b16f80921fe3e66c9730b3fa75b2732d464a9fcd4cab5a4ac75a42d", + "sha256:91bfa8c17dada639cf793cc4270db39fef8dc2d0c9c8a6be2f3d4d0d9ee58456" + ], + "index": "pypi", + "markers": "python_version >= '3.7'", + "version": "==2.3.2" }, "pickleshare": { "hashes": [ @@ -142,19 +170,19 @@ }, "pluggy": { "hashes": [ - "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849", - "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3" + "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1", + "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669" ], - "markers": "python_version >= '3.7'", - "version": "==1.2.0" + "markers": "python_version >= '3.8'", + "version": "==1.5.0" }, "prompt-toolkit": { "hashes": [ - "sha256:04505ade687dc26dc4284b1ad19a83be2f2afe83e7a828ace0c72f3a1df72aac", - "sha256:9dffbe1d8acf91e3de75f3b544e4842382fc06c6babe903ac9acb74dc6e08d88" + "sha256:0d7bfa67001d5e39d02c224b663abc33687405033a8c422d0d675a5a13361d10", + "sha256:1e1b29cb58080b1e69f207c893a1a7bf16d127a5c30c9d17a25a5d77792e5360" ], "markers": "python_full_version >= '3.7.0'", - "version": "==3.0.39" + "version": "==3.0.47" }, "ptyprocess": { "hashes": [ @@ -170,75 +198,93 @@ ], "version": "==0.2.2" }, + "py": { + "hashes": [ + "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719", + "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==1.11.0" + }, "pygments": { "hashes": [ - "sha256:8ace4d3c1dd481894b2005f560ead0f9f19ee64fe983366be1a21e171d12775c", - "sha256:db2db3deb4b4179f399a09054b023b6a586b76499d36965813c71aa8ed7b5fd1" + "sha256:786ff802f32e91311bff3889f6e9a86e81505fe99f2735bb6d60ae0c5004f199", + "sha256:b8e6aca0523f3ab76fee51799c488e38782ac06eafcf95e7ba832985c8e7b13a" ], - "markers": "python_version >= '3.7'", - "version": "==2.15.1" + "markers": "python_version >= '3.8'", + "version": "==2.18.0" }, "pytest": { "hashes": [ - "sha256:78bf16451a2eb8c7a2ea98e32dc119fd2aa758f1d5d66dbf0a59d69a3969df32", - "sha256:b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a" + "sha256:1377bda3466d70b55e3f5cecfa55bb7cfcf219c7964629b967c37cf0bda818b7", + "sha256:4f365fec2dff9c1162f834d9f18af1ba13062db0c708bf7b946f8a5c76180c39" ], "index": "pypi", - "version": "==7.4.0" + "markers": "python_version >= '3.7'", + "version": "==7.1.3" }, "python-dateutil": { "hashes": [ - "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86", - "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9" + "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", + "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", - "version": "==2.8.2" + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.9.0.post0" + }, + "rich": { + "hashes": [ + "sha256:4edbae314f59eb482f54e9e30bf00d33350aaa94f4bfcd4e9e3110e64d0d7222", + "sha256:9be308cb1fe2f1f57d67ce99e95af38a1e2bc71ad9813b0e247cf7ffbcc3a432" + ], + "index": "pypi", + "markers": "python_full_version >= '3.7.0'", + "version": "==13.7.1" }, "six": { "hashes": [ "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.16.0" }, "stack-data": { "hashes": [ - "sha256:32d2dd0376772d01b6cb9fc996f3c8b57a357089dec328ed4b6553d037eaf815", - "sha256:cbb2a53eb64e5785878201a97ed7c7b94883f48b87bfb0bbe8b623c74679e4a8" + "sha256:836a778de4fec4dcd1dcd89ed8abff8a221f58308462e1c4aa2a3cf30148f0b9", + "sha256:d5558e0c25a4cb0853cddad3d77da9891a08cb85dd9f9f91b9f8cd66e511e695" ], - "version": "==0.6.2" + "version": "==0.6.3" }, "tomli": { "hashes": [ "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" ], - "markers": "python_version > '3.6' and python_version < '3.11'", + "markers": "python_version >= '3.7'", "version": "==2.0.1" }, "traitlets": { "hashes": [ - "sha256:9e6ec080259b9a5940c797d58b613b5e31441c2257b87c2e795c5228ae80d2d8", - "sha256:f6cde21a9c68cf756af02035f72d5a723bf607e862e7be33ece505abf4a3bad9" + "sha256:9ed0579d3502c94b4b3732ac120375cda96f923114522847de4b3bb98b96b6b7", + "sha256:b74e89e397b1ed28cc831db7aea759ba6640cb3de13090ca145426688ff1ac4f" ], - "markers": "python_version >= '3.7'", - "version": "==5.9.0" + "markers": "python_version >= '3.8'", + "version": "==5.14.3" }, "typing-extensions": { "hashes": [ - "sha256:440d5dd3af93b060174bf433bccd69b0babc3b15b1a8dca43789fd7f61514b36", - "sha256:b75ddc264f0ba5615db7ba217daeb99701ad295353c45f9e95963337ceeeffb2" + "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", + "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8" ], - "markers": "python_version <= '3.8'", - "version": "==4.7.1" + "markers": "python_version < '3.9'", + "version": "==4.12.2" }, "wcwidth": { "hashes": [ - "sha256:795b138f6875577cd91bba52baf9e445cd5118fd32723b460e30a0af30ea230e", - "sha256:a5220780a404dbe3353789870978e472cfe477761f06ee55077256e509b156d0" + "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859", + "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5" ], - "version": "==0.2.6" + "version": "==0.2.13" } }, "develop": {} diff --git a/lib/cli.py b/lib/cli.py index d005c3c..49d648a 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -3,6 +3,7 @@ from sqlite3 import * import os import random +import ipdb from models.player import Player from models.game_space import Game_space from models.game import Game @@ -17,7 +18,6 @@ def main_menu(): print("Please select an option:") print("1 Start New Game") print("2 Exit Game") - def main(): while True: @@ -37,9 +37,9 @@ def main(): main() def exit_program(): - os.system('clear') - print("Goodbye!") - exit() + os.system('clear') + print("Goodbye!") + exit() def new_game_setup_menu(): print("New Game Menu:") @@ -49,29 +49,29 @@ def new_game_setup_menu(): print("4 Quit Game") def new_game_setup(game): - new_game_setup_menu() - choice = input() - if choice == "1": - os.system('clear') - player_setup(game) - elif choice == "2": - os.system('clear') - set_win_condition(game) - elif choice == "3": - os.system('clear') - start_game(game) - elif choice == "4": - exit_program() - else: - os.system('clear') - print("That is not a valid input.") - print("Enter the number next to your choice.\n") - time.sleep(2.5) - new_game_setup(game) + new_game_setup_menu() + choice = input() + if choice == "1": + os.system('clear') + player_setup(game) + elif choice == "2": + os.system('clear') + set_win_condition(game) + elif choice == "3": + os.system('clear') + start_game(game) + elif choice == "4": + exit_program() + else: + os.system('clear') + print("That is not a valid input.") + print("Enter the number next to your choice.\n") + time.sleep(2.5) + new_game_setup(game) def player_setup_menu(): - print("Players") + print("Players Menu") print("1 Add Player") print("2 See All Players") print("3 Remove Player") #add home position back into list @@ -80,23 +80,23 @@ def player_setup_menu(): print("6 Quit Game") def player_setup(game): - players = Player.get_all_players_by_gameid(game.id) player_setup_menu() print("What would you like to do?") choice = input() if choice == "1": os.system('clear') - enter_new_player(game) + if len(player_home_position) != 0: + enter_new_player(game) + else: + print("Max number of players reached") + player_setup(game) elif choice == "2": os.system('clear') - ipdb.set_trace() - for player in players: - print(player.name) + print_players(game) player_setup(game) elif choice == "3": os.system('clear') - remove_player(game, players) - player_setup(game) + remove_player(game) elif choice == "4": os.system('clear') edit_player(game) @@ -107,106 +107,121 @@ def player_setup(game): players = Player.get_all_players_by_gameid(game.id) homes = Game_space.get_all_homes_by_gameid(game.id) os.system('clear') - exit_program_prestart(game, players, homes) + exit_program(game, players, homes) else: os.system('clear') print("Invalid choice, please select again") time.sleep(2.5) player_setup(game) - -def remove_player(game, players): + +def check_num_players(game): + players = Player.get_all_players_by_gameid(game) + return len(players) + +def remove_player(game): os.system('clear') - for player in players: - print(f'{player.index} - {player.name}') - print("Enter number next to the player you would like to remove") - value = input() - if value >= len(players): + players = print_players(game) + print("Enter the number of the player you would like to remove") + print("0 - Back to Player Setup") + choice = input() + value = int(choice) if choice in ["0","1","2","3","4"] else 10 + if value > len(players): os.system('clear') - print("Invalid entry") - time.sleep(2.5) - remove_player(game, players) - remove_player_home(game, player[value]) - print(f"{player[value].name}'s home has been deleted") - Player.delete(player[value]) - print(f'{player[value].name} has been deleted') + print("INVALID ENTRY \n") + time.sleep(1) + remove_player(game) + elif value == 0: + player_setup(game) + remove_player_home(game, players[(value - 1)]) + print(f"{players[(value - 1)].name}'s home has been deleted") + print(f'{players[(value -1)].name} has been deleted') + Player.delete(players[(value - 1)]) + print("press ENTER to continue") + input() + remove_player(game) - -def remove_player_home(player, game): - home = Game_space.get_game_space_by_playerid_gameid(game, player) - Game_space.delete(home) +def remove_player_home(game, player): + sql = """ SELECT position FROM game_spaces WHERE game_id = ? AND player_id = ?; """ + position = CURSOR.execute(sql, (game.id, player.id)).fetchone() + player_home_position.append(position[0]) + Game_space.delete(game, player) def enter_new_player(game): - print("Enter Your Player's Name (required)") - print("Name must be less than 16 characters") - name = input() - if not 0 < len(name) < 16: - os.system('clear') - print("Name is invalid") - enter_new_player(game) - else: - os.system('clear') - create_player_type(game, name) + print("Enter Your Player's Name (required)") + print("Name must be less than 16 characters") + name = input() + if not 0 < len(name) < 16: + os.system('clear') + print("INVALID ENTRY\n") + enter_new_player(game) + else: + os.system('clear') + create_player_type(game, name) def create_player_type(game, name): - print(f"{name}, which type of player you would like to be?") - print('1 REALTOR = The REALTOR receives 10 percent of all property purchases') - print('2 COP = The COP receives $50 from any player occupying the same space') - print('3 BUILDER = The BUILDER recieves a 20 percent discount on home purchases') - print('4 PILOT = The PILOT can roll an unlimited number of doubles') - value = input() - if value == "1": - player_type = "REALTOR" - elif value == "2": - player_type = "COP" - elif value == "3": - player_type = "BUILDER" - elif value == "4": - player_type = "PILOT" - else: - os.system('clear') - print("You must choose from the 4 player types\n") - time.sleep(2.5) - create_player_type(game,name) - - player = Player.create(name, player_type, 0, 1800, 1800, game.id) - print(f"Good Luck {player.name}!") - time.sleep(2) - position = player_home_position.pop() + print(f"{name}, which type of player you would like to be?\n") + print('1 REALTOR = The REALTOR receives 10 percent of all property purchases') + print('2 COP = The COP receives $50 from any player occupying the same space') + print('3 BUILDER = The BUILDER recieves a 20 percent discount on home purchases') + print('4 PILOT = The PILOT can roll an unlimited number of doubles') + value = input() + if value == "1": + player_type = "REALTOR" + elif value == "2": + player_type = "COP" + elif value == "3": + player_type = "BUILDER" + elif value == "4": + player_type = "PILOT" + else: os.system('clear') - enter_player_home(position, player, game) + print("You must choose from the 4 player types\n") + time.sleep(2.5) + create_player_type(game, name) + + player = Player.create(name, player_type, 0, 1800, 1800, game.id) + print(f"Good Luck {player.name}!") + time.sleep(.5) + position = player_home_position.pop() + os.system('clear') + enter_player_home(position, player, game) def enter_player_home(position, player, game): - print("Each player begins with a home property") - print(f"{player.name} enter a name for your home's street?") - street_name = input() - if len(street_name) == 0: - os.system('clear') - print("Street cannot be left blank") - time.sleep(2.5) - enter_player_home(position, player, game) - else: - assign_game_space(game.id, player.id, position, street_name, 0, 100, position, None, 0, 0, game, player) + print("Each player begins with a home property.\n") + print(f"{player.name} enter a name for your home's street?") + street_name = input() + if len(street_name) == 0: + os.system('clear') + print("Street cannot be left blank/n") + time.sleep(2.5) + enter_player_home(position, player, game) + else: + assign_game_space(game.id, player.id, position, street_name, position, 0, 100, "player", 0, 0, game) -def assign_game_space(game_id, player_id, space_id, street_name, price, rent, position, neighborhood, houses, monopoly, game, player): - Game_space.create(game_id, player_id, space_id, street_name, price, rent, position, neighborhood, houses, monopoly) - print("\n \n CONGRATULATIONS! You now own your first property.") - print(f"You can find your home on the {position}th position on the board") - time.sleep(2.5) - os.system('clear') - player_setup(game) +def assign_game_space(game_id, player_id, space_id, street_name, position, price, rent, neighborhood, houses, monopoly, game): + home = Game_space.create(game_id, player_id, space_id, street_name, position, price, rent, neighborhood, houses, monopoly) + print("\n CONGRATULATIONS! You now own your first property.") + print(f"You can find {home.street_name} on the {position}th position on the board") + print("press ENTER to continue") + input() + os.system('clear') + player_setup(game) def set_win_condition(game): - print("Enter net worth needed to win") - print("Must be between 5000 and 20000") - win_condition = input() - if not 5000 <= int(win_condition) <= 20000: - print("Invalid entry") - time.sleep(2.5) - set_win_condition(game) - else: - update_game_win_cond(game, win_condition) + print("enter NET WORTH needed to win") + print("Must be between 5000 and 20000") + win_condition = input() + try: + if 5000 <= int(win_condition) <= 20000: + update_game_win_cond(game, win_condition) + except ValueError: + os.system('clear') + print("Must enter a number between 5000 and 20000") + time.sleep(1.25) + finally: + return set_win_condition(game) def update_game_win_cond(game, win_condition): game.win_condition = int(win_condition) @@ -216,6 +231,20 @@ def update_game_win_cond(game, win_condition): os.system('clear') new_game_setup(game) +def get_player_list(game): + return Player.get_all_players_by_gameid(game) + +def print_players(game): + players = get_player_list(game) + if len(players) == 0: + print("Game has no players yet\n") + player_setup(game) + + print("Players") + for i, player in enumerate(players, start=1): + print(f'{i} - {player}') + return players + def start_game(game): pass diff --git a/lib/debug.py b/lib/debug.py index 47aa6c0..973657c 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -3,11 +3,31 @@ from models.__init__ import CONN, CURSOR import os +import ipdb +from models.player import Player +from models.game import Game +from models.space import Space +from models.game_space import Game_space +from sqlite3 import * -#ipdb.set_trace() -os.system("echo 'hello world'") -os.system("say -v Zarvox 'hello world'") + + + + + + + +ipdb.set_trace() + + + + + + + +#os.system("echo 'hello world'") +#os.system("say -v Zarvox 'hello world'") diff --git a/lib/models/__init__.py b/lib/models/__init__.py index 6f6dfa7..36cf1be 100644 --- a/lib/models/__init__.py +++ b/lib/models/__init__.py @@ -1,4 +1,4 @@ import sqlite3 -CONN = sqlite3.connect('./monopolython.db') +CONN = sqlite3.connect('./lib/monopolython.db') CURSOR = CONN.cursor() diff --git a/lib/models/game.py b/lib/models/game.py index a506d69..978ed97 100644 --- a/lib/models/game.py +++ b/lib/models/game.py @@ -1,6 +1,7 @@ from sqlite3 import * from models.__init__ import CONN, CURSOR +import ipdb class Game(): diff --git a/lib/models/game_space.py b/lib/models/game_space.py index 92c2800..885c926 100644 --- a/lib/models/game_space.py +++ b/lib/models/game_space.py @@ -1,4 +1,5 @@ from sqlite3 import * +import ipdb from models.__init__ import CONN, CURSOR from models.space import Space @@ -41,15 +42,15 @@ def create(cls, game_id, player_id, space_id, street_name, position, price, rent game_space.save() return game_space - def __init__(self, game_id, player_id, space_id, street_name, position, price = 0, rent = 0, neighborhood = None, houses = 0, monopoly = False, id = None): + def __init__(self, game_id, player_id, space_id, street_name, position, price = 0, rent = 0, neighborhood = None, houses = 0, monopoly = 0, id = None): space = Space.find_by_space_position(position) self.game_id = game_id self.player_id = player_id self.space_id = space_id self.street_name = street_name + self.position = position self.price = space.price self.rent = space.rent - self.position = position self.neighborhood = space.neighborhood self.houses = 0 self.monopoly = False @@ -75,10 +76,11 @@ def update(self): """ CURSOR.execute(sql, (self.player_id, self.street_name, self.rent, self.houses, self.monopoly, self.id)) CONN.commit() - - def delete(self): - sql = """ DELETE FROM game_spaces WHERE id = ?;""" - CURSOR.execute(self, (self.id,)) + + @classmethod + def delete(cls, game, player): + sql = """ DELETE FROM game_spaces WHERE game_id = ? AND player_id = ? and neighborhood = ?;""" + CURSOR.execute(sql, (game.id, player.id, "Player")) CONN.commit() @classmethod @@ -90,20 +92,21 @@ def get_all_homes_by_gameid(cls, gameid): @classmethod def instance_from_db(cls, row): game_space = cls( - id = row[0], - game_id = row[1], - player_id = row[2], - space_id = row[3], - street_name = row[4], - position = [5], - price = [6], - rent = [7], - neighborhood = [8], - houses = [9], - monopoly = [10]) + row[1], + row[2], + row[3], + row[4], + row[5], + row[6], + row[7], + row[8], + row[9], + row[10], + row[0],) @classmethod - def get_game_space_by_playerid_gameid(cls, game, player): - sql = """ SELECT * FROM game_spaces WHERE (game_id = ? AND player_id = ?) LIMIT 1;""" - row = CURSOR.execute(sql, (game.id, player.id)).fetchone() + def get_player_home(cls, game, player): + sql = """ SELECT * FROM game_spaces WHERE (game_id = ? AND player_id = ? AND neighborhood = ?) LIMIT 1;""" + row = CURSOR.execute(sql, (game.id, player.id, "Player")).fetchone() + ipdb.set_trace() return cls.instance_from_db(row) if row else None \ No newline at end of file diff --git a/lib/models/player.py b/lib/models/player.py index 1a0cbd1..f4bd076 100644 --- a/lib/models/player.py +++ b/lib/models/player.py @@ -1,7 +1,9 @@ from sqlite3 import * -from models.__init__ import CONN, CURSOR +from models. __init__ import CONN, CURSOR from models.game_space import Game_space - +import ipdb +#CONN = sqlite3.connect('./monopolython.db') +#CURSOR = CONN.cursor() class Player(): @classmethod @@ -9,7 +11,7 @@ def create_table(cls): try: with CONN: CURSOR.execute( - """CREATE TABLE IF NOT EXISTS players ( + """ CREATE TABLE IF NOT EXISTS players ( id INTEGER PRIMARY KEY, name TEXT, player_type TEXT, @@ -30,24 +32,24 @@ def drop_table(cls): CONN.commit() @classmethod - def create(cls, name, player_type, curr_pos = 0, money = 1800, net_worth = 1800, game_id = None): + def create(cls, name, player_type, curr_pos = 1, money = 1800, net_worth = 1800, game_id = None): player = cls(name, player_type, curr_pos, money, net_worth, game_id) player.save() return player @classmethod def instance_from_db(cls, row): - player = cls( - id = row[0], - name = row[1], - player_type = row[2], - curr_pos = row[3], - money = row[4], - net_worth = row[5], - game_id = row[6]) + return cls( + row[1], + row[2], + row[3], + row[4], + row[5], + row[6], + row[0],) - def __init__(self, name, player_type, curr_pos = 0, money = 1800, net_worth = 1800, game_id = None, id = None): + def __init__(self, name, player_type, curr_pos = 1, money = 1800, net_worth = 1800, game_id = None, id = None): self.name = name self.player_type = player_type self.curr_pos = curr_pos @@ -57,7 +59,7 @@ def __init__(self, name, player_type, curr_pos = 0, money = 1800, net_worth = 18 self.id = id def __repr__(self): - return f"<{self.name}: ID# = {self.id}\nPlayer Type = {self.player_type}\nMoney = {self.money}\nNet Worth = {self.net_worth}\n Postion = {self.curr_pos}>" + return f"{self.name} | {self.player_type} | Money:${self.money} | Net Worth:{self.net_worth}" def save(self): sql = """ @@ -77,15 +79,24 @@ def update(self): CURSOR.execute(sql, (self.name, self.player_type, self.curr_pos, self.money, self.net_worth, self.id)) CONN.commit() - def delete(self): + @classmethod + def delete(cls, player): sql = """ DELETE FROM players WHERE id = ?;""" - CURSOR.execute(sql, (self.id,)) + CURSOR.execute(sql, (player.id,)) CONN.commit() @classmethod - def get_all_players_by_gameid(cls, gameid): - sql = """ SELECT * FROM players WHERE game_id = ?; """ - rows = CURSOR.execute(sql, (gameid,)).fetchall() - players = [cls.instance_from_db(row) for row in rows] - [print(player) for player in players] - return players \ No newline at end of file + def get_all_players_by_gameid(cls, game): + try: + with CONN: + result = CURSOR.execute("SELECT * FROM players WHERE game_id = ?;", (game.id,)) + rows = result.fetchall() + return [cls.instance_from_db(row) for row in rows] + except Exception as e: + return e + #sql = """ SELECT * FROM players WHERE game_id = ?; """ + #rows = CURSOR.execute(sql, (gameid,)).fetchall() + #players = [cls.instance_from_db(row) for row in rows] + #[print(player) for player in players] + #return players +