-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnectivity.py
More file actions
68 lines (52 loc) · 1.91 KB
/
connectivity.py
File metadata and controls
68 lines (52 loc) · 1.91 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pyodbc
import os
import sys
import keyboard
import time
SERVER = 'localhost'
DATABASE = 'db_flappy_bird_game'
conn_str = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={SERVER};DATABASE={DATABASE};Trusted_Connection=yes;'
def enable_ansi_windows():
if os.name == 'nt':
import ctypes
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
def print_frame_fast(rows):
output_buffer = ["\033[H"]
for row in rows:
line = ''.join(str(cell) if cell else ' ' for cell in row[1:])
output_buffer.append(line)
sys.stdout.write('\n'.join(output_buffer))
sys.stdout.flush()
def main():
enable_ansi_windows()
os.system('cls' if os.name == 'nt' else 'clear')
try:
conn = pyodbc.connect(conn_str)
conn.autocommit = True
cursor = conn.cursor()
print("Initializing game...")
cursor.execute("EXEC InitializeGame")
print("Starting...")
time.sleep(0.5)
os.system('cls' if os.name == 'nt' else 'clear')
while True:
user_input = 's' if keyboard.is_pressed('space') else ''
cursor.execute("EXEC ProcessBackFrameReturnRenderedFrontFrame ?", user_input)
collision = cursor.fetchone()[0]
cursor.nextset()
frame_rows = cursor.fetchall()
print_frame_fast(frame_rows)
if collision == 1:
sys.stdout.write(f"\033[{len(frame_rows)+2}H")
print("\nGAME OVER!")
break
except KeyboardInterrupt:
sys.stdout.write("\nGame stopped!\n")
except Exception as e:
sys.stdout.write(f"\nError: {e}\n")
finally:
if 'cursor' in locals(): cursor.close()
if 'conn' in locals(): conn.close()
if __name__ == "__main__":
main()