How to make this Java Code in NetBeans
Ok this is game name Envelope but i dont know how does it work.??please i need a hand.
Code java:
/**
* Draw envelope without lifting your pen.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Scanner; // to read input
public class envelope
{
public static void main (String [] args) {
//1. Display Instruction
System.out.println("In this game player must choose path to draw an envelope");
System.out.println("Whithout lifting a pen");
System.out.println(" E");
System.out.println(" /\\");
System.out.println(" / \\");
System.out.println(" ___");
System.out.println("D C");
System.out.println(" | X |");
System.out.println(" ___");
System.out.println("A B");
//2. Reset the game environment
// Possible choice for node A = {B,C,D}
char [] nodeA = {'B','C','D'};
char [] nodeB={'A','C','D'};
char [] nodeC={'A','B','D','E'};
char [] nodeD={'A','B','C','D'};
char [] nodeE={'C','D'};
// path chosen by user
char [] path = {'\0','\0','\0','\0','\0','\0','\0','\0','\0'};
// object Scanner to read input from keyboard
Scanner in = new Scanner (System.in);
//3. Start the game
// 3.1 User choose node
System.out.println(" Please select node to start: A, B, C, D or E");
String userInputStr = in.next();
char currentNode = userInputStr.charAt(0);
// 3.2 Display possible node
Boolean gameover = false;
while (!gameover) {
switch (currentNode) {
case 'A' :
System.out.println("Choices");
for (int i=0; i < nodeA.length; i++)
System.out.print(nodeA[i]+" ");
System.out.println();
break;
case 'B' :
System.out.println("Choices");
for (int i=0; i < nodeB.length; i++)
System.out.print(nodeB[i]+" ");
System.out.println();
break;
case 'C' :
System.out.println("Choices");
for (int i=0; i < nodeC.length; i++)
System.out.print(nodeC[i]+" ");
System.out.println();
break;
case 'D' :
System.out.println("Choices");
for (int i=0; i < nodeD.length; i++)
System.out.print(nodeD[i]+" ");
System.out.println();
break;
case 'E' :
System.out.println("Choices");
for (int i=0; i < nodeE.length; i++)
System.out.print(nodeE[i]+" ");
System.out.println();
break;
default: System.out.println("Node NOT in the list");
}
// 3.3 User choose next node
char nextNode;
do {
System.out.println(" Please select next node");
userInputStr = in.next();
nextNode = userInputStr.charAt(0);
// 3.4 Check valid choice
if (nextNode == currentNode){
System.out.println("Invalid path- repeat path");
}
} while (nextNode == currentNode);
// 3.5 if game not over
// 3.5.1 Store choice in path
// 3.5.2 Repeat 3.2
currentNode = nextNode;
} // gameover
}// main
} // envelope
Re: How to make this Java Code in NetBeans
Please wrap your code in the
[highlight=java][/highlight] tags to get the formatting
Define don't know how it works. I presume this is not your code...then study the lines in the code, step through it with a debugger, or add some println's to evaluate how variables change.
Re: How to make this Java Code in NetBeans
The user presumably means that the code works, but they don't know the logic or it or why it is what it is.
The game goes on forever. You don't seem to have a thing that will end it.
Re: How to make this Java Code in NetBeans
my teacher give it to me.. to finish the work...
but i really stupid in java..
my teacher just teach me Raptor and BlueJ Software
But she didnt teach me how to use NetBeans
then she want me make a game using the NetBeans.
She told me to make Envelope game how make Envelope from line to line til it finish completely Envelope.
then she give me that CODE haaa i raealy confuse..
Re: How to make this Java Code in NetBeans
thanks those who make the code seen good.
Emm
but any want can teach me how to edit it make it little dif.. but same woking.
btw.. how do the will over..i already play it in bluej its good but i dont know how to edit it to see it little dif