Oct-05-2018, 10:41 PM
So I was tasked to create a Card Comparison Game, named 'Celebrity Dogs' (Funny name right?), I've so far used my basic knowledge on Python, I'm not very good at it yet but getting there. I wanna know if there's any way to improve it.
Here's is what in the dogs.txt file:
Annie the Afgan Hound,
Bertie the Boxer,
Betty the Borzoi,
Charlie the Chihuahua,
Chaz the Cocker Spaniel,
Donald the Dalmatian,
Dottie the Doberman,
Fern the Fox Terrier,
Frank the French Bulldog,
George the Great Dane,
Gertie the Greyhound,
Harry the Harrier,
Ian the Irish Wolfhound,
Juno the Jack Russell,
Keith the Kerry Blue,
Larry the Labrador,
Marge the Maltese,
Max the Mutt,
Nutty the Newfoundland,
Olive the Old English Sheepdog,
Peter the Pug,
Poppy the Pekingese,
Rosie the Rottweiler,
Ruby the Retriever,
Sam the Springer Spaniel,
Sukie the Saluki,
Vernon the Vizsla,
Whilma the West Highland Terrier,
William the Whippet,
Yolande the Yorkshire Terrier,
Here's is what in the dogs.txt file:
Annie the Afgan Hound,
Bertie the Boxer,
Betty the Borzoi,
Charlie the Chihuahua,
Chaz the Cocker Spaniel,
Donald the Dalmatian,
Dottie the Doberman,
Fern the Fox Terrier,
Frank the French Bulldog,
George the Great Dane,
Gertie the Greyhound,
Harry the Harrier,
Ian the Irish Wolfhound,
Juno the Jack Russell,
Keith the Kerry Blue,
Larry the Labrador,
Marge the Maltese,
Max the Mutt,
Nutty the Newfoundland,
Olive the Old English Sheepdog,
Peter the Pug,
Poppy the Pekingese,
Rosie the Rottweiler,
Ruby the Retriever,
Sam the Springer Spaniel,
Sukie the Saluki,
Vernon the Vizsla,
Whilma the West Highland Terrier,
William the Whippet,
Yolande the Yorkshire Terrier,
#Celebrity Dog Games """ The progam is a similar to the card game 'Trump Card' Where the players compare cards to see which chosen value is higher than their opponents. The aim of the program is to allow the user to play the game agaisnt the computer and that the cards generated are placed into arrays and hopefully have it choose a random name that hasn't been used. """ import random #Allows the use to randomly choose. menu = "Welcome to Celebrity Dog Game!\n\ Please Select an Option:\n\ 1 - Begin Game\n\ 2 - Quit\n\ Option: " categorychoice = "Please select a category you wish to compare.\n\ 1 - Excerise\n\ 2 - Friendliness\n\ 3 - Intelligence\n\ 4 - Drool" x=0 a=0 playerspile = 0 computerpile = 0 cardchoice = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30] multiple2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30] def menu(): #Defines the Menu while a == 0: option = int(input(menu)) #Gives the user the option to leave or quit the game if option == 2: print("Goodbye, please come again!") raise SystemExit elif option == 1: cardselection() def cardselection(): while x == 0: print("Please select a number between 4 and 30 and a multiple of two.") pilenumber=int(input("Number of cards: ")) #Ask the users to imput their wanted Pile Size if (pilenumber < 4 and pilenumber >= 30): print("Please select a number between 4 to 30.") #Tells the user that the number is not between 4 and 30. elif pilenumber not in multiple2: print("Please select a number which is a multiple of two.") #Tells the user that the number is not a multiple of two. elif pilenumber not in cardchoice: print("Please select a valid number") #Tells the user that the input is not a number else: x = 1 cardgeneration() def cardgeneration(): with open('dogs.txt') as cards: #Opens the file and saves it as variable cards cards = f.read().splitlines() #Reads the text file and seperates them cards = [line.split(",") for line in cards #This splits the list into arrays #Anything between this message to the next message generates the value for both the player's and the computer's first and other cards middle = pilenumber / 2 playerdeck =[0,middle-1] computerdeck = [middle,pilenumber] plength = len(playerdeck) clength = len(computerdeck) #Here should be a line of code to select a name from the created array. p_excercise = random.randint(1,5) p_intelligence = random.randint(1,100) p_friendliness = random.randint(1,10) p_drool = random.randint(1,10) c_excercise = random.randint(1,5) c_intelligence = random.randint(1,100) c_friendliness = random.randint(1,10) c_drool = random.randint(1,10) #Anything between this message to the previous message generates the value for the cards. gamestart() def gamestart(): #Beyond this point is where the game begins. while y == 0: print("You have: ", plength, "Cards") #Prints out the player's card print("The Computer have: ",clength, " Cards")#Prints out the computer's deck size print("Your dog name is: " + dogname + " Excercise: " + p_excercise + " Friendliness:" + p_friendliness + "Intelligence: " + p_intelligence + " Drool:" + p_drool)#Prints out the player's first card print("Please know that the value of these cards are auto generated.") print("categorychoice") category = int(input("Please Select an Option: ")) #Tells the user to select a category from the list #Beneath this code is where the Chosen Category is being compared with the computer's card. if category == 1: print("You've chosen to compare your Excerise.") if c_excercise > p_excercise: print("Computer wins!") playerdeck = playerdeck - 1 computerdeck = computerdeck + 1 cardgeneration() elif c_excercise <= p_excercise: print("Player wins!") playerdeck = playerdeck + 1 computerdeck = computerdeck - 1 cardgeneration() elif category == 2: print("You've chosen to compare your Friendliness.") if c_friendliness > p_friendliness: print("Computer wins!") playerdeck = playerdeck - 1 computerdeck = computerdeck + 1 cardgeneration() elif c_friendliness <= p_friendliness: print("Player wins!") playerdeck = playerdeck + 1 computerdeck = computerdeck - 1 cardgeneration() elif category == 3: print("You've chosen to compare your Intelligence.") if c_intelligence > p_intelligence: print("Computer wins!") playerdeck = playerdeck - 1 computerdeck = computerdeck + 1 cardgeneration() elif c_intelligence <= p_intelligence: print("Player wins!") playerdeck = playerdeck + 1 computerdeck = computerdeck - 1 cardgeneration() elif category == 4: print("You've chosen to compare your Drool.") if c_drool > p_drool: print("Player wins!") playerdeck = playerdeck + 1 computerdeck = computerdeck - 1 cardgeneration() elif c_drool <= p_drool: print("Computer wins!") playerdeck = playerdeck - 1 computerdeck = computerdeck + 1 cardgeneration() if playerdeck == pilenumber: print("Player wins the game!") y = 1 leave() elif computerdeck == pilenumber: print("Computer wins the game!") y = 1 leave() def leave(): #The player is given the option if they wish to play again or end the code by changing the 'a' variable to 1 leave = input(("Would you like to play again or leave the game?")) if (leave == Y or leave == Y): print("Please come again!") raise SystemExit #Stops the whole code elif (leave == N or leave == n): print("Returning to main menu.") menu() #Returns to the main menu