Skip to content

Commit 56a66d6

Browse files
author
basantnema31
committed
Resolve merge conflict in Tic-Tac-Toe.py
2 parents 9711cd6 + 6bb43d9 commit 56a66d6

75 files changed

Lines changed: 5124 additions & 3363 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

0 Bytes
Binary file not shown.

.github/workflows/python-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
3434
- name: Run automated tests
3535
run: |
36-
python -m unittest discover -s tests -v
36+
pytest tests/ -v --tb=short

README.md

Lines changed: 79 additions & 40 deletions
Large diffs are not rendered by default.

WEB_APP_GUIDE.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,76 @@ Then open `http://localhost:8000` in your browser.
6666
- Works on mobile, tablet, and desktop
6767
- No console errors
6868

69+
## 🎯 Modal Requirements
70+
71+
For modals to work correctly in the web app, the following IDs are required:
72+
73+
| ID | Purpose |
74+
|----|---------|
75+
| `projectModal` | Main modal container |
76+
| `modalBody` | Container for project content |
77+
| `modalClose` | Button to close modal |
78+
79+
**Example HTML structure:**
80+
81+
```html
82+
<div class="modal" id="projectModal">
83+
<div class="modal-content">
84+
<div class="modal-header">
85+
<button class="modal-close" id="modalClose">&times;</button>
86+
</div>
87+
<div id="modalBody"></div>
88+
</div>
89+
</div>
90+
```
91+
92+
## 📦 Adding a Project Card
93+
94+
To add a new project card to the homepage, add this HTML inside `projectsTemplate`:
95+
96+
```html
97+
<div class="project-card" data-category="games" data-project="your-project-name" data-tags="tag1,tag2,tag3">
98+
<img class="card-banner" src="assets/banners/your-project.webp" alt="Project Name" loading="lazy">
99+
<div class="card-actions">
100+
<button class="btn-play">Try It</button>
101+
</div>
102+
<h3>Project Name</h3>
103+
<p>Brief description of your project</p>
104+
</div>
105+
```
106+
107+
**Required attributes:**
108+
109+
- `data-category`: `games`, `math`, or `utilities`
110+
- `data-project`: Unique project identifier
111+
- `data-tags`: Search keywords (comma separated)
112+
113+
## ✅ Web PR Testing Checklist
114+
115+
Before submitting a web-related PR, test the following:
116+
117+
- Project modal opens when clicking "Try It"
118+
- Theme toggle switches between dark/light mode
119+
- Search bar filters projects correctly
120+
- No console errors (`F12` → Console)
121+
- Mobile view works (320px width)
122+
- Keyboard navigation (Tab, Enter, Escape)
123+
- Project closes properly with ✕ button and Escape key
124+
125+
## 🚫 What NOT to Do
126+
127+
Avoid these common mistakes:
128+
129+
| Mistake | Why It's Bad |
130+
|---------|--------------|
131+
| Duplicate element IDs | Breaks JavaScript functionality |
132+
| Opening `index.html` directly | Use `python -m http.server 8000` |
133+
| Forgetting to register in `projects.js` | Project won't load |
134+
| Hardcoding colors | Use CSS variables instead |
135+
| Breaking template structure | Causes project cards to disappear |
136+
69137
## Notes
70138

71139
- Use the worker for any long-running Python execution.
72140
- Stop execution by terminating the worker and creating a fresh one.
73-
- Keep changes small and consistent with the existing UI.
141+
- Keep changes small and consistent with the existing UI.

games/2048-Game/2048-Game.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def load_high_score(self):
104104
def save_high_score(self):
105105
try:
106106
HIGH_SCORE_PATH.write_text(str(self.high_score))
107-
except Exception as e:
107+
except OSError as e:
108108
print(f"Warning: Could not save high score: {e}")
109109

110110
def create_grid(self):
@@ -330,7 +330,10 @@ def restart_game(self):
330330
self.root.bind("<Key>", self.handle_keypress)
331331

332332

333-
if __name__ == "__main__":
333+
def main():
334334
root = tk.Tk()
335335
game = Game2048(root)
336-
root.mainloop()
336+
root.mainloop()
337+
338+
if __name__ == "__main__":
339+
main()
Lines changed: 114 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,28 @@
11
import random
22

