Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ordering pizza python project #533

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions connectfour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
import random

board = [["-"] * 6, ["-"] * 6, ["-"] * 6, ["-"] * 6, ["-"] * 6, ["-"] * 6, ["-"] * 6]


def gamePlayTwoPlayers(p1, p2):
win = ""
while win == "":
column = int(input("{}'s turn. Enter which column you would like to drop your piece into: ".format(p1)))
connectFourBoard(column, "X")

if check_vertical_win(p1, p2, column):
print()
print(check_vertical_win(p1, p2, column))
break
if check_horizontal_win(p1, p2):
print()
print(check_horizontal_win(p1, p2))
break
if check_positive_diagonal_win(p1, p2):
print()
print(check_positive_diagonal_win(p1, p2))
break
if check_negative_diagonal_win(p1, p2):
print()
print(check_negative_diagonal_win(p1, p2))
break

column = int(input("{}'s turn. Enter which column you would like to drop your piece into: ".format(p2)))
connectFourBoard(column, "O")

if check_vertical_win(p1, p2, column):
print()
print(check_vertical_win(p1, p2, column))
break
if check_horizontal_win(p1, p2):
print()
print(check_horizontal_win("x", "O"))
break
if check_positive_diagonal_win(p1, p2):
print()
print(check_positive_diagonal_win(p1, p2))
break
if check_negative_diagonal_win(p1, p2):
print()
print(check_negative_diagonal_win(p1, p2))
break


def gamePlayOnePlayer(p1, p2):
win = ""
while win == "":
column = int(input("{}'s turn. Enter which column you would like to drop your piece into: ".format(p1)))
connectFourBoard(column, "X")

if check_vertical_win(p1, p2, column):
print()
print(check_vertical_win(p1, p2, column))
break
if check_horizontal_win(p1, p2):
print()
print(check_horizontal_win(p1, p2))
break
if check_positive_diagonal_win(p1, p2):
print()
print(check_positive_diagonal_win(p1, p2))
break
if check_negative_diagonal_win(p1, p2):
print()
print(check_negative_diagonal_win(p1, p2))
break

print()

column = random.randint(1, 7)
connectFourBoard(column, "O")

if check_vertical_win(p1, p2, column):
print()
print(check_vertical_win(p1, p2, column))
break
if check_horizontal_win(p1, p2):
print()
print(check_horizontal_win(p1, p2))
break
if check_positive_diagonal_win(p1, p2):
print()
print(check_positive_diagonal_win(p1, p2))
break
if check_negative_diagonal_win(p1, p2):
print()
print(check_negative_diagonal_win(p1, p2))
break


def connectFourBoard(col, playerIcon):
col -= 1
coordinate = []

for row in range(len(board[col])-1, -1, -1):
if board[col][row] == "-":
board[col][row] = playerIcon
coordinate.append([row, col])
break
for row in range(len(board)):
for col in range(len(board[row])):
print("|", board[row][col], "|", board[row+1][col], "|", board[row+2][col], "|", board[row+3][col], "|",
board[row+4][col], "|", board[row+5][col], "|", board[row+6][col], "|")
break


def check_vertical_win(p1, p2, col):
playerCount1 = 0
playerCount2 = 0
col -= 1

for row in range(len(board[col])-1, -1, -1):
if board[col][row] == "X":
playerCount1 += 1
playerCount2 = 0
elif board[col][row] == "O":
playerCount2 += 1
playerCount1 = 0

if playerCount1 == 4:
return "{} Wins".format(p1)
elif playerCount2 == 4:
return "{} Wins".format(p2)


def check_horizontal_win(p1, p2):
for row in range(len(board[0])-1, -1, -1):
playerCount1 = 0
playerCount2 = 0
for col in range(len(board)):
if board[col][row] == "X":
playerCount1 += 1
playerCount2 = 0
elif board[col][row] == "O":
playerCount2 += 1
playerCount1 = 0
elif board[col][row] == "-":
playerCount1 = 0
playerCount2 = 0

if playerCount1 == 4:
return "{} Wins".format(p1)
elif playerCount2 == 4:
return "{} Wins".format(p2)


def check_positive_diagonal_win(p1, p2):
playerCount1 = 0
playerCount2 = 0

for row in range(len(board[0])-1, -1, -1):
for col in range(len(board)-3):
if board[col][row] == "X":
playerCount1 += 1
while playerCount1 < 4:
col += 1
row -= 1
if board[col][row] == "X":
playerCount1 += 1
else:
playerCount1 = 0
break
elif board[col][row] == "O":
playerCount1 += 1
while playerCount1 < 4:
col += 1
row -= 1
if board[col][row] == "O":
playerCount1 += 1
else:
playerCount1 = 0
break

if playerCount1 == 4:
return "{} Wins".format(p1)
elif playerCount2 == 4:
return "{} Wins".format(p2)
else:
playerCount1 = 0
playerCount2 = 0


