forked from technolyceum/ai6-m2
262 lines
8.4 KiB
Plaintext
262 lines
8.4 KiB
Plaintext
DIMA - BACKEND DEVELOPER MISSION
|
|
Your Role: Game Brain Developer | Your File: app.py
|
|
|
|
💡 What You're Building: You're creating the "brain" of the game - all the rules, scoring, and game logic!
|
|
|
|
📋 LESSON 1-2: SETUP & PRIZE SYSTEM
|
|
|
|
Step 1: Fork and Clone (10 minutes)
|
|
1. Go to: https://gitea.techshare.cc/technolyceum/ai6-m2
|
|
2. Click the "Fork" button (creates your copy)
|
|
3. Copy your forked repository URL
|
|
4. Open Terminal and type:
|
|
git clone [YOUR-FORKED-URL-HERE]
|
|
cd ai6-m2
|
|
git checkout -b dima-backend-work
|
|
|
|
Step 2: Create the Prize Money System (20 minutes)
|
|
Open app.py and find these lines around line 8:
|
|
|
|
# TODO: Dima - Implement prize structure (15 levels)
|
|
PRIZE_LEVELS = [
|
|
# Format: [1000, 2000, 4000, 8000, 16000, 32000, ... up to 15 values]
|
|
]
|
|
|
|
DELETE those lines and TYPE THIS instead:
|
|
|
|
PRIZE_LEVELS = [
|
|
1000, # Level 1 - Question 1
|
|
2000, # Level 2 - Question 2
|
|
4000, # Level 3 - Question 3
|
|
8000, # Level 4 - Question 4
|
|
16000, # Level 5 - Question 5 ✅ Safe level!
|
|
32000, # Level 6 - Question 6
|
|
64000, # Level 7 - Question 7
|
|
128000, # Level 8 - Question 8
|
|
256000, # Level 9 - Question 9
|
|
512000, # Level 10 - Question 10 ✅ Safe level!
|
|
1024000, # Level 11 - Question 11
|
|
2048000, # Level 12 - Question 12
|
|
4096000, # Level 13 - Question 13
|
|
8192000, # Level 14 - Question 14
|
|
16384000 # Level 15 - Question 15 🏆 JACKPOT!
|
|
]
|
|
|
|
Save the file and test:
|
|
git add app.py
|
|
git commit -m "feat: added prize money system"
|
|
git push origin dima-backend-work
|
|
|
|
📋 LESSON 3-4: GAME SESSION & QUESTIONS
|
|
|
|
Step 3: Make the Game Start Working (25 minutes)
|
|
Find these lines around line 25:
|
|
|
|
@app.route('/start')
|
|
def start_game():
|
|
# TODO: Dima - Initialize game session
|
|
# Set up: score, current_question, lifelines, questions
|
|
return render_template('game.html')
|
|
|
|
DELETE those lines and TYPE THIS instead:
|
|
|
|
@app.route('/start')
|
|
def start_game():
|
|
# Initialize a new game session
|
|
session['score'] = 0
|
|
session['current_question'] = 0
|
|
session['guaranteed_prize'] = 0
|
|
session['lifelines'] = {
|
|
'fifty_fifty': True,
|
|
'phone_friend': True
|
|
}
|
|
session['game_over'] = False
|
|
|
|
# Load questions and shuffle them
|
|
with open('questions.json', 'r') as f:
|
|
session['questions'] = json.load(f)
|
|
|
|
return render_template('game.html')
|
|
|
|
Step 4: Make Questions Appear (15 minutes)
|
|
Find these lines around line 35:
|
|
|
|
@app.route('/get_question')
|
|
def get_question():
|
|
# TODO: Dima - Serve questions to frontend
|
|
# Return: question, options, question_number, current_prize
|
|
return jsonify({"error": "Not implemented"})
|
|
|
|
DELETE those lines and TYPE THIS instead:
|
|
|
|
@app.route('/get_question')
|
|
def get_question():
|
|
if session.get('game_over'):
|
|
return jsonify({'error': 'Game over'})
|
|
|
|
question_index = session.get('current_question', 0)
|
|
questions = session.get('questions', [])
|
|
|
|
if question_index >= len(questions):
|
|
session['game_over'] = True
|
|
return jsonify({'game_over': True, 'final_score': session['score']})
|
|
|
|
question = questions[question_index]
|
|
current_prize = PRIZE_LEVELS[question_index] if question_index < len(PRIZE_LEVELS) else 0
|
|
|
|
return jsonify({
|
|
'question': question['question'],
|
|
'options': question['options'],
|
|
'question_number': question_index + 1,
|
|
'total_questions': len(questions),
|
|
'current_prize': current_prize,
|
|
'score': session['score']
|
|
})
|
|
|
|
Save and push:
|
|
git add app.py
|
|
git commit -m "feat: game start and questions working"
|
|
git push origin dima-backend-work
|
|
|
|
📋 LESSON 5-6: ANSWER CHECKING & LIFELINES
|
|
|
|
Step 5: Make Answer Checking Work (30 minutes)
|
|
Find these lines around line 45:
|
|
|
|
@app.route('/answer', methods=['POST'])
|
|
def check_answer():
|
|
# TODO: Dima - Validate answers and update score
|
|
# Check if answer is correct, update session, return result
|
|
return jsonify({"error": "Not implemented"})
|
|
|
|
DELETE those lines and TYPE THIS instead:
|
|
|
|
@app.route('/answer', methods=['POST'])
|
|
def check_answer():
|
|
if session.get('game_over'):
|
|
return jsonify({'error': 'Game over'})
|
|
|
|
data = request.json
|
|
user_answer = data.get('answer')
|
|
question_index = session.get('current_question', 0)
|
|
questions = session.get('questions', [])
|
|
|
|
if question_index >= len(questions):
|
|
return jsonify({'error': 'No more questions'})
|
|
|
|
question = questions[question_index]
|
|
correct_answer = question['correct_answer']
|
|
prize_won = PRIZE_LEVELS[question_index] if question_index < len(PRIZE_LEVELS) else 0
|
|
|
|
if user_answer == correct_answer:
|
|
# Correct answer! Update score
|
|
session['score'] = prize_won
|
|
|
|
# Update guaranteed prize if reached safe level
|
|
if (question_index + 1) in GUARANTEED_LEVELS:
|
|
session['guaranteed_prize'] = prize_won
|
|
|
|
session['current_question'] += 1
|
|
|
|
# Check if game is won
|
|
if session['current_question'] >= len(questions):
|
|
session['game_over'] = True
|
|
return jsonify({
|
|
'correct': True,
|
|
'score': session['score'],
|
|
'prize_won': prize_won,
|
|
'game_won': True,
|
|
'final_score': session['score']
|
|
})
|
|
|
|
return jsonify({
|
|
'correct': True,
|
|
'score': session['score'],
|
|
'prize_won': prize_won,
|
|
'next_question': session['current_question'] < len(questions)
|
|
})
|
|
else:
|
|
# Wrong answer - game over!
|
|
session['game_over'] = True
|
|
final_prize = session.get('guaranteed_prize', 0)
|
|
|
|
return jsonify({
|
|
'correct': False,
|
|
'correct_answer': correct_answer,
|
|
'game_over': True,
|
|
'final_score': final_prize,
|
|
'prize_lost': prize_won
|
|
})
|
|
|
|
Step 6: Create Lifelines (20 minutes)
|
|
Find these lines around line 55:
|
|
|
|
@app.route('/lifeline/<lifeline_name>')
|
|
def use_lifeline(lifeline_name):
|
|
# TODO: Dima - Implement 50:50 and Phone a Friend
|
|
# Note: Ask AI will be version 2
|
|
return jsonify({"error": "Not implemented"})
|
|
|
|
DELETE those lines and TYPE THIS instead:
|
|
|
|
@app.route('/lifeline/<lifeline_name>')
|
|
def use_lifeline(lifeline_name):
|
|
if session.get('game_over'):
|
|
return jsonify({'error': 'Game over'})
|
|
|
|
if lifeline_name not in session['lifelines']:
|
|
return jsonify({'error': 'Invalid lifeline'})
|
|
|
|
if not session['lifelines'][lifeline_name]:
|
|
return jsonify({'error': 'Lifeline already used'})
|
|
|
|
question_index = session.get('current_question', 0)
|
|
questions = session.get('questions', [])
|
|
question = questions[question_index]
|
|
|
|
if lifeline_name == 'fifty_fifty':
|
|
# Remove two wrong answers
|
|
correct_answer = question['correct_answer']
|
|
options = question['options'].copy()
|
|
|
|
# Keep correct answer + one wrong answer
|
|
remaining_options = [correct_answer]
|
|
wrong_options = [opt for opt in options if opt != correct_answer]
|
|
remaining_options.append(random.choice(wrong_options))
|
|
random.shuffle(remaining_options)
|
|
|
|
session['lifelines'][lifeline_name] = False
|
|
return jsonify({
|
|
'lifeline': 'fifty_fifty',
|
|
'remaining_options': remaining_options
|
|
})
|
|
|
|
elif lifeline_name == 'phone_friend':
|
|
# Phone a friend simulation
|
|
correct_answer = question['correct_answer']
|
|
friend_names = ["Ivan", "Svetlana", "Dmitri", "Anastasia"]
|
|
confidence = random.randint(50, 90)
|
|
|
|
session['lifelines'][lifeline_name] = False
|
|
return jsonify({
|
|
'lifeline': 'phone_friend',
|
|
'friend_says': f"{random.choice(friend_names)} says: 'I think it's {correct_answer}, but I'm only {confidence}% sure'"
|
|
})
|
|
|
|
Final push:
|
|
git add app.py
|
|
git commit -m "feat: completed backend with answers and lifelines"
|
|
git push origin dima-backend-work
|
|
|
|
✅ DIMA'S COMPLETION CHECKLIST
|
|
☐ Prize money system (15 levels) working
|
|
☐ Game starts and creates new session
|
|
☐ Questions load from JSON file
|
|
☐ Answer checking works (right/wrong)
|
|
☐ 50:50 lifeline removes 2 wrong answers
|
|
☐ Phone a Friend gives hints
|
|
☐ Safe levels save your money at Q5 and Q10
|
|
☐ All code pushed to your branch
|
|
☐ Created Pull Request for teacher to review
|
|
|
|
🎉 Congratulations Dima! You built the entire game engine! |