CSC112 Spring 2016 Examples
// The Peg Class Functions1// Revision: $Revision: 1.1 $2// Change Log3// $Log: peg.cpp,v $4// Revision 1.1 2016/03/17 15:53:21 pngwen5// Initial revision6//78#include <iostream>9#include "termmanip.h"10#include "peg.h"1112using namespace std;131415//constructors16Peg::Peg(int _x, int _y) : Widget(_x, _y, 3, 1)17{18_selected = _occupied = false;19_color = normal;20}212223Peg::Peg() : Peg(1,1)24{25//pass!26}2728//display the peg29void30Peg::display()31{32cout << cursorPosition(_x, _y);33cout << "(";34cout << color(); //the color!35//selected means reverse video!36if(isSelected()) {37cout << reverseVideo;38}3940//filled or not41if(isOccupied()) {42cout << "*";43} else {44cout << " ";45}4647//back to normal video48cout << normal;49cout << ")";5051cout.flush();52}535455//select the peg56void57Peg::select()58{59_selected = true;60display();61}6263//deselect the peg64void65Peg::deselect()66{67_selected = false;68display();69}7071//fill the peg hole72void73Peg::place()74{75_occupied = true;76display();77}787980//take the peg from the hole81void82Peg::take()83{84_occupied = false;85display();86}878889//get the status of the peg hole90bool91Peg::isSelected()92{93return _selected;94}959697bool98Peg::isOccupied()99{100return _occupied;101}102103104//get and set the color105colorType106Peg::color()107{108return _color;109}110111112void113Peg::color(colorType c)114{115_color = c;116}117118119