Long time user, first time asker. Just started using pygame and need some help as right now, my game isn't working as there seems to be a problem with the program choosing a gradient for the ball, and the ball now seems to go in a straight line across the x axis. The code is below, thanks in advance for any help
from pygame import *
import time
import random
init()
width = 1000
height = 1000
screen = display.set_mode((width,height))
display.set_caption('Graphics')
ball1 = Rect(10,10,40,40)
ball1dx = 2
ball1dy = 3
ball2 = Rect(500,500,40,40)
gradient = [-0.25,-0.5,-0.75,-1]
ran = 0
endProgram = False
a = 0
d = 0
w = 0
s = 0
while not endProgram:
for e in event.get():
if e.type == KEYUP:
if (e.key == K_a):
a = True
d = False
w = False
s = False
if (e.key == K_d):
d = True
a = False
w = False
s = False
if (e.key == K_w):
w = True
a = False
d = False
s = False
if (e.key == K_s):
s = True
a = False
d = False
w = False
if a:
ball2.x -= 1
if d:
ball2.x += 1
if w:
ball2.y -= 1
if s:
ball2.y += 1
ball1.move_ip(ball1dx,ball1dy)
if ball1.y < 0 or ball1.y > height - 40:
ran = random.random()
ball1dy *= random.choice(gradient)
if ball1.x < 0 or ball1.x > width - 40:
ran = random.random()
ball1dx *= random.choice(gradient)
screen.fill((0,0,200))
draw.ellipse(screen, (0,255,0), ball1)
draw.ellipse(screen, (255,0,0),ball2)
display.update()
I don't know what you were expecting but if you keep multiplying a number by a fraction between 1 and 0 you will start to approach 0 and essentially get 0. If you add a print statement after you pick the gradient you will see that your number is quickly heading towards zero.
-1.5
-0.5
0.5
-0.375
0.28125
-0.2109375
0.158203125
-0.0791015625
0.059326171875
-0.0296630859375
0.0222473144531
-0.0111236572266
.
.
.
-1.28840161923e-281
6.44200809614e-282
-3.22100404807e-282
3.22100404807e-282
I'm assuming you are just trying to get the ball to bounce around screen which you can do by just multiplying by -1. If you want variable speed while bouncing you will have to set up a range for min and max speed and only multiply by your gradient if it doesn't exceed those boundaries. You could do it like this
ball1.move_ip(ball1dx,ball1dy)
if ball1.y < 0 or ball1.y > height - 40:
choice = random.choice(gradient)
if abs(ball1dy*choice) < 5 and abs(ball1dy*choice) > 0.25:
ball1dy *= choice
else:
ball1dy*=-1
if ball1.x < 0 or ball1.x > width - 40:
choice = random.choice(gradient)
if abs(ball1dx*choice) < 5 and abs(ball1dx*choice) > 0.25:
ball1dx *= choice
else:
ball1dx*=-1
As a side note you can condense your if statements by changing them all to False right before the ifs and then only switching one to True like so
for e in event.get():
if e.type == KEYUP:
w = False
a = False
s = False
d = False
if (e.key == K_a):
a = True
if (e.key == K_d):
d = True
if (e.key == K_w):
w = True
if (e.key == K_s):
s = True
Related
I'm making a Flappy Bird clone.
I'm still kinda new to Pygame. I have watched a tutorial about json saving (as you can see). I've tried to make everything work, which it is, but I'm having trouble figuring out how to save the high score value still.
The tutorial shown was on a clicker game. I followed along, but a clicker game is different to saving a high score on a Flappy Bird clone and displaying it. I've tried to do what the tutorial says about displaying the amount saved, but it didn't work.
The code:
import pygame, sys, random
import json
def draw_floor():
screen.blit(floor_surface,(floor_x_pos,900))
screen.blit(floor_surface,(floor_x_pos + 576,900))
def create_pipe():
random_pipe_pos = random.choice(pipe_height)
bottom_pipe = pipe_surface.get_rect(midtop = (584,random_pipe_pos))
top_pipe = pipe_surface.get_rect(midbottom = (584,random_pipe_pos -300))
return bottom_pipe,top_pipe
def move_pipes(pipes):
for pipe in pipes:
pipe.centerx -= 5
visible_pipes = [pipe for pipe in pipes if pipe.right > -50]
return visible_pipes
def draw_pipes(pipes):
for pipe in pipes:
if pipe.bottom >= 1024:
screen.blit(pipe_surface,pipe)
else:
flip_pipe = pygame.transform.flip(pipe_surface,False,True)
screen.blit(flip_pipe,pipe)
def check_collision(pipes):
global can_score
for pipe in pipes:
if bird_rect.colliderect(pipe):
hit_sound.play()
can_score = True
return False
if bird_rect.top <= -100 or bird_rect.bottom >= 900:
can_score = True
hit_sound.play()
return False
return True
def rotate_bird(bird):
new_bird = pygame.transform.rotozoom(bird,-bird_movement * 3,1)
return new_bird
def bird_animation():
new_bird = bird_frames[bird_index]
new_bird_rect = new_bird.get_rect(center = (100,bird_rect.centery))
return new_bird,new_bird_rect
# Data
data = {
'highscore': 0
}
try:
with open('highscore.txt') as highscore_file:
data = json.load(highscore_file)
except:
print('No file')
def score_display(game_state):
if game_state == 'main_game':
score_surface = game_font.render(str(int(score)),True,(255,255,255))
score_rect = score_surface.get_rect(center = (288,100))
screen.blit(score_surface,score_rect)
if game_state == 'game_over':
score_surface = game_font.render(f'Score: {int(score)}',True,(255,255,255))
score_rect = score_surface.get_rect(center = (288,100))
screen.blit(score_surface,score_rect)
high_score_surface = game_font.render(f'High score: {int(high_score)}',True,(255,255,255))
high_score_rect = high_score_surface.get_rect(center = (288,850))
screen.blit(high_score_surface,high_score_rect)
def update_score(score,high_score):
if score > high_score:
high_score = score
return high_score
def pipe_score_check():
global score, can_score
if pipe_list:
for pipe in pipe_list:
if 95 < pipe.centerx < 105 and can_score:
score += 1
point_sound.play()
can_score = False
if pipe.centerx < 0:
can_score = True
# pygame.mixer.pre_init(frequency = 44100, size = 16, channels = 1, buffer = 512)
pygame.init()
screen = pygame.display.set_mode((576,1024))
clock = pygame.time.Clock()
game_font = pygame.font.Font('04B_19.ttf',40)
# Variables
gravity = 0.25
bird_movement = 0
game_active = True
score = 0
high_score = 0
can_score = True
# Loading images
bg_surface = pygame.image.load('assets/background-day.png').convert()
bg_surface = pygame.transform.scale2x(bg_surface)
floor_surface = pygame.image.load('assets/base.png').convert()
floor_surface = pygame.transform.scale2x(floor_surface)
floor_x_pos = 0
bird_downflap = pygame.transform.scale2x(pygame.image.load('assets/yellowbird-downflap.png').convert_alpha())
bird_midflap = pygame.transform.scale2x(pygame.image.load('assets/yellowbird-midflap.png').convert_alpha())
bird_upflap = pygame.transform.scale2x(pygame.image.load('assets/yellowbird-upflap.png').convert_alpha())
bird_frames = [bird_downflap,bird_midflap,bird_upflap]
bird_index = 0
bird_surface = bird_frames[bird_index]
bird_rect = bird_surface.get_rect(center = (100,512))
BIRDFLAP = pygame.USEREVENT + 1
pygame.time.set_timer(BIRDFLAP,200)
# bird_surface = pygame.image.load('assets/yellowbird-midflap.png').convert_alpha()
# bird_surface = pygame.transform.scale2x(bird_surface)
# bird_rect = bird_surface.get_rect(center = (100,512))
pipe_surface = pygame.image.load('assets/pipe-green.png').convert()
pipe_surface = pygame.transform.scale2x(pipe_surface)
pipe_list = []
SPAWNPIPE = pygame.USEREVENT
pygame.time.set_timer(SPAWNPIPE,1500)
pipe_height = [400,600,800]
game_over_surface = pygame.transform.scale2x(pygame.image.load('assets/message.png').convert_alpha())
game_over_rect = game_over_surface.get_rect(center = (288,512))
# Sounds
flap_sound = pygame.mixer.Sound('sound/sfx_wing.wav')
hit_sound = pygame.mixer.Sound('sound/sfx_hit.wav')
point_sound = pygame.mixer.Sound('sound/sfx_point.wav')
countdown_sound_score = 100
# Event loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
with open('highscore.txt','w') as highscore_file:
json.dump(data,highscore_file)
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_movement = 0
bird_movement -= 12
flap_sound.play()
if event.key == pygame.K_SPACE and game_active == False:
game_active = True
pipe_list.clear()
bird_rect.center = (100,512)
bird_movement = 0
score = 0
if event.type == SPAWNPIPE:
pipe_list.extend(create_pipe())
if event.type == BIRDFLAP:
if bird_index < 2:
bird_index += 1
else:
bird_index = 0
bird_surface,bird_rect = bird_animation()
# Pasting background image
screen.blit(bg_surface,(0,0))
if game_active:
# Bird movement and pasting bird
bird_movement += gravity
rotated_bird = rotate_bird(bird_surface)
bird_rect.centery += bird_movement
screen.blit(rotated_bird,bird_rect)
game_active = check_collision(pipe_list)
# Pipes
pipe_list = move_pipes(pipe_list)
draw_pipes(pipe_list)
# Score
pipe_score_check()
score_display('main_game')
else:
screen.blit(game_over_surface,game_over_rect)
high_score = update_score(score,high_score)
score_display('game_over')
# Floor movement and pasting floor image
floor_x_pos -= 1
draw_floor()
if floor_x_pos <=-576:
floor_x_pos = 0
pygame.display.update()
clock.tick(120)
You have to initialize the highscore variable with the data from the dictionary:
data = { 'highscore': 0 }
try:
with open('highscore.txt') as highscore_file:
data = json.load(highscore_file)
except:
print('No file')
high_score = 0
high_score = data.get('highscore', 0)
And you must create a dictionary with the new high score before writing the dictionary to the JSON file
if score > highscore:
with open('highscore.txt','w') as highscore_file:
data = { 'highscore': score }
json.dump(data, highscore_file)
I'm trying to create a collision detection between 4 controllable characters on an RPG battle map. Here is the function I'm using
def player_collission(Lord_x,Lord_y,Journeyman_x,Journeyman_y,Archer_x,Archer_y,
Cleric_x,Cleric_y):
print("Running")
if abs(Lord_x - Journeyman_x) <= 0 and abs(Lord_y - Journeyman_y) <= 0:
print("Colission detected")
return True
elif abs(Lord_x - Archer_x) <= 0 and abs(Lord_y - Archer_y) <= 0:
print("Colission detected")
return True
elif abs(Lord_x - Cleric_x) <= 0 and abs(Lord_y == Cleric_y) <= 0:
print("Colission detected")
return True
elif abs(Journeyman_x - Archer_x) <= 0 and abs(Journeyman_y - Archer_y) <= 0:
print("Colission detected")
return True
elif abs(Journeyman_x - Cleric_x) <= 0 and abs(Journeyman_y - Cleric_y) <= 0:
print("Colission detected")
return True
elif abs(Archer_x - Cleric_x) <= 0 and abs(Archer_y == Cleric_y) <= 0:
print("Colission detected")
return True
else:
return False #I didnt use classes so it has alot of if statements
if player_up:
p_collide = player_collission(Lord_x,Lord_y,Journeyman_x,Journeyman_y,Archer_x,Archer_y,
Cleric_x,Cleric_y)
if current_player == "lord":
if p_collide != True:
Lord_y -= tile_increment
if Lord_y <= 0:
Lord_y = 50
What happens is that the characters still move into each other but it detects the collision after it has already moved into each other and freezes all movement. I'm not sure how to re arrange it to make it work properly.
You detect collision when it has already happened. This is why you see characters overlapping.
Instead, you should detect if a collision is going to happen, an prevent a motion that would lead to that.
An example:
def move(coords, velocity):
"""Moves coords according to velocity."""
x, y = coords # Unpack a 2-tuple.
vx, vy = velocity
return (x + vx, y + vy)
tom_coords = (0, 0) # Tom is in the corner.
tom_v = (1, 1) # Tom moves by diagonal.
jerry_coords = (5, 0) # Jerry is a bit away from Tom.
jerry_v = (0, 1) # Jerry moves vertically.
while True:
new_tom_coords = move(tom_coords, tom_v) # Tom moves without fear.
new_jerry_coords = move(jerry_coords, jerry_v)
if new_jerry_coords == new_tom_coords: # Would be a collision!
new_jerry_coords = jerry_coords # Back to previous tile.
vx, vy = jerry_v
jerry_v = (-vx, -vy) # Jerry runs back.
print("Collision imminent, Jerry runs away!")
else:
jerry_coords = new_jerry_coords # Only update if no collision.
# Could also check collisions with walls, etc.
tom_coords = new_tom_coords
# Not inside pygame, so just print it and wait for a key press.
print('Tom:', tom_coords, 'Jerry:', jerry_coords)
input("Enter to continue, Ctrl+C to stop ")
Run it in and see how Tom and Jerry come close to each other but never occupy the same tile.
At the moment, I managed to code, successfully, a simulation for a work that I need to do. However, I'm fairly new to python. And so, I'm now in the process of making the simulation more efficient.
For instance:
if random.random() < mm:
z = numpy.random.choice(pat)
if random.random() < 0.5:
if random.random() < mut:
if maleadult[z][0] == 0:
malejuv[y][x][0] = 1
elif maleadult[z][0] == 1:
malejuv[y][x][0] = 0
else:
malejuv[y][x][0] = maleadult[z][0]
else:
if random.random() < mut:
if femaleadult[z][0] == 0:
malejuv[y][x][0] = 1
elif femaleadult[z][0] == 1:
malejuv[y][x][0] = 0
else:
malejuv[y][x][0] = femaleadult[z][0]
if random.random() < 0.5:
if random.random() < mut:
if maleadult[z][1] == 0:
malejuv[y][x][1] = 1
elif maleadult[z][1] == 1:
malejuv[y][x][1] = 0
else:
malejuv[y][x][1] = maleadult[z][1]
else:
if random.random() < mut:
if femaleadult[z][1] == 0:
malejuv[y][x][1] = 1
elif femaleadult[z][1] == 1:
malejuv[y][x][1] = 0
else:
malejuv[y][x][1] = femaleadult[z][0]
where:
mm - male dispersal,
mf - female dispersal,
mut - mutations,
pat - patch,
maleadult - adult male,
femaleadult - adult female,
malejuv - juvenile male,
femalejuv - juvenile female.
As you can see, the code is big. And this is only for males and when they disperse. The rest of the code is very similar. These are standard genetic and demographic processes - but I feel like this can be improved. I feel like these processes are simple enough, so maybe code as big as this is not necessary.
Does anyone have any ideas to shorten this and, by consequence, making it more efficient?
Your example does not have any loops but it looks like it could be simplified by one:
if random.random() < mm:
z = numpy.random.choice(pat)
for i in range(2):
if random.random() < 0.5:
if random.random() < mut:
if maleadult[z][i] == 0:
malejuv[y][x][i] = 1
elif maleadult[z][i] == 1:
malejuv[y][x][i] = 0
else:
malejuv[y][x][i] = maleadult[z][i]
else:
if random.random() < mut:
if femaleadult[z][i] == 0:
malejuv[y][x][i] = 1
elif femaleadult[z][i] == 1:
malejuv[y][x][i] = 0
else:
malejuv[y][x][i] = femaleadult[z][i]
It is also possible to pass a mutable object as reference to a function which can modify it, which allows further reduction of almost redundant code. I've added some data to test it:
#!python3
#coding=utf-8
import random
maleadult = [[["male adult"], ["another male adult"], ]]
femaleadult = [[["female adult"], ["another female adult"], ]]
malejuv = [[[["male juv"],["another male juv"]]]]
mut = 0.5
mm = 1.0
x = 0
y = 0
z = 0
def some_logic(a, j):
""" does something """
if random.random() < mut:
if a[z][i] == 0:
j[y][x][i] = 1
elif a[z][i] == 1:
j[y][x][i] = 0
# added!
else:
j[y][x][i] = 0
else:
j[y][x][i] = a[z][i]
if random.random() < mm:
z = 0 #numpy.random.choice(pat)
for i in range(2):
print(i)
if random.random() < 0.5:
some_logic(maleadult, malejuv)
else:
some_logic(femaleadult, malejuv)
print(maleadult)
print(malejuv)
print(femaleadult)
I'm trying to approximate pi using a monte carlo with turtles in python. The code is running well but I've got a problem, my "approximations" are all terribly wrong. I' always get values smaller than 1 so??? My code is here below
import turtle
import math
import random
fred = turtle.Turtle()
fred.speed(0)
fred.up()
wn = turtle.Screen()
wn.setworldcoordinates(-1,-1,1,1)
numdarts = int(input("How many darts will you throw"))
for i in range(numdarts):
x = random.random()
y = random.random()
numIncircle = 0
if i == 0 or i == 1:
fred.up()
fred.goto(x, y)
if fred.distance(0, 0) <= 1:
numIncircle += 1
fred.color("Indianred")
fred.stamp()
fred.up()
else:
numIncircle += 0
fred.color("cyan")
fred.stamp()
fred.up()
else:
fred.goto(x, y)
if fred.distance(0, 0) <= 1:
numIncircle += 1
fred.color("Indianred")
fred.stamp()
fred.up()
else:
numIncircle += 0
fred.color("cyan")
fred.stamp()
fred.up()
piapproximation = float(float(numIncircle) / float(numdarts)) * 4
print piapproximation
wn.exitonclick()
You're setting numIncircle = 0 inside your for loop, effectively losing count each time.
Occasionally it'll count the last one, so the approximation will be 1 / number of darts * 4. This will happen with frequency pi / 4 ≈ 0.78539816339.
Here is my suggestion:
import turtle
import math
import random
fred = turtle.Turtle()
fred.speed(0)
fred.up()
wn = turtle.Screen()
wn.setworldcoordinates(-1,-1,1,1)
numdarts = int(input("How many darts will you throw"))
// this MUST come before the for loop
numIncircle = 0
for i in range(numdarts):
x = random.random() * 2 - 1
y = random.random() * 2 - 1
if i == 0 or i == 1:
fred.up()
fred.goto(x, y)
if fred.distance(0, 0) <= 1:
numIncircle += 1
fred.color("Indianred")
fred.stamp()
fred.up()
else:
numIncircle += 0
fred.color("cyan")
fred.stamp()
fred.up()
else:
fred.goto(x, y)
if fred.distance(0, 0) <= 1:
numIncircle += 1
fred.color("Indianred")
fred.stamp()
fred.up()
else:
numIncircle += 0
fred.color("cyan")
fred.stamp()
fred.up()
piapproximation = float(float(numIncircle) / float(numdarts)) * 4
print piapproximation
wn.exitonclick()
How do I change the picture and 3 answering options after clicking on one of them. My code already checks if the answer is true or false but I can't seem to find how to put on a new picture and new answer options after I have clicked one of them.
import os, sys
import math
from pygame import *
from random import *
init()
must = [0,0,0]
suurus = [1000,600]
screen = display.set_mode(suurus)
screen.fill(must)
punktid = 1
samblikud=[]
vastused=[]
#pildid = {"samblik1.jpg":"vaguapiksamblik","samblik2.jpg":"alpipõdrasamblik"}
for i in range(7):
pilt = image.load("samblik"+str(i+1)+".jpg")
samblikud.append(pilt)
for i in range(7):
pilt = image.load("vastus"+str(i+1)+".jpg")
vastused.append(pilt)
jargmine = image.load("jargmine.jpg")
s = randint(0,6) #pildi number
nr = {} #sõnastik, kuhu valime kolm vastusevarianti
nr[s]=1 #samblik
vo = True
to = True
while (vo == True) or (to == True):
v = randint(0,6)#vastusevariandi nr
t = randint(0,6)
if v in nr:
v = randint(0,6) #kui olemas genereerib uue
else:
nr[v]=0
vo = False
if t in nr: #kui t on olemas
t = randint(0,6)
else:
nr[t]=0
to = False
var=[]
for key in nr:
var.append(key)
o = [] #milline õige, kui väärtus on 1
for key in nr:
if nr[key] == 1:
o.append(key)
print(var)
print(nr)
def joonista():
screen.fill(must)
screen.blit(samblikud[o[0]],[0,0]) #samblik
screen.blit(vastused[var[0]], [500,100])
screen.blit(vastused[var[1]], [500,200])
screen.blit(vastused[var[2]], [500,300])
screen.blit(jargmine, [500, 500])
display.flip()
def kysimus():
teksti_font = font.Font(None,25)
tekst1_pildina = teksti_font.render('Milline samblik on pildil?',1,[0,255,0])
tekst1_raam = tekst1_pildina.get_rect()
screen.blit(tekst1_pildina,(500,50))
tekst2_pildina = teksti_font.render('Vastamiseks vajuta õigel vastusel.',1,[0,255,0])
tekst2_raam = tekst2_pildina.get_rect()
screen.blit(tekst2_pildina,(500,75))
display.flip()
x_v=347#vastuse kasti x suurus
y_v=81#vastuse kasti y suurus
def kontrolli():
while True:
if var[0]==o[0]:
y_o = 100 #õige vastuse koordi
y_w1 = 200
y_w2 = 300
elif var[1]==o[0]:
y_o = 200
y_w1 = 100
y_w2 = 300
elif var[2]==o[0]:
y_o = 300
y_w1 = 200
y_w2 = 100
for i in event.get():
if i.type == QUIT:
sys.exit()
if i.type == MOUSEBUTTONDOWN:
x, y = i.pos
# Check to see if the click is in the range we want
if ( x in range(500,500+x_v)) and (y in range(y_o,y_o+y_v)):
# Grab the next image,
next_image = image.load('oige_v.png') #õige vastuse kuvamine
screen.blit(next_image, (500,y_o)) #uus pilt
punktid = punktid + 1
display.flip()
elif (x in range(500,500+x_v)) and (y in range(y_w1,y_w1+y_v)):
next_image = image.load('vale_v.png')
screen.blit(next_image, (500,y_w1)) # vale vastus
display.flip()
elif (x in range(500,500+x_v)) and (y in range(y_w2,y_w2+y_v)):
next_image = image.load('vale_v.png')
screen.blit(next_image, (500,y_w2)) #vale vastus
display.flip()
elif (x in range(500,500+x_v)) and (y in range(500,500+y_v)):
break
while True:
for i in range(punktid):
joonista()
kysimus()
#joonista()
#kysimus()
while True:
if var[0]==o[0]:
y_o = 100
y_w1 = 200
y_w2 = 300
elif var[1]==o[0]:
y_o = 200
y_w1 = 100
y_w2 = 300
elif var[2]==o[0]:
y_o = 300
y_w1 = 200
y_w2 = 100
for i in event.get():
if i.type == QUIT:
sys.exit()
if i.type == MOUSEBUTTONDOWN:
x, y = i.pos
# Check to see if the click is in the range we want
if ( x in range(500,500+x_v)) and (y in range(y_o,y_o+y_v)):
# Grab the next image,
next_image = image.load('oige_v.png') #õige vastuse kuvamine
screen.blit(next_image, (500,y_o)) #uus pilt
punktid = punktid + 1
display.flip()
elif (x in range(500,500+x_v)) and (y in range(y_w1,y_w1+y_v)):
next_image = image.load('vale_v.png')
screen.blit(next_image, (500,y_w1)) # vale vastus
display.flip()
elif (x in range(500,500+x_v)) and (y in range(y_w2,y_w2+y_v)):
next_image = image.load('vale_v.png')
screen.blit(next_image, (500,y_w2)) #vale vastus
display.flip()
elif (x in range(500,500+x_v)) and (y in range(500,500+y_v)):
next_image = image.load('vale_v.png')
screen.blit(next_image, (500,500)) #vale vastus
display.flip()
#kontrolli()
display.flip()
done()
I would try and use a question class. So here is basically what I would do.
class Question:
def __init__(self, image, question, answer, numOfAnswers):
self.image = image
self.question = question
self.answer = {}
self.answer[1] = answer
self.totalAnswers = len(answer)
def newImage(image):
self.image = image
def newQuestion(question, answer):
self.question = question
self.answer.clear()
self.answer[1] = answer
def addAnswer(answer):
self.answer[len(answer)+1] = answer
Another thing is that your code is really sloppy because you have a while loop inside of your main game loop which i wouldn't recommend most especially considering that you only have one break and that is if your x is greater than 500. And I dont understand any of your variables, because I speak English, but tell me if you need any more clarification regarding accessing the class or using it. Just for your information classes are very useful in any programming language for uses such as this.