How To Start A Puzzle Game
Nov 25, 2014
I am trying to make a puzzle game in java.I have made it successfully.But the problem is,when it starts its already solved.I want it to start unsolved so the user can solve it.My code is:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.io.*;
class Puzzle extends JFrame implements ActionListener
[code]....
View Replies
ADVERTISEMENT
Oct 20, 2014
I have a simple Word Program here called PuzzleGame.java. It works perfectly but I wanted to add some bells and whistles to it. So I want to be able that if the user selects the same letter more than once a message comes up letting the user know that "That letter has already been selected, try another letter."
I am certain that if would go in the 'else' of the 'if( )' that I am providing.
import java.util.Scanner;
public class PuzzleGame {
public static void main(String[] args){
String secretPhrase = "BIG JAVA";
String guesses = " ";
[Code] .....
I am thinking maybe after the else in this if statement.
if(guesses.indexOf(secretLetter)== -1) {
System.out.print("-");
notDone = true;
} else {
//something here. I am not sure how to go about it.
System.out.print(secretLetter);
}
View Replies
View Related
Oct 16, 2014
I am new to making an installer so far i have made only one and i used "install creator"
I just make a watch (clock) application and i want when the windows start its also starts automatically except if it is closed by the user
just like widows clock widget.
View Replies
View Related
Oct 31, 2014
How to write a mini sudoku in 4x4 puzzle using java The entries of each grid are 1,2,3 or 4 only.
No number will be the on a row.
No number will be the same in a column.
There are 4 regions in the puzzle and no number will be the same in a region.
I want to ask how to finish the below code, because I don't know how to extend using the below code
import java.util.*;
public class MiniSudoku {
final static int SIZE=4;
[Code]....
View Replies
View Related
Oct 4, 2014
I have been working on a program that takes in a 2d array (there is a method to convert to 1d as necessary) and uses it as an 8 puzzle, which the program then solves (if it is solvable) using the A* Search algorithm, outputting each solution move. It needs error checkers/traps/exception handlers, and be able to create an 8 puzzle from user input, create an 8 puzzle from file input, and create an 8 puzzle from file input and then output to another file the solution move sequence. I have gotten nearly everything done except for implement the algorithm itself and the methods for handling input from files or output to files (the input/output file methods are a minor problem that I can probably solve fairly easily, I just want to be able to test the a* with the puzzle created from user input first.
I have taken several cracks at it, but I am not really good with Java in this type of situation and this is hurting me a lot. I have put in a method to determine if a puzzle is solvable, but the A* algorithm still eludes me. I understand the concept of the algorithm, you have a heuristic function, a cost function (each move equals 1 in this case), and you add the two together to get f(n), choosing the move that will get you the closest to your goal (best first search basically). here is what I have so far that works:
import java.io.File;
import java.io.IOException;
import java.util.Queue;
import java.util.Scanner;
public class Puzzle {
public static void main(String[] args) throws IOException {
[Code] ....
I have it outputting things to make sure all that works already, I have all the error handlers, but I think that before I can even implement the A*search algorithm, there may be something else I need. Conceptually, I understand I need Nodes, States and Stacks, and Queues (I think, I am not sure about this), but with the way my code has been made so far, I am not sure how to implement those and then implement them with the A* algorithm. What I should do next? I have looked at the code of other uses of A* algorithm(that is how I found out I might need Java data structures like queue and stack and list), but I am not sure exactly where to go to from where I am.
View Replies
View Related
Jun 8, 2014
When I add the first car only, it puts it in the correct spot and I can move it correctly. However when I attempt to add another car, the image of the second car repaint itself onto the first one, and the second car is not functioning at all (not moving)...
[code=Java]
View Replies
View Related
Feb 7, 2015
Coding (must follow pseudocode algorithm provided) for comparing characters of a word to a puzzle board char[][].
I've gotten the horizontal and vertical searches to work, but I'm having a difficult time figuring out how to search diagonally.
Here's the search algorithm format I have to use:
for each guess word
for each letter of the puzzle
for each letter of the guess word
check for diagonal match
if found, add word to list, break to next guess
I'm assuming there should be a +1 horizontal offset after I find the first letter, but every index I've bumped has caused me to screw up my array bounds. I'm missing something.
Here's the algorithm I'm using for diagonal search. This same algorithm worked for vertical search (minus the offset of course)
//diagonal search
for(String word : guessWords) {//for each guess word
int letterCount = 0;
int index = 0;
for(int j=0; j<grid[index].length; j++) {//for each puzzle letter
[Code] ....
View Replies
View Related
Mar 12, 2015
Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.
Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.
In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.
Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:
**o******
means that the player is at location 2 on the board.
Here are the other Opoly game rules:
If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.
If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).
If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,
Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.
Here is the driver class for the game:
import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();
[Code] ....
heres the methods:
REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:
playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.
spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.
spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.
move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.
isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.
drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.
displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.
View Replies
View Related
May 9, 2015
Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.
import java.util.Random;
import java.util.Scanner;
public class TicTacToe {
private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
[Code] ....
View Replies
View Related
Apr 27, 2014
how to start a new thread
public class pracDraw extends JFrame {
private Color red=Color.red;
public int i;
private Color white = Color.white;
JPanel pr=new JPanel();
JTextField t=new JTextField();
[code]....
If u run it you can see that the JTextField (t1) is drawn on the panel along the line but it does so with a gray border. How do i eliminate that grey border and only draw the text field along the line and finally make the text field green after it reaches the end of line?
View Replies
View Related
May 4, 2015
package com.example;
import com.example.domain.Admin;
import com.example.domain.Director;
[Code]....
View Replies
View Related
Nov 24, 2014
So, I have a gameOver() method that should when oval goes out of bounds abort game but, as soon as I start the game it runs the gameOver method. I've been looking over it for a while trying different things. I think what stood out to me is removing the abort sequence the game runs mostly as it should after, popup is closed and that if I replace game.gameOver(); with ya = -1 the ball bounces off the wall.
gameOver()
public void gameOver(){
JOptionPane.showMessageDialog(this, "Game Over", "Game Over", JOptionPane.YES_NO_OPTION);
System.exit(ABORT);
[Code] ....
View Replies
View Related
Jul 30, 2014
How that's possible
import java.util.*;
public class Stars {
public static void main(String[] args) {
line (13);
line (7);
line (35);
System.out.println();
box(10,3);
[Code] ....
View Replies
View Related
Aug 20, 2014
I am getting the error "Line 54, illegal start of expression". Line 54 is where my "for" starts. It was running ok earlier, now I can't get this error to go away?
public static void main(String[] args) {
double salary;
double commission;
double totalSales;
double annualComp;
double salesTarget;
double incentive;
double accel;
double incentive1;
double notAccel;
double increment;
[code]....
View Replies
View Related
Mar 17, 2014
Lines 7 , 10 ,13 .... All have a Illegal Start of Expression error.
[color=blue]private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Random rd = new Random();
int random = 0;
random=rd.nextInt(6)+1;
switch(random){
[Code] ....
View Replies
View Related
Jun 11, 2014
How to print 10 numbers in Fibonacci serious aftet given number?
Like 13 21 34...
View Replies
View Related
Apr 21, 2015
Where are all these illegal start of operations and all of these other method errors coming from.I've written enough methods not to have this problem.
----jGRASP exec: javac -g Assessement.java
Assessement.java:29: error: illegal start of expression
public void addQuestionAnswer(){
^
Assessement.java:29: error: illegal start of expression
[code].....
View Replies
View Related
May 5, 2014
I'm trying to get a timer to work to decrease the value of a stats bar (like Hunger Level, Energy Level), but it won't paint the bars in the first place, it won't let me start the timer (the start after t.start() is underlined) and now I'm getting an error that won't let me run it at all without putting public static void main (String [] args), even though adding it anywhere is causing other errors
public void hungerTimer () {
int delay = 300;
int period = 300;
interval = 100;
hungerBar.setValue(100);
hungerBar.repaint();
timer = new Timer();
[Code] .....
View Replies
View Related
Apr 1, 2014
I have two txt view
I have a counter that it starts from 0
I want it keep on to 30 and then stop and next txt view start from 0 to 30...
View Replies
View Related
Feb 23, 2014
I have an applet and start some process on Windows from applet. When I start this process just from another code(test), this code works fine and process runs from rt.exec() to proc.destroy(). When I use html call for applet - process runs only for 5 seconds every time (!!!) and then just alive, doesn't work, to proc.destroy(). This is really interesting for me (newbie in applets). I think, this issue caused by AccessController. I use Windows, medium Java security lever and applet is self-signed. It asks me to 'allow', applet works.Here's the code:
public String startRecording(final String filename) throws IOException {
try {
return (String) AccessController
.doPrivileged(new PrivilegedAction<String>() {
public String run() {
try {
proc = Runtime
.getRuntime()
[code]....
It's FFMPEG process, which records desktop video and writes it to file, maybe AccessController blocks access to file system.
View Replies
View Related
Nov 15, 2014
I made a tiny app that saves notes to a folder within the classes directory where I created the .jar file.Let's say I wanted to add this to Java Web Start. Would I be able to transfer the jar file within a folder(s) or would I have to change the program so that It creates a new folder to save texts In automatically ? Basically , can jar files be transferred with other files/folders ?
View Replies
View Related
Jun 12, 2014
On a MS Windows Server 2003 SP2 32-bit, java.exe crashes at start. I've tried ver. 7.0_55-b14 and 7.0_60-b19.
C:>java
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (virtualspace.cpp:114), pid=784, tid=3436
# fatal error: os::release_memory failed
[Code] ....
I know Java worked earlier on that server. JRE installation was fine. What could cause this crashing?
On another MS Windows Server 2003 SP2 32-bit, java.exe runs successfully, both ver. 7.0_55-b14 and 7.0_60-b19.
-- rpr.
View Replies
View Related
Jul 21, 2014
why the complier is giving the following error message "illegal start of expression" once it reach the countSpaces method.The way I see it (and I am obviously seeing it wrong), the code is public since why not, int since it returns an int # and the method has return int in it, and static I am not too sure but I get the same error message whether or not it is included
public static void main (String args[]) {
Scanner in = new Scanner(System.in);
String sentence;
System.out.println("type a sentence");
sentence = in.nextLine();
countSpaces (sentence);
[code]....
View Replies
View Related
Nov 11, 2014
I have a jtextfield that I want to make invisible on start. I do not see an option for that in the design side under properties. I am a VB programmer and in VB there is an option under properties to make it visible or invisible.
View Replies
View Related
May 25, 2014
am trying to Develop a download manager that will improve the downloading process, by splitting big files into different parts, and download each part of the file parallel and then combine them properly Just like JDownloader not really too complex like it though but more like it especially the split download part of it. I was able to get a script from some eBook but that doesn't really solve my problem as it only downloads pause and resumes which is not really what am looking for.
View Replies
View Related
Nov 23, 2014
I've written my program and don't know the algorithm for a postfix notation and how to make one correctly?how to start my algorithm for my enterAction actionPerformed button?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
[code]....
View Replies
View Related