Skip to content

Commit

Permalink
Merge pull request #3 from CKjolhede/spaceclass
Browse files Browse the repository at this point in the history
added space seeds, add player, home, wincond working
  • Loading branch information
CKjolhede authored Jun 19, 2024
2 parents 74835cd + 86d18ff commit 46f8f22
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 300 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ faker = "*"
pytest = "7.1.3"
rich = "13.7.1"
pick = "2.3.2"
sqlite3 = "*"

[dev-packages]

Expand Down
162 changes: 117 additions & 45 deletions lib/cli.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
# lib/cli.py
import sqlite3
import rich
import pick
import time
from sqlite3 import *
import os
import random
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_house_positions = [4, 10, 16, 22]
player_home_position = random.sample(player_house_positions, k=4)
os.system('clear')
def main_menu():
print("WELCOME TO MONOPOLYTHON!")
print("Please select an option:")
print("1 Start New Game")
print("2 Exit Game")

def exit_program():
print("Goodbye!")
exit()

def main():
while True:
main_menu()
choice = input("What would you like to do?\n Enter the number of your choice")
print("Enter the number of your choice:")
choice = input("")
if choice == "1":
game = Game.create()
os.system('clear')
new_game_setup(game)
elif choice == "2":
exit_program()
else:
print("Invalid choice")
os.system('clear')
print("Invalid choice\n")
time.sleep(2.5)
main()

def exit_program():
os.system('clear')
print("Goodbye!")
exit()

def new_game_setup_menu():
print("New Game Menu:")
Expand All @@ -45,66 +49,108 @@ def new_game_setup_menu():
print("4 Quit Game")

def new_game_setup(game):
os.system('clear')
new_game_setup_menu()
choice = input()
if choice == "1":
os.system('clear')
player_setup(game)
elif choice == "2":
print("Enter net worth needed to win")
print("Must be between 5000 and 20000")
game.win_condition == input(10000)
game.update()
os.system('clear')
set_win_condition(game)
elif choice == "3":
os.system('clear')
start_game(game)
elif choice == "4":
exit_program_prestart(game)
exit_program()
else:
os.system('clear')
print("That is not a valid input.")
print("Enter the number next to your choice")
print("Enter the number next to your choice.\n")
time.sleep(2.5)
new_game_setup(game)


def player_setup_menu():
print("Players")
print("1 Add Player")
print("2 See All Players")
print("3 Remove Player")
print("3 Remove Player") #add home position back into list
print("4 Edit Player")
print("5 Return to Game Setup")
print("6 Quit Game")

def player_setup(game):
os.system('clear')
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)
elif choice == "2":
get_all_players_by_game(game)
os.system('clear')
ipdb.set_trace()
for player in players:
print(player.name)
player_setup(game)
elif choice == "3":
remove_player(game)
os.system('clear')
remove_player(game, players)
player_setup(game)
elif choice == "4":
os.system('clear')
edit_player(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_prestart(game, players, homes)
else:
os.system('clear')
print("Invalid choice, please select again")
time.sleep(2.5)
player_setup(game)

def enter_new_player(game):
def remove_player(game, players):
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):
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')


def remove_player_home(player, game):
home = Game_space.get_game_space_by_playerid_gameid(game, player)
Game_space.delete(home)



def enter_new_player(game):
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}')
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("\n, \n, \n, \n, \n")
print("Enter which type of player you would like to be")
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')
Expand All @@ -119,37 +165,63 @@ def enter_new_player(game):
elif value == "4":
player_type = "PILOT"
else:
print("You must choose from the 4 player types")
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)
position = player_home_position.pop
print(f"Good Luck {player.name}!")
time.sleep(2)
position = player_home_position.pop()
os.system('clear')
enter_player_home(position, player, game)

def enter_player_home(position, player, game):
print("\n, \n, \n, \n, \n")
print("Each player begins with a home property")
print("What is your home's street name?")
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")

Game_space(game.id, player.id, street_name, 0, 100, position, None, 0, False)
player_setup(game)
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)

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 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)

def update_game_win_cond(game, win_condition):
game.win_condition = int(win_condition)
game.update()
print(f'Get to ${win_condition} net worth and you will win!')
time.sleep(2.5)
os.system('clear')
new_game_setup(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 remove_player(game):
pass

def edit_player(game):
pass

Expand Down
1 change: 0 additions & 1 deletion lib/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# lib/debug.py

from models.__init__ import CONN, CURSOR
import ipdb
import os


Expand Down
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('../monopolython.db')
CONN = sqlite3.connect('./monopolython.db')
CURSOR = CONN.cursor()
39 changes: 14 additions & 25 deletions lib/models/game.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sqlite3

from sqlite3 import *
from models.helper import Helper
from models.__init__ import CONN, CURSOR

class Game():
Expand All @@ -12,14 +11,13 @@ def create_table(cls):
with CONN:
CURSOR.execute(
"""CREATE TABLE IF NOT EXISTS games (
id INTEGER PRIMARY KEY,
win_condition INTEGER,
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 All @@ -30,18 +28,18 @@ def drop_table(cls):
CONN.commit()

@classmethod
def create(cls, win_condition = 10000):
def create(cls, win_condition = 10000, curr_player = None, next_player = None):
""" Initialize a new Game instance and save the object to the database """
game = cls(win_condition)
game = cls()
game.save()
return game

def __init__(self, win_condition, id = None):
def __init__(self, win_condition = 10000, curr_player = None, next_player = None, id = None):
self.win_condition = win_condition
self.players = []
self.curr_player = ""
self.next_player = ""
self.curr_player = curr_player
self.next_player = next_player
self.id = id
self.players = []

def __repr__(self):
return f"<Game {self.id}: First Net-Worth = {self.win_condition} wins: List of players: {self.players}>"
Expand All @@ -59,7 +57,7 @@ def update(self):
sql = """
UPDATE games
SET win_condition = ?, curr_player = ?, next_player = ?
WHERE id = ?
WHERE id = ?;
"""
CURSOR.execute(sql, (self.win_condition, self.curr_player, self.next_player, self.id))
CONN.commit()
Expand All @@ -68,18 +66,9 @@ def delete(self):
sql = """ DELETE FROM games WHERE id = ? """
CURSOR.execute(sql, (self.id,))
CONN.commit()



Game.drop_table()
Game.create_table()
#@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



Loading

0 comments on commit 46f8f22

Please sign in to comment.