• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Suman Adhikari

Game Not Working

9 posts in this topic

Well, this a Game from the HEAD FIRST JAVA book...and there I found an error when I compiled it!!
Please help me compile the program without error!!
 
It's a game called Sink the Dot Com !!
 
____________________________________________________________________________________
 
import java.io.*;
import java.util.*;
public class GameHelper {
 
private static final String alphabet ="abcdefg";
private int gridLength = 7;
private int gridSize = 49;
private int [] grid = new int[gridSize];
private int comCount = 0;
public String getUserInput(String prompt) {
String inputLine=null;
System.out.println(prompt + "  ");
try{
BufferedReader is=new BufferedReader(new InputStreamReader(System.in));
inputLine=is.readLine();
if(inputLine.length()==0)
return null;
}catch (IOException e){
System.out.println(" IOException "+ e);
}
return inputLine.toLowerCase();
}
 
public ArrayList<String> placeDotCom(int comSize){
ArrayList<String> alphaCells = new ArrayList<String>();
String [] alphacoords = new String [comSize];
String temp = null; 
int [] coords = new int[comSize];
int attempts = 0;
boolean success = false;
int location = 0;
comCount++;
int incr = 1;         
if ((comCount % 2) == 1) {
incr = gridLength; 
}
while ( !success & attempts++ < 200 ) { 
location = (int) (Math.random() * gridSize);
int x = 0; 
success = true;
while (success && x < comSize) {
if (grid[location] == 0) {
coords[x++] = location;
location += incr;
if (location >= gridSize){
success = false;
}
if (x>0 && (location % gridLength == 0)) {
success = false;
}
} else {
success = false;
}
}
}
int x = 0;
int row = 0;
int column = 0;
while (x < comSize) {
grid[coords[x]] = 1;
row = (int) (coords[x] / gridLength);
column = coords[x] % gridLength;
temp = String.valueOf(alphabet.charAt(column));
alphaCells.add(temp.concat(Integer.toString(row)));
x++;      
}
return alphaCells;
}
}
 
 
____________________________________________________________________________________
 
 

public class DotComBust {
private GameHelper helper = new GameHelper();
private ArrayList<DotCom> dotComsList = new ArrayList<DotCom>();
private int numOfGuesses = 0;
 
private void setUpGame() {
DotCom one = new DotCom();
one.setName("Pets.com");
DotCom two = new DotCom();
two.setName("eToys.com");
DotCom three = new DotCom();
three.setName("Go2.com");
dotComsList.add(one);  
dotComsList.add(two);
dotComsList.add(three);
 
System.out.println("Your goal is to sink three dot coms.");
System.out.println("Pets.com, eToys.com, Go2.com");
System.out.println("Try to sink them all in the fewest number of guesses");
 
for (DotCom dotComToSet : dotComsList) {
ArrayList<String> newLocation = helper.placeDotCom(3);
dotComToSet.setLocationCells(newLocation);
}
}
 
private void startPlaying() {
while(!dotComsList.isEmpty()) {
String userGuess = helper.getUserInput("Enter a guess");
checkUserGuess(userGuess);
}
finishGame();
}
 
 
private void checkUserGuess(String userGuess) {
numOfGuesses++;
String result  = "miss";
for (DotCom dotComToTest:dotComsList) {
result = dotComToTest.checkYourself(userGuess);
if (result.equals("hit")) {
break;
}
if (result.equals("kill")) {
dotComsList.remove(dotComToTest);
break;
}
}
System.out.println(result);
}
 
 
private void finishGame() {
System.out.println("All Dot Coms are dead! Your stock is now worthless.");
if (numOfGuesses <= 18) {
System.out.println("It only took you “ + numOfGuesses + “ guesses.");
System.out.println(" You got out before your options sank.");
} else {
System.out.println("Took you long enough. “+ numOfGuesses + “ guesses.");
System.out.println("Fish are dancing with your options");
}
}
 
public static void main(String[] args) {
DotComBust game = new DotComBust();
game.setUpGame();
game.startPlaying();
}
 
}
 
 
____________________________________________________________________________________
 
import java.util.*;
public class DotCom {
private ArrayList<String> locationCells;
private String name;
 
public void setLocationCells(ArrayList<String> loc) {
locationCells = loc;
}
 
public void setName(String n) {
name = n;
}
 
public String checkYourself(String userInput) {
String result = "miss";
int index = locationCells.indexOf(userInput); 
if (index >= 0) {
locationCells.remove(index);
if (locationCells.isEmpty()) {
result = "kill";
System.out.println("Ouch! You sunk " + name + "   : ( ");
} else {
result = "hit";
}
}
}
}
 
____________________________________________________________________________________
 
 
What seems to be the error in the above code!! 
When I compile it...The following error occurs!!
 
 
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
 
at DotComBust.main(DotComBust.java:65)
 
 
 
 
 
