-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.cpp
114 lines (102 loc) · 3.43 KB
/
color.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
/*
#############################################################################
# Tux in Space - space exploration game #
# Copyright (C) 2016-2017 [email protected] #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, version 3 or compatibles. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc. #
#############################################################################
*
* In this file there are things correlated whit colors
*/
#include "color.h"
using namespace std;
/***
* The color_Scan function get a color and return it
*/
void color::Scan(const setting& set, const color& range_min, const color& range_max) {
// scan them and chek if the value given are true
// red
stringstream ss;
ss << "Put the value of the red:\n&tdThe value must be between " << range_min.red << " and " << range_max.red;
OPS(set, ss.str());
red = in_i();
while(1) {
ss.clear();
ss.str("");
if((red <= range_max.red) && (red >= range_min.red))
break;
ss << "The value " << red << "you put is wrong. Correct values areee between ";
ss << range_min.red << " and " << range_max.red << ". Type another value for the red component of the color";
OPS_Error(set, ss.str());
red = in_i();
}
// green
ss.clear();
ss.str("");
ss << "Put the value of the green:\n&tdThe value must be between " << range_min.green << " and " << range_max.green;
OPS(set, ss.str());
green = in_i();
while(1) {
if((green <= range_max.green) && (green >= range_min.green))
break;
ss << "The value " << green << "you put is wrong. Correct values areee between ";
ss << range_min.green << " and " << range_max.green << ". Type another value for the green component of the color";
OPS_Error(set, ss.str());
green = in_i();
}
// blue
ss.clear();
ss.str("");
ss << "Put the value of the blue:\n&tdThe value must be between " << range_min.blue << " and " << range_max.blue;
OPS(set, ss.str());
blue = in_i();
while(1) {
if((blue <= range_max.blue) && (blue >= range_min.blue))
break;
ss << "The value " << blue << "you put is wrong. Correct values areee between ";
ss << range_min.blue << " and " << range_max.blue << ". Type another value for the blue component of the color";
OPS_Error(set, ss.str());
blue = in_i();
}
}
/***
* This function check if the color is in/out the color range given
*/
bool color::CheckRange(const color& min, const color& max) {
if(red < min.red)
return false;
if(green < min.green)
return false;
if(blue < min.blue)
return false;
if(red > max.red)
return false;
if(green > max.green)
return false;
if(blue > max.blue)
return false;
return true;
}
bool color::operator== (const color& c) const{
return
(blue == c.blue) &&
(red == c.red) &&
(green == c.green);
}
bool color::operator!= (const color& c) const{
return
(blue != c.blue) ||
(red != c.red) ||
(green != c.green);
}