-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows.cc
148 lines (115 loc) · 3.11 KB
/
windows.cc
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright 2022 Trevor Gale
*
* This file is part of MacWords
*
* MacWords is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* MacWords is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with MacWords. If not,
* see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <QuickDraw.h>
#include "board.hh"
#include "windows.hh"
Score::Score(WindowPtr w, BOOL win, char rounds, char* correctWord)
{
type = ScoreWindow;
window = w;
didWin = win;
numRounds = rounds;
strcpy(word, correctWord);
word[WORD_LENGTH] = '\0';
}
void Score::draw()
{
SetPort(window);
EraseRect(&window->portRect);
// Scope for grey color
{
RGBColor macGrey;
macGrey.red = 204 << 8;
macGrey.green = 204 << 8;
macGrey.blue = 204 << 8;
PixPatHandle macGreyPixPat = NewPixPat();
MakeRGBPat(macGreyPixPat, &macGrey);
FillCRect(&window->portRect, macGreyPixPat);
DisposePixPat(macGreyPixPat);
}
int squareSize = 32;
int bufferSpace = 8;
Rect topRightSquare;
topRightSquare.right = window->portRect.right - bufferSpace;
topRightSquare.left = topRightSquare.right - squareSize;
topRightSquare.top = window->portRect.top + bufferSpace;
topRightSquare.bottom = topRightSquare.top + squareSize;
if (didWin)
{
RGBColor green;
green.red = 93 << 8;
green.green = 170 << 8;
green.blue = 107 << 8;
PixPatHandle greenPixPat = NewPixPat();
MakeRGBPat(greenPixPat, &green);
FillCRect(&topRightSquare, greenPixPat);
DisposePixPat(greenPixPat);
}
else
{
RGBColor grey;
grey.red = 119 << 8;
grey.green = 124 << 8;
grey.blue = 126 << 8;
PixPatHandle greyPixPat = NewPixPat();
MakeRGBPat(greyPixPat, &grey);
FillCRect(&topRightSquare, greyPixPat);
DisposePixPat(greyPixPat);
}
short winLoseFS = 24;
PenState oldState;
GetPenState(&oldState);
Style s = {0};
Str255 fontName;
short fontFamily = 0;
c2pstrcpy_cust(fontName, "geneva");
GetFNum(fontName, &fontFamily);
TextFont(fontFamily);
TextSize(winLoseFS);
PenState ps = {0};
ps.pnLoc.v = window->portRect.top + 35;
ps.pnLoc.h = window->portRect.left + 8;
ps.pnSize.v = 1;
ps.pnSize.h = 1;
SetPenState(&ps);
Str255 str;
if (didWin)
{
c2pstrcpy_cust(str, "You Won!");
}
else
{
c2pstrcpy_cust(str, "You Lost :(");
}
DrawString(str);
ps.pnLoc.v += 35;
SetPenState(&ps);
char recordString[255];
sprintf(recordString, "Guesses: %d/%d", numRounds, NUM_OF_GUESSES);
c2pstrcpy_cust(str, recordString);
DrawString(str);
ps.pnLoc.v += 35;
SetPenState(&ps);
TextSize(14);
char correctWordString[255];
sprintf(correctWordString, "The word was %s", word);
c2pstrcpy_cust(str, correctWordString);
DrawString(str);
SetPenState(&oldState);
}