Please...Someone help me on this JAVA stuff!!
 
 
 
 
 
 
Edited by DummyID
0

Share this post


Link to post
Share on other sites
Can you put code tags around your code?
 
// It will be easier to read your code that way.
Edited by ultramailman
0

Share this post


Link to post
Share on other sites

Here is the fix: Above the last 2 braces of the DotCom Class, type "return result". The author forgot to put that. Your program will work now if you put that return statement. 

 

What chapter of the book is this? If you are just starting out with Java, this program would be an overkill because it involves built-in classes in the language and some he is writing from scratch. I would suggest focusing and writing one class with the main method instead of 4 classes and see what the code is doing line by line.

Edited by warnexus
0

Share this post


Link to post
Share on other sites
// This is what he meant by putting tags around it
// just put '[code]' in front of the beginning of the code, and '[/code]' at the end
// and you might want to space it out like it should be, so we can all read it lol
 
import java.io.*;
import java.util.*;
public class GameHelper {
 
private static final String alphabet ="abcdefg";
private int gridLength = 7;
private int gridSize = 49;
private int [] grid = new int[gridSize];
private int comCount = 0;
public String getUserInput(String prompt) {
String inputLine=null;
System.out.println(prompt + "  ");
try{
BufferedReader is=new BufferedReader(new InputStreamReader(System.in));
inputLine=is.readLine();
if(inputLine.length()==0)
return null;
}catch (IOException e){
System.out.println(" IOException "+ e);
}
return inputLine.toLowerCase();
}
 
public ArrayList<String> placeDotCom(int comSize){
ArrayList<String> alphaCells = new ArrayList<String>();
String [] alphacoords = new String [comSize];
String temp = null; 
int [] coords = new int[comSize];
int attempts = 0;
boolean success = false;
int location = 0;
comCount++;
int incr = 1;         
if ((comCount % 2) == 1) {
incr = gridLength; 
}
while ( !success & attempts++ < 200 ) { 
location = (int) (Math.random() * gridSize);
int x = 0; 
success = true;
while (success && x < comSize) {
if (grid[location] == 0) {
coords[x++] = location;
location += incr;
if (location >= gridSize){
success = false;
}
if (x>0 && (location % gridLength == 0)) {
success = false;
}
} else {
success = false;
}
}
}
int x = 0;
int row = 0;
int column = 0;
while (x < comSize) {
grid[coords[x]] = 1;
row = (int) (coords[x] / gridLength);
column = coords[x] % gridLength;
temp = String.valueOf(alphabet.charAt(column));
alphaCells.add(temp.concat(Integer.toString(row)));
x++;      
}
return alphaCells;
}
}
 
____________________________________________________________________________________
 

 
public class DotComBust {
private GameHelper helper = new GameHelper();
private ArrayList<DotCom> dotComsList = new ArrayList<DotCom>();
private int numOfGuesses = 0;
 
private void setUpGame() {
DotCom one = new DotCom();
one.setName("Pets.com");
DotCom two = new DotCom();
two.setName("eToys.com");
DotCom three = new DotCom();
three.setName("Go2.com");
dotComsList.add(one);  
dotComsList.add(two);
dotComsList.add(three);
 
System.out.println("Your goal is to sink three dot coms.");
System.out.println("Pets.com, eToys.com, Go2.com");
System.out.println("Try to sink them all in the fewest number of guesses");
 
for (DotCom dotComToSet : dotComsList) {
ArrayList<String> newLocation = helper.placeDotCom(3);
dotComToSet.setLocationCells(newLocation);
}
}
 
private void startPlaying() {
while(!dotComsList.isEmpty()) {
String userGuess = helper.getUserInput("Enter a guess");
checkUserGuess(userGuess);
}
finishGame();
}
 
 
private void checkUserGuess(String userGuess) {
numOfGuesses++;
String result  = "miss";
for (DotCom dotComToTest:dotComsList) {
result = dotComToTest.checkYourself(userGuess);
if (result.equals("hit")) {
break;
}
if (result.equals("kill")) {
dotComsList.remove(dotComToTest);
break;
}
}
System.out.println(result);
}
 
 
private void finishGame() {
System.out.println("All Dot Coms are dead! Your stock is now worthless.");
if (numOfGuesses <= 18) {
System.out.println("It only took you “ + numOfGuesses + “ guesses.");
System.out.println(" You got out before your options sank.");
} else {
System.out.println("Took you long enough. “+ numOfGuesses + “ guesses.");
System.out.println("Fish are dancing with your options");
}
}
 
public static void main(String[] args) {
DotComBust game = new DotComBust();
game.setUpGame();
game.startPlaying();
}
 
}
 
____________________________________________________________________________________
 

