You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

726 lines
14 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #include "game.hpp"
  2. // Adding this a fix if gluPerspective is not defined, opengl 3+ I think?
  3. void gluPerspective(double fovy,double aspect, double zNear, double zFar)
  4. {
  5. // Start in projection mode.
  6. glMatrixMode(GL_PROJECTION);
  7. glLoadIdentity();
  8. double xmin, xmax, ymin, ymax;
  9. ymax = zNear * tan(fovy * M_PI / 360.0);
  10. ymin = -ymax;
  11. xmin = ymin * aspect;
  12. xmax = ymax * aspect;
  13. glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
  14. }
  15. namespace betacore
  16. {
  17. Game::Game(MODE mode,
  18. int port,
  19. std::string url): ME(mode)
  20. {
  21. this->TITLE = Parser::mode(mode).c_str();
  22. printf("%s\t%s\t%d\t%d\n",this->TITLE, Parser::mode(mode).c_str(),
  23. this->MONITOR_WIDTH, this->MONITOR_HEIGHT);
  24. if (init())
  25. {
  26. printf("Error loading init\n");
  27. return;
  28. }
  29. using namespace std::placeholders;
  30. std::function<void(SHAPE & s, MODE & m)> fn =
  31. std::bind(&Game::update, this, _1, _2);
  32. this->client = new Client(mode, port, url, fn);
  33. this->MONITOR_HEIGHT = 1080;
  34. this->MONITOR_WIDTH = 1920;
  35. SDL_Event event;
  36. while (this->KEEP_ALIVE)
  37. {
  38. //Handle Events
  39. this->events(event);
  40. this->paint();
  41. }
  42. close();
  43. }
  44. Game::~Game()
  45. {
  46. if (this->client != nullptr)
  47. delete this->client;
  48. this->client = nullptr;
  49. }
  50. int Game::init()
  51. {
  52. int result = 0;
  53. //Initialize SDL
  54. if (SDL_Init(SDL_INIT_VIDEO) < 0)
  55. {
  56. printf("Problem loading SLD Error: %s\n", SDL_GetError());
  57. }
  58. else
  59. {
  60. //OPEN GL VERSION 2.X
  61. SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  62. //OPEN GL VERSION ^.1
  63. SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
  64. //Create window
  65. int videoFlags = SDL_WINDOW_OPENGL;
  66. videoFlags |= SDL_WINDOW_SHOWN;
  67. videoFlags |= SDL_WINDOW_RESIZABLE;
  68. this->WINDOW = SDL_CreateWindow(
  69. this->TITLE,
  70. SDL_WINDOWPOS_CENTERED,
  71. SDL_WINDOWPOS_CENTERED,
  72. this->SCREEN_WIDTH,
  73. this->SCREEN_HEIGHT,
  74. videoFlags);
  75. if (WINDOW == NULL)
  76. {
  77. printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
  78. result = -1;
  79. }
  80. else
  81. {
  82. glContext = SDL_GL_CreateContext(WINDOW);
  83. if (glContext == NULL)
  84. {
  85. printf("Unable to crate Open GL Context: %s\n", SDL_GetError());
  86. result = -2;
  87. }
  88. else
  89. {
  90. //Try Vsync
  91. if (SDL_GL_SetSwapInterval(1) < 0)
  92. {
  93. printf("Vsync error:%s\n", SDL_GetError());
  94. }
  95. if (initGL())
  96. {
  97. printf("Problem working with OpenGL");
  98. }
  99. }
  100. }
  101. }
  102. return result;
  103. }
  104. int Game::initGL()
  105. {
  106. int result = 0;
  107. glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
  108. glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
  109. glDepthFunc(GL_LESS);
  110. glEnable(GL_DEPTH_TEST); // Enables Depth Testing
  111. glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
  112. glMatrixMode(GL_PROJECTION);
  113. /* Really Nice Perspective Calculations */
  114. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  115. glLoadIdentity();
  116. GLenum error = glGetError();
  117. if (error != GL_NO_ERROR)
  118. {
  119. printf("OpenGL Error %s\n");
  120. result = -1;
  121. return result;
  122. }
  123. glMatrixMode(GL_MODELVIEW);
  124. // Set up the view port
  125. glViewport(0, 0, this->SCREEN_WIDTH, this->SCREEN_HEIGHT);
  126. glMatrixMode(GL_PROJECTION);
  127. glLoadIdentity();
  128. gluPerspective(
  129. 45.0f,
  130. (GLfloat)this->SCREEN_WIDTH / (GLfloat)this->SCREEN_HEIGHT,
  131. 0.1f,
  132. 100.0f);
  133. glMatrixMode(GL_MODELVIEW);
  134. return result;
  135. }
  136. void Game::close()
  137. {
  138. SDL_DestroyWindow(this->WINDOW);
  139. WINDOW = NULL;
  140. SDL_Quit();
  141. }
  142. void Game::grid()
  143. {
  144. glPushMatrix();
  145. glTranslatef(0.0f, 0.0f, 0.0f);
  146. glLineWidth(2.5);
  147. glColor3f(1.0, 1.0, 1.0);
  148. /*grid*/
  149. float GRIDE_SIZE = 100;
  150. //X
  151. glBegin(GL_LINES);
  152. glVertex2f(-GRIDE_SIZE, 0);
  153. glVertex2f(GRIDE_SIZE, 0);
  154. glEnd();
  155. //Y
  156. glBegin(GL_LINES);
  157. glVertex2f(0, -GRIDE_SIZE);
  158. glVertex2f(0, GRIDE_SIZE);
  159. glEnd();
  160. //Z
  161. glBegin(GL_LINES);
  162. glVertex3f(0, 0, -GRIDE_SIZE);
  163. glVertex3f(0, 0, GRIDE_SIZE);
  164. glEnd();
  165. //X ticks
  166. float TICK_SIZE = .5;
  167. for (float f = -GRIDE_SIZE; f <= GRIDE_SIZE; f += 1)
  168. {
  169. //X
  170. glBegin(GL_LINES);
  171. glVertex3f(f, -TICK_SIZE, 0);
  172. glVertex3f(f, TICK_SIZE, 0);
  173. glEnd();
  174. //Y
  175. glBegin(GL_LINES);
  176. glVertex2f(-TICK_SIZE, f);
  177. glVertex2f(TICK_SIZE, f);
  178. glEnd();
  179. //Z
  180. glBegin(GL_LINES);
  181. glVertex3f(0, -TICK_SIZE, f);
  182. glVertex3f(0, TICK_SIZE, f);
  183. glEnd();
  184. }
  185. glPopMatrix();
  186. }
  187. void Game::triangle()
  188. {
  189. this->triangle(true);
  190. }
  191. void Game::triangle(bool filled)
  192. {
  193. glColor3f(1.0f, 0.0f, 0.0f);
  194. if (filled)
  195. glBegin(GL_POLYGON); // start drawing a polygon
  196. else
  197. glBegin(GL_LINE_LOOP);
  198. glColor3f(1.0f, 0.0f, 0.0f); // Set The Color To Red
  199. glVertex3f(0.0f, 1.0f, 0.0f); // Top
  200. glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
  201. glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
  202. glEnd(); // we're done with the polygon (smooth color interpolation)
  203. }
  204. void Game::square()
  205. {
  206. this->square(true);
  207. }
  208. void Game::square(bool filled)
  209. {
  210. glColor3f(0.0f, 0.0f, 1.0f);
  211. if (filled)
  212. glBegin(GL_QUADS); // start drawing a polygon (4 sided)
  213. else
  214. glBegin(GL_LINE_LOOP);
  215. glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
  216. glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
  217. glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
  218. glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
  219. glEnd(); // done with the polygon
  220. }
  221. void Game::box()
  222. {
  223. glColor3f(1.0f, 1.0f, 1.0f);
  224. glBegin(GL_LINE_LOOP);
  225. glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
  226. glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
  227. glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
  228. glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
  229. glEnd();
  230. }
  231. void Game::rectangle()
  232. {
  233. glColor3f(1.0f, 1.0f, 1.0f);
  234. glBegin(GL_LINE_LOOP);
  235. glVertex3f(-2.5f, 1.0f, 0.0f); // Top Left
  236. glVertex3f(2.5f, 1.0f, 0.0f); // Top Right
  237. glVertex3f(2.5f, -1.0f, 0.0f); // Bottom Right
  238. glVertex3f(-2.5f, -1.0f, 0.0f); // Bottom Left
  239. glEnd();
  240. }
  241. void Game::cross(bool filled)
  242. {
  243. double width = 0.15;
  244. if (filled)
  245. glBegin(GL_QUADS);
  246. else
  247. glBegin(GL_LINE_LOOP);
  248. glVertex3f(-0.5f, width, 0.0f); // Top Left
  249. glVertex3f(0.5f, width, 0.0f); // Top Right
  250. glVertex3f(0.5f, -width, 0.0f); // Bottom Right
  251. glVertex3f(-0.5f, -width, 0.0f); // Bottom Left
  252. glEnd();
  253. glPushMatrix();
  254. glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);
  255. if (filled)
  256. glBegin(GL_QUADS);
  257. else
  258. glBegin(GL_LINE_LOOP);
  259. glVertex3f(-0.5f, width, 0.0f); // Top Left
  260. glVertex3f(0.5f, width, 0.0f); // Top Right
  261. glVertex3f(0.5f, -width, 0.0f); // Bottom Right
  262. glVertex3f(-0.5f, -width, 0.0f); // Bottom Left
  263. glEnd();
  264. glPopMatrix();
  265. }
  266. void Game::compass()
  267. {
  268. glPushMatrix();
  269. glTranslatef(-1.5f, 0.0f, 0.0f);
  270. glColor3f(1.0f, 1.0f, 1.0f);
  271. this->cross(false);
  272. //MINI TRIANGLE
  273. glPushMatrix();
  274. glScalef(0.12f, 0.12f, 0.0f);
  275. glTranslatef(0.0f, 2.6f, 0.0f);
  276. this->triangle(this->KEY_UP_ARROW_ACTIVE);
  277. glPopMatrix();
  278. // MINI SQUARE
  279. glPushMatrix();
  280. glScalef(0.12f, 0.12f, 0.0f);
  281. glTranslatef(0.0f, -2.6f, 0.0f);
  282. this->square(this->KEY_DOWN_ARROW_ACTIVE);
  283. glPopMatrix();
  284. // MINI PENTAGON
  285. glPushMatrix();
  286. glScalef(0.12f, 0.12f, 0.0f);
  287. glTranslatef(-2.56f, 0.0f, 0.0f);
  288. this->pentagon(this->KEY_LEFT_ARROW_ACTIVE);
  289. glPopMatrix();
  290. // MINI CIRCLE
  291. glPushMatrix();
  292. glScalef(0.12f, 0.12f, 0.0f);
  293. glTranslatef(2.56f, 0.0f, 0.0f);
  294. glColor3f(0.0f, 1.0f, 0.0f);
  295. this->circle(this->KEY_RIGHT_ARROW_ACTIVE);
  296. glPopMatrix();
  297. glPushMatrix();
  298. glScalef(0.35f, 0.35f, 0.0f);
  299. glTranslatef(7.0f, 0.0f, 0.0f);
  300. glColor3f(0.0f, 1.0f, 1.0f);
  301. this->circle(this->KEY_SPACE_ACTIVE);
  302. glPopMatrix();
  303. glPushMatrix();
  304. glScalef(0.35f, 0.35f, 0.0f);
  305. glTranslatef(10.0f, 0.0f, 0.0f);
  306. glColor3f(1.0f, 1.0f, 0.0f);
  307. this->circle(this->KEY_RETURN_ACTIVE);
  308. glPopMatrix();
  309. glPopMatrix();
  310. }
  311. void Game::circle()
  312. {
  313. this->circle(true);
  314. }
  315. void Game::circle(bool filled)
  316. {
  317. double radius = 1;
  318. if (filled)
  319. glBegin(GL_POLYGON);
  320. else
  321. glBegin(GL_LINE_LOOP);
  322. double angle1 = 0.0;
  323. glVertex2d(radius * cos(0.0), radius * sin(0.0));
  324. static const int circle_points = 100;
  325. static const float angle = 2.0f * 3.1416f / circle_points;
  326. int i;
  327. for (i = 0; i < circle_points; i++)
  328. {
  329. glVertex2d(radius * cos(angle1), radius * sin(angle1));
  330. angle1 += angle;
  331. }
  332. glEnd();
  333. }
  334. void Game::pentagon()
  335. {
  336. this->pentagon(true);
  337. }
  338. void Game::pentagon(bool filled)
  339. {
  340. glRotatef(-54.0f, 0.0f, 0.0f, 1.0f);
  341. glColor3f(1.0f, 0.0f, 1.0f);
  342. float angle_increment = 360.0f / 5.0f;
  343. angle_increment *= PI / 180.0f;
  344. if (filled)
  345. glBegin(GL_TRIANGLE_FAN);
  346. else
  347. glBegin(GL_LINE_LOOP);
  348. float angle = 0.0f;
  349. double radius = 1;
  350. for (int k = 0; k < 100; ++k)
  351. {
  352. glVertex3f(radius * cos(angle), radius * sin(angle), 0.0f);
  353. angle += angle_increment;
  354. }
  355. glEnd();
  356. }
  357. void Game::user_screen()
  358. {
  359. glPushMatrix();
  360. glTranslatef(-1.5f, -1.0f, -6.0f);
  361. this->box();
  362. glTranslatef(-1.5f, -1.0f, -6.0f);
  363. switch (USER_CURRENT)
  364. {
  365. case TRIANGLE:
  366. this->triangle();
  367. break;
  368. case CIRCLE:
  369. glColor3f(0.0f, 1.0f, 0.0f);
  370. this->circle();
  371. break;
  372. case SQUARE:
  373. this->square();
  374. break;
  375. case PENTAGON:
  376. this->pentagon();
  377. break;
  378. case UNKOWN:
  379. float gray = 105.0 / 255.0;
  380. glColor3f(gray, gray, gray);
  381. glPushMatrix();
  382. glRotatef(-45.0f, 0.0f, 0.0f, 1.0f);
  383. glScalef(2.0f, 2.0f, 0.0f);
  384. this->cross(true);
  385. glPopMatrix();
  386. break;
  387. }
  388. glPopMatrix();
  389. }
  390. void Game::guest_screen()
  391. {
  392. glPushMatrix();
  393. glTranslatef(1.5f, -1.0f, -6.0f);
  394. this->box();
  395. glTranslatef(1.5f, -1.0f, -6.0f);
  396. switch (GUST_CURRENT)
  397. {
  398. case TRIANGLE:
  399. this->triangle();
  400. break;
  401. case CIRCLE:
  402. glColor3f(0.0f, 1.0f, 0.0f);
  403. this->circle();
  404. break;
  405. case SQUARE:
  406. this->square();
  407. break;
  408. case PENTAGON:
  409. this->pentagon();
  410. break;
  411. case UNKOWN:
  412. float gray = 105.0 / 255.0;
  413. glColor3f(gray, gray, gray);
  414. glPushMatrix();
  415. glRotatef(-45.0f, 0.0f, 0.0f, 1.0f);
  416. glScalef(2.0f, 2.0f, 0.0f);
  417. this->cross(true);
  418. glPopMatrix();
  419. break;
  420. }
  421. glPopMatrix();
  422. }
  423. void Game::top_screen()
  424. {
  425. glPushMatrix();
  426. glTranslatef(-0.0f, 1.25f, -6.0f);
  427. this->rectangle();
  428. this->compass();
  429. glPopMatrix();
  430. }
  431. void Game::paint()
  432. {
  433. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
  434. glMatrixMode(GL_MODELVIEW);
  435. glLoadIdentity();
  436. if (this->SHOW_GRID)
  437. {
  438. this->grid();
  439. }
  440. this->top_screen();
  441. this->user_screen();
  442. this->guest_screen();
  443. SDL_GL_SwapWindow(this->WINDOW);
  444. }
  445. void Game::resize(int width, int height)
  446. {
  447. glViewport(0, 0, width, height); // Reset The USER_CURRENT Viewport And Perspective Transformation
  448. glMatrixMode(GL_PROJECTION);
  449. glLoadIdentity();
  450. gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 100.0f);
  451. glMatrixMode(GL_MODELVIEW);
  452. }
  453. /**
  454. * key down
  455. * SDL_Keycode key_code
  456. */
  457. void Game::key_down(SDL_Keycode key_code)
  458. {
  459. switch (key_code)
  460. {
  461. case SDLK_ESCAPE:
  462. case SDLK_q:
  463. printf("Escape\n");
  464. this->KEEP_ALIVE = false;
  465. break;
  466. case SDLK_UP:
  467. printf("UP Key Pressed\n");
  468. this->on_key_up_arrow();
  469. this->KEY_UP_ARROW_ACTIVE = true;
  470. break;
  471. case SDLK_DOWN:
  472. printf("Down Key Pressed\n");
  473. this->on_key_down_arrow();
  474. this->KEY_DOWN_ARROW_ACTIVE = true;
  475. break;
  476. case SDLK_LEFT:
  477. printf("Left Key Pressed\n");
  478. this->on_key_left_arrow();
  479. this->KEY_LEFT_ARROW_ACTIVE = true;
  480. break;
  481. case SDLK_RIGHT:
  482. printf("Right Key Pressed\n");
  483. this->on_key_right_arrow();
  484. this->KEY_RIGHT_ARROW_ACTIVE = true;
  485. break;
  486. case SDLK_g:
  487. this->SHOW_GRID = !SHOW_GRID;
  488. break;
  489. case SDLK_SPACE:
  490. this->KEY_SPACE_ACTIVE = true;
  491. this->on_key_space();
  492. break;
  493. case SDLK_RETURN:
  494. this->KEY_RETURN_ACTIVE = true;
  495. this->on_key_enter();
  496. break;
  497. case SDLK_F11:
  498. if (FULL_SCREEN)
  499. {
  500. SDL_SetWindowPosition(this->WINDOW, 100, 100);
  501. SDL_RestoreWindow(this->WINDOW);
  502. SDL_SetWindowSize(this->WINDOW, SCREEN_WIDTH, SCREEN_HEIGHT);
  503. }
  504. else
  505. {
  506. SDL_SetWindowPosition(this->WINDOW, 0, 0);
  507. SDL_SetWindowSize(this->WINDOW, MONITOR_WIDTH, MONITOR_HEIGHT);
  508. }
  509. this->FULL_SCREEN = !this->FULL_SCREEN;
  510. SDL_ShowCursor(this->FULL_SCREEN);
  511. break;
  512. default:
  513. //Do nothing
  514. break;
  515. }
  516. }
  517. /**
  518. * key down
  519. * SDL_Keycode key_code
  520. */
  521. void Game::key_up(SDL_Keycode key_code)
  522. {
  523. switch (key_code)
  524. {
  525. case SDLK_UP:
  526. this->KEY_UP_ARROW_ACTIVE = false;
  527. break;
  528. case SDLK_DOWN:
  529. this->KEY_DOWN_ARROW_ACTIVE = false;
  530. break;
  531. case SDLK_LEFT:
  532. this->KEY_LEFT_ARROW_ACTIVE = false;
  533. break;
  534. case SDLK_RIGHT:
  535. this->KEY_RIGHT_ARROW_ACTIVE = false;
  536. break;
  537. case SDLK_SPACE:
  538. this->KEY_SPACE_ACTIVE = false;
  539. break;
  540. case SDLK_RETURN:
  541. this->KEY_RETURN_ACTIVE = false;
  542. break;
  543. default:
  544. //Do nothing
  545. break;
  546. }
  547. }
  548. void Game::events(SDL_Event &event)
  549. {
  550. while (SDL_PollEvent(&event) != 0)
  551. {
  552. //https://wiki.libsdl.org/SDL_EventType
  553. switch (event.type)
  554. {
  555. case SDL_WINDOWEVENT:
  556. switch (event.window.event)
  557. {
  558. case SDL_WINDOWEVENT_RESIZED:
  559. //resize();
  560. break;
  561. case SDL_WINDOWEVENT_SIZE_CHANGED:
  562. this->resize(event.window.data1, event.window.data2);
  563. break;
  564. }
  565. break;
  566. //user-requested quit
  567. case SDL_QUIT:
  568. this->KEEP_ALIVE = false;
  569. break;
  570. //Mouse events
  571. case SDL_MOUSEBUTTONDOWN:
  572. case SDL_MOUSEMOTION:
  573. case SDL_MOUSEBUTTONUP:
  574. case SDL_MOUSEWHEEL:
  575. break;
  576. //Keyboard Events
  577. case SDL_KEYDOWN:
  578. this->key_down(event.key.keysym.sym);
  579. break;
  580. case SDL_KEYUP:
  581. this->key_up(event.key.keysym.sym);
  582. break;
  583. } //end switch(event.type)
  584. } //end-while
  585. }
  586. void Game::on_key_up_arrow()
  587. {
  588. // Toggle triangle
  589. this->USER_CURRENT = TRIANGLE;
  590. }
  591. void Game::on_key_down_arrow()
  592. {
  593. this->USER_CURRENT = SQUARE;
  594. }
  595. void Game::on_key_left_arrow()
  596. {
  597. this->USER_CURRENT = PENTAGON;
  598. }
  599. void Game::on_key_right_arrow()
  600. {
  601. this->USER_CURRENT = CIRCLE;
  602. }
  603. void Game::on_key_space()
  604. {
  605. this->client->send(false,this->USER_CURRENT);
  606. }
  607. void Game::on_key_enter()
  608. {
  609. this->client->send(true,this->USER_CURRENT);
  610. }
  611. void Game::update(SHAPE &s, MODE &m)
  612. {
  613. if (m == ME || (ME==EVE && m == ALICE))
  614. this->USER_CURRENT = s;
  615. else
  616. this->GUST_CURRENT = s;
  617. }
  618. } // namespace betacore
  619. void ussage(){
  620. std::cout
  621. << "Ussage:\n"
  622. << "\tMODE: 1-3\n"
  623. << "\t\t1)Alice\n"
  624. << "\t\t2)Bob\n"
  625. << "\t\t2)Eve\n"
  626. << "\tport\n"
  627. << "\taddress"
  628. << std::endl;
  629. }
  630. int main(int argc, char *argv[])
  631. {
  632. if(argc < 4){
  633. ussage();
  634. return 1;
  635. }
  636. betacore::MODE mode = betacore::EVE;
  637. int a = atoi(argv[1]);
  638. std::cout << "Running mode" << a << std::endl;
  639. switch( a){
  640. case 1:
  641. mode = betacore::ALICE;
  642. break;
  643. case 2:
  644. mode = betacore::BOB;
  645. break;
  646. default:
  647. mode = betacore::EVE;
  648. break;
  649. }
  650. betacore::Game game(mode, atoi(argv[2]),argv[3]);
  651. return 0;
  652. }