CSC112 Spring 2016 Examples
head 1.1;
access;
symbols;
locks; strict;
comment @// @;
1.1
date 2016.03.17.15.53.21; author pngwen; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@// The Peg Class Functions
// Revision: $Revision$
// Change Log
// $Log$
#include <iostream>
#include "termmanip.h"
#include "peg.h"
using namespace std;
//constructors
Peg::Peg(int _x, int _y) : Widget(_x, _y, 3, 1)
{
_selected = _occupied = false;
_color = normal;
}
Peg::Peg() : Peg(1,1)
{
//pass!
}
//display the peg
void
Peg::display()
{
cout << cursorPosition(_x, _y);
cout << "(";
cout << color(); //the color!
//selected means reverse video!
if(isSelected()) {
cout << reverseVideo;
}
//filled or not
if(isOccupied()) {
cout << "*";
} else {
cout << " ";
}
//back to normal video
cout << normal;
cout << ")";
cout.flush();
}
//select the peg
void
Peg::select()
{
_selected = true;
display();
}
//deselect the peg
void
Peg::deselect()
{
_selected = false;
display();
}
//fill the peg hole
void
Peg::place()
{
_occupied = true;
display();
}
//take the peg from the hole
void
Peg::take()
{
_occupied = false;
display();
}
//get the status of the peg hole
bool
Peg::isSelected()
{
return _selected;
}
bool
Peg::isOccupied()
{
return _occupied;
}
//get and set the color
colorType
Peg::color()
{
return _color;
}
void
Peg::color(colorType c)
{
_color = c;
}
@