dirtylevel.cpp
2.38 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
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
#include "dirtylevel.h"
#include <QDateTime>
namespace {
QDateTime cookStartTime;
bool cookStarted = false;
qint64 cookingTime;
int cookingCount;
void decountState(int level)
{
int current = DirtyLevel::state();
int target = qMax(current - level, 0);
switch (target)
{
case 0:
cookingCount = 0;
break;
case 1:
cookingCount = 1;
break;
case 2:
cookingCount = 6;
break;
case 3:
cookingCount = 11;
break;
case 4:
cookingCount = 16;
break;
case 5:
cookingCount = 21;
break;
}
}
}
void DirtyLevel::cookStart()
{
cookStarted = true;
cookStartTime = QDateTime::currentDateTime();
::cookingCount++;
}
void DirtyLevel::cookEnd()
{
if (cookStarted)
{
cookStarted = true;
::cookingTime += cookStartTime.secsTo(QDateTime::currentDateTime());
}
}
void DirtyLevel::wash(int type)
{
switch (type)
{
case 1:
::cookingTime = qMax(::cookingTime - 2 * 3600, (qint64) 0);
decountState(1);
break;
case 2:
::cookingTime = qMax(::cookingTime - 3 * 3600, (qint64) 0);
decountState(1);
break;
case 3:
::cookingTime = qMax(::cookingTime - 4 * 3600, (qint64) 0);
decountState(2);
break;
case 4:
::cookingTime = qMax(::cookingTime - 10 * 3600, (qint64) 0);
decountState(2);
break;
case 5:
::cookingTime = qMax(::cookingTime - 2 * 3600, (qint64) 0);
decountState(1);
break;
}
}
int DirtyLevel::dirty()
{
if (::cookingCount < 1)
return 0;
if (::cookingTime < 1 * 3600)
return 1;
if (::cookingTime < 3 * 3600)
return 2;
if (::cookingTime < 5 * 3600)
return 3;
if (::cookingTime < 7 * 3600)
return 4;
return 5;
}
int DirtyLevel::state()
{
if (::cookingCount < 1)
return 0;
if (::cookingCount <= 5)
return 1;
if (::cookingCount <= 10)
return 2;
if (::cookingCount <= 15)
return 3;
if (::cookingCount <= 20)
return 4;
return 5;
}
void DirtyLevel::setCookingTime(qint64 secs)
{
::cookingTime = secs;
}
int DirtyLevel::cookingTime()
{
return ::cookingTime;
}
int DirtyLevel::cookingCount()
{
return ::cookingCount;
}
void DirtyLevel::setCookingCount(int count)
{
::cookingCount = count;
}