Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 3 10 Making the game for two players
- # Run two instances on two IDE s
- # Else develop this to run two players on one computer.
- import sqlite3
- from random import randint
- from time import time
- conn = sqlite3.connect("computer_cards.db")
- def read_all_cards():
- result = conn.execute("SELECT * FROM computer")
- return result.fetchall()
- def pick_card():
- cards = read_all_cards()
- last_picked_card = read_last_picked()
- random_card = cards[randint(0, len(cards) - 1)]
- while random_card[0] == last_picked_card[0]:
- random_card = cards[randint(0, len(cards) - 1)]
- insert_picked(random_card[0])
- return random_card
- def insert_picked(name):
- insert_sql = "INSERT INTO picked(name, time) VALUES ('{}', {})".format(name, time())
- conn.execute(insert_sql)
- conn.commit()
- def read_last_picked():
- result = conn.execute("SELECT * FROM picked ORDER BY time DESC")
- return result.fetchone()
- player = input("Are you player (1) or (2) > ")
- choosing_player = "1" # for a start.
- for round in range(5): # Default =5 Change if you want
- input("Press enter to pick a card when both players are ready > ")
- card = pick_card()
- card_text = ("{}, cores={}, speed={}GHz, RAM={}MB, cost={}$"
- .format(card[0], card[1], card[2], card[3], card[4]))
- print(card)
- print("Player " + choosing_player + " picks a statistic.")
- winner = input("Did you win? (Y)es, (N)o, (D)raw > ").lower()
- if winner == "y":
- choosing_player = player
- elif winner == "n":
- choosing_player = "2" if player == "1" else "1"
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement