-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRules.cpp
181 lines (145 loc) · 3.95 KB
/
Rules.cpp
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//
// Rules.cpp
// battleeee
//
// Created by Ingy on 1/4/15.
// Copyright (c) 2015 Ingy. All rights reserved.
//
#include "Rules.h"
#include <fstream>
#include <iostream>
#include "ResourcePath.hpp"
Rules :: Rules (RenderWindow * w, Settings * S)
{
name= w;
this->S=S;
initialize();
gameloop();
}
Rules :: ~ Rules()
{
}
void Rules :: initialize()
{
// read settings from file / music/ theme/ difficulty
const string RULES_E = resourcePath()+"RulesE.txt";
const string RULES_F = resourcePath()+"RulesF.txt";
const string RULES_A = resourcePath()+ "RulesA.txt";
string back = resourcePath()+"background7.png";
string curs = resourcePath()+"cursor2.png";
backTexture.loadFromFile(back);
backImage.setTexture(backTexture);
rules.erase(rules.begin(), rules.end());
ifstream in;
pageFont=S->overallFont;
if (S->language== "English")
{
// open english
in.open(RULES_E);
title.setFont(pageFont);
title.setCharacterSize(50);
title.setString("RULES");
title.setPosition((name->getSize().x)/2-120, 100);
title.setColor(Color(10,15,80));
backText.setFont(pageFont);
backText.setCharacterSize(40);
backText.setString("BACK");
backText.setPosition(90,50);
backText.setColor(Color(10,15,80));
}
else if(S->language== "French")
{
in.open(RULES_F);
title.setFont(pageFont);
title.setCharacterSize(50);
title.setString(L"RÈGLES DU JEU");
title.setPosition((name->getSize().x)/2-120, 100);
title.setColor(Color(10,15,80));
backText.setFont(pageFont);
backText.setCharacterSize(40);
backText.setString("REVENIR");
backText.setPosition(90,50);
backText.setColor(Color(10,15,80));
}
// Getting the text
string temp;
getline (in, temp);
do
{
for(int i=0; i<temp.size(); i++)
if(isalpha(temp[i]))
temp[i]=toupper(temp[i]);
rules.push_back(Text(temp, pageFont));
getline (in, temp);
}while(temp!="END");
in.close();
for(int i=0; i<rules.size();i++)
{
rules[i].setPosition(50, 200+30*i);
rules[i].setCharacterSize(22);
rules[i].setScale(0.92, 1);
rules[i].setColor(Color::White);
}
cursorTexture=this->S->cursorTexture;
cursor.setTexture(cursorTexture);
cursor.setPosition(50,backText.getPosition().y+5);
cursor.setScale(0.42, 0.38);
cursorXpos = cursor.getPosition().x;
cursorYpos =cursor.getPosition().y; // text +5
}
void Rules :: gameloop()
{
bool flag =true;
while (name->isOpen() && flag)
{
flag=handleEvents();
update();
renderScreen();
}
}
void Rules:: renderScreen()
{
this->name->clear();
// pictures
name->draw(backImage);
//Text
name->draw(title);
name->draw(backText);
for(int i=0; i<rules.size();i++)
{
name->draw(rules[i]);
}
//cursor
name->draw(cursor);
this->name->display();
}
bool Rules :: handleEvents()
{
bool flag =true; Event event;
while (name -> pollEvent(event) && flag)
{
switch(event.type)
{
case Event::Closed:
name->close();
flag=false;
break;
case Event::KeyPressed:
if (event.key.code == Keyboard::Escape)
{
flag=false;
}
if (event.key.code == Keyboard::Return && cursor.getPosition().y == backText.getPosition().y+5)
{
flag=false;
}
break;
// case ....
}
}
return flag;
}
void Rules :: update()
{
// animations not linked to the user
}