Skip to content

Instantly share code, notes, and snippets.

View R3DHULK's full-sized avatar
🏠
Working from home

Sumalya Chatterjee R3DHULK

🏠
Working from home
View GitHub Profile
@R3DHULK
R3DHULK / survival-game.rb
Created March 28, 2023 09:46
Survival Game Written In Ruby
# Define player class
class Player
attr_accessor :health, :hunger, :thirst, :location
def initialize(location)
@health = 100
@hunger = 0
@thirst = 0
@location = location
end
@R3DHULK
R3DHULK / memorygame.rb
Created March 28, 2023 09:33
Mmeory Game Written In Ruby
# 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
@R3DHULK
R3DHULK / rock-paper-scissor.rb
Created March 28, 2023 06:06
Rock Paper Scissor In Ruby
# 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
@R3DHULK
R3DHULK / minesweeper.rb
Created March 28, 2023 05:44
Minesweeper Written In Ruby
# 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
@R3DHULK
R3DHULK / detective-game.rb
Created March 27, 2023 18:33
Detective Game Written In Ruby
# 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
@R3DHULK
R3DHULK / virtual-pet-game.rb
Created March 27, 2023 18:30
Virtual Pet Game In Ruby
class Pet
attr_accessor :name, :hunger, :happiness
def initialize(name)
@name = name
@hunger = 0
@happiness = 5
end
def feed
@R3DHULK
R3DHULK / asteroid.py
Created March 27, 2023 18:19
Asteroid game in python
import pygame
import random
# initialize pygame
pygame.init()
# game constants
WIDTH = 800
HEIGHT = 600
FPS = 60
@R3DHULK
R3DHULK / asteroid.rb
Created March 27, 2023 18:16
Asteroid Game In Ruby
# define constants
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 20
SHIP_CHAR = '^'
BULLET_CHAR = '|'
ASTEROID_CHAR = '*'
# define variables
ship_x = SCREEN_WIDTH / 2
bullet_x = nil
@R3DHULK
R3DHULK / mastermind.rb
Created March 27, 2023 18:03
Mastermind Game Written In Ruby
# 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
@R3DHULK
R3DHULK / city-building-game.py
Created March 27, 2023 17:49
City Building Game In Python
import random
# initialize variables
money = 1000
population = 10
city_name = ""
buildings = []
# define functions
def display_menu():