Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- import time
- import random
- with sqlite3.connect("dice.db") as db:
- cursor = db.cursor()
- cursor.execute('''
- CREATE TABLE IF NOT EXISTS user(
- userID INTEGER PRIMARY KEY,
- username VARCHAR(20) NOT NULL,
- firstname VARCHAR(20) NOT NULL,
- surname VARCHAR(20) NOT NULL,
- password VARCHAR(20) NOT NULL);
- ''')
- cursor.execute("""
- INSERT INTO user(username,firstname,surname,password)
- VALUES("test","test","big","test")
- """)
- db.commit()
- import random
- def gameactual():
- game1 = 0
- finalscoreone = 0
- print("###RULES### \nIf the total score adds up to an even number, an additional 10 points are added to your score \nIf the total score adds up to an odd number, 5 points is subtracted form your score \nIf you roll a double, you get to roll one extra dice and get the number of points rolled added to your score\n")
- while game1 < 5:
- ask = input("Would you like to roll the dice player 1 (y) ")
- if ask == "y":
- dice1 = random.randint(1,6)
- dice11 = random.randint(1,6)
- score1 = dice1 + dice11
- if score1 % 2 == 0:
- finalscoreone = finalscoreone + 10
- else:
- finalscoreone = finalscoreone - 5
- if finalscoreone < 0:
- finalscoreone = 0
- finalscoreone = finalscoreone + score1
- print("You rolled",dice1,dice11,"// PLAYER 1 SCORE:", finalscoreone)
- if dice1 == dice11:
- dicedoubleplayer11 = random.randint(1,6)
- dicedoubleplayer1 = random.randint(1,6)
- askdouble = input(" ### You rolled a double would you like to roll again? ### (roll) ")
- if askdouble == "roll":
- score1 = score1 + dicedoubleplayer1 + dicedoubleplayer11
- finalscoreone = finalscoreone + score1
- print("You rolled ",dicedoubleplayer1,dicedoubleplayer11,"// PLAYER 1 SCORE:", finalscoreone)
- game1 = game1 + 1
- game2 = 0
- finalscoretwo = 0
- while game2 < 5:
- ask2 = input("Would you like to roll the dice player 2 (y) ")
- if ask2 == "y":
- dice2 = random.randint(1,6)
- dice22 = random.randint(1,6)
- score2 = dice2 + dice22
- if score2 % 2 == 0:
- finalscoretwo = finalscoretwo + 10
- else:
- finalscoretwo = finalscoretwo - 5
- finalscoretwo = finalscoretwo + score2
- if finalscoretwo < 0:
- finalscoretwo = 0
- print("You rolled ",dice1,dice22,"// PLAYER 2 SCORE:", finalscoretwo)
- if dice2 == dice22:
- dicedouble = random.randint(1,6)
- dicedouble2 = random.randint(1,6)
- askdouble = input("### You rolled a double would you like to roll again? ### (roll) ")
- if askdouble == "roll":
- score2 = score2 + dicedouble + dicedouble2
- finalscoretwo = finalscoretwo + score2
- print("You rolled ",dicedouble,dicedouble2,"// PLAYER 2 SCORE:", finalscoretwo)
- game2 = game2 + 1
- if finalscoretwo == finalscoreone:
- asksd = input("Both players have the same score. The game will now go into sudden death, player 1 would you like to roll? (y)")
- if asksd == "y":
- dice2 = random.randint(1,6)
- dice22 = random.randint(1,6)
- score2 = dice2 + dice22
- if score2 % 2 == 0:
- finalscoretwo = finalscoretwo + 8
- else:
- finalscoretwo = finalscoretwo - 8
- finalscoretwo = finalscoretwo + score2
- if finalscoretwo < 0:
- finalscoretwo = 0
- print("You rolled ",dice1,dice22,"// PLAYER 2 SCORE:", finalscoretwo)
- if dice2 == dice22:
- dicedouble = random.randint(1,6)
- dicedouble2 = random.randint(1,6)
- askdouble = input("### You rolled a double would you like to roll again? ### (roll) ")
- if askdouble == "roll":
- score2 = score2 + dicedouble + dicedouble2
- finalscoretwo = finalscoretwo + score2
- print("You rolled ",dicedouble,dicedouble2,"// PLAYER 2 SCORE:", finalscoretwo)
- if finalscoretwo > finalscoreone:
- print("player 2 wins with a score of ", finalscoretwo)
- if finalscoreone > finalscoretwo:
- print("player 1 wins with a score of ", finalscoreone)
- def login():
- while True:
- username = input("Please enter your username player 1: ")
- password = input("Please enter your password player 1: ")
- with sqlite3.connect("dice.db") as db:
- cursor = db.cursor()
- find_user = ("SELECT * FROM user WHERE username = ? AND password = ?")
- cursor.execute(find_user,[(username),(password)])
- results = cursor.fetchall()
- if results:
- for i in results:
- print("Welcome "+i[2])
- player2()
- #return("exit")
- break
- else:
- print("Username and password not recognised")
- again = input("Would you like to try again?(y/n): ")
- if again.lower == "n":
- print("Goodbye")
- time.sleep(1)
- #return("exit")
- break
- def login2():
- while True:
- username = input("Please enter your username player 2: ")
- password = input("Please enter your password player 2: ")
- with sqlite3.connect("dice.db") as db:
- cursor = db.cursor()
- find_user = ("SELECT * FROM user WHERE username = ? AND password = ?")
- cursor.execute(find_user,[(username),(password)])
- results = cursor.fetchall()
- if results:
- for i in results:
- print("Welcome "+i[2])
- gameactual()
- #return("exit")
- break
- else:
- print("Username and password not recognised")
- again = input("Would you like to try again?(y/n): ")
- if again.lower == "n":
- print("Goodbye")
- time.sleep(1)
- #return("exit")
- break
- def player2():
- player2login = input("Would you like to create an account player 2 (y/n) ")
- if player2login == "y":
- newUser2()
- else:
- player2login = input("Would you like to create an account player 2 (y/n) ")
- if player2login == "n":
- login2()
- else:
- player2login = input("Would you like to create an account player 2 (y/n) ")
- def newUser2():
- found = 0
- while found ==0:
- username = input("Please enter a username: ")
- with sqlite3.connect("dice.db") as db:
- cursor = db.cursor()
- findUser = ("SELECT * FROM user WHERE username = ?")
- cursor.execute(findUser,[(username)])
- if cursor.fetchall():
- print("Username taken please try again")
- else:
- found = 1
- firstName = input("Enter your desired first name: ")
- surname = input("Enter your desired surname: ")
- password = input("Please enter your password: ")
- password1 = input("please enter your password again: ")
- while password !=password1:
- print("Your passwords did not match")
- password = input("Please enter your password: ")
- password1 = input("pleae enter your password again: ")
- insertData = '''INSERT INTO user(username,firstname,surname,password)
- VALUES(?,?,?,?)'''
- cursor.execute(insertData,[(username),(firstName),(surname),(password)])
- db.commit()
- gameactual()
- def newUser():
- found = 0
- while found ==0:
- username = input("Please enter a username: ")
- with sqlite3.connect("dice.db") as db:
- cursor = db.cursor()
- findUser = ("SELECT * FROM user WHERE username = ?")
- cursor.execute(findUser,[(username)])
- if cursor.fetchall():
- print("Username taken please try again")
- else:
- found = 1
- firstName = input("Enter your desired first name: ")
- surname = input("Enter your desired surname: ")
- password = input("Please enter your password: ")
- password1 = input("please enter your password again: ")
- while password !=password1:
- print("Your passwords did not match")
- password = input("Please enter your password: ")
- password1 = input("pleae enter your password again: ")
- insertData = '''INSERT INTO user(username,firstname,surname,password)
- VALUES(?,?,?,?)'''
- cursor.execute(insertData,[(username),(firstName),(surname),(password)])
- db.commit()
- player2()
- def testlog():
- test1 = input("Would you like to create an account player 1? (y/n) ")
- if test1 == "y":
- newUser()
- else:
- test1 = input("Would you like to create an account player 1? (y/n) ")
- if test1 == "n":
- login()
- else:
- test1 = input("Would you like to create an account player 1? (y/n) ")
- testlog()
- testlog()
- #8=============================================================D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement