-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
115 lines (107 loc) · 4.41 KB
/
Copy pathmain.cpp
File metadata and controls
115 lines (107 loc) · 4.41 KB
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
#include <iostream>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <SFML/Graphics/Sprite.hpp>
#include "struct.h"
#include "figury.h"
using namespace std;
using namespace sf;
int main(){
ContextSettings settings;
settings.antialiasingLevel = 8;
RenderWindow window{{windowWidth+200,windowHeight},"CHESS",sf::Style::Default,settings};
window.setFramerateLimit(60);
plansza szachownica;
boardstate ruchy;
ruchy.clear();
kwadrat pointer(to_vector2f({0,0}), 3);
kwadrat selected(to_vector2f({-1,-1}), 4);
Vector2i select={-1,-1};
int s=0;
char player='a';//'A'-black 'a' - white
while(true){
Vector2i mouse_position =Mouse::getPosition( window);
Vector2i wskaznik=mouse_position/boxHeight;
//cout<<wskaznik.x<<"\t"<<wskaznik.y<<"\n";
wskaznik*=boxHeight;
if(wskaznik.x>=0 && wskaznik.y>=0 && wskaznik.x<=900 && wskaznik.y<=900)
pointer.move(to_vector2f(wskaznik));
else
pointer.move(to_vector2f({-200,-200}));
sf::Event event;
while (window.pollEvent(event) && !szachownica.mat)
{
switch (event.type)
{
// window closed
case sf::Event::Closed:
window.close();
return 0;
break;
// key pressed
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left)
{
Vector2i tmp=wskaznik/boxHeight;
//select new piece
//cout<<"select1\n";
if(s<=0 && turn(szachownica.checkpiece(tmp))==player ) {// player && szachownica.checkpiece(tmp)<(int)player+26 ){
select=tmp;
s=1;
//cout<<"select2\n";
//cout<<szachownica.return_state(select);
ruchy=moves(select,szachownica.actualboardstate,szachownica.return_state(select));
}
// moves should return table of possible moves from Vector on boardstate
/* else if (moves(select,szachownica.actualboardstate)[tmp.x][tmp.y]=='*' ||moves(select,szachownica.actualboardstate)[tmp.x][tmp.y]=='x')
//try to move selected piecefrom select to mouse actual position
// szachownica.actualboardstate.ruch(select,tmp);
*/
else if(s==1 && ruchy.tab[tmp.x][tmp.y]!='0' && !(select.x==tmp.x && select.y==tmp.y)){
//cout<<"select3\n";
if (szachownica.ruch(select,tmp,window)){
s=0;
if(player=='A')
player='a';
else if(player=='a')
player='A';
}
ruchy.clear();
szachownica.change_state(tmp,0);
if(szachownica.szach()>0 ){
write_text(window,"Check",to_vector2f({windowWidth+10,100}));
}
else if(!szachownica.mat) window.clear(Color::Black);
select={-1,-1};
}
//else
// s=-1;
}
else if(event.mouseButton.button == sf::Mouse::Right){
s=0;
select={-1,-1};
ruchy.clear();
//szachownica.printtab();
}
break;
// we don't process other types of events
default:
break;
}
}
if(Keyboard::isKeyPressed(Keyboard::Key::Escape)) break;
selected.move(to_vector2f(select*boxHeight));
szachownica.draw(window);
ruchy.drawmoves(window);
pointer.draw(window);
selected.draw(window);
szachownica.figdraw(window);
window.display();
}
}