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
package chapter4; | |
public class PairOfDie { | |
private int _dieSides1; | |
private int _dieSides2; | |
private int _die1; | |
private int _die2; | |
PairOfDie(){ |
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
package chapter4; | |
import java.util.*; | |
public class BoxCars { | |
public static void main (String args[]) { | |
PairOfDie dice = new PairOfDie(); | |
________________________ // define integer called boxCarCounter and set it equal to zero | |
for(int i = 0; i < 1000; i++){ | |
dice.rollBothDie(); | |
if(dice.getDieTotal() == 12) | |
boxCarCounter ++; |
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
public class ComputerPlayer extends Player { | |
public ComputerPlayer(String name, PairOfDice pod) { | |
super(name, pod); | |
} | |
@Override | |
public boolean rollAgain() { | |
if(sk.getRoundTotal() < 20) { |
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
# This version of the game has a bug in it. See if you can figure out how to fix it. | |
# Bug Description: Graphics are messed up. | |
# Memory Puzzle | |
# By Al Sweigart al@inventwithpython.com | |
# Released under a "Simplified BSD" license | |
import random, pygame, sys | |
from pygame.locals import * |
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
# This version of the game has a bug in it. See if you can figure out how to fix it. | |
# Bug Description: NameError: global name 'getRandomizedBoard' is not defined | |
# Memory Puzzle | |
# By Al Sweigart al@inventwithpython.com | |
# Released under a "Simplified BSD" license | |
import random, pygame, sys | |
from pygame.locals import * |
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
Draws a scalable mirror | |
Goal (size 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
/** | |
The DrawingPanel class provides a simple interface for drawing persistent | |
images using a Graphics object. An internal BufferedImage object is used | |
to keep track of what has been drawn. A client of the class simply | |
constructs a DrawingPanel of a particular size and then draws on it with | |
the Graphics object, setting the background color if they so choose. | |
<p> | |
To ensure that the image is always displayed, a timer calls repaint at | |
regular intervals. |
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
public static void main(String[] args) | |
{ | |
int mystery = 100; | |
mystery = mystery + ___; | |
mystery = mystery - ___; | |
mystery = mystery ______; | |
mystery = mystery + 1; | |
mystery = mystery _____; | |
mystery = mystery + 15; |
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
// Introduction to DrawingPanel, Graphics, Color | |
import java.awt.*; // to use Graphics, Color | |
public class GraphicsIntro { | |
public static void main(String[] args) { | |
DrawingPanel panel = new DrawingPanel(300, 200); | |
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 java.util.Scanner; | |
public class ForgetfulMachine | |
{ | |
public static void main ( String [] args ) | |
{ | |
Scanner keyboard = new Scanner(System.in); | |
System.out.println( "" ); | |
keyboard.next(); |
OlderNewer