Advertisement
Guest User

Untitled

a guest
Jan 13th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.61 KB | None | 0 0
  1. // Betting_app.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Class.h"
  6. #include <iostream>
  7. #include <conio.h>
  8. #include <Windows.h>
  9. #include <vector>
  10.  
  11.  
  12.  
  13. using namespace std;
  14.  
  15.  
  16. int main_menu();
  17. bool add_player(vector<Player>&);
  18. void loading_players_from_file(vector<Player>&, int&);
  19. string delete_underscore(string&);
  20.  
  21.  
  22. int main()
  23. {
  24.     int player_counter = 0;
  25.     vector<Player> player_vector;
  26.     loading_players_from_file(player_vector, player_counter);
  27.  
  28.  
  29.     for (;;)
  30.     {
  31.         int main = main_menu();
  32.         if (main == 0)
  33.         {
  34.         /*  for (int i = 0; i < player_counter; i++)
  35.             {
  36.                 cout << player_vector[i].get_name() << endl;
  37.             }
  38.             cin.get();
  39.             cin.get();*/
  40.         }
  41.         else if (main == 1)
  42.         {
  43.  
  44.         }
  45.         else if (main == 2)
  46.         {
  47.             if (add_player(player_vector));
  48.             {
  49.                 player_vector[player_counter].save_player_to_file();
  50.                 player_counter++;
  51.             }
  52.         }
  53.         else if (main == 3)
  54.         {
  55.             return 0;
  56.         }
  57.  
  58.     }
  59.    
  60.    
  61.    
  62.    
  63. }
  64.  
  65.  
  66. int main_menu()
  67. {
  68.     HANDLE standart = GetStdHandle(STD_OUTPUT_HANDLE);
  69.     short b = 0;
  70.     for (;;)
  71.     {
  72.         if (b == 0)
  73.         {
  74.             system("CLS");
  75.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
  76.             cout << "\t\t\t\t\t\tWybierz lige" << endl;
  77.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
  78.             cout << "\t\t\t\t\t\tDodaj lige" << endl;
  79.             cout << "\t\t\t\t\t\tDodaj gracza" << endl;
  80.             cout << "\t\t\t\t\t\tWyjscie" << endl;
  81.         }
  82.         if (b == 1)
  83.         {
  84.             system("CLS");
  85.             system("Color 0F");
  86.             cout << "\t\t\t\t\t\tWybierz lige" << endl;
  87.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
  88.             cout << "\t\t\t\t\t\tDodaj lige" << endl;
  89.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
  90.             cout << "\t\t\t\t\t\tDodaj gracza" << endl;
  91.             cout << "\t\t\t\t\t\tWyjscie" << endl;
  92.         }
  93.         if (b == 2)
  94.         {
  95.             system("CLS");
  96.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
  97.             cout << "\t\t\t\t\t\tWybierz lige" << endl;
  98.             cout << "\t\t\t\t\t\tDodaj lige" << endl;
  99.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
  100.             cout << "\t\t\t\t\t\tDodaj gracza" << endl;
  101.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
  102.             cout << "\t\t\t\t\t\tWyjscie" << endl;
  103.         }
  104.         if (b == 3)
  105.         {
  106.             system("CLS");
  107.             cout << "\t\t\t\t\t\tWybierz lige" << endl;
  108.             cout << "\t\t\t\t\t\tDodaj lige" << endl;
  109.             cout << "\t\t\t\t\t\tDodaj gracza" << endl;
  110.             SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
  111.             cout << "\t\t\t\t\t\tWyjscie" << endl;
  112.         }
  113.         for (;;)
  114.         {
  115.             if (GetAsyncKeyState(VK_DOWN) & 1)
  116.             {  
  117.                 b += 1;
  118.                 if (b == 4)
  119.                 {
  120.                     b = 0;
  121.                     break;
  122.                 }
  123.                 break;
  124.             }
  125.             if (GetAsyncKeyState(VK_UP) & 1)
  126.             {
  127.                 b -= 1;
  128.                 if (b == -1)
  129.                 {
  130.                     b = 3;
  131.                     break;
  132.                 }
  133.                 break;
  134.             }
  135.             if (GetAsyncKeyState(VK_RETURN) & 1)
  136.             {
  137.                 return b;
  138.             }
  139.         }
  140.     }
  141. }
  142.  
  143.  
  144. bool add_player(vector<Player> &player_vector)
  145. {
  146.     HANDLE standart = GetStdHandle(STD_OUTPUT_HANDLE);
  147.  
  148.     string name;
  149.     string comp_name;
  150.     getline(cin, name);
  151.     system("CLS");
  152.     cout << "Podaj login gracza: ";
  153.     getline(cin, name);
  154.    
  155.     for (int i = 0; i < player_vector.size(); i++)
  156.     {
  157.         comp_name = player_vector[i].get_name();
  158.         if (name.compare(comp_name) == 0)
  159.         {
  160.             cout << endl;
  161.             cout << "Wybrany login jest zajety.";
  162.             //Sleep(2000);
  163.             return false;
  164.         }
  165.     }
  166.     player_vector.push_back(Player(name));
  167.     cout << "Gracz ";
  168.     SetConsoleTextAttribute(standart, FOREGROUND_RED | FOREGROUND_INTENSITY);
  169.     cout << name;
  170.     SetConsoleTextAttribute(standart, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
  171.     cout << " pomyslnie dodany do ligi.";
  172.     Sleep(2000);
  173.     cin.ignore(1);
  174.     return true;
  175. }
  176.  
  177.  
  178. void loading_players_from_file(vector<Player> &player_vector, int &player_counter)
  179. {
  180.     string test;
  181.     string name;
  182.     int score;
  183.     fstream count("data\\players.dab", ios::in);
  184.     while (!count.eof())
  185.     {
  186.         getline(count, test);
  187.         player_counter++;
  188.     }
  189.     player_counter--;
  190.     count.close();
  191.     fstream open("data\\players.dab", ios::in);
  192.     for (int i = 0; i < player_counter; i++)
  193.     {
  194.         open >> name;
  195.         delete_underscore(name);
  196.         open >> score;
  197.         player_vector.push_back(Player(name, score));
  198.     }
  199.     open.close();
  200.  
  201.  
  202.  
  203. }
  204.  
  205. string delete_underscore(string &name)
  206. {
  207.     for (int i = 0; i <= name.size(); i++)
  208.         if (name[i] == '_')
  209.             name.replace(i, 1, " ");
  210.     return name;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement