Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Game Creating
- start constructor
- inside if statement
- player created
- cards added
- Exception in thread "Animation Thread" java.lang.NullPointerException
- at processing.core.PApplet.image(PApplet.java:12783)
- at blackjack.Image.displayCard(Image.java:15)
- at blackjack.ImageManager.displayImage(ImageManager.java:30)
- at blackjack.Deck.displaySmall(Deck.java:21)
- at blackjack.Player.displayHandSmall(Player.java:24)
- at blackjack.Game.display(Game.java:32)
- at blackjack.Blackjack.draw(Blackjack.java:33)
- at processing.core.PApplet.handleDraw(PApplet.java:2386)
- at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
- at processing.core.PApplet.run(PApplet.java:2256)
- at java.lang.Thread.run(Unknown Source)
- package blackjack;
- import processing.core.PApplet;
- import processing.core.*;
- public class Blackjack extends PApplet {
- PImage table;
- float tableW = (float) (917*1.52);
- float tableH = (float) (461*1.52);
- // normal image dimensions are 360W by 540H
- float zoomCardW = 270;
- float zoomCardH = 405;
- float smallCardW = (float) (360/4);
- float smallCardH = (float) (540/4);
- String numPlayers = "";
- Game game;
- public void setup() {
- size(1400, 900);
- background(255);
- fill(0);
- textSize(44);
- text("Welcome to the Blackjack table!\nEnter the number of players (1, 2, or 3):", 200, 200);
- table = loadImage("blackjack_table.png");
- ImageManager.getInstance();
- }
- public void draw() {
- if (game != null) {
- game.display();
- }
- }
- public void keyPressed() {
- println("Game Creating");
- game = new Game(1);
- }
- public void mousePressed() {
- if (mouseX > 1000 && mouseY > 800) {
- game = null;
- }
- }
- }
- package blackjack;
- import processing.core.PApplet;
- import processing.core.*;
- public class Game extends PApplet {
- private int numPlayers;
- private Player[] players;
- public Game(int gNumPlayers) {
- println("start constructor");
- numPlayers = gNumPlayers;
- players = new Player[numPlayers+1];
- players[0] = new Player(660, 100);
- if (numPlayers == 1) {
- println("inside if statement");
- players[1] = new Player(660, 500);
- println("player created");
- players[1].addCard("diamonds", "J");
- players[1].addCard("spades", "Q");
- println("cards added");
- } else {
- fill(0);
- textSize(45);
- text("DERP! Please click restart, AKA the bottom bit.", 60, 60);
- }
- }
- public void display() {
- //background(255);
- for (int i=0; i<players.length; i++) {
- players[i].displayHandSmall();
- }
- }
- }
- package blackjack;
- public class ImageManager {
- private static ImageManager instance;
- private static Image[] cards;
- private ImageManager() {
- this.cards = new Image[52];
- String[] suits = {"clubs", "diamonds", "hearts", "spades"};
- String[] ids = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
- int index = 0;
- for (int i=0; i<4; i++) {
- for (int j=0; j<13; j++) {
- this.cards[index] = new Image(ids[j] + "-" + suits[i] + ".png");
- index++;
- }
- }
- }
- public static ImageManager getInstance() {
- if (instance == null) {
- instance = new ImageManager();
- }
- return instance;
- }
- public void displayImage(int card, int x, int y, int w, int h) {
- this.cards[card].displayCard(x, y, w, h);
- }
- }
- package blackjack;
- import processing.core.PImage;
- import processing.core.PApplet;
- public class Image extends PApplet{
- PImage image;
- public Image (String path) {
- image = loadImage(path);
- }
- public void displayCard(int x, int y, int w, int h) {
- image(image, x, y, w, h);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment