getfugu

Untitled

Apr 8th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.58 KB | None | 0 0
  1. Game Creating
  2. start constructor
  3. inside if statement
  4. player created
  5. cards added
  6. Exception in thread "Animation Thread" java.lang.NullPointerException
  7.     at processing.core.PApplet.image(PApplet.java:12783)
  8.     at blackjack.Image.displayCard(Image.java:15)
  9.     at blackjack.ImageManager.displayImage(ImageManager.java:30)
  10.     at blackjack.Deck.displaySmall(Deck.java:21)
  11.     at blackjack.Player.displayHandSmall(Player.java:24)
  12.     at blackjack.Game.display(Game.java:32)
  13.     at blackjack.Blackjack.draw(Blackjack.java:33)
  14.     at processing.core.PApplet.handleDraw(PApplet.java:2386)
  15.     at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
  16.     at processing.core.PApplet.run(PApplet.java:2256)
  17.     at java.lang.Thread.run(Unknown Source)
  18.  
  19. package blackjack;
  20.  
  21.  
  22. import processing.core.PApplet;
  23. import processing.core.*;
  24.  
  25.  
  26. public class Blackjack extends PApplet {
  27.  
  28.     PImage table;
  29.     float tableW = (float) (917*1.52);
  30.     float tableH = (float) (461*1.52);
  31.     // normal image dimensions are 360W by 540H
  32.     float zoomCardW = 270;
  33.     float zoomCardH = 405;
  34.     float smallCardW = (float) (360/4);
  35.     float smallCardH = (float) (540/4);
  36.     String numPlayers = "";
  37.     Game game;
  38.  
  39.     public void setup() {
  40.         size(1400, 900);
  41.         background(255);
  42.         fill(0);
  43.         textSize(44);
  44.         text("Welcome to the Blackjack table!\nEnter the number of players (1, 2, or 3):", 200, 200);
  45.         table = loadImage("blackjack_table.png");
  46.         ImageManager.getInstance();
  47.     }
  48.  
  49.     public void draw() {
  50.         if (game != null) {
  51.             game.display();
  52.         }
  53.     }
  54.    
  55.     public void keyPressed() {
  56.         println("Game Creating");
  57.         game = new Game(1);
  58.     }
  59.    
  60.     public void mousePressed() {
  61.         if (mouseX > 1000 && mouseY > 800) {
  62.             game = null;
  63.         }
  64.     }
  65. }
  66.  
  67.  
  68.  
  69. package blackjack;
  70.  
  71. import processing.core.PApplet;
  72. import processing.core.*;
  73.  
  74. public class Game extends PApplet {
  75.     private int numPlayers;
  76.     private Player[] players;
  77.    
  78.     public Game(int gNumPlayers) {
  79.         println("start constructor");
  80.         numPlayers = gNumPlayers;
  81.         players = new Player[numPlayers+1];
  82.         players[0] = new Player(660, 100);
  83.         if (numPlayers == 1) {
  84.             println("inside if statement");
  85.             players[1] = new Player(660, 500);
  86.             println("player created");
  87.             players[1].addCard("diamonds", "J");
  88.             players[1].addCard("spades", "Q");
  89.             println("cards added");
  90.         } else {
  91.             fill(0);
  92.             textSize(45);
  93.             text("DERP! Please click restart, AKA the bottom bit.", 60, 60);
  94.         }
  95.     }
  96.    
  97.     public void display() {
  98.         //background(255);
  99.         for (int i=0; i<players.length; i++) {
  100.             players[i].displayHandSmall();
  101.         }
  102.     }
  103. }
  104.  
  105.  
  106.  
  107.  
  108. package blackjack;
  109.  
  110. public class ImageManager {
  111.     private static ImageManager instance;
  112.     private static Image[] cards;
  113.  
  114.     private ImageManager() {
  115.         this.cards = new Image[52];
  116.         String[] suits = {"clubs", "diamonds", "hearts", "spades"};
  117.         String[] ids = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
  118.         int index = 0;
  119.        
  120.         for (int i=0; i<4; i++) {
  121.             for (int j=0; j<13; j++) {
  122.                 this.cards[index] = new Image(ids[j] + "-" + suits[i] + ".png");
  123.                 index++;
  124.             }
  125.         }
  126.     }
  127.  
  128.     public static ImageManager getInstance() {
  129.         if (instance == null) {
  130.             instance = new ImageManager();
  131.         }
  132.  
  133.         return instance;
  134.     }
  135.    
  136.     public void displayImage(int card, int x, int y, int w, int h) {
  137.         this.cards[card].displayCard(x, y, w, h);
  138.     }
  139. }
  140.  
  141.  
  142.  
  143.  
  144. package blackjack;
  145.  
  146. import processing.core.PImage;
  147. import processing.core.PApplet;
  148.  
  149. public class Image extends PApplet{
  150.    
  151.     PImage image;
  152.    
  153.     public Image (String path) {
  154.         image = loadImage(path);
  155.     }
  156.    
  157.     public void displayCard(int x, int y, int w, int h) {
  158.         image(image, x, y, w, h);
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment