Fishtank
screen.cpp
Go to the documentation of this file.
1 #include "screen.h"
2 #include <string>
3 #include <stdexcept>
4 
5 Screen::Screen(int width, int height) {
6  if (width < 0) {
7  throw std::out_of_range("width must be nonnegative");
8  }
9  if (height < 0) {
10  throw std::out_of_range("height must be nonnegative");
11  }
12  width_ = width;
13  height_ = height;
14 }
15 
16 void Screen::checkCoordinates(int col, int row) const {
17  if (col < 0) {
18  throw std::out_of_range("col must be nonnegative");
19  }
20  if (col >= width()) {
21  throw std::out_of_range("col must be < width");
22  }
23  if (row < 0) {
24  throw std::out_of_range("row must be nonnegative");
25  }
26  if (row >= height()) {
27  throw std::out_of_range("row must be < height");
28  }
29 }
30 
31 int Screen::width() const { return width_; }
32 
33 int Screen::height() const { return height_; }
Screen(int width, int height)
Definition: screen.cpp:5
int width_
Definition: screen.h:28
int width() const
Definition: screen.cpp:31
void checkCoordinates(int col, int row) const
Definition: screen.cpp:16
int height_
Definition: screen.h:29
int height() const
Definition: screen.cpp:33