Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
#include <unistd.h>
2
#include <iostream>
3
#include "termmanip.h"
4
#include "SmileyFace.h"
5
6
using namespace std;
7
8
9
SmileyFace::SmileyFace(int _x, int _y) : Widget(_x, _y, 5, 1)
10
{
11
state = NEUTRAL;
12
}
13
14
15
void SmileyFace::scare()
16
{
17
//stay scared for a short time
18
state = SCARED;
19
display();
20
usleep(500000);
21
state = NEUTRAL;
22
display();
23
}
24
25
26
void SmileyFace::chill()
27
{
28
state = CHILL;
29
display();
30
}
31
32
33
void SmileyFace::kill()
34
{
35
state = DEAD;
36
display();
37
}
38
39
40
void SmileyFace::click()
41
{
42
43
}
44
45
46
void SmileyFace::display()
47
{
48
cout << cursorPosition(_x, _y);
49
switch(state) {
50
case NEUTRAL:
51
cout << "(^_^)";
52
break;
53
54
case CHILL:
55
cout << "($_$)";
56
break;
57
58
case SCARED:
59
cout << "(O_O)";
60
break;
61
62
case DEAD:
63
cout << "(x_x)";
64
break;
65
}
66
cout.flush();
67
}
68
69
70
void SmileyFace::reset()
71
{
72
state = NEUTRAL;
73
display();
74
}
75
76