diff --git a/Src/Snake_Game/SnakeGame.cpp b/Src/Snake_Game/SnakeGame.cpp new file mode 100644 index 0000000..de015ed --- /dev/null +++ b/Src/Snake_Game/SnakeGame.cpp @@ -0,0 +1,158 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +/* +Snake Game in C++ (Console Version) + +How to Play: +- W → Up, A → Left, S → Down, D → Right +- Eat the food (*) to grow and increase your score +Snake head = @, body = o, food = * +- Avoid walls and your own body +- After Game Over, press Y to play again +*/ + +class Snake { +private: + vector> body; + char direction; +public: + Snake(int startX, int startY) { + body.push_back({startX, startY}); + direction = 'D'; + } + pair getHead() { return body.front(); } + vector> getBody() { return body; } + char getDirection() { return direction; } + void setDirection(char dir) { direction = dir; } + void move(bool grow=false) { + pair head = body.front(); + switch(direction) { + case 'W': head.first--; break; + case 'S': head.first++; break; + case 'A': head.second--; break; + case 'D': head.second++; break; + } + body.insert(body.begin(), head); + if(!grow) body.pop_back(); + } + bool checkCollision(int width, int height) { + pair head = getHead(); + if(head.first < 0 || head.first >= height || head.second < 0 || head.second >= width) + return true; + for(size_t i=1; i pos; +public: + Food(int width, int height) { respawn(width, height, {}); } + pair getPosition() { return pos; } + void respawn(int width, int height, vector> snakeBody) { + while(true) { + int x = rand()%height; + int y = rand()%width; + pos = {x, y}; + bool onSnake = false; + for(auto s: snakeBody) + if(s==pos) onSnake = true; + if(!onSnake) break; + } + } +}; + +class Game { +private: + int width, height, score; + Snake snake; + Food food; + bool gameOver; +public: + Game(int w,int h) : width(w), height(h), score(0), snake(w/2,h/2), food(w,h), gameOver(false) {} + void draw() { + system("cls"); + for(int i=0;i head = snake.getHead(); + if(head.first==i && head.second==j) cout<<"@ "; + else if(food.getPosition()==make_pair(i,j)) cout<<"* "; + else { + bool printed=false; + for(auto s:snake.getBody()) + if(s.first==i && s.second==j){cout<<"o "; printed=true; break;} + if(!printed) cout<<" "; + } + } + cout<<"#"< nextHead = snake.getHead(); + switch(snake.getDirection()){ + case 'W': nextHead.first--; break; + case 'S': nextHead.first++; break; + case 'A': nextHead.second--; break; + case 'D': nextHead.second++; break; + } + bool grow = (nextHead == food.getPosition()); + if(grow){score+=10; food.respawn(width,height,snake.getBody());} + snake.move(grow); + if(snake.checkCollision(width,height)) gameOver=true; + } + void reset() { + score = 0; + snake.reset(width/2, height/2); + food.respawn(width, height, snake.getBody()); + gameOver = false; + } + void run() { + do { + reset(); + while(!gameOver){ + draw(); + input(); + logic(); + Sleep(250); + } + draw(); + cout<<"\nGame Over! Final Score: "< +#include + + +#include +#include +using namespace std; + + +class Task { +private: + string title; + bool isCompleted; + +public: + + Task(string t) : title(t), isCompleted(false) {} + + void markCompleted() { + isCompleted = true; + } + + string getTitle() const { + return title; + } + + bool getStatus() const { + return isCompleted; + } +}; + + class ToDoList { +private: + vector tasks; + +public: + + void addTask(const string& title) { + if (title.empty()) { + cout << "❌ Task title cannot be empty!\n"; + return; + } + tasks.push_back(Task(title)); + cout << " ✅ Task added successfully!\n"; + } + + void showTasks() const { + if (tasks.empty()) { + cout << "📭 No tasks available!\n"; + return; + } + + cout << "\n------ To-Do List ------\n"; + for (size_t i = 0; i < tasks.size(); ++i) { + cout << i + 1 << ". " << tasks[i].getTitle() + << " [" << (tasks[i].getStatus() ? "✅ Done" : "🕓 Pending") << "]\n"; + } + cout << "------------------------\n"; + } + + void markTaskCompleted(int index) { + if (index < 1 || index > (int)tasks.size()) { + cout << "⚠️ Invalid task number!\n"; + return; + } + tasks[index - 1].markCompleted(); + cout << "✅ Task marked as completed!\n"; + } + + void deleteTask(int index) { + if (index < 1 || index > (int)tasks.size()) { + cout << "⚠️ Invalid task number!\n"; + return; + } + tasks.erase(tasks.begin() + index - 1); + cout << "🗑️ Task deleted successfully!\n"; + } +}; + +int getValidInt(const string& prompt) { + int value; + while (true) { + cout << prompt; + cin >> value; + if (cin.fail()) { + cout << "❌ Invalid input! Please enter a number.\n"; + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + } else { + cin.ignore(numeric_limits::max(), '\n'); + return value; + } + } +} + +int main() { + ToDoList todo; + int choice; + string title; + int index; + + cout << "\n===== 📝 TO-DO LIST APPLICATION =====\n"; + cout << "Manage your daily tasks efficiently.\n"; + + do { + cout << "\nMenu:\n"; + cout << "1. Add Task\n"; + cout << "2. View Tasks\n"; + cout << "3. Mark Task as Completed\n"; + cout << "4. Delete Task\n"; + cout << "5. Exit\n"; + choice = getValidInt("Enter your choice: "); + + switch (choice) { + case 1: + cout << "Enter task title: "; + getline(cin, title); + todo.addTask(title); + break; + + case 2: + todo.showTasks(); + break; + + case 3: + index = getValidInt("Enter task number to mark completed: "); + todo.markTaskCompleted(index); + break; + + case 4: + index = getValidInt("Enter task number to delete: "); + todo.deleteTask(index); + break; + + case 5: + cout << "👋 Exiting program. Goodbye!\n"; + break; + + default: + cout << "⚠️ Invalid choice. Try again!\n"; + } + } while (choice != 5); + + return 0; +} diff --git a/Src/To-Do-List/todo.exe b/Src/To-Do-List/todo.exe new file mode 100644 index 0000000..d803ea4 Binary files /dev/null and b/Src/To-Do-List/todo.exe differ