This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define player class | |
class Player | |
attr_accessor :health, :hunger, :thirst, :location | |
def initialize(location) | |
@health = 100 | |
@hunger = 0 | |
@thirst = 0 | |
@location = location | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define game loop | |
loop do | |
# Generate shuffled deck of cards | |
cards = ("A".."Z").to_a.sample(8) * 2 | |
cards.shuffle! | |
# Initialize game board | |
board = Array.new(4) { Array.new(4) { " " } } | |
# Define method to print board |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define game loop | |
loop do | |
# Prompt user to select rock, paper, or scissors | |
print "Choose rock (r), paper (p), or scissors (s): " | |
user_choice = gets.chomp.downcase | |
# Generate random computer choice | |
computer_choice = ["r", "p", "s"].sample | |
# Determine winner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define Minesweeper game board | |
board_size = 9 | |
num_mines = 10 | |
board = Array.new(board_size) { Array.new(board_size, 0) } | |
# Place mines randomly on the board | |
num_mines.times do | |
x, y = rand(board_size), rand(board_size) | |
board[x][y] = "X" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define clues for the detective game | |
clues = [ | |
{ suspect: "John", location: "Library", weapon: "Knife" }, | |
{ suspect: "Sarah", location: "Kitchen", weapon: "Poison" }, | |
{ suspect: "David", location: "Living Room", weapon: "Rope" } | |
] | |
# Select a random culprit and generate a case file | |
case_file = clues.sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pet | |
attr_accessor :name, :hunger, :happiness | |
def initialize(name) | |
@name = name | |
@hunger = 0 | |
@happiness = 5 | |
end | |
def feed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import random | |
# initialize pygame | |
pygame.init() | |
# game constants | |
WIDTH = 800 | |
HEIGHT = 600 | |
FPS = 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define constants | |
SCREEN_WIDTH = 80 | |
SCREEN_HEIGHT = 20 | |
SHIP_CHAR = '^' | |
BULLET_CHAR = '|' | |
ASTEROID_CHAR = '*' | |
# define variables | |
ship_x = SCREEN_WIDTH / 2 | |
bullet_x = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define variables | |
secret_code = [] | |
guess = [] | |
guess_count = 0 | |
max_guesses = 12 | |
colors = ['red', 'green', 'blue', 'yellow', 'orange', 'purple'] | |
# generate secret code | |
4.times do | |
secret_code << colors.sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
# initialize variables | |
money = 1000 | |
population = 10 | |
city_name = "" | |
buildings = [] | |
# define functions | |
def display_menu(): |