3-
while True:
4-
print("\n" + "="*40)
5-
print("🃏 WELCOME TO BLACKJACK 21 🃏")
6-
print("="*40 + "\n")
7-
8-
deck = [
9-
"A♠️", "2♠️", "3♠️", "4♠️", "5♠️", "6♠️", "7♠️", "8♠️", "9♠️", "10♠️", "J♠️", "Q♠️", "K♠️",
10-
"A♥️", "2♥️", "3♥️", "4♥️", "5♥️", "6♥️", "7♥️", "8♥️", "9♥️", "10♥️", "J♥️", "Q♥️", "K♥️",
11-
"A♦️", "2♦️", "3♦️", "4♦️", "5♦️", "6♦️", "7♦️", "8♦️", "9♦️", "10♦️", "J♦️", "Q♦️", "K♦️",
12-
"A♣️", "2♣️", "3♣️", "4♣️", "5♣️", "6♣️", "7♣️", "8♣️", "9♣️", "10♣️", "J♣️", "Q♣️", "K♣️"
13-
]
14-
random.shuffle(deck)
15-
16-
player_cards = []
17-
player_hand = []
18-
dealer_cards = []
19-
dealer_hand = []
20-
21-
# Initial Draw
22-
for _ in range(2):
23-
# Player draw
24-
card = deck.pop()
25-
player_cards.append(card)
26-
rank = card[:-2]
27-
if rank in ['Q','K','J']:
28-
player_hand.append(10)
29-
elif rank == 'A':
30-
player_hand.append(1)
31-
else:
32-
player_hand.append(int(rank))
3+
def main():
4+
global _, aces, card, choice, dealer_cards, dealer_count, dealer_hand, deck, player_bust, player_cards, player_count, player_hand, rank, replay
5+
while True:
6+
print("\n" + "="*40)
7+
print("🃏 WELCOME TO BLACKJACK 21 🃏")
8+
print("="*40 + "\n")
339

34-
# Dealer draw
35-
card = deck.pop()
36-
dealer_cards.append(card)
37-
rank = card[:-2]
38-
if rank in ['Q','K','J']:
39-
dealer_hand.append(10)
40-
elif rank == 'A':
41-
dealer_hand.append(1)
42-
else:
43-
dealer_hand.append(int(rank))
10+
deck = [
11+
"A♠️", "2♠️", "3♠️", "4♠️", "5♠️", "6♠️", "7♠️", "8♠️", "9♠️", "10♠️", "J♠️", "Q♠️", "K♠️",
12+
"A♥️", "2♥️", "3♥️", "4♥️", "5♥️", "6♥️", "7♥️", "8♥️", "9♥️", "10♥️", "J♥️", "Q♥️", "K♥️",
13+
"A♦️", "2♦️", "3♦️", "4♦️", "5♦️", "6♦️", "7♦️", "8♦️", "9♦️", "10♦️", "J♦️", "Q♦️", "K♦️",
14+
"A♣️", "2♣️", "3♣️", "4♣️", "5♣️", "6♣️", "7♣️", "8♣️", "9♣️", "10♣️", "J♣️", "Q♣️", "K♣️"
15+
]
16+
random.shuffle(deck)
4417

45-
# Calculate player score initially
46-
player_count = sum(player_hand)
47-
aces = player_hand.count(1)
48-
while aces > 0 and player_count + 10 <= 21:
49-
player_count += 10
50-
aces -= 1
18+
player_cards = []
19+
player_hand = []
20+
dealer_cards = []
21+
dealer_hand = []
5122

52-
# Main Player Loop
53-
player_bust = False
54-
while True:
55-
print(f"🃏 Dealer's visible card: {dealer_cards[0]}")
56-
print(f"🃏 Your cards: {', '.join(player_cards)} (Score: {player_count})")
57-
58-
choice = input("👉 Hit or Stand? [h/s]: ").strip().lower()
59-
60-
if choice in ['h', 'hit']:
23+
# Initial Draw
24+
for _ in range(2):
25+
# Player draw
6126
card = deck.pop()
6227
player_cards.append(card)
6328
rank = card[:-2]
@@ -67,36 +32,8 @@
6732
player_hand.append(1)
6833
else:
6934
player_hand.append(int(rank))
70-
71-
player_count = sum(player_hand)
72-
aces = player_hand.count(1)
73-
while aces > 0 and player_count + 10 <= 21:
74-
player_count += 10
75-
aces -= 1
76-
77-
if player_count > 21:
78-
print(f"🃏 Your cards: {', '.join(player_cards)} (Score: {player_count})")
79-
print("💥 BUST! You went over 21. Dealer wins!")
80-
player_bust = True
81-
break
82-
elif choice in ['s', 'stand']:
83-
print("🛑 You chose to stand.")
84-
break
85-
else:
86-
print("⚠️ Invalid choice. Please enter 'hit' or 'stand'.")
8735

