Skip to content

Commit

Permalink
Merge pull request #1 from CKjolhede/gamesetup
Browse files Browse the repository at this point in the history
game setup and add player
  • Loading branch information
CKjolhede authored Jun 18, 2024
2 parents 69bd04e + 6fadac8 commit 54e3420
Show file tree
Hide file tree
Showing 13 changed files with 1,301 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ name = "pypi"
ipdb = "*"
faker = "*"
pytest = "7.1.3"
rich = "13.7.1"
pick = "2.3.2"

[dev-packages]

Expand Down
131 changes: 116 additions & 15 deletions lib/cli.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,129 @@
# lib/cli.py
from rich import print
from rich import console
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 helpers import (
exit_program,
helper_1
)
player_home_positions = [3, 9, 15, 21]

def main_menu():
print("Please select an option:")
print("1 Start New Game")
print("2 Exit Game")

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

def main():
while True:
menu()
choice = input("> ")
if choice == "0":
main_menu()
choice = input("What would you like to do?\n Enter the number of your choice")
if choice == "1":
new_game_setup()
elif choice == "2":
exit_program()
elif choice == "1":
helper_1()
else:
print("Invalid choice")

if __name__ == "__main__":
main()

def menu():
print("Please select an option:")
print("0. Exit the program")
print("1. Some useful function")

def new_game_setup_menu():
print("New Game Menu:")
print("1 Add / Remove Players")
print("2 Change $ amount to win")
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)
os.system('clear')
new_game_setup_menu()
choice = input()
if choice == "1":
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()
elif choice == "3":
start_game()
elif choice == "4":
exit_program_prestart()
else:
print("That is not a valid input.")
print("Enter the number next to your choice")


def player_setup_menu():
print("Players")
print("1 Add Player")
print("2 See All Players")
print("3 Remove Player")
print("4 Edit Player")
print("5 Return to Game Setup")
print("6 Quit Game")

def player_setup(game):
os.system('clear')
player_setup_menu()
choice = input()
if choice == "1":
enter_new_player(game)

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

print("\n, \n, \n, \n, \n")
print("Enter 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')
print('4 PILOT = The PILOT can roll an unlimited number of doubles')
value = input()
if value == "1":
player_type = "REALTOR"
elif value == "2":
player_type = "COP"
elif value == "3":
player_type = "BUILDER"
elif value == "4":
player_type = "PILOT"
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
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?")
street_name = input()
if len(street_name) == 0:
print("Street cannot be left blank")

Game_space(game.id, player.id, street_name, 0, 100, position, None, 0, False)


if __name__ == "__main__":
main()
def start_game():
pass

def exit_program_prestart():
pass
25 changes: 24 additions & 1 deletion lib/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@

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


ipdb.set_trace()
#ipdb.set_trace()
os.system("echo 'hello world'")
os.system("say -v Zarvox 'hello world'")





#Mac OS X voices for using with the ‘say’ command

#You can pick alternate voice profiles with the -v argument.

#You can also use effects tags:

#Having fun with say command

#[[ slnc 5000 ]] : silence for 5s.
#[[volm 0.9]] changes the volume to the indicated level.
#[[volm +0.1]] increases the volume by the indicated level.
#[[rate 150]] changes the speed
#[[pbas 50]] changes the pitch.
#[[ rset ]] resets all these parameters to default
#'word' :quotes also put the emphasis on the word.
9 changes: 0 additions & 9 deletions lib/helpers.py

This file was deleted.

File renamed without changes.
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('company.db')
CONN = sqlite3.connect('../monopolython.db')
CURSOR = CONN.cursor()
96 changes: 96 additions & 0 deletions lib/models/game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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

class Game(Helper):

@classmethod
def create_table(cls):
""" Create a new table to persist the attributes of Game instances """
try:
with CONN:
CURSOR.execute(
"""CREATE TABLE IF NOT EXISTS games (
win_condition INTEGER,
current_player TEXT,
next_player TEXT);""")
except IntegrityError as e:
return e

@classmethod
def drop_table(cls):
""" Drop the table that persists Game instances """
sql = """
DROP TABLE IF EXISTS games;
"""
CURSOR.execute(sql)
CONN.commit()

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

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

def __repr__(self):
return f"<Game {self.id}: First Net-Worth = {self.win_condition} wins: List of players: {self.players}>"

def save(self):
sql = """
INSERT INTO games (win_condition, curr_player, next_player)
VALUES (?, ?, ?)
"""
CURSOR.execute(sql, (self.win_condition, self.curr_player, self.next_player))
CONN.commit()
self.id = CURSOR.lastrowid

def update(self):
sql = """
UPDATE games
SET win_condition = ?, curr_player = ?, next_player = ?
WHERE id = ?
"""
CURSOR.execute(sql, (self.win_condition, self.curr_player, self.next_player, self.id))
CONN.commit()

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

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

class Game_space:

@classmethod
def create_table(cls):
try:
with CONN:
CURSOR.execute(
"""CREATE TABLE IN NOT EXISTS game_spaces (
id INTEGER PRIMARY KEY,
game_id INTEGER FOREIGN KEY,
player_id INTEGER FOREIGN KEY,
street_name TEXT,
price INTEGER,
rent INTEGER,
position INTEGER,
neighborhood TEXT,
houses INTEGER
monopoly BOOLEAN);""")
except IntegrityError as e:
return e

@classmethod
def drop_table(cls):
sql = """
DROP TABLE IF EXISTS game_spaces;
"""
CURSOR.execute(sql)
CONN.commit()

@classmethod
def create(cls, game_id, player_id, street_name, price, rent, position, neighborhood, houses, monopoly):
game_space = cls(game_id, player_id, street_name, price, rent, position, neighborhood, houses, monopoly)
game_space.save()
return game_space

def __init__(self, game_id, position, id = None):
space = Space.find_by_space_position(position)
self.game_id = game_id
self.player_id = Game.curr_player.id
self.street_name = space.street_name
self.price = space.price
self.rent = space.rent
self.position = position
self.neighborhood = space.neighborhood
self.houses = 0
self.monopoly = False
self.id = id

def __repr__(self):
return f"<{self.street_name}: Price = {self.price}: Rent = {self.rent}: Neighborhood = {self.neighborhood}: Number of Houses = {self.houses}: Owner = {(self.find_owner_by_playerid(self.player_id)).name}>"

def save(self):
sql = """
INSERT INTO game_spaces (game_id, player_id, street_name, price, rent, position, neighborhood, houses, monopoly)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
"""
CURSOR.execute(sql, (self.game_id, self.player_id, self.street_name, self.price, self.rent, self.position, self.neighborhood, self.houses, self.monopoly))
CONN.commit()
self.id = CURSOR.lastrowid

def update(self):
sql = """
UPDATE game_spaces
SET player_id = ?, street_name = ?, rent = ?, houses = ?, monopoly = ?
WHERE id = ?;
"""
CURSOR.execute(sql, (self.player_id, self.street_name, self.rent, self.houses, self.monopoly, self.id))
CONN.commit()

def delete(self):
sql = """ DELETE FROM game_spaces WHERE id = ?;"""
CURSOR.execute(self, (self.id,))
CONN.commit()

Loading

0 comments on commit 54e3420

Please sign in to comment.