fork download
  1. // game1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4.  
  5. #include<cstdlib>
  6. #include<iostream>
  7. #include<deque>
  8. using namespace std;
  9. class cPlayer
  10. {
  11. public:
  12. int x; //player position on map (x cordinate)
  13. int y; //player position on map (y cordinate)
  14.  
  15. cPlayer(int width) // width is of the map
  16. {
  17. x = width / 2; // player wiill be on mid of x axis
  18. y = 0; // player on top of y axis
  19. }
  20. };
  21.  
  22. class cLane
  23. {
  24. deque<bool> cars;
  25.  
  26. public:
  27. cLane(int width)
  28. {
  29. for (int i = 0; i < width; i++)
  30. {
  31. cars.push_front(false); //lane initially initialize with 0
  32. }
  33. }
  34.  
  35. void Move()
  36. {
  37. if (rand() % 10 == 5)
  38. cars.push_front(true);
  39. else
  40. cars.push_front(false);
  41.  
  42. cars.pop_back();
  43. }
  44. bool checkPos(int pos)
  45. {
  46. return cars[pos];
  47. }
  48.  
  49.  
  50. };
  51.  
  52. class cGame //game class
  53. {
  54. bool quit;
  55.  
  56. public:
  57. void Draw()
  58. {
  59.  
  60. }
  61. void Input()
  62. {
  63.  
  64. }
  65.  
  66. void Logic()
  67. {
  68.  
  69. }
  70.  
  71. void Run()
  72. {
  73. while (!quit)
  74. {
  75. Input();
  76. Draw();
  77. Logic();
  78. }
  79. }
  80. };
  81.  
  82. int main()
  83. {
  84. cLane lane1(20);
  85.  
  86. for (int i = 0; i < 20; i++)
  87. {
  88. if (lane1.checkPos(i))
  89. cout << "1";
  90. else
  91. cout << "0";
  92. }
  93. lane1.Move();
  94. cout << endl;
  95. for (int i = 0; i < 20; i++)
  96. {
  97. if (lane1.checkPos(i))
  98. cout << "1";
  99. else
  100. cout << "0";
  101. }
  102. getchar();
  103. return 0;
  104. }
  105.  
  106.  
Success #stdin #stdout 0s 4316KB
stdin
Standard input is empty
stdout
00000000000000000000
00000000000000000000