diff --git a/lib/cli.py b/lib/cli.py index 65a32f5..8a0cce7 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1,15 +1,19 @@ # lib/cli.py -from rich import print -from rich import console +import sqlite3 +import rich +import pick import os import random -import time from models.player import Player from models.game_space import Game_space from models.game import Game from models.helper import Helper +from models.__init__ import CONN, CURSOR + +player_house_positions = [3, 9, 15, 21] +player_home_position = random.sample(player_house_positions, k=4) + -player_home_positions = [3, 9, 15, 21] def main_menu(): print("Please select an option:") @@ -25,15 +29,13 @@ def main(): main_menu() choice = input("What would you like to do?\n Enter the number of your choice") if choice == "1": - new_game_setup() + game = Game.create() + new_game_setup(game) elif choice == "2": exit_program() else: print("Invalid choice") -if __name__ == "__main__": - main() - def new_game_setup_menu(): print("New Game Menu:") @@ -42,10 +44,7 @@ def new_game_setup_menu(): print("3 Start Game") print("4 Quit Game") -def new_game_setup(): - game = Game.create() - player_house_positions = [3, 9, 15, 21] - player_home_position = random.sample(player_house_positions, k=4) +def new_game_setup(game): os.system('clear') new_game_setup_menu() choice = input() @@ -57,9 +56,9 @@ def new_game_setup(): game.win_condition == input(10000) game.update() elif choice == "3": - start_game() + start_game(game) elif choice == "4": - exit_program_prestart() + exit_program_prestart(game) else: print("That is not a valid input.") print("Enter the number next to your choice") @@ -77,18 +76,32 @@ def player_setup_menu(): def player_setup(game): os.system('clear') player_setup_menu() + print("What would you like to do?") choice = input() if choice == "1": enter_new_player(game) + elif choice == "2": + get_all_players_by_game(game) + elif choice == "3": + remove_player(game) + elif choice == "4": + edit_player(game) + elif choice == "5": + new_game_setup(game) + else: + print("Invalid choice, please select again") def enter_new_player(game): - while 0 < len(name) < 16: - print("Enter Your Player's Name (required)") - print("Name must be less than 16 characters") - name = input() - name = name.upper - if 0 < len(name) < 16: - print("Name is invalid") + os.system('clear') + print("Enter Your Player's Name (required)") + print("Name must be less than 16 characters") + value = input() + name = value + #print(f'my name is {name}') + if not 0 < len(name) < 16: + print("Name is invalid") + else: + print("\n, \n, \n, \n, \n") print("Enter which type of player you would like to be") @@ -108,7 +121,7 @@ def enter_new_player(game): else: print("You must choose from the 4 player types") player = Player.create(name, player_type, 0, 1800, 1800, game.id) - position = player_home_positions.pop + position = player_home_position.pop enter_player_home(position, player, game) def enter_player_home(position, player, game): @@ -120,10 +133,25 @@ def enter_player_home(position, player, game): print("Street cannot be left blank") Game_space(game.id, player.id, street_name, 0, 100, position, None, 0, False) - + player_setup(game) + -def start_game(): + + +def get_all_players_by_game(cls, game): + sql = """ SELECT * FROM players WHERE game_id = game.id """ + +def start_game(game): + pass + +def exit_program_prestart(game): pass -def exit_program_prestart(): - pass \ No newline at end of file +def remove_player(game): + pass + +def edit_player(game): + pass + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/lib/models/game.py b/lib/models/game.py index abbad59..fe5985a 100644 --- a/lib/models/game.py +++ b/lib/models/game.py @@ -1,11 +1,9 @@ -from __init__ import CURSOR, CONN -from sqlite3 import IntegrityError -from helper import Helper -from game_space import Game_space -from player import Player -from space import Space +import sqlite3 +from sqlite3 import * +from models.helper import Helper +from models.__init__ import CONN, CURSOR -class Game(Helper): +class Game(): @classmethod def create_table(cls): @@ -15,11 +13,13 @@ def create_table(cls): CURSOR.execute( """CREATE TABLE IF NOT EXISTS games ( win_condition INTEGER, - current_player TEXT, + curr_player TEXT, next_player TEXT);""") except IntegrityError as e: return e + + @classmethod def drop_table(cls): """ Drop the table that persists Game instances """ @@ -68,29 +68,18 @@ def delete(self): sql = """ DELETE FROM games WHERE id = ? """ CURSOR.execute(sql, (self.id,)) CONN.commit() - - @property - def win_condition(self): - return self._win_condtion - - @win_condition.setter - def win_condition(self, win_condition): - if not isinstance(win_condition, int): - raise TypeError("Win Condition must be an integer") - elif 5000 < self.win_condition < 20000: - raise ValueError("Dollar amount must be between 5000 and 20000") - else: - self._win_condition = win_condition - @property - def id(self): - return self._id +Game.drop_table() +Game.create_table() +#@property + #def win_condition(self): + # return self._win_condtion - @id.setter - def id(self, id): - if hasattr(self, "id"): - raise AttributeError("Cannot change player id") - elif not isinstance(id, int): - raise TypeError("Id must be an integer") - else: - self._id = id \ No newline at end of file + #@win_condition.setter + #def win_condition(self, win_condition): + # if not isinstance(win_condition, int): + # raise TypeError("Win Condition must be an integer") + # elif 5000 < self.win_condition < 20000: + # raise ValueError("Dollar amount must be between 5000 and 20000") + # else: + # self._win_condition = win_condition \ No newline at end of file diff --git a/lib/models/game_space.py b/lib/models/game_space.py index 32b9470..9fe2bb7 100644 --- a/lib/models/game_space.py +++ b/lib/models/game_space.py @@ -1,9 +1,6 @@ -from __init__ import CURSOR, CONN -from sqlite3 import IntegrityError -from space import Space -from game import Game -from player import Player -from helper import Helper +import sqlite3 +from sqlite3 import * +from models.__init__ import CONN, CURSOR class Game_space: diff --git a/lib/models/helper.py b/lib/models/helper.py index 43c1a2e..8b6f908 100644 --- a/lib/models/helper.py +++ b/lib/models/helper.py @@ -1,19 +1,7 @@ # lib/helper.py import os -from game import Game - - -class Helper(): - - - - - - def start_game(): - pass - - - +import sqlite3 +import random @@ -32,5 +20,8 @@ def start_game(): #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 - -from random import randint as ri \ No newline at end of file + +class Helper(): + + def blank(): + pass \ No newline at end of file diff --git a/lib/models/player.py b/lib/models/player.py index 3dc3d5f..bddcc07 100644 --- a/lib/models/player.py +++ b/lib/models/player.py @@ -1,11 +1,8 @@ -from __init__ import CURSOR, CONN +import sqlite3 from sqlite3 import IntegrityError -from helper import Helper -from game import Game -from game_space import Game_space -from space import Space +from models.__init__ import CONN, CURSOR -class Player(Helper): +class Player(): @classmethod def create_table(cls): @@ -36,6 +33,22 @@ def create(cls, name, player_type, curr_pos = 0, money = 1800, net_worth = 1800, 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]) + + @classmethod + def get_all_players(cls): + pass + def __init__(self, name, player_type, curr_pos = 0, money = 1800, net_worth = 1800, game_id = None, id = None): self.name = name @@ -74,15 +87,15 @@ def delete(self): - @property - def name(self): - return self._name + #@property + #def name(self): + # return self._name - @name.setter - def name(self, name): - if not isinstance(name, int): - raise TypeError("Player name must be a string") - elif 0 < len(name) < 16: - raise ValueError("Player name must be less than 16 characters") - else: - self._name = name \ No newline at end of file + #@name.setter + #def name(self, name): + # if not isinstance(name, str): + # raise TypeError("Player name must be a string") + # elif 0 < len(name) < 16: + # raise ValueError("Player name must be less than 16 characters") + # else: + # self._name = name \ No newline at end of file diff --git a/lib/models/space.py b/lib/models/space.py index 0f156dc..ac0c373 100644 --- a/lib/models/space.py +++ b/lib/models/space.py @@ -1,14 +1,10 @@ -from __init__ import CURSOR, CONN import sqlite3 -from sqlite3 import IntegrityError -from helper import Helper -from game_space import Game_space -from player import Player -CONN = sqlite3.connect('resources.db') -CURSOR = CONN.execute() +from models.helper import Helper +from models.__init__ import CONN, CURSOR -class Space(Helper): + +class Space(): @classmethod def create_table(cls):