Snake Eyes / Craps Dice Games

Jul 24, 2014

I am having a problem with my java program. My goal is to request the user to enter how many times they want to roll a pair of dices. Each dice have numbers 1-6. When rolling the dices, I randomly pick a number from each dice and total the number. My goal is to calculate the number of times snake-eyes was rolled which is a total of 2 and total number of times a total of 7 was rolled. Here is my code. I am calling the rollDice method to perform the random pick and calculations. The error I am getting is at the bottom of the code.

package dice;
import java.util.Scanner;
import java.util.Random;
public class Dice
{
public static void main(String[] args)
{
int numRolls; // number of rolls

[code]...

How many times would you like to roll the two dice? 1000 Exception in thread "main" java.lang.NullPointerException at dice.Dice.main(Dice.java:40)
Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)

View Replies


ADVERTISEMENT

Multi-sided Dice - Keep Track Of Total Sum Of All Dice In Array

May 7, 2014

I'm finishing up this assignment, and I'm stuck. These are the last 2 instructions:

. Roll each of the Dice by invoking the roll method on each Dice in the array.
. Keep track of the totals sum of all the dice in the array. Be sure to roll the dice array at least 10000 times.

How to finish it up?

Here's my code so far:

package homework3;

import java.util.Random;
public class Dice {
private int numberShowing;
private final int numberOfSides;
private static final Random randomNumber = new Random();
public Dice() {
numberOfSides = 6;

[Code] ....

View Replies View Related

Running Craps Game Using Methods?

Nov 4, 2014

I had to make a program that ran a craps game using methods and I keep getting an error ....

Here is my code :

public class CrapsGame {
public static void main(String[] args) { 
System.out.println(playGame());
}//end of main method
public static int rollDie(int n){
return (int)(Math.random()*n)+ 1;
}//end of rollDie method

[Code] .....

And this is the error im getting

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable roll might not have been initialized
at CrapsGame.playGame(CrapsGame.java:29)
at CrapsGame.main(CrapsGame.java:4)
Java Result: 1

View Replies View Related

Gridworld Snake Game

Apr 9, 2014

gridworld snake game all over the internet, but all of those are the "snakebug extends Bug" version, mine is different. im behind everyone else in apcs so i rarely have any idea what im doing(gridworld especially). our teacher gave us most of the code, which i coped down (hopefully correctly) and he told us that we still needed to fill in the "removeTail" method which i did. basically the snake moves by placing a segment in front then removing the last segment.

When i click run the snakerunner file, i can make the snake segment rotate by pressing the arrow keys, but it doesn't move. when i click the "run" on the gridworld window, the single snake segment just disappears. so the move method is triggering the "removetail" method but it isn't placing the next segment. im starting to think that i copied something wrong from the board, because he showed us the entire move method. i have attached my gridworld files, what is wrong with my snake.java that makes the move method delete a segment but not add one

View Replies View Related

Frames Per Second In Games

Nov 13, 2014

I have a question about Frames per second in games. In a simple game i should be able to pull off 60(exactly), right? So if i have this code for a game loop:

while(shouldRun){
Thread.sleep(1000/60);
 //loop code here
}

will that run at 60 fps?

The loop code takes a tiny bit of time, then it waits for (a second/60), so overall the code will be running overall since the code takes some time?

Is this the case , and if so is there a solution?

View Replies View Related

Snake Game Movement Algorithm

Jun 16, 2014

I am working on replicating this project: [URL] ....

What is wrong with the moveSnake method and the for loop within it?

View Replies View Related

Simple Snake Game - Timer And KeyListener

May 25, 2014

I'm trying to create a simple snake game, but I can't get my timer and keyListener to work...

//Timer
Timer tm = new Timer(5, this);
int x = 50, y = 250, vel = 2;
// The snake
g.setColor(Color.black);
g.fillRect(x, y, snakeSize, snakeSize);

[Code] .....

View Replies View Related

Game Run But Snake Does Not Move / Apples Are Spawned Everywhere

Apr 19, 2014

I tried to make a runnable snake game. When i try to run my code i get this:

Exception in thread "main" java.lang.NullPointerException
at Game.Move(Game.java:85)
at Game.run(Game.java:244)
at Game.main(Game.java:38)

The game runs, but the snake doesn't move, and apples are spawned everywhere.

Here are Move, run and main code:

public static void main(String[] args) {
JFrame frame = new JFrame("Snake");
Game game = new Game();
frame.add(game);
frame.setSize(406, 430);
frame.setVisible(true);
frame.setResizable(false);

[Code] .....

View Replies View Related

Building Multiple Math Games?

Nov 23, 2014

building a game. the game is all about the multiple times table with levels. easy medium and difficulty. I dont even know where to begin and what is the codes to use or even the platform. what websites can be access etc and what is the big deal with code tags.

View Replies View Related

Tracking Number Of Games Within Guessing Game

Aug 22, 2014

/*
/ GuessGame.java
*/

import java.util.Scanner;
import java.util.Random;
public class GuessGame {
public static void main(String[] args) {

[code]....

tracking the number of games played, and also when running the code, I have to press "1" twice for it to actually load up the game again.

View Replies View Related

Pogo Games - Java Is Not Detected On Computer

Jun 6, 2013

I am unable to open Pogo Poker with out receiving an error message saying "Oops, Java is not detected on your computer" (or something similar). I have reinstalled it several times and get the same results.

View Replies View Related

Snake Game - Refresh Grid Of ASCII Characters Every 0.2 Seconds

Mar 4, 2014

I am busy programming a clone of the popular phone game they had on Nokia cellphones a long time ago called Snake II but since I know very little about programming I will be using ASCII graphics instead of a 2D graphics engine.

My idea for implementation is having a main class called game which should refresh a grid of ascii characters every, say 0.2 seconds. Then I have another class called Dot. Each Dot object has x and y coordinates, and a direction in the x and y planes (dirx = -1 means left, dirx = 1 means right, diry = 1 means up, diry = -1 means down, and obviously the snake cant move the diagonals)

The Game class prints a "*" symbol where the Dot is, and what I'm trying to do is get the screen to refresh (I think I need to use the sleep() function for this to slow the game down to a reasonable pace), and go in the direction it is supposed to go.

(I haven't programmed this in yet but the snake will be an array of Dot, and at each refresh Dot at position 0 will pass it's coordinates and direction to Dot at position 1, Dot1 to Dot2, Dot2 to Dot3, etc.

Here's my code so far:

A first class called Game.

Java Code: //Not done yet but this is the start to my game of Snake. Basically the class Game generates a Grid of ASCII characters

import java.util.Scanner;
public class Game {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
final int WIDTH = 79;

[Code] .....

My problem now is that I am taking input from the Scanner class. What it does is wait for my input, then it goes on to executing the rest of the code in other words refresh the ASCII grid. This is a problem because I need the snake to keep moving at constant pace while listening to the keyboard.

How can I get my while loop to keep going (i will add a sleep() function later) while listening to the keyboard without stopping?

View Replies View Related

FC Barcelona Database - Updating Number Of Games Played By The Player

May 25, 2014

So I am working on a database pertaining FCBarcelona. I have three classes FCBarcelona.java Player.java and Roster.java

I am working on a method that updates the number of games played by the player ... Its not working it gives a runtime error ...

Roster.java
public Player changeNumGamesPlayed(Player nPlayer)
{
int index = play.indexOf(nPlayer);
if(index == -1)
return null;

[Code] .....

View Replies View Related

Jump Games - Put Images Into JTable For Organization And Character Selection Purposes

Jul 14, 2014

HTML Code:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.Border;
import javax.imageio.ImageIO;
public class Main extends JApplet implements Runnable, ActionListener {

[Code] .....

I am making a game and there are two problems that I have and can't seem to solve. I never made on applet before, and I'm not good with the swing components, but I am decent programming in Java.

Problem #1: the start button is in the JPanel, I don't want that, I want it to be above the JPanel.
Problem #2: I want to put images in to a JTable for organization and character selection purposes, but I keep on getting a string. Do I have to use an ImageIcon to get it to work, or does it matter?

In case you were wonder what kind of game I'm making, I'm making one of those jump games where you jump on platforms and try to go as high as you can without missing a platform. There is going to be character selection for the jumper, and the jumpers are going to be food, like a potato, a banana, a strawberry, etc.

View Replies View Related

Simulate Rolling Two Dice

Oct 18, 2014

Write a method called statistic that simulates the rolling of two dice 1000 times. (1000 times is a parameter of the method statistic).The program should have no input, and should use pseudo random numbers to simulate the rolls (one random number per die). Store the sum resulting from each roll of two dice, determine the number of times each 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and 12 was rolled. The out produced by the program is:

Sum 2 3 4 5 6 7 8 9 10 11 12
Total 33 49 93 103 127 159 150 124 85 49 28

This is my code:

public static void main(String[] args) {
statistic(1000);
}
public static void statistic(int number) {
Random randomNumbers = new Random();

[code]...

i have been trying for hours to make it look like the output above but no luck. I was wondering if there's any other way writing the code without using arrays.

View Replies View Related

Using Loops For Dice Probability

Oct 5, 2014

The instructions are to "write a program to simulate tossing a pair of 11-sided dice and determine the percentage of times each possible combination of the dice is rolled... then ask the user to enter the number of sides on a die" The code is all provided here, I just have to put it in the right spots. (Side note, I cannot use arrays.) Here's the original file I was given to work with:

Java Code:

import java.util.Random;
import java.util.Scanner;
public class DiceProbability
{
public static void main(String[] args) {
//Declare and initialize variables and objects
//Input: ask user for number of rolls and number of sides on a die
//Print heading for output table

[Code] ....

When I run it, I get something like this (just a part of my output):

Please enter the number of sides on a die: 6
Please enter the number of rolls: 2

Sum of dice Probability

20.0
20.0
30.0
30.0
40.0
40.0
50.0
50.0
650.0
650.0
70.0
70.0

Now I don't really understand the concept in the first place as the lesson was extremely uninformative, so I don't know what went wrong here.

View Replies View Related

Hi Lo Dice Betting Program

Jun 29, 2014

I want to write a small Hi Lo Betting Dice program that satisfies these conditions :

A player places a bet on whether the sum of two dice will come up High (totalling 8 or higher), Low (totalling 6 or less) or Sevens (totalling exactly 7). If the player wins, he receives a payout based on the schedule given in the table below:

Choice Payout
High 1 x Wager
Low 1 x Wager
Sevens 4 x Wager

The player will start with $100 for wagering. If the player chooses to wager $0 or if he runs out of money, the program should end. Otherwise it should ask him whether he's wagering on High, Low or Sevens, display the results of the die rolls, and update his money total accordingly.

some sample output:

You have 100 dollars.
Enter an amount to bet (0 to quit): 50
High, low or sevens (H/L/S): H
Die 1 rolls: 1
Die 2 rolls: 5
Total of two dice is: 6
You lost!

You have 50 dollars.
Enter an amount to bet (0 to quit): 25
High, low or sevens (H/L/S): L
Die 1 rolls: 6
Die 2 rolls: 2
Total of two dice is: 8
You lost!

You have 25 dollars.
Enter an amount to bet (0 to quit): 12
High, low or sevens (H/L/S): H
Die 1 rolls: 2
Die 2 rolls: 6
Total of two dice is: 8
You won 12 dollars!

I have written some code but now i am stuck at the logic ...

package com.peg.hilodice;
import java.util.Scanner;
public class DiceGame {
 public static void main(String[] args) {
// TODO Auto-generated method stub
 int money = 100;
int bet;

[Code] .....

View Replies View Related

Dice Roll GUI - Where To Place Constructor

Feb 17, 2014

I am making a Dice Roll GUI and I have most of it down and I only need this constructor to work for the program to work (I think). I don't know where to place the constructor, I tried placing it around the RollButton class but it still didn't work and gave me java error constructor in class cannot be applied to given types

Here's my constructor:

private JPanel panel;
public RollButton(JPanel panel){
this.panel = panel;
}

Here's my code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Random;
import javax.imageio.ImageIO;

[code]....

View Replies View Related

Obtain Dice As Text Not Numbers

Oct 2, 2014

package dicedemo;
public class DiceDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

final int Die1_SIDES = 6; // Number of side of dice 1
final int Die2_SIDES = 6; // Number of side of dice 2
// Create two instances of the Die class.

[Code] ....

I need converting the number output to text: example one, two, three, etc.

View Replies View Related

Changing Number Of Sides On A Dice From 6 To 12

May 29, 2014

I have this really a graphics program that I'm working on which displays a single die, and right now it is set to the default 6 sides. I need to change it to 12. Here is the program:

package homeworkweek6;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

[code]...

Do I have to add more code somewhere further up in the program, or is there a line to replace these two lines to make it 12-sided?

View Replies View Related

All Possible Outcomes Of Dice Roll Using Recursion

Nov 26, 2014

Here is what I have so far:

/**
* This class encapsulates a simple dice game. The number of dice and number of sides on those dice are given by instance variables. The outcomes ArrayList holds a list of all possible outcomes of throwing that number of dice with that number of sides.
*
* If there were 2 dice, each with 6 sides, then possible outcomes would include 1 1, 1 2, 1 3, 1 4, 1 5, 1 6, 2 1, 2 2, 2 3, and so on.
*
* Your task is to complete the methods that calculate the possible outcomes. One method calculates outcomes allowing for repeated numbers. One method calculates the outcomes of a fictional dice game where repeated numbers cannot occur.
*
* You must use recursion. This is a variation on the permutations problem from the book.
*/

public class Dice
{
private static int numberOfSides;
private static int numberOfDice;
public ArrayList<String> outcomes;

[code]...

I manage to calculate the numberOfOutcomes correctly, but then get a nullPointerException. Also, is there a way that I can use getNumberOf Outcomes without making it static? The testing code that the teacher provided is using it in another class and if I make it static, then it doesn't work in that file.

View Replies View Related

Not Counting Total Of Dice Rolls

Jan 25, 2015

I am currently trying to roll 5 dice 100,000 times and output the number of times each possible total (of dots/pips) occurs. It seems to output the incorrect thing and isnt counting the occurrences properly.

public class lab_DiceRollTest {
public static void main(String[] args) {
int total;
int total2;
String valid;
String isDifferent;
int rolls = 100000;
int d = 0;

[code]...

View Replies View Related

Add Program In Order To Dice To Roll

May 8, 2014

what code I should add to my program in order to get these dice to roll. The program, according to my teacher, is CORRECT so far, so I'm not going to change anything. I just need to know how to roll the 2 dice I added in. I just want to get it done. No math.Random. The direction is: Roll each of the Dice by invoking the roll method on each Dice in the array.

My code:

//Dice.java
package homework3;
import java.util.Random;
public class Dice {
private int numberShowing;
private int numberOfSides;
private static final Random randomNumber = new Random();

[code]....

View Replies View Related

Roll Two Dice / Add Them Together And Print The Result

Oct 23, 2014

Write a program that rolls two dice, adds the numbers and prints out the results. I have managed to do this but we have to make it a horizontal table instead of a vertical one. like the attached file "CORRECT", right now i only get the "NOTCORRECT". i have tried for hours to fix this but i can't.

import java.util.Random;

public class Statistikk {
public static void skrivStatistikk() {
Random rand = new Random();
int[] antall = new int[13]; {

[Code] .....

(Antall is basically frequency|side is the same as a face of a die)

Here is my code, does my code need improvement? Or is it my printf that is the issue? i've tried deleting the 's and adding the printf to the same line, but nothing worked.

Attached image(s)

View Replies View Related

Do While Loop - Rolling Dice And Getting Scores To Add Up To 100

Aug 21, 2014

I'm writing a program that is about rolling "dice" and getting the scores to add up to 100. There are two players in the game and each must take turns rolling dice choosing whether or not to keep rolling dice and accumulating more points during their turn while risking their points being lost by rolling a 1 or to add their turn points to their total points. The question I have is how would I exit the do while loop if the player chooses to add their turn score, thus adding their score and ending their turn?

Here is the coding so far.

Java Code:

import java.util.Scanner;
import java.util.Random;
public class Pig
{
public static void main(String[] args)
{
int die; int userTotalScore; int userTurnScore; int compTotalScore; int compTurnScore;

[Code] ....

View Replies View Related

Random Dice Roller Game

Oct 23, 2014

So far I have

import java.util.Random;
import java.util.Scanner;
public class DiceGame6 {
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
System.out.println("Welcome to Computer Dice!");
System.out.println("-------------------------------");
System.out.println("You will first roll your dice

[code]....

How would I get the code to count the number of times something occurred. In the end it's suppose to count how many times I played the game and how many times I've won vs lost.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved