Skip to content

Commit

Permalink
Merge pull request #2 from CKjolhede/gamesetup
Browse files Browse the repository at this point in the history
debugging cli setup
  • Loading branch information
CKjolhede authored Jun 18, 2024
2 parents 54e3420 + 6b7d303 commit 74835cd
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 105 deletions.
80 changes: 54 additions & 26 deletions lib/cli.py
Original file line number Diff line number Diff line change
@@ -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:")
Expand All @@ -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:")
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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):
Expand All @@ -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
def remove_player(game):
pass

def edit_player(game):
pass

if __name__ == "__main__":
main()
53 changes: 21 additions & 32 deletions lib/models/game.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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 """
Expand Down Expand Up @@ -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
#@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
9 changes: 3 additions & 6 deletions lib/models/game_space.py
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
23 changes: 7 additions & 16 deletions lib/models/helper.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
# lib/helper.py
import os
from game import Game


class Helper():





def start_game():
pass



import sqlite3
import random



Expand All @@ -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

class Helper():

def blank():
pass
47 changes: 30 additions & 17 deletions lib/models/player.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
#@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
12 changes: 4 additions & 8 deletions lib/models/space.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 74835cd

Please sign in to comment.