SlideShare a Scribd company logo
Kellyn Pot’Vin-Gorman, Consulting Member of
Technical Staff, Oracle
Programming Simple Games with a
Raspberry Pi and Using Python
Today’s Goal
Either on a Raspberry Pi or Oracle VirtualBox, (Vbox)
Raspberry Pi image, code two simulated games of chance…
Who Will Use Vbox?
Let Kellyn know if you need a copy of the image to import
onto your own PC. She will offer you a USB drive with the
500G OVA file.
The image requires 1G of free memory to use the image.
You will need to “Import” the appliance onto your pc.
The user name=rpi and the password=password
Root password=password
Open up a terminal once you’ve logged in.
Connect and Power Up Raspberry
Pi’s
If you are new to Raspberry Pi…
You should also have a micro or SD card for storage
A HDMI monitor
A USB mouse and keyboard
Already performed the setup. If you haven’t, please talk to
Kellyn, she has the OS setup and all appropriate libraries
updated on a secondary card, (both SD or Micro SD format)
Once everything is connected, attach the micro USB power and
plug it in to power up the OS.
Open up a terminal window!
Basics of Python
Writing a Python Script, (simple Python Coding) consists of
the following:
1. Import Modules- which are programs already stored in
the system that can be used, saving the programmer time and
allows them to re-use code already available.
2. Define Functions-
3. Build Code into each Function.
4. Execute Functions in order they are to be performed in.
Writing a Program/Script is Like
Outlining
What are your Requirements?
List them out, naming them as Functions and DEFINING
each. Entering the command PASS after each one to
“bypass” the function until you are ready to code.
Place them in the order they will execute
Code LAST, filling in each section as you go, testing through
each step.
A Python Script Outline
#Our modules will be put in as we go along at the top
def set_board():
pass
def start_motor():
pass
def forward_motor():
pass
def backward_motor():
pass
def motor_cleanup():
pass
#This set of commands executes our functions in the correct order.
set_board()
start_motor()
backward_motor()
motor_cleanup()
Fill it in
import time
import gpio
def set_board():
pass
GPIO.setmode(GPIO.BOARD) #Use
Breadboard
Motor1A = 16 #Location of Motor pins
Motor1B = 18
def start_motor():
pass
Coding Start and Forward of Motor
import time
import GPIO
def set_board():
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
def start_motor():
pass
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
def forward_motor():
pass
print "Going forwards"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
time.sleep(2)
Final Steps Scripting
import time
import GPIO
def set_board():
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
def start_motor():
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
def forward_motor():
print "Going forwards"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
time.sleep(2)
def backward_motor():
pass
print "Going backwards"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
time.sleep(2)
print "Now stop"
GPIO.output(Motor1B,GPIO.LOW)
def motor_cleanup():
pass
GPIO.cleanup()
set_board()
start_motor()
backward_motor()
motor_cleanup()
Time to Code
Log into Your Raspberry Pi and open up a Terminal
Window.
Ensure that the screen background and text is visible and
easy to read, if not, ask Kellyn how to update the preferences
or update it to your liking.
Use an text editor, (vi, nano, etc.) to start a script.
> vi dice_gm.py
To Create a Dice Game
Decide what your requirements are.
Create an outline of our simple script
Fill in the code for the function and add any modules that
will need to be imported at the top of the script.
Test and verify that the code works as expected.
The Dice Game Requirements
Import the RANDOM module.
Will “roll” the dice 2 times
Will use two dice, with random calls of 1-6.
Will output the first dice ‘+’ the second dice.
Finished Script
import time
import GPIO
def set_board():
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
def start_motor():
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
def forward_motor():
print "Going forwards"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
time.sleep(2)
def backward_motor():
print "Going backwards"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
time.sleep(2)
print "Now stop"
GPIO.output(Motor1B,GPIO.LOW)
def motor_cleanup():
GPIO.cleanup()
set_board()
start_motor()
backward_motor()
motor_cleanup()
Code Outline
#Dice Game
import random
def dice_role():
pass
dice_role()
Comments about what we are
coding
Import random module we’ll be
using with this script.
Define your function name
and put in pass as a
“placeholder”
End with Function we
defined to Execute
Build out first steps of function
#Dice Game
import random
def dice_role():
for x in range(1, 2):
dice_1 = random.randint(1, 6)
dice_2 = random.randint(1, 6)
dice_role()
We let the program know we are
coding the function by indenting,
using four spaces, then indenting
the subfunction step four more.
Finished Script
#Dice Game
import random
def dice_roll():
for x in range(1, 2):
dice_1 = random.randint(1, 6)
dice_2 = random.randint(1, 6)
total = dice_1 + dice_2
if total == 7:
print(‘Seven Thrown!’)
if total == 11:
print(‘Eleven Thrown!’)
if dice_1 == dice_2:
print(‘Doubles!!’)
dice_roll()
Now take the random integers
produced in our “dice roll”, total
them and provide feedback
and the rolls!
Execute The Program/Script!
Save the script: <Esc> :wq! or save and exit, etc.
Execute the script to see the results of your work:
> sudo python3 dice_gm.py
Pass the Pigs
From Dice to “Pigs”
We will want to show
the roll and display
the points that would
be gained by that roll.
We’ll immediately
break from the turn if
the player hits a Pig
out or an Oinker!
Pass the Pigs Script Outline
#Pass the Pigs
import random
def pick_pigs():
pass
pick_pigs()
Pass the Pigs, Define our Dice
#Pass the Pigs
import random
def pick_pigs():
for x in range(1, 3): #two dice to roll
dice_roll = random.randint(1, 6) #standard dice
print(dice_rol1) #show us the roll
break
pick_pigs()
Pick_Pigs Function, (Deep Breath!)
def pick_pigs():
for x in range(1, 3): #two dice to roll
dice_roll = random.randint(1, 6) #standard dice
print(dice_roll) #show us the roll
if dice_roll == 1:
print(‘Razorback, 5 pts! If you get doubles, 20 pts!’)
elif dice_roll == 2:
print(‘Trotter, 5 pts! If you get doubles, 20 pts!’)
elif dice_roll == 3:
print(‘Snouter, 10 pts! If you get doubles, 40 pts!’)
elif dice_roll == 4:
print(‘Leaning Jowl, 15 pts! If you get doubles, 60 pts!’)
elif dice_roll == 5:
print(‘Pig Out, Back to Zero, Next Players turn unless you get doubles,
then only 1pt!’)
break
elif dice_roll == 6:
print(‘Oinker, Back to ZERO, Next Players Turn!’)
break
Finished Program
#Pass the Pigs
import random
def pick_pigs():
for x in range(1, 3): #two dice to roll
dice_roll = random.randint(1, 6) #standard dice
print(dice_roll)
if dice_roll == 1:
print(‘Razorback, 5 pts! If you get doubles, 20 pts!’)
elif dice_roll == 2:
print(‘Trotter, 5 pts! If you get doubles, 20 pts!’)
elif dice_roll == 3:
print(‘Snouter, 10 pts! If you get doubles, 40 pts!’)
elif dice_roll == 4:
print(‘Leaning Jowl, 15 pts! If you get doubles, 60 pts!’)
elif dice_roll == 5:
print(‘Pig Out, Back to Zero, Next Players turn unless you get doubles, then
only 1pt!
break
elif dice_roll == 6:
print(‘Oinker, Back to ZERO, Next Players Turn!’)
break
pick_pigs()
Execute our Script
Save our script/code: <Esc> :wq! Or Save and Quit.
Execute our script to see what we’ve coded!
>sudo python3 pass_pigs.py
2
Trotter, 5 pts…
1
Razorback, 5 pts… (for total of 10 pts!)
But if you roll a six in either roll?
6
Oinker, Back to Zero, Next Players
Turn…
Next Steps
Consider how this code could be used for other games…
Consider enhancements or using this code in conjunction
with Pygame, (there’s your Google research term… )
Think about how many ways the RANDOM module could
be used for different functional scripts and smarthome
modules, (turn on lights while on vacation at random times
throughout day and evening, etc….)
Connect With Me…

More Related Content

What's hot

PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
Edureka!
 
Introduction to Game programming with PyGame Part 1
Introduction to Game programming with PyGame Part 1Introduction to Game programming with PyGame Part 1
Introduction to Game programming with PyGame Part 1
Abhishek Mishra
 
Hug presentation for android tech talks #14
Hug presentation for android tech talks #14Hug presentation for android tech talks #14
Hug presentation for android tech talks #14
Artur Staniec
 
PenO 3 2014 sessie 2
PenO 3 2014 sessie 2PenO 3 2014 sessie 2
PenO 3 2014 sessie 2
Sven Charleer
 
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Chris Adamson
 
Flappy bird game in c#
Flappy bird game in c#Flappy bird game in c#
Flappy bird game in c#
Comstas
 
Atari 2600 Programming for Fun
Atari 2600 Programming for FunAtari 2600 Programming for Fun
Atari 2600 Programming for Fun
Paul Dixon
 
Details on WannaCry malware virus operations
Details on WannaCry malware virus operationsDetails on WannaCry malware virus operations
Details on WannaCry malware virus operations
David Sweigert
 
Project report 393_395
Project report 393_395Project report 393_395
Project report 393_395
VishruthKhare
 

What's hot (10)

PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
PyGame Tutorial | PyGame Python Tutorial For Beginners | Python Certification...
 
Introduction to Game programming with PyGame Part 1
Introduction to Game programming with PyGame Part 1Introduction to Game programming with PyGame Part 1
Introduction to Game programming with PyGame Part 1
 
Hug presentation for android tech talks #14
Hug presentation for android tech talks #14Hug presentation for android tech talks #14
Hug presentation for android tech talks #14
 
xyz
xyzxyz
xyz
 
PenO 3 2014 sessie 2
PenO 3 2014 sessie 2PenO 3 2014 sessie 2
PenO 3 2014 sessie 2
 
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
 
Flappy bird game in c#
Flappy bird game in c#Flappy bird game in c#
Flappy bird game in c#
 
Atari 2600 Programming for Fun
Atari 2600 Programming for FunAtari 2600 Programming for Fun
Atari 2600 Programming for Fun
 
Details on WannaCry malware virus operations
Details on WannaCry malware virus operationsDetails on WannaCry malware virus operations
Details on WannaCry malware virus operations
 
Project report 393_395
Project report 393_395Project report 393_395
Project report 393_395
 

Similar to Programming simple games with a raspberry pi and

CorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. ProgrammingCorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. Programming
Slide_N
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
Ganesh Samarthyam
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
Sunjid Hasan
 
Using the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdfUsing the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdf
acteleshoppe
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
Tom Paulus
 
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in PythonCodemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
Yothin Muangsommuk
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Tom Paulus
 
Pygame presentation
Pygame presentationPygame presentation
Pygame presentation
Felix Z. Hoffmann
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
Kris Findlay
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
Quinn Wilton
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
Eduard Tomàs
 
Poker, packets, pipes and Python
Poker, packets, pipes and PythonPoker, packets, pipes and Python
Poker, packets, pipes and Python
Roger Barnes
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Romain Dorgueil
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Pôle Systematic Paris-Region
 
Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013
Tom Paulus
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
ysolanki78
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
Sarwan Singh
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 
Python in details
Python in detailsPython in details
Python in details
Khalid AL-Dhanhani
 

Similar to Programming simple games with a raspberry pi and (20)

CorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. ProgrammingCorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. Programming
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
Using the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdfUsing the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdf
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in PythonCodemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
 
Pygame presentation
Pygame presentationPygame presentation
Pygame presentation
 
Scratch pcduino
Scratch pcduinoScratch pcduino
Scratch pcduino
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Poker, packets, pipes and Python
Poker, packets, pipes and PythonPoker, packets, pipes and Python
Poker, packets, pipes and Python
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
 
Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Python in details
Python in detailsPython in details
Python in details
 

More from Kellyn Pot'Vin-Gorman

Redgate_summit_atl_kgorman_intersection.pptx
Redgate_summit_atl_kgorman_intersection.pptxRedgate_summit_atl_kgorman_intersection.pptx
Redgate_summit_atl_kgorman_intersection.pptx
Kellyn Pot'Vin-Gorman
 
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptxSQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
Kellyn Pot'Vin-Gorman
 
Boston_sql_kegorman_highIO.pptx
Boston_sql_kegorman_highIO.pptxBoston_sql_kegorman_highIO.pptx
Boston_sql_kegorman_highIO.pptx
Kellyn Pot'Vin-Gorman
 
Oracle on Azure IaaS 2023 Update
Oracle on Azure IaaS 2023 UpdateOracle on Azure IaaS 2023 Update
Oracle on Azure IaaS 2023 Update
Kellyn Pot'Vin-Gorman
 
IaaS for DBAs in Azure
IaaS for DBAs in AzureIaaS for DBAs in Azure
IaaS for DBAs in Azure
Kellyn Pot'Vin-Gorman
 
Being Successful with ADHD
Being Successful with ADHDBeing Successful with ADHD
Being Successful with ADHD
Kellyn Pot'Vin-Gorman
 
Azure DBA with IaaS
Azure DBA with IaaSAzure DBA with IaaS
Azure DBA with IaaS
Kellyn Pot'Vin-Gorman
 
Turning ADHD into "Awesome Dynamic Highly Dependable"
Turning ADHD into "Awesome Dynamic Highly Dependable"Turning ADHD into "Awesome Dynamic Highly Dependable"
Turning ADHD into "Awesome Dynamic Highly Dependable"
Kellyn Pot'Vin-Gorman
 
PASS Summit 2020
PASS Summit 2020PASS Summit 2020
PASS Summit 2020
Kellyn Pot'Vin-Gorman
 
DevOps in Silos
DevOps in SilosDevOps in Silos
DevOps in Silos
Kellyn Pot'Vin-Gorman
 
Azure Databases with IaaS
Azure Databases with IaaSAzure Databases with IaaS
Azure Databases with IaaS
Kellyn Pot'Vin-Gorman
 
How to Win When Migrating to Azure
How to Win When Migrating to AzureHow to Win When Migrating to Azure
How to Win When Migrating to Azure
Kellyn Pot'Vin-Gorman
 
Securing Power BI Data
Securing Power BI DataSecuring Power BI Data
Securing Power BI Data
Kellyn Pot'Vin-Gorman
 
Cepta The Future of Data with Power BI
Cepta The Future of Data with Power BICepta The Future of Data with Power BI
Cepta The Future of Data with Power BI
Kellyn Pot'Vin-Gorman
 
Pass Summit Linux Scripting for the Microsoft Professional
Pass Summit Linux Scripting for the Microsoft ProfessionalPass Summit Linux Scripting for the Microsoft Professional
Pass Summit Linux Scripting for the Microsoft Professional
Kellyn Pot'Vin-Gorman
 
Taming the shrew Power BI
Taming the shrew Power BITaming the shrew Power BI
Taming the shrew Power BI
Kellyn Pot'Vin-Gorman
 
PASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and TricksPASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and Tricks
Kellyn Pot'Vin-Gorman
 
Power BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle CloudPower BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle Cloud
Kellyn Pot'Vin-Gorman
 
ODTUG Leadership Talk- WIT and Sponsorship
ODTUG Leadership Talk-  WIT and SponsorshipODTUG Leadership Talk-  WIT and Sponsorship
ODTUG Leadership Talk- WIT and Sponsorship
Kellyn Pot'Vin-Gorman
 
DevOps and Decoys How to Build a Successful Microsoft DevOps Including the Data
DevOps and Decoys  How to Build a Successful Microsoft DevOps Including the DataDevOps and Decoys  How to Build a Successful Microsoft DevOps Including the Data
DevOps and Decoys How to Build a Successful Microsoft DevOps Including the Data
Kellyn Pot'Vin-Gorman
 

More from Kellyn Pot'Vin-Gorman (20)

Redgate_summit_atl_kgorman_intersection.pptx
Redgate_summit_atl_kgorman_intersection.pptxRedgate_summit_atl_kgorman_intersection.pptx
Redgate_summit_atl_kgorman_intersection.pptx
 
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptxSQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
 
Boston_sql_kegorman_highIO.pptx
Boston_sql_kegorman_highIO.pptxBoston_sql_kegorman_highIO.pptx
Boston_sql_kegorman_highIO.pptx
 
Oracle on Azure IaaS 2023 Update
Oracle on Azure IaaS 2023 UpdateOracle on Azure IaaS 2023 Update
Oracle on Azure IaaS 2023 Update
 
IaaS for DBAs in Azure
IaaS for DBAs in AzureIaaS for DBAs in Azure
IaaS for DBAs in Azure
 
Being Successful with ADHD
Being Successful with ADHDBeing Successful with ADHD
Being Successful with ADHD
 
Azure DBA with IaaS
Azure DBA with IaaSAzure DBA with IaaS
Azure DBA with IaaS
 
Turning ADHD into "Awesome Dynamic Highly Dependable"
Turning ADHD into "Awesome Dynamic Highly Dependable"Turning ADHD into "Awesome Dynamic Highly Dependable"
Turning ADHD into "Awesome Dynamic Highly Dependable"
 
PASS Summit 2020
PASS Summit 2020PASS Summit 2020
PASS Summit 2020
 
DevOps in Silos
DevOps in SilosDevOps in Silos
DevOps in Silos
 
Azure Databases with IaaS
Azure Databases with IaaSAzure Databases with IaaS
Azure Databases with IaaS
 
How to Win When Migrating to Azure
How to Win When Migrating to AzureHow to Win When Migrating to Azure
How to Win When Migrating to Azure
 
Securing Power BI Data
Securing Power BI DataSecuring Power BI Data
Securing Power BI Data
 
Cepta The Future of Data with Power BI
Cepta The Future of Data with Power BICepta The Future of Data with Power BI
Cepta The Future of Data with Power BI
 
Pass Summit Linux Scripting for the Microsoft Professional
Pass Summit Linux Scripting for the Microsoft ProfessionalPass Summit Linux Scripting for the Microsoft Professional
Pass Summit Linux Scripting for the Microsoft Professional
 
Taming the shrew Power BI
Taming the shrew Power BITaming the shrew Power BI
Taming the shrew Power BI
 
PASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and TricksPASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and Tricks
 
Power BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle CloudPower BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle Cloud
 
ODTUG Leadership Talk- WIT and Sponsorship
ODTUG Leadership Talk-  WIT and SponsorshipODTUG Leadership Talk-  WIT and Sponsorship
ODTUG Leadership Talk- WIT and Sponsorship
 
DevOps and Decoys How to Build a Successful Microsoft DevOps Including the Data
DevOps and Decoys  How to Build a Successful Microsoft DevOps Including the DataDevOps and Decoys  How to Build a Successful Microsoft DevOps Including the Data
DevOps and Decoys How to Build a Successful Microsoft DevOps Including the Data
 

Recently uploaded

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

Programming simple games with a raspberry pi and

  • 1. Kellyn Pot’Vin-Gorman, Consulting Member of Technical Staff, Oracle Programming Simple Games with a Raspberry Pi and Using Python
  • 2. Today’s Goal Either on a Raspberry Pi or Oracle VirtualBox, (Vbox) Raspberry Pi image, code two simulated games of chance…
  • 3. Who Will Use Vbox? Let Kellyn know if you need a copy of the image to import onto your own PC. She will offer you a USB drive with the 500G OVA file. The image requires 1G of free memory to use the image. You will need to “Import” the appliance onto your pc. The user name=rpi and the password=password Root password=password Open up a terminal once you’ve logged in.
  • 4. Connect and Power Up Raspberry Pi’s If you are new to Raspberry Pi… You should also have a micro or SD card for storage A HDMI monitor A USB mouse and keyboard Already performed the setup. If you haven’t, please talk to Kellyn, she has the OS setup and all appropriate libraries updated on a secondary card, (both SD or Micro SD format) Once everything is connected, attach the micro USB power and plug it in to power up the OS. Open up a terminal window!
  • 5. Basics of Python Writing a Python Script, (simple Python Coding) consists of the following: 1. Import Modules- which are programs already stored in the system that can be used, saving the programmer time and allows them to re-use code already available. 2. Define Functions- 3. Build Code into each Function. 4. Execute Functions in order they are to be performed in.
  • 6. Writing a Program/Script is Like Outlining What are your Requirements? List them out, naming them as Functions and DEFINING each. Entering the command PASS after each one to “bypass” the function until you are ready to code. Place them in the order they will execute Code LAST, filling in each section as you go, testing through each step.
  • 7. A Python Script Outline #Our modules will be put in as we go along at the top def set_board(): pass def start_motor(): pass def forward_motor(): pass def backward_motor(): pass def motor_cleanup(): pass #This set of commands executes our functions in the correct order. set_board() start_motor() backward_motor() motor_cleanup()
  • 8. Fill it in import time import gpio def set_board(): pass GPIO.setmode(GPIO.BOARD) #Use Breadboard Motor1A = 16 #Location of Motor pins Motor1B = 18 def start_motor(): pass
  • 9. Coding Start and Forward of Motor import time import GPIO def set_board(): GPIO.setmode(GPIO.BOARD) Motor1A = 16 Motor1B = 18 def start_motor(): pass GPIO.setup(Motor1A,GPIO.OUT) GPIO.setup(Motor1B,GPIO.OUT) def forward_motor(): pass print "Going forwards" GPIO.output(Motor1A,GPIO.HIGH) GPIO.output(Motor1B,GPIO.LOW) time.sleep(2)
  • 10. Final Steps Scripting import time import GPIO def set_board(): GPIO.setmode(GPIO.BOARD) Motor1A = 16 Motor1B = 18 def start_motor(): GPIO.setup(Motor1A,GPIO.OUT) GPIO.setup(Motor1B,GPIO.OUT) def forward_motor(): print "Going forwards" GPIO.output(Motor1A,GPIO.HIGH) GPIO.output(Motor1B,GPIO.LOW) time.sleep(2) def backward_motor(): pass print "Going backwards" GPIO.output(Motor1A,GPIO.LOW) GPIO.output(Motor1B,GPIO.HIGH) time.sleep(2) print "Now stop" GPIO.output(Motor1B,GPIO.LOW) def motor_cleanup(): pass GPIO.cleanup() set_board() start_motor() backward_motor() motor_cleanup()
  • 11. Time to Code Log into Your Raspberry Pi and open up a Terminal Window. Ensure that the screen background and text is visible and easy to read, if not, ask Kellyn how to update the preferences or update it to your liking. Use an text editor, (vi, nano, etc.) to start a script. > vi dice_gm.py
  • 12. To Create a Dice Game Decide what your requirements are. Create an outline of our simple script Fill in the code for the function and add any modules that will need to be imported at the top of the script. Test and verify that the code works as expected.
  • 13. The Dice Game Requirements Import the RANDOM module. Will “roll” the dice 2 times Will use two dice, with random calls of 1-6. Will output the first dice ‘+’ the second dice.
  • 14. Finished Script import time import GPIO def set_board(): GPIO.setmode(GPIO.BOARD) Motor1A = 16 Motor1B = 18 def start_motor(): GPIO.setup(Motor1A,GPIO.OUT) GPIO.setup(Motor1B,GPIO.OUT) def forward_motor(): print "Going forwards" GPIO.output(Motor1A,GPIO.HIGH) GPIO.output(Motor1B,GPIO.LOW) time.sleep(2) def backward_motor(): print "Going backwards" GPIO.output(Motor1A,GPIO.LOW) GPIO.output(Motor1B,GPIO.HIGH) time.sleep(2) print "Now stop" GPIO.output(Motor1B,GPIO.LOW) def motor_cleanup(): GPIO.cleanup() set_board() start_motor() backward_motor() motor_cleanup()
  • 15. Code Outline #Dice Game import random def dice_role(): pass dice_role() Comments about what we are coding Import random module we’ll be using with this script. Define your function name and put in pass as a “placeholder” End with Function we defined to Execute
  • 16. Build out first steps of function #Dice Game import random def dice_role(): for x in range(1, 2): dice_1 = random.randint(1, 6) dice_2 = random.randint(1, 6) dice_role() We let the program know we are coding the function by indenting, using four spaces, then indenting the subfunction step four more.
  • 17. Finished Script #Dice Game import random def dice_roll(): for x in range(1, 2): dice_1 = random.randint(1, 6) dice_2 = random.randint(1, 6) total = dice_1 + dice_2 if total == 7: print(‘Seven Thrown!’) if total == 11: print(‘Eleven Thrown!’) if dice_1 == dice_2: print(‘Doubles!!’) dice_roll() Now take the random integers produced in our “dice roll”, total them and provide feedback and the rolls!
  • 18. Execute The Program/Script! Save the script: <Esc> :wq! or save and exit, etc. Execute the script to see the results of your work: > sudo python3 dice_gm.py
  • 19. Pass the Pigs From Dice to “Pigs” We will want to show the roll and display the points that would be gained by that roll. We’ll immediately break from the turn if the player hits a Pig out or an Oinker!
  • 20. Pass the Pigs Script Outline #Pass the Pigs import random def pick_pigs(): pass pick_pigs()
  • 21. Pass the Pigs, Define our Dice #Pass the Pigs import random def pick_pigs(): for x in range(1, 3): #two dice to roll dice_roll = random.randint(1, 6) #standard dice print(dice_rol1) #show us the roll break pick_pigs()
  • 22. Pick_Pigs Function, (Deep Breath!) def pick_pigs(): for x in range(1, 3): #two dice to roll dice_roll = random.randint(1, 6) #standard dice print(dice_roll) #show us the roll if dice_roll == 1: print(‘Razorback, 5 pts! If you get doubles, 20 pts!’) elif dice_roll == 2: print(‘Trotter, 5 pts! If you get doubles, 20 pts!’) elif dice_roll == 3: print(‘Snouter, 10 pts! If you get doubles, 40 pts!’) elif dice_roll == 4: print(‘Leaning Jowl, 15 pts! If you get doubles, 60 pts!’) elif dice_roll == 5: print(‘Pig Out, Back to Zero, Next Players turn unless you get doubles, then only 1pt!’) break elif dice_roll == 6: print(‘Oinker, Back to ZERO, Next Players Turn!’) break
  • 23. Finished Program #Pass the Pigs import random def pick_pigs(): for x in range(1, 3): #two dice to roll dice_roll = random.randint(1, 6) #standard dice print(dice_roll) if dice_roll == 1: print(‘Razorback, 5 pts! If you get doubles, 20 pts!’) elif dice_roll == 2: print(‘Trotter, 5 pts! If you get doubles, 20 pts!’) elif dice_roll == 3: print(‘Snouter, 10 pts! If you get doubles, 40 pts!’) elif dice_roll == 4: print(‘Leaning Jowl, 15 pts! If you get doubles, 60 pts!’) elif dice_roll == 5: print(‘Pig Out, Back to Zero, Next Players turn unless you get doubles, then only 1pt! break elif dice_roll == 6: print(‘Oinker, Back to ZERO, Next Players Turn!’) break pick_pigs()
  • 24. Execute our Script Save our script/code: <Esc> :wq! Or Save and Quit. Execute our script to see what we’ve coded! >sudo python3 pass_pigs.py 2 Trotter, 5 pts… 1 Razorback, 5 pts… (for total of 10 pts!) But if you roll a six in either roll? 6 Oinker, Back to Zero, Next Players Turn…
  • 25. Next Steps Consider how this code could be used for other games… Consider enhancements or using this code in conjunction with Pygame, (there’s your Google research term… ) Think about how many ways the RANDOM module could be used for different functional scripts and smarthome modules, (turn on lights while on vacation at random times throughout day and evening, etc….)