-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.cpp
More file actions
79 lines (68 loc) · 1.76 KB
/
key.cpp
File metadata and controls
79 lines (68 loc) · 1.76 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
#include "key.h"
namespace da_game {
/**
* Creates a new key with the given key code.
*
* @param key_code The key code for this key
*/
Key::Key(std::string key_code) : key_code(key_code) {
}
/**
* Returns the weight of this key.
*
* @return the weight
*/
int Key::weight() const {
return 1;
}
/**
* Returns the volume of this key.
*
* @return the volume
*/
int Key::volume() const {
return 1;
}
/**
* Returns the price of this key.
*
* @return the price
*/
int Key::price() const {
return 50;
}
/**
* Returns the type of this key.
*
* @return the type
*/
std::string Key::type() const {
return "Key (" + key_code + ")";
}
/**
* Returns the key code of this key.
*
* @return the key code
*/
std::string Key::get_key_code() const {
return this->key_code;
}
/**
* Compares the specified object to this key and returns true if
* they are considered equal. In this case they are considered
* equal if and only if the specified object is also a key and
* all of its parameters coincide with the ones of this key.
*
* @return true iff the object is identically equal to this key
*/
bool Key::operator==(Key & key) const {
return key.weight() != this->weight() ||
key.volume() != this->volume() ||
key.price() != this->price() ||
key.type() != this->type();
}
void Key::save(std::fstream & save) {
save << "OBJ" << id << ":" << type();
save << ":" << weight() << "kg," << volume() << "liter," << price() << "kr" << std::endl;
}
}