88-
# Dealer Turn
89-
if not player_bust:
90-
dealer_count = sum(dealer_hand)
91-
aces = dealer_hand.count(1)
92-
while aces > 0 and dealer_count + 10 <= 21:
93-
dealer_count += 10
94-
aces -= 1
95-
96-
print(f"\n🃏 Dealer's full cards: {', '.join(dealer_cards)} (Score: {dealer_count})")
97-
98-
while dealer_count < 17:
99-
print("🃏 Dealer hits...")
36+
# Dealer draw
10037
card = deck.pop()
10138
dealer_cards.append(card)
10239
rank = card[:-2]
@@ -106,37 +43,106 @@
10643
dealer_hand.append(1)
10744
else:
10845
dealer_hand.append(int(rank))
46+
47+
# Calculate player score initially
48+
player_count = sum(player_hand)
49+
aces = player_hand.count(1)
50+
while aces > 0 and player_count + 10 <= 21:
51+
player_count += 10
52+
aces -= 1
53+
54+
# Main Player Loop
55+
player_bust = False
56+
while True:
57+
print(f"🃏 Dealer's visible card: {dealer_cards[0]}")
58+
print(f"🃏 Your cards: {', '.join(player_cards)} (Score: {player_count})")
59+
60+
choice = input("👉 Hit or Stand? [h/s]: ").strip().lower()
61+
62+
if choice in ['h', 'hit']:
63+
card = deck.pop()
64+
player_cards.append(card)
65+
rank = card[:-2]
66+
if rank in ['Q','K','J']:
67+
player_hand.append(10)
68+
elif rank == 'A':
69+
player_hand.append(1)
70+
else:
71+
player_hand.append(int(rank))
72+
73+
player_count = sum(player_hand)
74+
aces = player_hand.count(1)
75+
while aces > 0 and player_count + 10 <= 21:
76+
player_count += 10
77+
aces -= 1
10978

79+
if player_count > 21:
80+
print(f"🃏 Your cards: {', '.join(player_cards)} (Score: {player_count})")
81+
print("💥 BUST! You went over 21. Dealer wins!")
82+
player_bust = True
83+
break
84+
elif choice in ['s', 'stand']:
85+
print("🛑 You chose to stand.")
86+
break
87+
else:
88+
print("⚠️ Invalid choice. Please enter 'hit' or 'stand'.")
89+
90+
# Dealer Turn
91+
if not player_bust:
11092
dealer_count = sum(dealer_hand)
11193
aces = dealer_hand.count(1)
11294
while aces > 0 and dealer_count + 10 <= 21:
11395
dealer_count += 10
11496
aces -= 1
115-
print(f"🃏 Dealer's cards: {', '.join(dealer_cards)} (Score: {dealer_count})")
97+
98+
print(f"\n🃏 Dealer's full cards: {', '.join(dealer_cards)} (Score: {dealer_count})")
99+
100+
while dealer_count < 17:
101+
print("🃏 Dealer hits...")
102+
card = deck.pop()
103+
dealer_cards.append(card)
104+
rank = card[:-2]
105+
if rank in ['Q','K','J']:
106+
dealer_hand.append(10)
107+
elif rank == 'A':
108+
dealer_hand.append(1)
109+
else:
110+
dealer_hand.append(int(rank))
111+
112+
dealer_count = sum(dealer_hand)
113+
aces = dealer_hand.count(1)
114+
while aces > 0 and dealer_count + 10 <= 21:
115+
dealer_count += 10
116+
aces -= 1
117+
print(f"🃏 Dealer's cards: {', '.join(dealer_cards)} (Score: {dealer_count})")
116118

117-
# Determine Winner
118-
print("\n" + "-"*30)
119-
print("🎯 FINAL RESULTS 🎯")
120-
print(f"🧑 Your Score: {player_count}")
121-
print(f"🤖 Dealer Score: {dealer_count}")
122-
print("-"*30)
119+
# Determine Winner
120+
print("\n" + "-"*30)
121+
print("🎯 FINAL RESULTS 🎯")
122+
print(f"🧑 Your Score: {player_count}")
123+
print(f"🤖 Dealer Score: {dealer_count}")
124+
print("-"*30)
123125

124-
if dealer_count > 21:
125-
print("🎉 DEALER BUSTED! YOU WIN! 🎉")
126-
elif player_count == dealer_count:
127-
print("🤝 IT'S A DRAW! 🤝")
128-
elif player_count > dealer_count:
129-
print("🏆 YOU WIN! 🏆")
130-
else:
131-
print("💸 DEALER WINS! 💸")
126+
if dealer_count > 21:
127+
print("🎉 DEALER BUSTED! YOU WIN! 🎉")
128+
elif player_count == dealer_count:
129+
print("🤝 IT'S A DRAW! 🤝")
130+
elif player_count > dealer_count:
131+
print("🏆 YOU WIN! 🏆")
132+
else:
133+
print("💸 DEALER WINS! 💸")
132134

133-
# Replay loop
134-
while True:
135-
replay = input("\n🔄 Play again? [y/n]: ").strip().lower()
136-
if replay in ['y', 'yes', 'n', 'no']:
137-
break
138-
print("⚠️ Invalid input. Please enter 'y' or 'n'.")
135+
# Replay loop
136+
while True:
137+
replay = input("\n🔄 Play again? [y/n]: ").strip().lower()
138+
if replay in ['y', 'yes', 'n', 'no']:
139+
break
140+
print("⚠️ Invalid input. Please enter 'y' or 'n'.")
139141

140-
if replay in ['n', 'no']:
141-
print("👋 Thanks for playing! Goodbye!")
142-
break
142+
if replay in ['n', 'no']:
143+
print("👋 Thanks for playing! Goodbye!")
144+
break
145+
146+
147+
if __name__ == '__main__':
148+
main()

0 commit comments

Comments
 (0)