Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
// This is a class which implements those notorious little golf-tee puzzles
2
// found at certain country-themed restaraunts.
3
// Revision: $Revision: 1.1 $
4
// Change Log
5
// $Log: trianglePuzzle.h,v $
6
// Revision 1.1 2016/03/17 16:01:01 pngwen
7
// Initial revision
8
//
9
10
#ifndef TRIANGLEPUZZLE_H
11
#define TRIANGLEPUZZLE_H
12
#include <vector>
13
#include "widget.h"
14
#include "peg.h"
15
16
class TrianglePuzzle : public Widget
17
{
18
public:
19
//Construct a triangle puzzle with a x, y coordinate for the upper
20
//left hand corner. (As laid out on a 9x27 grid)
21
TrianglePuzzle(int _x, int _y);
22
23
//Construct a triangle puzzle in the center of the screen
24
TrianglePuzzle();
25
26
//Volguus Zildrohar the traveler has come!
27
~TrianglePuzzle();
28
29
//display the puzzle
30
virtual void display();
31
32
//select a given peg
33
virtual void selectPeg(int px, int py);
34
35
//move the selection up a row
36
virtual void up();
37
38
//move the selection down a row
39
virtual void down();
40
41
//move the selection right a column
42
virtual void right();
43
44
//move the selection left a column
45
virtual void left();
46
47
//perform a part of a move. Returns true if valid, false if invalid
48
virtual bool move();
49
50
//reset the puzzle back to its starting state
51
virtual void reset();
52
53
private:
54
std::vector<std::vector<Peg *> > pegs; //the pegs in the puzzle (of course)
55
int cx, cy; //cursor position
56
int mx, my; //position of the selected peg for the move
57
};
58
59
#endif
60
61