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,sys | |
import random | |
# Initialize Pygame | |
pygame.init() | |
# Set up the game window | |
WINDOW_WIDTH = 800 | |
WINDOW_HEIGHT = 600 | |
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) |
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
# Virtual reality game in Ruby | |
# Define the game map | |
GAME_MAP = { | |
"room1" => { "name" => "Room 1", "description" => "You are in a dimly lit room. There is a door to the east.", "east" => "room2" }, | |
"room2" => { "name" => "Room 2", "description" => "You are in a hallway. There are doors to the north and south.", "north" => "room3", "south" => "room1" }, | |
"room3" => { "name" => "Room 3", "description" => "You are in a bright room. There is a door to the south.", "south" => "room2" } | |
} | |
# Define the player class |
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
# Simon Says game in Ruby | |
# Define an array of valid Simon Says commands | |
SIMON_SAYS_COMMANDS = ["simon says", "Simon says", "SIMON SAYS"] | |
# Define the game function | |
def play_simon_says(num_rounds) | |
puts "Welcome to Simon Says!" | |
# Loop through the specified number of rounds |
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
# Monster battle game in Ruby | |
class Monster | |
attr_accessor :name, :health, :attack | |
def initialize(name, health, attack) | |
@name = name | |
@health = health | |
@attack = attack | |
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
# Tower of Hanoi game in Ruby | |
def tower_of_hanoi(num_disks, from_rod, to_rod, aux_rod) | |
if num_disks == 1 | |
puts "Move disk 1 from #{from_rod} to #{to_rod}" | |
return | |
end | |
tower_of_hanoi(num_disks-1, from_rod, aux_rod, to_rod) | |
puts "Move disk #{num_disks} from #{from_rod} to #{to_rod}" |
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 Animal | |
attr_accessor :name, :species, :age | |
def initialize(name, species, age) | |
@name = name | |
@species = species | |
@age = age | |
end | |
def info |
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 WhacAMole | |
attr_reader :score | |
def initialize(num_holes) | |
@num_holes = num_holes | |
@holes = Array.new(num_holes) { Hole.new } | |
@score = 0 | |
end | |
def start |
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 Team | |
attr_accessor :name, :players | |
def initialize(name) | |
@name = name | |
@players = [] | |
end | |
def add_player(player) | |
@players << player |
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 | |
# Define Crop class | |
class Crop: | |
def __init__(self, name, growth_rate, water_need, light_need): | |
self.name = name | |
self.growth_rate = growth_rate | |
self.water_need = water_need | |
self.light_need = light_need | |
self.age = 0 |
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 Crop class | |
class Crop | |
attr_reader :name, :growth_rate, :water_need, :light_need | |
def initialize(name, growth_rate, water_need, light_need) | |
@name = name | |
@growth_rate = growth_rate | |
@water_need = water_need | |
@light_need = light_need | |
@age = 0 |