-
Notifications
You must be signed in to change notification settings - Fork 0
/
InchWorm.h
61 lines (53 loc) · 1.66 KB
/
InchWorm.h
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
/**
* @file InchWorm.h - Cody the Inch Worm!
* @author Kevin Lundeen
* @see "Seattle University, CPSC 2430, Spring 2018"
*/
#pragma once
#include "adt/Critter.h"
/**
* @class InchWorm - Critter that moves like an inch worm across the screen.
*
* Model/view/controller object for a Menagerie-style critter.
*
* Rendered as a 7-pixel green and white body whose midsection oscillates
* on each movement, propelling the hind quarters forward by two units
* then the head forward by two units on the next move.
*/
class InchWorm : public Critter {
public:
/**
* InchWorm is created EASTbound and in BUNCHED state.
*
* @param row initial placement of head
* @param col initial placement of head
*/
InchWorm(int row, int col);
void move();
void reverse();
void rotate();
void render(PixelMatrix &pxm) const;
Critter::Direction getHeading() const;
int getColumn() const;
std::ostream& print(std::ostream&) const;
private:
/**
* Movement state of an InchWorm.
* STRAIGHT is all body parts in a straight line behind the head at (r,c)
* BUNCHED has the middle part of the body above the line of the rest and
* the tail pulled forward two units
*/
enum State { STRAIGHT, BUNCHED };
State state;
Critter::Direction heading;
int r, c; // head is at this (r,c) location
bool eastwest() const;
int sign() const;
/**
* print out State
* @param out where to print out
* @param state the state, either "STRAIGHT" or "BUNCHED"
* @return out, at the end
*/
friend std::ostream& operator<<(std::ostream& out, InchWorm::State state);
};