@@ -4,90 +4,19 @@ const std::string FILEPATH = "C:/Users/Steve/Documents/Visual Studio 2012/Projec
4
4
5
5
namespace chesspp
6
6
{
7
- AppStateGame::AppStateGame ( Application* _app ) : app(_app)
7
+ AppStateGame::AppStateGame ( Application* _app, sf::RenderWindow *_display ) : app(_app), AppState(_display), graphics(display )
8
8
{
9
- backgroundPath = FILEPATH + " res/img/chessboard_640x640.png" ;
10
- piecePath = FILEPATH + " res/img/chess_pieces_80x80_each.png" ;
11
- validMovePath = FILEPATH + " res/img/valid_move.png" ;
12
- std::string gamePath (FILEPATH);
13
- try
14
- {
15
- background = sf::Sprite (TextureManager::getInstance ().Load (backgroundPath));
16
- pieces = sf::Sprite (TextureManager::getInstance ().Load (piecePath));
17
- validMove = sf::Sprite (TextureManager::getInstance ().Load (validMovePath));
18
9
19
- board = new Board ();
20
-
21
- gamePath += " res/games/new_game.txt" ;
22
- board->newGame (gamePath);
23
- }
24
- catch (chesspp::exception e)
25
- {
26
- std::cout << " Files not loaded here are the paths:\n "
27
- << backgroundPath << ' \n '
28
- << piecePath << ' \n '
29
- << validMovePath << ' \n '
30
- << gamePath << ' \n '
31
- << " \n Do Not Hit Enter. Quit the Game\n " ;
32
- std::cin.get ();
33
- }
10
+ std::string gamePath (FILEPATH + " res/games/new_game.txt" );
11
+ board = new Board ();
12
+ board->newGame (gamePath);
34
13
}
35
14
36
15
int AppStateGame::id () { return 1 ; }
37
16
38
- void AppStateGame::OnRender (sf::RenderWindow &display )
17
+ void AppStateGame::OnRender ()
39
18
{
40
- // We can't do anything with these sprites unless we declare them
41
- // Might as well only call load once...
42
-
43
- // Draw the background
44
- display.draw (background);
45
-
46
-
47
- static const int SIZE = 80 ; // To Be defined somwhere
48
-
49
- // Valid moves are drawn for the piece being hovered over
50
- // Or the piece that is currently selected
51
-
52
- Piece* pCurrent = board->getCurrent ();
53
- Piece* pSelect = board->getSelected ();
54
- if (pSelect)
55
- {
56
- for (posList::const_iterator iter = pSelect->getTrajectory ().begin (); iter != pSelect->getTrajectory ().end (); iter++)
57
- {
58
- if (!iter->isValid ()) continue ;
59
- validMove.setPosition (iter->getX () * SIZE, iter->getY () * SIZE);
60
- display.draw (validMove);
61
- }
62
- }
63
- else if (pCurrent)
64
- {
65
- for (posList::const_iterator iter = pCurrent->getTrajectory ().begin (); iter != pCurrent->getTrajectory ().end (); iter++)
66
- {
67
- if (!iter->isValid ()) continue ;
68
- validMove.setPosition (iter->getX () * SIZE, iter->getY () * SIZE);
69
- display.draw (validMove);
70
- }
71
- }
72
-
73
- // Draw the non-selected pieces
74
- for (auto iter = board->pieces .begin (); iter != board->pieces .end (); iter++)
75
- {
76
- if (!*iter || *iter == board->getSelected ()) continue ;
77
-
78
- pieces.setTextureRect (sf::IntRect ((*iter)->getTexturePos ().getX (), (*iter)->getTexturePos ().getY (), SIZE, SIZE));
79
- pieces.setPosition ((*iter)->getBoardPos ().getX () * SIZE, (*iter)->getBoardPos ().getY () * SIZE);
80
- display.draw (pieces);
81
- }
82
-
83
- // Draw the selected piece
84
- if (board->getSelected ())
85
- {
86
- pieces.setTextureRect (sf::IntRect (board->getSelected ()->getTexturePos ().getX (), board->getSelected ()->getTexturePos ().getY (), SIZE, SIZE));
87
- sf::Vector2i mPos = sf::Mouse::getPosition (display);
88
- pieces.setPosition (mPos .x - (SIZE / 2 ), mPos .y - (SIZE / 2 ));
89
- display.draw (pieces);
90
- }
19
+ graphics.drawBoard (board);
91
20
}
92
21
93
22
void AppStateGame::OnLButtonPressed (int x, int y)
0 commit comments