-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.py
More file actions
executable file
·59 lines (52 loc) · 1.92 KB
/
save.py
File metadata and controls
executable file
·59 lines (52 loc) · 1.92 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
import sqlite3
import os
files = os.listdir();
class Saver:
def __init__(self,kind="Load"):
self.con = sqlite3.connect("mydb")
self.cur = self.con.cursor()
self.dataexists = False
self.createtablecommand="create table player(" \
"id int primary key,"\
"posx integer," \
"posy integer," \
"velx integer," \
"vely integer," \
"angle integer," \
"accx integer," \
"accy integer" \
");"
self.insertnewvalue="insert into player (id, posx, posy, velx, vely, angle, accx, accy) values (?,?,?,?,?,?,?,?)"
self.fetchcountins="select count(*) from player"
if kind == "create":
self.dataexists = False
self.cur.execute(self.createtablecommand)
else:
self.dataexists = True
def createnew(self):
self.cur.execute(self.createtablecommand)
def show(self):
self.cur.execute("select * from player")
print(self.cur.fetchall())
def save(self,player):
self.cur.execute(self.fetchcountins)
id = self.cur.fetchall()[0][0] +1
self.cur.execute(self.insertnewvalue,(id,player.pos[0],player.pos[1],player.vel[0],player.vel[1],player.angle,player.accel[0],player.accel[1]))
def deleteall(self):
self.cur.execute("delete from player")
def commit(self):
self.con.commit()
def dataexist(self):
return self.dataexists
def loadrecent(self):
self.cur.execute("select * from player")
k = self.cur.fetchall()[-1]
return k;
if __name__ == '__main__':
from ship import *
p = Player([1000,2000])
s = Saver()
#s.save(p)
s.show()
#s.deleteall()
#s.commit()