forked from Kostas1209/SpectrRect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
189 lines (183 loc) · 5.96 KB
/
main.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
182
183
184
185
186
187
188
189
#include<SFML/Graphics.hpp>
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<ctime>
#include<windows.h>
using namespace sf;
//using namespace std;
int n;
bool Live=false;
void Menu()
{
bool Level=false;
RenderWindow menu(VideoMode(500,500),"SFML");
Texture NewGametex,Exittex,Easytex,Normaltex,Hardtex;
NewGametex.loadFromFile("NewGame.png");
Exittex.loadFromFile("Exit.png");
Easytex.loadFromFile("Easy.png");
Normaltex.loadFromFile("Normal.png");
Hardtex.loadFromFile("Hard.png");
Sprite NewGame(NewGametex),Easy(Easytex),Normal(Normaltex),Hard(Hardtex),Exit(Exittex);
NewGame.setPosition(50,50);
Easy.setPosition(100,100);
Normal.setPosition(100,150);
Hard.setPosition(100,200);
Exit.setPosition(50,100);
RectangleShape Background(Vector2f (500,500));
Background.setFillColor(Color::Blue);
Background.setPosition(0,0);
bool menuIsOpen = true;
while(menuIsOpen)
{
if(IntRect(50,50,100,50).contains(Mouse::getPosition(menu)))
{
NewGame.setColor(Color::Yellow);
if(Mouse::isButtonPressed(Mouse::Left))
{
Exit.setPosition(50,250);
Level=true;
}
}
if(IntRect(100,100,50,50).contains(Mouse::getPosition(menu)) && Mouse::isButtonPressed(Mouse::Left))
{
n=5;
menuIsOpen=false;
}
if(IntRect(100,150,50,50).contains(Mouse::getPosition(menu)) && Mouse::isButtonPressed(Mouse::Left))
{
n=10;
menuIsOpen=false;
}
if(IntRect(100,200,50,50).contains(Mouse::getPosition(menu)) && Mouse::isButtonPressed(Mouse::Left))
{
n=15;
menuIsOpen=false;
}
if(IntRect(50,100,50,50).contains(Mouse::getPosition(menu))&& Mouse::isButtonPressed(Mouse::Left))
{
//Live=true;
menu.close();
}
if(IntRect(50,250,50,50).contains(Mouse::getPosition(menu))&& Mouse::isButtonPressed(Mouse::Left))
{
//Live=true;
menu.close();
}
menu.clear();
menu.draw(Background);
if(Level==true)
{
menu.draw(Easy);
menu.draw(Normal);
menu.draw(Hard);
}
menu.draw(NewGame);
menu.draw(Exit);
menu.display();
}
}
int main()
{
int xForRand[2];
int yForRand[2];
int x[2];
int y[2];
int temp=0;
srand(time(0));
int posx;
int posy;
bool yes=true;
RenderWindow window(VideoMode(500,500),"SFML");
RectangleShape shape[10][10];
bool press[10][10];
for(int i=0;i<10;++i)
{
for(int j=0;j<10;++j)
{
shape[i][j].setSize(Vector2f(50,50));
shape[i][j].setFillColor(Color(255,i*20,j*20));
shape[i][j].setPosition(50*i,50*j);
press[i][j]=false;
}
}
std::cout<<"Press Space for bland rect"<<std::endl;
Menu();
while(window.isOpen())
{
Event evt;
while(window.pollEvent(evt))
{
if(evt.type==Event::Closed/* && Live */|| Event::KeyPressed && evt.key.code==Keyboard::Escape)
{
window.close();
}
}
for(int i=0;i<10;++i)
{
for(int j=0;j<10;++j)
{
if(press[i][j]==false)
{
shape[i][j].setSize(Vector2f(50,50));
// shape[i][j].setFillColor(Color(255,20*i,20*j));
shape[i][j].setPosition(50*i,50*j);
shape[i][j].setOutlineThickness(0);
}
}
}
Vector2i localCursor=Mouse::getPosition(window);
if(localCursor.x>0 && localCursor.x<500 && localCursor.y>0 && localCursor.y<500 )
{
shape[localCursor.x/50][localCursor.y/50].setSize(Vector2f(40,40));
shape[localCursor.x/50][localCursor.y/50].setOutlineThickness(5);
shape[localCursor.x/50][localCursor.y/50].setOutlineColor(Color::Yellow);
posx=localCursor.x/50;
posy=localCursor.y/50;
}
if(Keyboard::isKeyPressed(Keyboard::Space))
{
for(int i=0;i<n;++i)
{
xForRand[0]=rand()%10;
yForRand[0]=rand()%10;
xForRand[1]=rand()%10;
yForRand[1]=rand()%10;
shape[xForRand[0]][yForRand[0]].setFillColor(Color(255,20*xForRand[1],20*yForRand[1]));
shape[xForRand[1]][yForRand[1]].setFillColor(Color(255,20*xForRand[0],20*yForRand[0]));
Sleep(100);
}
}
if(Mouse::isButtonPressed(Mouse::Left))
{
press[localCursor.x/50][localCursor.y/50]=true;
temp++;
Sleep(150);
}
if(temp==1 && yes==true)
{
x[0]=localCursor.x/50;
y[0]=localCursor.y/50;
yes=false;
}
if(temp==2)
{
x[1]=localCursor.x/50;
y[1]=localCursor.y/50;
std::swap(shape[x[0]][y[0]],shape[x[1]][y[1]]);
press[x[0]][y[0]]=false;
press[x[1]][y[1]]=false;
temp=0;
yes=true;
}
window.clear();
for(int i=0;i<10;++i)
{
for(int j=0;j<10;++j)
{
window.draw(shape[i][j]);
}
}
window.display();
}
}