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 | |
import time | |
def simon_says(): | |
# Define the colors | |
colors = ["red", "green", "blue", "yellow"] | |
# Keep track of the sequence | |
sequence = [] |
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 tkinter as tk | |
class TicTacToe: | |
def __init__(self): | |
self.board = [" "] * 9 | |
self.players = ["X", "O"] | |
self.current_player = 0 | |
self.game_over = False | |
self.root = tk.Tk() |
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
def print_board(board): | |
print(" " + board[0] + " | " + board[1] + " | " + board[2]) | |
print("---|---|---") | |
print(" " + board[3] + " | " + board[4] + " | " + board[5]) | |
print("---|---|---") | |
print(" " + board[6] + " | " + board[7] + " | " + board[8]) | |
def check_win(board): | |
# Check rows | |
for i in range(0, 9, 3): |
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
# Roller Coaster Simulator | |
# Define track | |
track <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) | |
# Define cart position and speed | |
cart_pos <- 0 | |
cart_speed <- 0 | |
# Define game loop |
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
# Set up initial game parameters | |
player_distance <- 0 | |
obstacle_distance <- 20 | |
game_over <- FALSE | |
# Define functions for game mechanics | |
move_player <- function(distance) { | |
player_distance <<- player_distance + distance | |
cat(sprintf("You ran %d meters.\n", distance)) | |
} |
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
# Set up initial island parameters | |
water_level <- 10 | |
coconut_trees <- 20 | |
coconuts <- sample(5:15, coconut_trees, replace = TRUE) | |
player_hunger <- 0 | |
player_health <- 5 | |
# Define functions for game mechanics | |
grow_coconuts <- function() { | |
coconuts <<- coconuts + rnorm(coconut_trees, mean = 0.5, sd = 0.2) |
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
# Set up initial desert parameters | |
water_level <- 10 | |
cactus_plants <- 20 | |
cactus_heights <- sample(5:15, cactus_plants, replace = TRUE) | |
player_hunger <- 0 | |
player_health <- 5 | |
# Define functions for game mechanics | |
grow_cacti <- function() { | |
cactus_heights <<- cactus_heights + rnorm(cactus_plants, mean = 0.5, sd = 0.2) |
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
# Set up initial forest parameters | |
num_trees <- 50 | |
tree_heights <- sample(10:30, num_trees, replace = TRUE) | |
tree_health <- sample(1:5, num_trees, replace = TRUE) | |
player_hunger <- 0 | |
player_health <- 5 | |
# Define functions for game mechanics | |
grow_trees <- function() { | |
tree_heights <<- tree_heights + rnorm(num_trees, mean = 0.5, sd = 0.2) |
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
# Set up initial forest parameters | |
num_trees <- 50 | |
tree_heights <- sample(10:30, num_trees, replace = TRUE) | |
tree_health <- sample(1:5, num_trees, replace = TRUE) | |
# Define functions for game mechanics | |
grow_trees <- function() { | |
tree_heights <<- tree_heights + rnorm(num_trees, mean = 0.5, sd = 0.2) | |
tree_heights[tree_heights < 0] <<- 0 # make sure heights don't go below zero | |
} |
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 the wrestlers | |
wrestler1 <- list(name = "Yokozuna", strength = 8, agility = 5, stamina = 6) | |
wrestler2 <- list(name = "Mongolian Giant", strength = 9, agility = 4, stamina = 5) | |
# Define the match settings | |
rounds <- 3 | |
winning_rounds <- ceiling(rounds / 2) | |
# Define the function to simulate a round of the match | |
simulate_round <- function(wrestler1, wrestler2) { |