Skip to content

Commit 602df6e

Browse files
committed
added ai-typing game
1 parent 029cc5f commit 602df6e

File tree

7 files changed

+141
-4
lines changed

7 files changed

+141
-4
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import random
2+
import time
3+
4+
# Word lists for different difficulty levels
5+
easy_words = ['cat', 'dog', 'sun', 'book', 'tree', 'car', 'bird']
6+
medium_words = ['elephant', 'giraffe', 'balloon', 'umbrella', 'vacation']
7+
hard_words = ['substitution', 'enlightenment', 'interrogation', 'psychological', 'astronomy']
8+
9+
# Function to select a random word based on difficulty
10+
def generate_word(level):
11+
if level == 'Easy':
12+
return random.choice(easy_words)
13+
elif level == 'Medium':
14+
return random.choice(medium_words)
15+
elif level == 'Hard':
16+
return random.choice(hard_words)
17+
18+
# Function to adjust difficulty based on score
19+
def adjust_difficulty(score):
20+
if score >= 50 and score < 100:
21+
return 'Medium'
22+
elif score >= 100:
23+
return 'Hard'
24+
else:
25+
return 'Easy'
26+
27+
# Function to run the typing game
28+
def start_game():
29+
score = 0
30+
level = 'Easy'
31+
32+
print("Welcome to the AI-Powered Typing Game!\n")
33+
print("Instructions:")
34+
print("Type the given word correctly to score points.")
35+
print("Difficulty will increase as your score increases.\n")
36+
37+
# Main game loop
38+
for round_num in range(10): # Number of rounds (10 in this example)
39+
print(f"\nRound {round_num + 1}: Difficulty Level - {level}")
40+
word_to_type = generate_word(level)
41+
print(f"Type this word: {word_to_type}")
42+
43+
start_time = time.time() # Start the timer
44+
user_input = input("Your input: ")
45+
46+
# Check if the user typed the correct word
47+
if user_input.lower() == word_to_type.lower():
48+
time_taken = time.time() - start_time
49+
score += 10 # Increase score for correct input
50+
print(f"Correct! You took {time_taken:.2f} seconds.")
51+
print(f"Your score: {score}")
52+
else:
53+
print("Incorrect! Try harder next time.")
54+
55+
# Adjust the difficulty based on score
56+
level = adjust_difficulty(score)
57+
58+
print("\nGame Over!")
59+
print(f"Your final score: {score}")
60+
if score >= 100:
61+
print("You're a typing master!")
62+
elif score >= 50:
63+
print("Good job! Keep practicing!")
64+
else:
65+
print("Keep trying! You'll get better.")
66+
67+
# Run the game
68+
start_game()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# AI-Powered Typing Game
2+
3+
This is a simple AI-powered typing game written in pure Python. The game challenges players to type words correctly to score points. The difficulty level increases as the score improves, making the game progressively harder.
4+
5+
## How to Play
6+
7+
1. You will be given a word to type, starting at an **Easy** difficulty level.
8+
2. Type the word exactly as shown (case-insensitive) and press Enter.
9+
3. If you type the word correctly, you will score 10 points.
10+
4. The game consists of 10 rounds, and the difficulty will increase as follows:
11+
- **Easy**: 0 - 49 points
12+
- **Medium**: 50 - 99 points
13+
- **Hard**: 100+ points
14+
5. At the end of the game, your final score will be displayed, and you'll get feedback based on your performance.
15+
16+
## Running the game
17+
1. Download the ai-typing.py file.
18+
2. Run the game using the following command:
19+
python ai-typing.py
20+
3. Enjoy playing!
21+
22+
23+
## Game Features
24+
25+
- The game adjusts difficulty dynamically as the player progresses.
26+
- Timed responses show how long it took you to type the word (though it doesn’t affect your score).
27+
- Encouraging feedback at the end of the game based on your total score:
28+
- **100+ points**: Typing master!
29+
- **50 - 99 points**: Good job!
30+
- **0 - 49 points**: Keep practicing!
31+
32+
## Example Gameplay
33+
34+
```bash
35+
Welcome to the AI-Powered Typing Game!
36+
37+
Instructions:
38+
Type the given word correctly to score points.
39+
Difficulty will increase as your score increases.
40+
41+
Round 1: Difficulty Level - Easy
42+
Type this word: cat
43+
Your input: cat
44+
Correct! You took 1.23 seconds.
45+
Your score: 10
46+
47+
Round 2: Difficulty Level - Easy
48+
Type this word: dog
49+
Your input: doog
50+
Incorrect! Try harder next time.
51+
52+
...
53+
54+
Game Over!
55+
Your final score: 70
56+
Good job! Keep practicing!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Python 3.x

Generative AI & LLMs/LLM Copilot Ext for VS Code IDE/package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Generative AI & LLMs/LLM Copilot Ext for VS Code IDE/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"vscode-test": "^1.6.1"
3535
},
3636
"dependencies": {
37-
"axios": "^1.7.3"
37+
"axios": "^1.7.3",
38+
"my-ext": "file:"
3839
}
3940
}

Website/package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Website/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"dotenv": "^16.4.5",
1717
"express": "^4.19.2",
18-
"node-fetch": "^3.3.2"
18+
"node-fetch": "^3.3.2",
19+
"server": "file:"
1920
}
2021
}

0 commit comments

Comments
 (0)