From 37ad0a297fd1aaf9b1d657425252773739aef79d Mon Sep 17 00:00:00 2001 From: ckjolhede Date: Thu, 20 Jun 2024 01:06:43 -0600 Subject: [PATCH 1/4] mvp --- lib/cli.py | 116 ++++++++++++++++++++++++++++++------- lib/migrate.py | 51 ++++++++++++++++ lib/models/helper.py | 23 -------- lib/models/setup_helper.py | 29 ++++++++++ lib/seeds.py | 13 +---- 5 files changed, 178 insertions(+), 54 deletions(-) create mode 100644 lib/migrate.py delete mode 100644 lib/models/helper.py create mode 100644 lib/models/setup_helper.py diff --git a/lib/cli.py b/lib/cli.py index 49d648a..d693793 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -8,6 +8,7 @@ from models.game_space import Game_space from models.game import Game from models.__init__ import CONN, CURSOR +from models.setup_helper import (exit_program, exit_program_early, player_home_position, ) player_house_positions = [4, 10, 16, 22] @@ -40,6 +41,16 @@ def exit_program(): os.system('clear') print("Goodbye!") exit() + +def exit_program_early(game, players, homes): + for player in players: + Player.delete(player) + for home in homes: + Game_space.delete(home) + Game.delete(game) + os.system('clear') + print("Goodbye!") + exit() def new_game_setup_menu(): print("New Game Menu:") @@ -66,7 +77,7 @@ def new_game_setup(game): os.system('clear') print("That is not a valid input.") print("Enter the number next to your choice.\n") - time.sleep(2.5) + time.sleep(1) new_game_setup(game) @@ -74,7 +85,7 @@ def player_setup_menu(): print("Players Menu") print("1 Add Player") print("2 See All Players") - print("3 Remove Player") #add home position back into list + print("3 Remove Player") print("4 Edit Player") print("5 Return to Game Setup") print("6 Quit Game") @@ -99,7 +110,7 @@ def player_setup(game): remove_player(game) elif choice == "4": os.system('clear') - edit_player(game) + edit_player_menu(game) elif choice == "5": os.system('clear') new_game_setup(game) @@ -107,7 +118,7 @@ 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(game, players, homes) + exit_program_early(game, players, homes) else: os.system('clear') print("Invalid choice, please select again") @@ -119,7 +130,6 @@ def check_num_players(game): return len(players) def remove_player(game): - os.system('clear') players = print_players(game) print("Enter the number of the player you would like to remove") print("0 - Back to Player Setup") @@ -127,10 +137,11 @@ def remove_player(game): value = int(choice) if choice in ["0","1","2","3","4"] else 10 if value > len(players): os.system('clear') - print("INVALID ENTRY \n") + print("INVALID ENTRY\n") time.sleep(1) remove_player(game) elif value == 0: + os.system('clear') player_setup(game) remove_player_home(game, players[(value - 1)]) print(f"{players[(value - 1)].name}'s home has been deleted") @@ -138,6 +149,7 @@ def remove_player(game): Player.delete(players[(value - 1)]) print("press ENTER to continue") input() + os.system('clear') remove_player(game) def remove_player_home(game, player): @@ -147,12 +159,76 @@ def remove_player_home(game, player): Game_space.delete(game, player) +def edit_player_menu(game): + players = print_players(game) + print("enter the number of the player you would like to EDIT") + 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\n") + time.sleep(1) + edit_player_menu(game) + elif value == 0: + os.system('clear') + player_setup(game) + else: + player = players[(value - 1)] + edit_player(game, player) + +def edit_player(game, player): + os.system('clear') + print(f"Enter {player.name}'s new name") + print("Name must be less than 16 characters") + name = input() + if not 0 < len(name) < 16: + os.system('clear') + print("INVALID ENTRY\n") + edit_player(game, player) + else: + os.system('clear') + player.name = name + + while True: + print(f"{player.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.player_type = "REALTOR" + break + elif value == "2": + player.player_type = "COP" + break + elif value == "3": + player.player_type = "BUILDER" + break + elif value == "4": + player.player_type = "PILOT" + break + else: + os.system('clear') + print("You must choose from the 4 player types\n") + time.sleep(2.5) + player.update() + os.system('clear') + print("Updated Player Info:\n") + print(player) + print(" ") + player_setup(game) def enter_new_player(game): print("Enter Your Player's Name (required)") print("Name must be less than 16 characters") + print("Enter '0' to return to Player Setup") name = input() - if not 0 < len(name) < 16: + if name == "0": + os.system('clear') + player_setup(game) + elif not 0 < len(name) < 16: os.system('clear') print("INVALID ENTRY\n") enter_new_player(game) @@ -166,6 +242,7 @@ def create_player_type(game, name): 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') + print('0 Return to Player Setup') value = input() if value == "1": player_type = "REALTOR" @@ -175,18 +252,23 @@ def create_player_type(game, name): player_type = "BUILDER" elif value == "4": player_type = "PILOT" + elif value == "0": + os.system('clear') + player_setup(game) 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(.5) - position = player_home_position.pop() - os.system('clear') - enter_player_home(position, player, game) + set_player(game, name, player_type) + +def set_player(game, name, player_type): + 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.\n") @@ -248,11 +330,5 @@ def print_players(game): def start_game(game): pass -def exit_program_prestart(game): - pass - -def edit_player(game): - pass - if __name__ == "__main__": main() \ No newline at end of file diff --git a/lib/migrate.py b/lib/migrate.py new file mode 100644 index 0000000..f7b87bc --- /dev/null +++ b/lib/migrate.py @@ -0,0 +1,51 @@ +from models.__init__ import CONN, CURSOR +from models.game import Game +from models.space import Space +from models.player import Player +from models.game_space import Game_space +from sqlite3 import * + +def migrate(): + Game.drop_table() + Space.drop_table() + Game_space.drop_table() + Player.drop_table() + print("Tables have been dropped") + Game_space.create_table() + Game.create_table() + Space.create_table() + Player.create_table() + print("Tables have been created") + +def seed_spaces(): + spaces = [('GO', 0, 0, 1, "Game", 1), + ('unowned', 60, 30, 2, "Pink", 0), + ('unowned', 80, 40, 3, "Pink", 0), + ('unowned', 0, 100, 4, "Player", 0), + ('unowned', 100, 50, 5, "Lt Blue", 0), + ('unowned', 120, 60, 6, "Lt Blue", 0), + ('CASINO', 0, 0, 0, "Game", 1), + ('unowned', 140, 70, 8, "Purple", 0), + ('unowned', 160, 80, 9, "Purple", 0), + ('unowned', 0, 100, 10, "Player", 0), + ('unowned', 180, 90, 11, "Orange", 0), + ('unowned', 200, 100, 12, "Orange", 0), + ("Free Spasce", 0, 0, 13, "Game", 1), + ("unowned", 220, 110, 14, "Red", 0), + ("unowned", 240, 120, 15, "Red", 0), + ("unowned", 0, 100, 16, "Player", 0), + ('unowned', 260, 130, 17, "Yellow", 0), + ("unowned", 280, 140, 18, "Yellow", 0), + ("Pay HOA", 0, 200, 19, "Game", 1), + ("unowned", 300, 150, 20, "Green", 0), + ("unowned", 320, 160, 21, "Green", 0), + ("unowned", 0, 100, 22, "Player", 0), + ("unowned", 360, 130, 23, "Blue", 0), + ("unowned", 400, 200, 24, "Blue", 0)] + for space in spaces: + Space.create(*space) + print("Spaces have successfully seeded") + +if __name__ == "__main__": + migrate() + seed_spaces() \ No newline at end of file diff --git a/lib/models/helper.py b/lib/models/helper.py deleted file mode 100644 index f07f805..0000000 --- a/lib/models/helper.py +++ /dev/null @@ -1,23 +0,0 @@ -# lib/helper.py -import os -import sqlite3 -import random - -# Larger example that inserts many records at a time -#purchases = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00), -# ('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), -# ('2006-04-06', 'SELL', 'IBM', 500, 53.00), -# ] -#cur.executemany('INSERT INTO stocks VALUES (?,?,?,?,?)', purchases) - -# exec(string) will execute the string as regular code, string must be properly formatted -# from random import choice, sample, choices -# names = list[str] = ['a', 'b', 'c', 'd'] - #winner: str = choice(names) - #print(winner) produces random selecton from list - - #winners: list[str] = sample(names, k=(#number of selections from list you want) <-- output unique list - #winners: list[str] = choices(names, k=(#number of selections from list you want) <-- may have repeat selections - -def blank(): - pass \ No newline at end of file diff --git a/lib/models/setup_helper.py b/lib/models/setup_helper.py new file mode 100644 index 0000000..ed17dc3 --- /dev/null +++ b/lib/models/setup_helper.py @@ -0,0 +1,29 @@ +# lib/helper.py +import time +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 +from models.__init__ import CONN, CURSOR + +player_house_positions = [4, 10, 16, 22] +player_home_position = random.sample(player_house_positions, k=4) + +def exit_program(): + os.system('clear') + print("Goodbye!") + exit() + +def exit_program_early(game, players, homes): + for player in players: + Player.delete(player) + for home in homes: + Game_space.delete(home) + Game.delete(game) + os.system('clear') + print("Goodbye!") + exit() + diff --git a/lib/seeds.py b/lib/seeds.py index 84b335b..7554877 100644 --- a/lib/seeds.py +++ b/lib/seeds.py @@ -5,17 +5,8 @@ from models.game_space import Game_space from sqlite3 import * -Game.drop_table() -Space.drop_table() -Game_space.drop_table() -Player.drop_table() -print("Tables have been dropped") -#ipdb.set_trace() -Game_space.create_table() -Game.create_table() -Space.create_table() -Player.create_table() -print("Tables have been created") + + def seed_spaces(): spaces = [('GO', 0, 0, 1, "Game", 1), From 981a2d83aac85e03e5466cc41d45856db70b87ce Mon Sep 17 00:00:00 2001 From: ckjolhede Date: Thu, 20 Jun 2024 08:47:51 -0600 Subject: [PATCH 2/4] cleanup setup --- lib/cli.py | 12 +++--------- lib/models/__init__.py | 2 +- lib/models/setup_helper.py | 20 ++------------------ 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index d693793..69d307d 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -42,11 +42,7 @@ def exit_program(): print("Goodbye!") exit() -def exit_program_early(game, players, homes): - for player in players: - Player.delete(player) - for home in homes: - Game_space.delete(home) +def exit_program_early(game): Game.delete(game) os.system('clear') print("Goodbye!") @@ -72,7 +68,7 @@ def new_game_setup(game): os.system('clear') start_game(game) elif choice == "4": - exit_program() + exit_program_early() else: os.system('clear') print("That is not a valid input.") @@ -115,10 +111,8 @@ def player_setup(game): os.system('clear') new_game_setup(game) elif choice == "6": - players = Player.get_all_players_by_gameid(game.id) - homes = Game_space.get_all_homes_by_gameid(game.id) os.system('clear') - exit_program_early(game, players, homes) + exit_program_early(game) else: os.system('clear') print("Invalid choice, please select again") diff --git a/lib/models/__init__.py b/lib/models/__init__.py index 36cf1be..6f6dfa7 100644 --- a/lib/models/__init__.py +++ b/lib/models/__init__.py @@ -1,4 +1,4 @@ import sqlite3 -CONN = sqlite3.connect('./lib/monopolython.db') +CONN = sqlite3.connect('./monopolython.db') CURSOR = CONN.cursor() diff --git a/lib/models/setup_helper.py b/lib/models/setup_helper.py index ed17dc3..460b29b 100644 --- a/lib/models/setup_helper.py +++ b/lib/models/setup_helper.py @@ -9,21 +9,5 @@ from models.game import Game from models.__init__ import CONN, CURSOR -player_house_positions = [4, 10, 16, 22] -player_home_position = random.sample(player_house_positions, k=4) - -def exit_program(): - os.system('clear') - print("Goodbye!") - exit() - -def exit_program_early(game, players, homes): - for player in players: - Player.delete(player) - for home in homes: - Game_space.delete(home) - Game.delete(game) - os.system('clear') - print("Goodbye!") - exit() - +def base(): + pass From 7a1586f36f3ab8643d651ab9a4858d33fafa24bd Mon Sep 17 00:00:00 2001 From: ckjolhede Date: Thu, 20 Jun 2024 08:53:13 -0600 Subject: [PATCH 3/4] exit fixed --- lib/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index 69d307d..d786676 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -8,7 +8,6 @@ from models.game_space import Game_space from models.game import Game from models.__init__ import CONN, CURSOR -from models.setup_helper import (exit_program, exit_program_early, player_home_position, ) player_house_positions = [4, 10, 16, 22] @@ -43,6 +42,10 @@ def exit_program(): exit() def exit_program_early(game): + players = get_player_list(game) + for player in players: + Game_space.delete(game, player) + Player.delete(player) Game.delete(game) os.system('clear') print("Goodbye!") From 6700cd9ffe90505e60af3f1ab8d6959183ca3332 Mon Sep 17 00:00:00 2001 From: ckjolhede Date: Thu, 20 Jun 2024 09:02:11 -0600 Subject: [PATCH 4/4] finalizing --- lib/cli.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index d786676..322e941 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -71,7 +71,7 @@ def new_game_setup(game): os.system('clear') start_game(game) elif choice == "4": - exit_program_early() + exit_program_early(game) else: os.system('clear') print("That is not a valid input.") @@ -289,18 +289,22 @@ def assign_game_space(game_id, player_id, space_id, street_name, position, price 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() - 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) + while True: + try: + print("enter NET WORTH needed to win") + print("Must be between 5000 and 20000") + win_condition = input() + if not 5000 <= int(win_condition) <= 20000: + os.system('clear') + print("INVALID ENTRY\n") + time.sleep(2.5) + continue + else: + update_game_win_cond(game, win_condition) + new_game_setup(game) + break + except ValueError: + continue def update_game_win_cond(game, win_condition): game.win_condition = int(win_condition)