Journal #15


Formating your sd for the raspberry pi 2.

I went through a various number of programs to rewrite over the sd card. The one that worked for me was the WinDisk32 imager. But for Mac Apple Pi baker is going to be your best bet.

First you are required to get the image file from the retropie website. From there you want to make sure you have your sd card formatted to fat32.

From their you can use the image you have downloaded and rewrite the sd card with the image rewriting tool.


Journal 14

fatalrun2600screenThis is a very simple code for a basic racing game I haven’t tested it out on my computer so I’m not sure it will work properly but if anything this will be a good starting point. I used two different modules time and msvcrt which I believe detects key presses for simple text based games.

import msvcrt
import time
high_score = 0
name = “Car Driver”
while True: distance = int(0)

print(‘Welcome to the race track. tap b to move.’)
print(‘n/Press enter to begin.)
k1 = msvcrt.getch().decode (ASCII’)
k1 = ‘z’:

distance += 1

if distance == 100
print (” You finished the race.”)

Journal 13

20130718-89a718ff85be19c11c3b23029d6df275c65dd9a127126bc96e1924b-1024 This is a code for a very simplified game of blackjack, I used two new modules itertools for looping and a random module. Essentially this should pull out two cards of a different number and different suit. The numbers for the cards are labeled 1 – 13.

11 being Jack, 12 Being Queen, 13 Being King.

import pygame, itertools, random
deck = list(itertools.product(range(1,14), [‘Spade’,’Heart’,Diamond’,’Club’]))

print(” You cards are:”)
for i in range(2):
print (deck [i] [0], “of, deck[i] [1])


Journal #12

Using the coding skills I have learned so far I had made a game for one of the projects on the website. Essentially you are a snake that moves around this project was more for practicing using the sprites.

import pygame
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
segment_width = 15
segment_height = 15
segment_margin = 3
x_change = segment_width + segment_margin
y_change = 0
class Segment(pygame.sprite.Sprite):
""" Class to represent one segment of the snake. """
# -- Methods
# Constructor function
def __init__(self, x, y):
# Call the parent's constructor
self.image = pygame.Surface([segment_width, segment_height])
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
screen = pygame.display.set_mode([800, 600])
pygame.display.set_caption('Snake Example')
allspriteslist = pygame.sprite.Group()
snake_segments = []
for i in range(15):
x = 250 - (segment_width + segment_margin) * i
y = 30
segment = Segment(x, y)
clock = pygame.time.Clock()
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = (segment_width + segment_margin) * -1
y_change = 0
if event.key == pygame.K_RIGHT:
x_change = (segment_width + segment_margin)
y_change = 0
if event.key == pygame.K_UP:
x_change = 0
y_change = (segment_height + segment_margin) * -1
if event.key == pygame.K_DOWN:
x_change = 0
y_change = (segment_height + segment_margin)
old_segment = snake_segments.pop()
x = snake_segments[0].rect.x + x_change
y = snake_segments[0].rect.y + y_change
segment = Segment(x, y)
snake_segments.insert(0, segment)

Journal #11

In this chapter I learned about using the search tool with binary logic. Referred as to a “binary search”. This allows for shorter and more efficient ways to gather information for example having a game where a the computer has to figure out the number.

import random
secret_number = random.randrange(1, 129)
guess = 0
while guess != secret_number:
guess = (int)(input("Guess a number 1 to 128: "))
if guess < secret_number:
print("Too low.")
elif guess > secret_number:
print("Too high.")
Using binary search we can reduce the amount of guesses the computer will take. For linear it would guess 1 to 129 but with binary we give the computer an idea of how to do it more efficiently. In this case we will use half of the range of the secret number.
Binary search
key = "Secret Number"
lower_bound = 0
upper_bound = 128
found = False
while lower_bound <= upper_bound and not found:
middle_pos = (lower_bound + upper_bound) // 2
if secret_number[middle_pos] < key:
lower_bound = middle_pos + 1
elif secret_number[middle_pos] > key:
upper_bound = middle_pos - 1
found = True
if found:
print( "The number is ", middle_pos)