-
Notifications
You must be signed in to change notification settings - Fork 0
/
person.cpp
141 lines (111 loc) · 3.35 KB
/
person.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "person.h"
struct personinper{
QString name;
QString pass;
QString username;
QString email;
int coin;
int exp;
int level;
int shenaseP;
int maxExp;
int day;
};
QDataStream &operator>>(QDataStream &in, struct personinper &p){ //for read from the file
in >> p.name >> p.pass >>p.username>>p.email>>p.coin>>p.exp>>p.level>>p.shenaseP>>p.maxExp>>p.day;
return in;
}
QDataStream &operator<<(QDataStream &out, struct personinper &p){ //for writing from the file
out << p.name <<p.pass <<p.username<<p.email<<p.coin<<p.exp<<p.level<<p.shenaseP<<p.maxExp<<p.day;
return out;
}
void person0::Update_file(){
struct personinper p;
QFile outfile("person-temp.txt");//for writing in new file.
QFile infile("person.txt");//for reading.
infile.open(QIODevice::ReadOnly);
if(infile.isOpen()){
outfile.open(QIODevice::Append);//make file.
while(!infile.atEnd()){
QDataStream in(&infile);
in>>p;
if(shenaseP==p.shenaseP){
p.name=name;
p.pass=pass;
p.username=username;
p.email=email;
p.coin=coin;
p.exp=exp;
p.level=level;
p.shenaseP=shenaseP;
p.maxExp=maxExp;
p.day=day;
}
//outfile.write((char*)&p,sizeof(p));
QDataStream out(&outfile);
out<<p;
}
infile.remove();
outfile.rename("person.txt");
outfile.close();
infile.close();
}
}
///
void person0::setName(QString _name){name=_name;}
void person0::setPass(QString _Pass){pass=_Pass;}
void person0::setUsername(QString _username){username=_username;}
void person0::setEmail(QString _Email){email=_Email;}
void person0::setCoin(int _coin){coin=_coin;}
void person0::setExp(int _Exp){exp=_Exp;}
void person0::setLevel(int _Level){level=_Level;}
void person0::setShenaseP(int _Shenasep){shenaseP=_Shenasep;}
void person0::setMaxExp(int _MaxExp){maxExp=_MaxExp;}
/////
person0::person0(int _shenasep){
struct personinper p;
QFile infile("person.txt");//for reading.
infile.open(QIODevice::ReadOnly);
if(infile.isOpen()){
while(!infile.atEnd()){
QDataStream in(&infile);
in>>p;
if(_shenasep==p.shenaseP){
name=p.name;
pass=p.pass;
username=p.username;
email=p.email;
coin=p.coin;
exp=p.exp;
level=p.level;
shenaseP=p.shenaseP;
maxExp=p.maxExp;
day=p.day;
break;
}
}
infile.close();
}
}
QString person0::getName(){return name;}
QString person0::getUsername(){return username;}
QString person0::getEmail(){return email;}
int person0::getShenaseP(){return shenaseP;}
int person0::changeCoin(int _coin){
return coin+=_coin;
}
int person0::changeExp(int _Exp){
return exp+=_Exp;
}
int person0::changeLevel(){
if(exp==maxExp){
level++;
maxExp=2*maxExp+10;
return level;
}
return 0;
}
int person0::getMaxExp(){return maxExp;}
int person0::getExp(){return exp;}
int person0::getCoin(){return coin;}
int person0::getLevel(){return level;}