Want to build your own game? Here are 10 ideas from simple to complex, complete with starter code!
1. ๐ฒ Guess the Number
Difficulty: โญ Easy
What you need to know: random, loops, if/else
import random
secret = random.randint(1, 100)
attempts = 0
print('๐ฒ Guess a number between 1 and 100!\n')
while True:
guess = int(input('Your guess: '))
attempts += 1
if guess == secret:
print(f'๐ Got it in {attempts} attempts!')
break
elif guess < secret:
print('โ๏ธ Higher!')
else:
print('โ๏ธ Lower!')
Ideas to extend it:
- Difficulty levels (different ranges)
- Hot/cold hints
- Attempt limit
- High score table
2. โโโ๏ธ Rock-Paper-Scissors
Difficulty: โญ Easy
What you need to know: random, dicts, logic
import random
choices = ['rock', 'scissors', 'paper']
wins = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}
score = {'player': 0, 'computer': 0}
while True:
print(f'\n๐ฎ Score {score["player"]}:{score["computer"]}')
player = input('Your choice (or "quit"): ').lower()
if player == 'quit':
break
if player not in choices:
print('โ Invalid choice!')
continue
computer = random.choice(choices)
print(f'Computer: {computer}')
if player == computer:
print('Draw!')
elif wins[player] == computer:
print('โ
You win!')
score['player'] += 1
else:
print('โ Computer wins!')
score['computer'] += 1
print(f'\nFinal score: {score["player"]}:{score["computer"]}')
Ideas to extend it:
- Add “lizard” and “Spock”
- First to N wins mode
- Choice statistics
3. ๐ค Hangman
Difficulty: โญโญ Medium
What you need to know: strings, lists, sets
import random
words = ['python', 'program', 'computer', 'game', 'code']
word = random.choice(words)
guessed = set()
attempts = 6
print('๐ค HANGMAN\n')
while attempts > 0:
# Show current state
display = ''.join(letter if letter in guessed else '_' for letter in word)
print(f'\nWord: {display}')
print(f'Attempts left: {attempts}')
print(f'Used: {" ".join(sorted(guessed))}')
# Check win
if '_' not in display:
print('\n๐ You win!')
break
# Get letter
letter = input('\nEnter a letter: ').lower()
if len(letter) != 1:
print('โ Enter exactly one letter!')
continue
if letter in guessed:
print('โ ๏ธ Already used!')
continue
guessed.add(letter)
if letter not in word:
attempts -= 1
print('โ Wrong!')
else:
print(f'\n๐ Game over! The word was: {word}')
Ideas to extend it:
- ASCII art gallows
- Different word categories
- Hints
4. ๐ Snake (text version)
Difficulty: โญโญโญ Hard
What you need to know: lists, coordinates, movement logic
import random
import time
import os
# Settings
width, height = 10, 10
snake = [[5, 5], [5, 4], [5, 3]]
direction = 'right'
food = [random.randint(0, width-1), random.randint(0, height-1)]
score = 0
def draw():
os.system('clear' if os.name == 'posix' else 'cls')
print(f'๐ Snake | Score: {score}\n')
for y in range(height):
for x in range(width):
if [x, y] == snake[0]:
print('๐ข', end='')
elif [x, y] in snake:
print('๐ฉ', end='')
elif [x, y] == food:
print('๐', end='')
else:
print('โฌ', end='')
print()
print('\nControls: w/a/s/d or arrow keys')
# Main game loop (simplified demo)
while True:
draw()
# Auto-move (for demo)
head = snake[0].copy()
if direction == 'right':
head[0] += 1
elif direction == 'left':
head[0] -= 1
elif direction == 'up':
head[1] -= 1
elif direction == 'down':
head[1] += 1
# Check bounds
if head[0] < 0 or head[0] >= width or head[1] < 0 or head[1] >= height:
print('๐ Hit the wall!')
break
# Check food
if head == food:
score += 1
food = [random.randint(0, width-1), random.randint(0, height-1)]
else:
snake.pop()
snake.insert(0, head)
time.sleep(0.3)
Ideas to extend it:
- Keyboard controls (keyboard library)
- Different speed levels
- Obstacles
5. ๐ฐ Slot Machine
Difficulty: โญโญ Medium
What you need to know: random, lists, counting
import random
import time
symbols = ['๐', '๐', '๐', '๐', '๐', '7๏ธโฃ']
balance = 100
def spin():
"""Spin the reels"""
return [random.choice(symbols) for _ in range(3)]
def calculate_win(reels):
"""Calculate winnings"""
if reels[0] == reels[1] == reels[2]:
if reels[0] == '๐':
return 50
elif reels[0] == '7๏ธโฃ':
return 30
else:
return 10
elif reels[0] == reels[1] or reels[1] == reels[2]:
return 2
return 0
print('๐ฐ SLOT MACHINE\n')
while balance > 0:
print(f'๐ฐ Balance: {balance} coins')
bet = input('\nBet (or "quit"): ')
if bet == 'quit':
break
bet = int(bet)
if bet > balance:
print('โ Not enough coins!')
continue
balance -= bet
# Animation
for _ in range(5):
reels = spin()
print(f'\r{" ".join(reels)}', end='', flush=True)
time.sleep(0.1)
# Final result
reels = spin()
print(f'\r{" ".join(reels)}')
win = calculate_win(reels) * bet
if win > 0:
print(f'\n๐ You won: {win} coins!')
balance += win
else:
print('\n๐ No luck!')
print(f'\nFinal balance: {balance} coins')
Ideas to extend it:
- Different bet types
- Bonus games
- Progress bars
6. ๐ฏ Bulls and Cows
Difficulty: โญโญ Medium
What you need to know: strings, lists, logic
import random
secret = ''.join(random.sample('0123456789', 4))
attempts = 0
print('๐ฏ BULLS AND COWS')
print('Guess the 4-digit number (no repeated digits)\n')
while True:
guess = input('Your guess: ')
attempts += 1
if len(guess) != 4 or not guess.isdigit():
print('โ Enter exactly 4 digits!')
continue
if guess == secret:
print(f'๐ Correct in {attempts} attempts!')
break
bulls = sum(g == s for g, s in zip(guess, secret))
cows = sum(g in secret for g in guess) - bulls
print(f'๐ Bulls: {bulls}, ๐ Cows: {cows}')
Hint:
- Bull = right digit in the right position
- Cow = right digit in the wrong position
7. ๐ Blackjack (simplified)
Difficulty: โญโญโญ Hard
What you need to know: lists, dicts, game logic
import random
def create_deck():
"""Create a deck"""
values = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
suits = ['โ ','โฅ','โฆ','โฃ']
return [{'value': v, 'suit': s} for v in values for s in suits]
def card_value(card):
"""Value of a card"""
if card['value'] in ['J', 'Q', 'K']:
return 10
elif card['value'] == 'A':
return 11
return int(card['value'])
def hand_value(hand):
"""Total value of a hand"""
total = sum(card_value(card) for card in hand)
aces = sum(1 for card in hand if card['value'] == 'A')
while total > 21 and aces:
total -= 10
aces -= 1
return total
# Game
deck = create_deck()
random.shuffle(deck)
player = [deck.pop(), deck.pop()]
dealer = [deck.pop(), deck.pop()]
print('๐ BLACKJACK\n')
print(f'Your cards: {player[0]["value"]}{player[0]["suit"]} {player[1]["value"]}{player[1]["suit"]} ({hand_value(player)})')
print(f'Dealer shows: {dealer[0]["value"]}{dealer[0]["suit"]}\n')
# Player's turn
while hand_value(player) < 21:
action = input('Hit? (yes/no): ').lower()
if action == 'yes':
card = deck.pop()
player.append(card)
print(f'Dealt: {card["value"]}{card["suit"]}')
print(f'Total: {hand_value(player)}')
else:
break
player_sum = hand_value(player)
dealer_sum = hand_value(dealer)
# Dealer's turn
if player_sum <= 21:
print(f'\nDealer reveals: {dealer[1]["value"]}{dealer[1]["suit"]} ({dealer_sum})')
while dealer_sum < 17:
card = deck.pop()
dealer.append(card)
dealer_sum = hand_value(dealer)
print(f'Dealer draws: {card["value"]}{card["suit"]} ({dealer_sum})')
# Result
print()
if player_sum > 21:
print('๐ Bust! You lose')
elif dealer_sum > 21:
print('๐ Dealer busts! You win!')
elif player_sum > dealer_sum:
print('๐ You win!')
elif player_sum < dealer_sum:
print('๐ You lose')
else:
print('๐ค Push')
8. ๐ Endless Runner (text version)
Difficulty: โญโญโญ Hard
What you need to know: timing, animation, reaction
import random
import time
import sys
score = 0
position = 1
game_over = False
print('๐ ENDLESS RUNNER')
print('Jump with spacebar, dodge obstacles!\n')
time.sleep(2)
while not game_over:
# Generate track
obstacle = random.random() < 0.3
# Display
track = ['_'] * 5
if obstacle:
track[0] = '๐ต'
if position == 1:
track[position] = '๐'
print('\r' + ''.join(track), end='', flush=True)
# Collision check
if obstacle and position == 0:
game_over = True
print('\n๐ Crashed!')
break
score += 1
time.sleep(0.3)
print(f'Score: {score}')
9. ๐งฉ Tic-Tac-Toe with AI
Difficulty: โญโญโญ Hard
What you need to know: 2D lists, minimax (simplified)
board = [[' ' for _ in range(3)] for _ in range(3)]
def print_board():
print('\n 0 1 2')
for i, row in enumerate(board):
print(f'{i} {"|".join(row)}')
if i < 2:
print(' -----')
def check_win(player):
# Check rows and columns
for i in range(3):
if all(board[i][j] == player for j in range(3)):
return True
if all(board[j][i] == player for j in range(3)):
return True
# Diagonals
if all(board[i][i] == player for i in range(3)):
return True
if all(board[i][2-i] == player for i in range(3)):
return True
return False
def ai_move():
# Simple AI โ first empty cell
for i in range(3):
for j in range(3):
if board[i][j] == ' ':
board[i][j] = 'O'
return
# Game
print('โโญ TIC-TAC-TOE')
for turn in range(9):
print_board()
if turn % 2 == 0:
# Player's turn
row = int(input('\nYour move, row: '))
col = int(input('Column: '))
if board[row][col] == ' ':
board[row][col] = 'X'
else:
print('Already taken!')
continue
if check_win('X'):
print_board()
print('\n๐ You win!')
break
else:
# AI's turn
ai_move()
print('\nComputer moves')
if check_win('O'):
print_board()
print('\n๐ Computer wins!')
break
else:
print_board()
print('\n๐ค Draw!')
10. ๐ฒ Text RPG
Difficulty: โญโญโญโญ Very Hard
What you need to know: classes, dicts, game logic
import random
class Player:
def __init__(self, name):
self.name = name
self.hp = 100
self.gold = 0
self.inventory = []
def is_alive(self):
return self.hp > 0
class Enemy:
def __init__(self, name, hp, damage, gold):
self.name = name
self.hp = hp
self.damage = damage
self.gold = gold
# Enemies
enemies = [
Enemy('Slime', 20, 5, 10),
Enemy('Goblin', 40, 10, 25),
Enemy('Orc', 60, 15, 50),
Enemy('Dragon', 100, 25, 100)
]
# Game
player = Player(input('Your name: '))
print(f'\nWelcome, {player.name}!\n')
while player.is_alive():
print(f'HP: {player.hp} | Gold: {player.gold}')
print('\n1. Search for enemies')
print('2. Rest (+20 HP)')
print('3. Quit')
choice = input('\nAction: ')
if choice == '1':
enemy = random.choice(enemies)
print(f'\nโ๏ธ Encountered: {enemy.name}!')
while enemy.hp > 0 and player.is_alive():
action = input('\n[a]ttack / [r]un: ').lower()
if action == 'a':
damage = random.randint(10, 20)
enemy.hp -= damage
print(f'Dealt {damage} damage!')
if enemy.hp > 0:
player.hp -= enemy.damage
print(f'{enemy.name} dealt {enemy.damage} damage!')
else:
print('You ran away!')
break
if enemy.hp <= 0:
print(f'\n๐ Defeated {enemy.name}!')
player.gold += enemy.gold
print(f'Received {enemy.gold} gold')
elif choice == '2':
player.hp = min(player.hp + 20, 100)
print('Rested (+20 HP)')
elif choice == '3':
break
print(f'\nGame over! Gold collected: {player.gold}')
๐ Tips
- Start simple โ don’t try to build a complex game right away
- Test often โ after every new feature
- Add incrementally โ nail the core mechanic first, then improve
- Play your own game โ best way to find bugs
- Let friends play โ they’ll find things you missed
๐ What’s next?
After text games, try:
- Pygame โ 2D games with graphics
- Turtle โ simple graphics library
- Tkinter โ GUI for your games
Build games and level up your coding skills! ๐ฎ
๐ฌ Comments (0)
No comments yet
Be the first to share your opinion about this article!