import java.util.*;
public class DotCom {
private ArrayList<String> locationCells;
private String name;
 
public void setLocationCells(ArrayList<String> loc) {
locationCells = loc;
}
 
public void setName(String n) {
name = n;
}
 
public String checkYourself(String userInput) {
String result = "miss";
int index = locationCells.indexOf(userInput); 
if (index >= 0) {
locationCells.remove(index);
if (locationCells.isEmpty()) {
result = "kill";
System.out.println("Ouch! You sunk " + name + "   : ( ");
} else {
result = "hit";
}
}
}
}


Edited by Muzzy A
0

Share this post


Link to post
Share on other sites

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
 
at DotComBust.main(DotComBust.java:65)

Also, the error message should give you some hint as to where it went wrong, even if it doesn't tell you exactly what. In this case, it points to DotComBust.java, line 65 (or somewhere near that line).
0

Share this post


Link to post
Share on other sites

Can you put code tags around your code?
 

// It will be easier to read your code that way.

Will remember that next time!!

0

Share this post


Link to post
Share on other sites

hat chapter of the book is this? If you are just starting out with Java, this program would be an overkill because it involves built-in classes in the language and some he is writing from scratch. I would suggest focusing and writing one class with the main method instead of 4 classes and see what the code is doing line by line.

Well, it;s the full game...and I'm learning from 5 books at the same time so 

having a little hangover!!

 

Plus exams on head!!

 

Will finish it in about a week if I use the forum well!!

 

And I MEAN 1 WEEK TIME CONTINUOUSLY!!

 

not with break!!

 

P.S. chk my page!! 

 

http://fb.com/IntelligenceIsMyCommonSense

0

Share this post


Link to post
Share on other sites


public class DotComBust {
private GameHelper helper = new GameHelper();
private ArrayList<DotCom> dotComsList = new ArrayList<DotCom>();
private int numOfGuesses = 0;
 
private void setUpGame() {
DotCom one = new DotCom();
one.setName("Pets.com");
DotCom two = new DotCom();
two.setName("eToys.com");
DotCom three = new DotCom();
three.setName("Go2.com");
dotComsList.add(one);  
dotComsList.add(two);
dotComsList.add(three);
 
System.out.println("Your goal is to sink three dot coms.");
System.out.println("Pets.com, eToys.com, Go2.com");
System.out.println("Try to sink them all in the fewest number of guesses");
 
for (DotCom dotComToSet : dotComsList) {
ArrayList<String> newLocation = helper.placeDotCom(3);
dotComToSet.setLocationCells(newLocation);
}
}
 
private void startPlaying() {
while(!dotComsList.isEmpty()) {
String userGuess = helper.getUserInput("Enter a guess");
checkUserGuess(userGuess);
}
finishGame();
}
 
 
private void checkUserGuess(String userGuess) {
numOfGuesses++;
String result  = "miss";
for (DotCom dotComToTest:dotComsList) {
result = dotComToTest.checkYourself(userGuess);
if (result.equals("hit")) {
break;
}
if (result.equals("kill")) {
dotComsList.remove(dotComToTest);
break;
}
}
System.out.println(result);
}
 
 
private void finishGame() {
System.out.println("All Dot Coms are dead! Your stock is now worthless.");
if (numOfGuesses <= 18) {
System.out.println("It only took you “ + numOfGuesses + “ guesses.");
System.out.println(" You got out before your options sank.");
} else {
System.out.println("Took you long enough. “+ numOfGuesses + “ guesses.");
System.out.println("Fish are dancing with your options");
}
}
 
public static void main(String[] args) { //Line 65!!
DotComBust game = new DotComBust();
game.setUpGame();
game.startPlaying();
}
}

The error still exists at line 65...I marked the error!!

 

 
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
 
at DotComBust.main(DotComBust.java:65)
 
Some1 plz help with this stupid error!!
 
I am using Eclipse... Is it because of Eclipse??
Edited by DummyID
0

Share this post


Link to post
Share on other sites

Some1 plz help with this stupid error!!

Don't you think it's a bit stupid that you ask people to sink quite a bit of time into your problem and you don't even have the time or interest to type "someone" and "please"?

I am using Eclipse... Is it because of Eclipse??

No.

You told Eclipse to launch the application despite the fact that your program is not a valid, compilable Java program. Fix whatever error is around line 65 in DotComBust.java.
0

Share this post


Link to post
Share on other sites

Some1 plz help with this stupid error!!

Don't you think it's a bit stupid that you ask people to sink quite a bit of time into your problem and you don't even have the time or interest to type "someone" and "please"?

>I am using Eclipse... Is it because of Eclipse??

No.

You told Eclipse to launch the application despite the fact that your program is not a valid, compilable Java program. Fix whatever error is around line 65 in DotComBust.java.

 

Well...First of all...I am not a JAVA professional...am still a learner!!

 

Now would you please look into it!!

 

if(you.are.happy){

System.out.println("Please look into it!!");

}else{

System.out.println("Knowledge is Peace!!");

}

-2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0