def check_negative_diagonal_win(p1, p2):
playerCount1 = 0
playerCount2 = 0

for row in range(len(board[0])-3):
for col in range(len(board)-3):
if board[col][row] == "X":
playerCount1 += 1
while playerCount1 < 4:
col += 1
row -= 1
if board[col][row] == "X":
playerCount1 += 1
else:
playerCount1 = 0
break
elif board[col][row] == "O":
playerCount1 += 1
while playerCount1 < 4:
col += 1
row += 1
if board[col][row] == "O":
playerCount1 += 1
else:
playerCount1 = 0
break

if playerCount1 == 4:
return "{} Wins".format(p1)
elif playerCount2 == 4:
return "{} Wins".format(p2)
else:
playerCount1 = 0
playerCount2 = 0


def main():
print("Welcome to Connect Four! Connect 4 of your pieces in either horizontal, vertical, or diagonal to win.")

numPlayers = int(input("Choose how many players: "))

while numPlayers not in [1,2]:
numPlayers = int(input("Sorry for the value you entered was invalid. Are you playing with 1 or 2 players: "))

if numPlayers == 1:
player1 = input("Player 1, please enter your name: ")
player2 = "CPU"
gamePlayTwoPlayers(player1, player2)
elif numPlayers == 2:
player1 = input("Player 1, please enter your name: ")
player2 = input("Player 2, please enter your name: ")
gamePlayTwoPlayers(player1, player2)


main()
80 changes: 80 additions & 0 deletions pizzaOrder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# purpose of order.py is the front end for users to submit their order
from pizzaReceipt import * # asks to import all functions found in the pizzaReceipt.py file

# set all initial variables before beginning
size = ""
pizza_lst = []
pizza_lst_current = []
toppings_lst = [] # list to be a parameter for generateReceipt function
list_order_yes = ["Yes", "yes", "Y", "y", "YES"]
list_order_no = ["No", "no", "Q", "NO", "N", "n"]
TOPPINGS = ("ONION", "TOMATO", "GREEN PEPPER", "MUSHROOM", "OLIVE", "SPINACH", "BROCCOLI", "PINEAPPLE",
"HOT PEPPER", "PEPPERONI", "HAM", "BACON", "GROUND BEEF", "CHICKEN", "SAUSAGE")

# ask user whether they want to order.
order = input("Do you want to order a pizza? ")

# case for when an invalid input is submitted
while (order not in list_order_yes) and (order not in list_order_no):
order = input("Do you want to order a pizza? ")

# ask for size
if order in list_order_yes:
size = input("Choose a size: ")
size.upper()

# case for when a user inputs invalid size
while size.upper() not in ["S", "M", "L", "XL"]:
size = input("Choose a size: ")

# entire loop to repeat if user wants to order more than one pizza
while order in list_order_yes:
# set empty toppings list as it will show empty each time loop is made
toppings_lst = []
# ask user for topping, whether they want to see a list of the toppings, or to finish ordering toppings.
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
'When you are done adding toppings, enter "X" ')

# cae for when a user places an invalid input for this question
while (topping.upper() != "X") and (topping.upper() != "LIST") and (topping.upper() not in TOPPINGS):
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
'When you are done adding toppings, enter "X" ')

print()
# toppings while loop which ask for toppings selection or list view, multiple times until user enters X
while topping.upper() != "X":
TOPPINGS = ("ONION", "TOMATO", "GREEN PEPPER", "MUSHROOM", "OLIVE", "SPINACH", "BROCCOLI", "PINEAPPLE",
"HOT PEPPER", "PEPPERONI", "HAM", "BACON", "GROUND BEEF", "CHICKEN", "SAUSAGE")
if topping.upper() == "LIST":
print(topping.upper())
print(TOPPINGS)
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
'When you are done adding toppings, enter "X" \n \n')
elif topping.upper() in TOPPINGS:
print(topping.upper())
print("Added", topping.upper(), "to your pizza")
toppings_lst.append(topping)
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
'When you are done adding toppings, enter "X" \n \n')

# add the size and toppings list as a tuple to pizza_lst
pizza_lst.append((size.upper(), toppings_lst))
print(pizza_lst)
# ask whether they want to continue ordering
order = input("Do you want to continue ordering? ")

# case for when user types invalid input
while (order not in list_order_yes) and (order not in list_order_no):
order = input("Do you want to order a pizza? ")

# if they say no, break the loop and go through the last line of the code
if order in list_order_no:
break
elif order in list_order_yes:
size = input("Choose a size: ") # if they want to order again start by asking size

# case for when user types invalid input
while size.upper() not in ["S", "M", "L", "XL"]:
size = input("Choose a size: ")

generateReceipt(pizza_lst) # at the end of program, call function using pizza_lst as a parameter
Loading
Oops, something went wrong.