Skip to content

Commit

Permalink
Merge pull request #5 from CKjolhede/finalizesetup
Browse files Browse the repository at this point in the history
Finalizesetup
  • Loading branch information
CKjolhede authored Jun 20, 2024
2 parents e902b14 + 6700cd9 commit b503644
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 70 deletions.
147 changes: 112 additions & 35 deletions lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def exit_program():
os.system('clear')
print("Goodbye!")
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!")
exit()

def new_game_setup_menu():
print("New Game Menu:")
Expand All @@ -61,20 +71,20 @@ def new_game_setup(game):
os.system('clear')
start_game(game)
elif choice == "4":
exit_program()
exit_program_early(game)
else:
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)


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")
Expand All @@ -99,15 +109,13 @@ 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)
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(game, players, homes)
exit_program_early(game)
else:
os.system('clear')
print("Invalid choice, please select again")
Expand All @@ -119,25 +127,26 @@ 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")
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")
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")
print(f'{players[(value -1)].name} has been deleted')
Player.delete(players[(value - 1)])
print("press ENTER to continue")
input()
os.system('clear')
remove_player(game)

def remove_player_home(game, player):
Expand All @@ -147,12 +156,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)
Expand All @@ -166,6 +239,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"
Expand All @@ -175,18 +249,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")
Expand All @@ -210,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)
Expand All @@ -248,11 +331,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()
51 changes: 51 additions & 0 deletions lib/migrate.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion lib/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sqlite3

CONN = sqlite3.connect('./lib/monopolython.db')
CONN = sqlite3.connect('./monopolython.db')
CURSOR = CONN.cursor()
23 changes: 0 additions & 23 deletions lib/models/helper.py

This file was deleted.

13 changes: 13 additions & 0 deletions lib/models/setup_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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

def base():
pass
13 changes: 2 additions & 11 deletions lib/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b503644

Please sign in to comment.