Creating a map container where snake and fruit appears
| 49 | |
| 50 | //Creating a map container where snake and fruit appears |
| 51 | void Map() { |
| 52 | system("cls"); |
| 53 | SetConsoleTextAttribute(hConsole, 180); |
| 54 | for (int i = 0; i < width + 2; i++) |
| 55 | cout << "#"; |
| 56 | cout << endl; |
| 57 | |
| 58 | for (int i = 0; i < height; i++) |
| 59 | { |
| 60 | for (int j = 0; j < width; j++) |
| 61 | { |
| 62 | if (j == 0) |
| 63 | cout << "#"; |
| 64 | if (i == y && j == x) |
| 65 | cout << "O"; |
| 66 | else if (i == fy && j == fx) |
| 67 | cout << "X"; |
| 68 | else |
| 69 | { |
| 70 | bool print = false; |
| 71 | for (int k = 0; k < nt; k++) { |
| 72 | if (tx[k] == j && ty[k] == i) |
| 73 | { |
| 74 | cout << "o"; |
| 75 | print = true; |
| 76 | } |
| 77 | |
| 78 | } |
| 79 | if (!print) |
| 80 | cout << " "; |
| 81 | } |
| 82 | |
| 83 | if (j == width - 1) |
| 84 | cout << "#"; |
| 85 | } |
| 86 | cout << endl; |
| 87 | } |
| 88 | |
| 89 | for (int i = 0; i < width + 2; i++) |
| 90 | cout << "#"; |
| 91 | cout << endl; |
| 92 | cout << "Score is " << score << endl; |
| 93 | |
| 94 | } |
| 95 | // managing input of keyboard to control snake |
| 96 | void Input() { |
| 97 | if (_kbhit()) |