-
Notifications
You must be signed in to change notification settings - Fork 0
/
newsource.cpp
534 lines (413 loc) · 28.1 KB
/
newsource.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
// #include <SFML/Graphics.hpp>
// #include <iostream>
// #include<SFML/Window.hpp>
// #include<SFML/System.hpp>
// #include "PlayerYellow.h"
// #include "PlayerBlue.h"
// #include "PlayerGreen.h"
// #include "PlayerRed.h"
// #include "dice.cpp"
// #include "Menu.hpp"
// using namespace std;
// int main()
// {
// //Variable declaration
// int Playerturn = 1;
// int moveBluePlayer = 10, moveYellowPlayer = 10 , moveGreenPlayer = 10,moveRedPlayer=10;
// float Yellow1PosX, Yellow1PosY ,Yellow2PosX,Yellow2PosY,Yellow3PosX,Yellow3PosY,Yellow4PosX,Yellow4PosY;
// float Blue1PosX, Blue1PosY, Blue2PosX, Blue2PosY, Blue3PosX, Blue3PosY, Blue4PosX, Blue4PosY;
// float Green1PosX, Green1PosY, Green2PosX, Green2PosY, Green3PosX, Green3PosY, Green4PosX, Green4PosY;
// float Red1PosX, Red1PosY, Red2PosX, Red2PosY, Red3PosX, Red3PosY, Red4PosX, Red4PosY;
// float MousePosY, MousePosX;
// sf::RenderWindow window, MENU_WINDOW;
// sf::View view(sf::Vector2f(750, 750), sf::Vector2f(1500, 1500));
// MENU_WINDOW.create(sf::VideoMode(800, 600), "Main Menu");
// Menu menu(MENU_WINDOW.getSize().x, MENU_WINDOW.getSize().y);
// sf::Texture texture;
// if (!texture.loadFromFile("gotti/main_menu.jfif"))
// {
// std::cout << "Error loading menu background image.";
// }
// sf::Sprite menuBackground(texture);
// while (MENU_WINDOW.isOpen())
// {
// sf::Event event;
// while (MENU_WINDOW.pollEvent(event))
// {
// sf::Vector2i mouseClickPosition = sf::Mouse::getPosition(MENU_WINDOW);
// menu.checkUsingMouse(mouseClickPosition);
// if (event.type == sf::Event::Closed)
// MENU_WINDOW.close();
// //while
// if (event.type == sf::Event::KeyPressed || event.type == sf::Event::MouseButtonPressed)
// {
// // Up arrow key pressed
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up))
// {
// // Shift selected label to down
// menu.moveUp();
// }
// // Down arrow key pressed
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down))
// {
// // Shift selected label to down
// menu.moveDown();
// }
// sf::Vector2i mouseClickPos = sf::Mouse::getPosition(MENU_WINDOW);
// // Enter key pressed
// if (event.key.code == sf::Keyboard::Enter || event.type == sf::Event::MouseButtonPressed)
// {
// if (menu.getPressedLabel() == 1 || menu.returnClickedValue(mouseClickPos) == 1)
// {
// //credits here
// }
// if (menu.getPressedLabel() == 0 || menu.returnClickedValue(mouseClickPos) == 0)
// {
// MENU_WINDOW.close();
// //Main game loop here
// window.create(sf::VideoMode(1000, 1000), "LUDO");
// sf::RectangleShape background(sf::Vector2f(1000.0f, 1000.0f));
// sf::Font font;
// sf::Text t1;
// sf::Texture boardTexture;
// sf::Texture playerb;
// sf::Texture player;
// //Yellow Player object declaration
// PlayerYellow yellowPlayer1(207.f, 800.f);
// PlayerYellow yellowPlayer2(93.f, 800.f);
// PlayerYellow yellowPlayer3(93.f, 685.f);
// PlayerYellow yellowPlayer4(207.f, 685.f);
// PlayerBlue bluePlayer1(807.f, 800.f);
// PlayerBlue bluePlayer2(692.f, 800.f);
// PlayerBlue bluePlayer3(807.f, 692.f);
// PlayerBlue bluePlayer4(692.f, 685.f);
// PlayerGreen greenPlayer1(206.f, 191.f);
// PlayerGreen greenPlayer2(92.f, 191.f);
// PlayerGreen greenPlayer3(207.f, 77.f);
// PlayerGreen greenPlayer4(92.f, 77.f);
// PlayerRed redPlayer1(807.f, 77.f);
// PlayerRed redPlayer2(692.f, 77.f);
// PlayerRed redPlayer3(807.f, 191.f);
// PlayerRed redPlayer4(692.f, 191.f);
// dice d;
// int diceno = 0;
// boardTexture.loadFromFile("ludo-board.png");
// playerb.loadFromFile("Gotti/blue.png");
// player.loadFromFile("Gotti/PlayerTexture.png");
// font.loadFromFile("Chocolate Covered Raindrops.ttf");
// sf::Vector2u playertexturesize = player.getSize();
// t1.setFont(font);
// t1.setCharacterSize(32);
// t1.setString("Home");
// t1.setPosition(window.getSize().x / 2.2f, 400.f);
// background.setOrigin(500.0f, 500.0f);
// background.setPosition(500.0f, 500.0f);
// background.setTexture(&boardTexture);
// playertexturesize.x /= 4;
// sf::Text text;
// text.setString("Home");
// text.setCharacterSize(24);
// text.setStyle(sf::Text::Bold);
// //game window
// while (window.isOpen())
// {
// sf::Event event;
// while (window.pollEvent(event))
// {
// if (event.type == sf::Event::Closed) {
// window.close();
// }
// }
// window.clear();
// window.draw(background);
// //Players Turn
// if (Playerturn == 1) { //For yellow player movement
// window.pollEvent(event);
// if (moveYellowPlayer == 1) {
// yellowPlayer1.draw(window, diceno);
// cout << "\n \n Player green turn";
// Playerturn += 1;
// }
// else if (moveYellowPlayer == 2) {
// yellowPlayer2.draw(window, diceno);
// cout << "\n \n Player green turn";
// Playerturn += 1;
// }
// else if (moveYellowPlayer == 3) {
// yellowPlayer3.draw(window, diceno);
// cout << "\n \n Player green turn";
// Playerturn += 1;
// }
// else if (moveYellowPlayer == 4) {
// yellowPlayer4.draw(window, diceno);
// cout << "\n \n Player green turn";
// Playerturn += 1;
// }
// }
// else if (Playerturn == 2) { //For Green Player movement
// window.pollEvent(event);
// if (moveGreenPlayer == 1) {
// greenPlayer1.draw(window, diceno);
// cout << "\n \n Player red turn";
// Playerturn += 1;
// }
// else if(moveGreenPlayer == 2) {
// greenPlayer2.draw(window, diceno);
// cout << "\n \n Player red turn";
// Playerturn += 1;
// }
// else if (moveGreenPlayer == 3) {
// greenPlayer3.draw(window, diceno);
// cout << "\n \n Player red turn";
// Playerturn += 1;
// }
// else if (moveGreenPlayer == 3) {
// greenPlayer3.draw(window, diceno);
// cout << "\n \n Player red turn";
// Playerturn += 1;
// }
// }
// else if (Playerturn == 3) { //Move Red Player
// window.pollEvent(event);
// if (moveRedPlayer == 1) {
// redPlayer1.draw(window, diceno);
// cout << "\n \n Player blue turn";
// Playerturn += 1;
// }
// else if(moveRedPlayer == 2) {
// redPlayer2.draw(window, diceno);
// cout << "\n \n Player blue turn";
// Playerturn += 1;
// }
// else if (moveRedPlayer == 3) {
// redPlayer3.draw(window, diceno);
// cout << "\n \n Player blue turn";
// Playerturn += 1;
// }
// else if (moveRedPlayer == 4) {
// redPlayer4.draw(window, diceno);
// cout << "\n \n Player blue turn";
// Playerturn += 1;
// }
// }
// else if (Playerturn == 4) { //Move blue Player
// window.pollEvent(event);
// if (moveBluePlayer == 1) {
// bluePlayer1.draw(window, diceno);
// cout << "\n \n Player yellow turn";
// Playerturn = 1;
// }
// else if (moveBluePlayer == 2) {
// bluePlayer2.draw(window, diceno);
// cout << "\n \n Player yellow turn";
// Playerturn = 1;
// }
// else if (moveBluePlayer == 3) {
// bluePlayer3.draw(window, diceno);
// cout << "\n \n Player yellow turn";
// Playerturn = 1;
// }
// else if (moveBluePlayer == 4) {
// bluePlayer4.draw(window, diceno);
// cout << "\n \n Player yellow turn";
// Playerturn = 1;
// }
// }
// yellowPlayer1.draw(window, 0);
// yellowPlayer2.draw(window, 0);
// yellowPlayer3.draw(window, 0);
// yellowPlayer4.draw(window, 0);
// bluePlayer1.draw(window, 0);
// bluePlayer2.draw(window, 0);
// bluePlayer3.draw(window, 0);
// bluePlayer4.draw(window, 0);
// greenPlayer1.draw(window, 0);
// greenPlayer2.draw(window, 0);
// greenPlayer3.draw(window, 0);
// greenPlayer4.draw(window, 0);
// redPlayer1.draw(window, 0);
// redPlayer2.draw(window, 0);
// redPlayer3.draw(window, 0);
// redPlayer4.draw(window, 0);
// window.draw(t1);
// window.display();
// diceno = d.askToRollDice();
// cout << "/n You got: " << diceno << endl;
// moveYellowPlayer = 10;
// moveBluePlayer = 10;
// moveGreenPlayer = 10;
// moveRedPlayer = 10;
// //Select players among same colors
// if (Playerturn == 1) {
// //For Yellow Player selection
// do
// {
// if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
// Yellow1PosX = yellowPlayer1.getPosx();
// Yellow1PosY = yellowPlayer1.getPosy();
// Yellow2PosX= yellowPlayer2.getPosx();
// Yellow2PosY= yellowPlayer2.getPosy();
// Yellow3PosX = yellowPlayer3.getPosx();
// Yellow3PosY = yellowPlayer3.getPosy();
// Yellow4PosX = yellowPlayer4.getPosx();
// Yellow4PosY = yellowPlayer4.getPosy();
// MousePosX = sf::Mouse::getPosition(window).x;
// MousePosY = sf::Mouse::getPosition(window).y;
// if ((MousePosX >= yellowPlayer1.getPositionx(0) + 30 && MousePosX <= yellowPlayer1.getPositionx(0) + 80 && MousePosY >= yellowPlayer1.getPositiony(0) + 30 && MousePosY <= yellowPlayer1.getPositiony(0) + 80
// ) || (MousePosX >= Yellow1PosX + 30 && MousePosX <= Yellow1PosX + 80 &&
// MousePosY >= Yellow1PosY + 30 && MousePosY <= Yellow1PosY + 80)) {
// moveYellowPlayer = 1;
// }
// if ((MousePosX >= yellowPlayer2.getPositionx(0)+30 && MousePosX <= yellowPlayer2.getPositionx(0) + 80 && MousePosY >= yellowPlayer2.getPositiony(0)+30 && MousePosY <= yellowPlayer2.getPositiony(0) + 80
// )|| (MousePosX >= Yellow2PosX+30 && MousePosX <= Yellow2PosX + 80 &&
// MousePosY >= Yellow2PosY+30 && MousePosY <= Yellow2PosY + 80) ) {
// moveYellowPlayer = 2;
// cout << "mousePos=" << sf::Mouse::getPosition(window).x << endl;
// cout << "PlayerPosition=" << yellowPlayer2.getPosx() << endl << endl;
// }
// if ((MousePosX >= yellowPlayer3.getPositionx(0) + 30 && MousePosX <= yellowPlayer3.getPositionx(0) + 80 && MousePosY >= yellowPlayer3.getPositiony(0) + 30 && MousePosY <= yellowPlayer3.getPositiony(0) + 80
// )|| (MousePosX >= Yellow3PosX + 30 && MousePosX <= Yellow3PosX + 80 &&
// MousePosY >= Yellow3PosY + 30 && MousePosY <= Yellow3PosY + 80)) {
// moveYellowPlayer = 3;
// }
// if ((MousePosX >= yellowPlayer4.getPositionx(0) + 30 && MousePosX <= yellowPlayer4.getPositionx(0) + 80 && MousePosY >= yellowPlayer4.getPositiony(0) + 30 && MousePosY <= yellowPlayer4.getPositiony(0) + 80
// )|| (MousePosX >= Yellow4PosX + 30 && MousePosX <= Yellow4PosX + 80 &&
// MousePosY >= Yellow4PosY + 30 && MousePosY <= Yellow4PosY + 80)) {
// moveYellowPlayer = 4;
// }
// }
// } while (moveYellowPlayer > 4 && Playerturn == 1);
// }
// if (Playerturn == 2) {
// //For Green Player selection
// do
// {
// if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
// Green1PosX = greenPlayer1.getPosx();
// Green1PosY = greenPlayer1.getPosy();
// Green2PosX = greenPlayer2.getPosx();
// Green2PosY = greenPlayer2.getPosy();
// Green3PosX = greenPlayer3.getPosx();
// Green3PosY = greenPlayer3.getPosy();
// Green4PosX = greenPlayer4.getPosx();
// Green4PosY = greenPlayer4.getPosy();
// MousePosX = sf::Mouse::getPosition(window).x;
// MousePosY = sf::Mouse::getPosition(window).y;
// if ((MousePosX >= greenPlayer1.getPositionx(0) + 30 && MousePosX <= greenPlayer1.getPositionx(0) + 80 && MousePosY >= greenPlayer1.getPositiony(0) + 30 && MousePosY <= greenPlayer1.getPositiony(0) + 80
// )|| (MousePosX >= Green1PosX + 30 && MousePosX <= Green1PosX + 80 &&
// MousePosY >= Green1PosY + 30 && MousePosY <= Green1PosY + 80)) {
// moveGreenPlayer = 1;
// }
// if ((MousePosX >= greenPlayer2.getPositionx(0) + 30 && MousePosX <= greenPlayer2.getPositionx(0) + 80 && MousePosY >= greenPlayer2.getPositiony(0) + 30 && MousePosY <= greenPlayer2.getPositiony(0) + 80
// )|| (MousePosX >= Green2PosX + 30 && MousePosX <= Green2PosX + 80 &&
// MousePosY >= Green2PosY + 30 && MousePosY <= Green2PosY + 80)) {
// moveGreenPlayer = 2;
// }
// if ((MousePosX >= greenPlayer3.getPositionx(0) + 30 && MousePosX <= greenPlayer3.getPositionx(0) + 80 && MousePosY >= greenPlayer3.getPositiony(0) + 30 && MousePosY <= greenPlayer3.getPositiony(0) + 80
// )|| (MousePosX >= Green3PosX + 30 && MousePosX <= Green3PosX + 80 &&
// MousePosY >= Green3PosY + 30 && MousePosY <= Green3PosY + 80)) {
// moveGreenPlayer = 3;
// }
// if ((MousePosX >= greenPlayer4.getPositionx(0) + 30 && MousePosX <= greenPlayer4.getPositionx(0) + 80 && MousePosY >= greenPlayer4.getPositiony(0) + 30 && MousePosY <= greenPlayer4.getPositiony(0) + 80
// )|| (MousePosX >= Green4PosX + 30 && MousePosX <= Green4PosX + 80 &&
// MousePosY >= Green4PosY + 30 && MousePosY <= Green4PosY + 80)) {
// moveGreenPlayer = 4;
// }
// }
// } while (moveGreenPlayer > 4 && Playerturn == 2);
// }
// if (Playerturn == 3) {
// //For red Player selection
// do
// {
// if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
// Red1PosX = redPlayer1.getPosx();
// Red1PosY = redPlayer1.getPosy();
// Red2PosX = redPlayer2.getPosx();
// Red2PosY = redPlayer2.getPosy();
// Red3PosX = redPlayer3.getPosx();
// Red3PosY = redPlayer3.getPosy();
// Red4PosX = redPlayer4.getPosx();
// Red4PosY = redPlayer4.getPosy();
// MousePosX = sf::Mouse::getPosition(window).x;
// MousePosY = sf::Mouse::getPosition(window).y;
// if ((MousePosX >= redPlayer1.getPositionx(0) + 30 && MousePosX <= redPlayer1.getPositionx(0) + 80 && MousePosY >= redPlayer1.getPositiony(0) + 30 && MousePosY <= redPlayer1.getPositiony(0) + 80
// )|| (MousePosX >= Red1PosX + 30 && MousePosX <= Red1PosX + 80 &&
// MousePosY >= Red1PosY + 30 && MousePosY <= Red1PosY + 80)) {
// moveRedPlayer = 1;
// }
// if ((MousePosX >= redPlayer2.getPositionx(0) + 30 && MousePosX <= redPlayer2.getPositionx(0) + 80 && MousePosY >= redPlayer2.getPositiony(0) + 30 && MousePosY <= redPlayer2.getPositiony(0) + 80
// )|| (MousePosX >= Red2PosX + 30 && MousePosX <= Red2PosX + 80 &&
// MousePosY >= Red2PosY + 30 && MousePosY <= Red2PosY + 80)) {
// moveRedPlayer = 2;
// }
// if ((MousePosX >= redPlayer3.getPositionx(0) + 30 && MousePosX <= redPlayer3.getPositionx(0) + 80 && MousePosY >= redPlayer3.getPositiony(0) + 30 && MousePosY <= redPlayer3.getPositiony(0) + 80
// )|| (MousePosX >= Red3PosX + 30 && MousePosX <= Red3PosX + 80 &&
// MousePosY >= Red3PosY + 30 && MousePosY <= Red3PosY + 80)) {
// moveRedPlayer = 3;
// }
// if ((MousePosX >= redPlayer4.getPositionx(0) + 30 && MousePosX <= redPlayer4.getPositionx(0) + 80 && MousePosY >= redPlayer4.getPositiony(0) + 30 && MousePosY <= redPlayer4.getPositiony(0) + 80
// )|| (MousePosX >= Red4PosX + 30 && MousePosX <= Red4PosX + 80 &&
// MousePosY >= Red4PosY + 30 && MousePosY <= Red4PosY + 80)) {
// moveRedPlayer = 4;
// }
// }
// } while (moveRedPlayer > 4 && Playerturn == 3);
// }
// if (Playerturn == 4) {
// //for blue player selection
// do
// {
// if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
// Blue1PosX = bluePlayer1.getPosx();
// Blue1PosY = bluePlayer1.getPosy();
// Blue2PosX = bluePlayer2.getPosx();
// Blue2PosY = bluePlayer2.getPosy();
// Blue3PosX = bluePlayer3.getPosx();
// Blue3PosY = bluePlayer3.getPosy();
// Blue4PosX = bluePlayer4.getPosx();
// Blue4PosY = bluePlayer4.getPosy();
// MousePosX = sf::Mouse::getPosition(window).x;
// MousePosY = sf::Mouse::getPosition(window).y;
// if ((MousePosX >= bluePlayer1.getPositionx(0) + 30 && MousePosX <= bluePlayer1.getPositionx(0) + 80 && MousePosY >= bluePlayer1.getPositiony(0) + 30 && MousePosY <= yellowPlayer1.getPositiony(0) + 80
// )|| (MousePosX >= Blue1PosX + 30 && MousePosX <= Blue1PosX + 80 &&
// MousePosY >= Blue1PosY + 30 && MousePosY <= Blue1PosY + 80)) {
// moveBluePlayer = 1;
// }
// if ((MousePosX >= bluePlayer2.getPositionx(0) + 30 && MousePosX <= bluePlayer2.getPositionx(0) + 80 && MousePosY >= bluePlayer2.getPositiony(0) + 30 && MousePosY <= bluePlayer2.getPositiony(0) + 80
// )|| (MousePosX >= Blue2PosX + 30 && MousePosX <= Blue2PosX + 80 &&
// MousePosY >= Blue2PosY + 30 && MousePosY <= Blue2PosY + 80)) {
// moveBluePlayer = 2;
// }
// if ((MousePosX >= bluePlayer3.getPositionx(0) + 30 && MousePosX <= bluePlayer3.getPositionx(0) + 80 && MousePosY >= bluePlayer3.getPositiony(0) + 30 && MousePosY <= bluePlayer3.getPositiony(0) + 80
// )|| (MousePosX >= Blue3PosX + 30 && MousePosX <= Blue3PosX + 80 &&
// MousePosY >= Blue3PosY + 30 && MousePosY <= Blue3PosY + 80)) {
// moveBluePlayer = 3;
// }
// if ((MousePosX >= bluePlayer4.getPositionx(0) + 30 && MousePosX <= bluePlayer4.getPositionx(0) + 80 && MousePosY >= bluePlayer4.getPositiony(0) + 30 && MousePosY <= bluePlayer4.getPositiony(0) + 80
// )|| (MousePosX >= Blue4PosX + 30 && MousePosX <= Blue4PosX + 80 &&
// MousePosY >= Blue4PosY + 30 && MousePosY <= Blue4PosY + 80)) {
// moveBluePlayer = 4;
// }
// }
// } while (moveBluePlayer > 4 && Playerturn == 4);
// }
// }
// }
// if (menu.getPressedLabel() == 2 || menu.returnClickedValue(mouseClickPos) == 2)
// {
// MENU_WINDOW.close();
// }
// }
// }
// MENU_WINDOW.clear();
// // Draw menu background
// MENU_WINDOW.draw(menuBackground);
// // Member function of menu obj to draw menu
// menu.draw(MENU_WINDOW);
// // end of current frame
// MENU_WINDOW.display();
// }
// }
// return 0;
// }