Jump to content
  • Advertisement
Sign in to follow this  
obi-wan shinobi

text-based demo code

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my latest text-based work, which is somewhat based on my other thread a while ago, but with a few differences. To test it out, just copy and paste into your Java IDE/editor. Notes: -This is roughly 700 lines of Java (instead of c++) code done over 2 weeks -The code may very well be confusing; sorry for not commenting it yet -I realize now that there is a better way to do this, so I'm going to try that way next (using more than 1 class, inheritance, etc.) Any questions or comments?
import java.io.*;
import java.lang.*;

class areaone {
	BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	int room;			String input;			int score;
	String o;			String i;				String t;
	int xaxis=5;		int yaxis=5;			int zaxis=2;			
	int[][] state=new int[50][4];	
	int[][] object=new int[50][4];	
	int[][] path=new int[50][4];
	int[] pitem=new int[16];
	String[] items=new String[50];
	String[] choice=new String[16];
	String wrongway="You cannot move in that direction here.\n";
	public areaone() {
		room=0;							score=0;
		choice[0]="Move North ";		choice[1]="Move East  ";
		choice[2]="Move West  ";		choice[3]="Move South ";
		choice[4]="Pull       ";		choice[5]="Push       ";
		choice[6]="Operate    ";		choice[7]="Inspect    ";
		choice[8]="Take       ";		choice[9]="Use item   ";
		choice[10]="Look Around";		choice[11]="Check Items";
		choice[12]="View Map   ";
		items[0]="";					items[1]="rusted key";
		items[2]="locked door";			items[3]="wall lever";
		items[4]="dead soldier";		items[5]="dead child";
		items[6]="dead scientist";		items[7]="cardboard box";
		items[8]="combination lock";	items[9]="fuse";
		items[10]="fuse box";			items[11]="chemical A1";
		items[12]="chemical B2";		items[13]="chemical C3";
		items[14]="chemical D4";		items[15]="flashing button";
		items[16]="red gauge";			items[17]="green gauge";
		items[18]="blue gauge";			items[19]="startup circuit";
		items[20]="red button";			items[21]="green button";
		items[22]="blue button";		items[23]="luminous rock";
		items[24]="elevator";			items[25]="dim rock";
		items[26]="crumbled note";		items[27]="card key";
		items[28]="turret";				items[29]="explosives";
		items[30]="rusty pick";			items[31]="dull pick";
		items[32]="unrefined coal";		items[33]="refined coal";
		items[34]="exposed wires";		items[35]="security door";
		items[36]="sharp pick";			items[37]="coal refiner";
		items[38]="coal furnace";		items[39]="mining lift";
		items[40]="radar jammer";		items[41]="command console";
		items[42]="sunbeam cover";		items[43]="sunbeam path";
		items[44]="giant door";
		object[2][0]=2;		object[2][1]=3;
		object[4][0]=15;	object[4][1]=16;	object[4][2]=17;	object[4][3]=18;
		object[6][0]=4;		object[6][1]=5;		object[6][2]=6;
		object[7][0]=7;		object[7][1]=8;
		object[8][0]=10;	object[8][1]=24;
		object[9][0]=11;	object[9][1]=12;	object[9][2]=13;
		object[10][0]=41;	object[10][1]=26;
		object[13][0]=19;	object[13][1]=20;	object[13][2]=21;	object[13][3]=22;
		object[14][0]=42;	object[14][1]=40;
		path[1][1]=1;		path[1][2]=1;
		path[8][0]=1;		path[8][1]=1;		path[8][2]=1;
		path[9][0]=1;		path[9][2]=1;
		path[11][2]=1;		path[11][3]=1;
		path[16][0]=1;		path[16][3]=1;
		path[18][1]=1;		path[18][2]=1;
		path[19][2]=1;		path[19][3]=1;
		path[21][0]=1;		path[21][1]=1;
		path[22][1]=1;		path[22][2]=1;
		path[23][1]=1;		path[23][2]=1;
		path[24][0]=1;		path[24][2]=1;
		path[29][2]=1;		path[29][3]=1;
		path[34][0]=1;		path[34][2]=1;		path[34][3]=1;
		path[35][0]=1;		path[35][3]=1;
		path[38][1]=1;		path[38][3]=1;
		path[39][0]=1;		path[39][2]=1;		path[39][3]=1;
		path[42][1]=1;		path[42][3]=1;
		path[43][0]=1;		path[43][2]=1;
		path[44][0]=1;		path[44][3]=1;		
		path[47][0]=1;		path[47][1]=1;
	public void roomname() {
		System.out.print("Current Location: ");
		switch(room) {
			case 0:		System.out.println("[ Cave Entrance ]");		break;
			case 1:		System.out.println("[ Creepy Corridor ]");		break;
			case 2:		System.out.println("[ Scrap Dump ]");			break;
			case 3:		System.out.println("[ Illuminated Tunnel ]");	break;
			case 4:		System.out.println("[ Engine Chamber ]");		break;
			case 6:		System.out.println("[ Dungeon Cell ]");			break;
			case 7:		System.out.println("[ Guard Station A ]");		break;
			case 8:		System.out.println("[ Central Hub - B1 ]");		break;
			case 9:		System.out.println("[ Chemical Storage ]");		break;
			case 10:	System.out.println("[ Lab Control Center ]");	break;
			case 11:	System.out.println("[ Laboratory ]");			break;
			case 12:	System.out.println("[ Mining Workshop ]");		break;
			case 13:	System.out.println("[ Adjustment Room ]");		break;
			case 14:	System.out.println("[ Sunny Balcony ]");		break;
			case 15:	System.out.println("[ Weapon Cache - Guns ]");	break;
			case 16:	System.out.println("[ Hall Leading to Lab ]");	break;
			case 17:	System.out.println("[ Outside the Workshop ]");	break;
			case 18:	System.out.println("[ Workshop Path ]");		break;
			case 19:	System.out.println("[ Guard Station B ]");		break;
			case 20:	System.out.println("[ Weapon Cache - Bombs ]"); break;
			case 21:	System.out.println("[ Specimen Archives ]");	break;
			case 22:	System.out.println("[ Narrow Passage ]");		break;
			case 23:	System.out.println("[ Mining Lift - B1 ]");		break;
			case 24:	System.out.println("[ Monitored Hall ]");		break;
			case 26:	System.out.println("[ Waste Disposal Room ]");	break;
			case 27:	System.out.println("[ Stalagmite Junction ]");	break;
			case 28:	System.out.println("[ Bridge Over A Pit ]");	break;
			case 29:	System.out.println("[ Torch-Lit Passage ]");	break;
			case 30:	System.out.println("[ Production Room ]");		break;
			case 31:	System.out.println("[ Refinery ]");				break;
			case 32:	System.out.println("[ Straightforward Hall ]");	break;
			case 33:	System.out.println("[ Central Hub - B2 ]");		break;
			case 34:	System.out.println("[ Chilly Hallway ]");		break;
			case 35:	System.out.println("[ Fork in the Road ]");		break;
			case 36:	System.out.println("[ Stalactite Junction ]");	break;
			case 37:	System.out.println("[ Guard Station C ]");		break;
			case 38:	System.out.println("[ Just Another Hall ]");	break;
			case 39:	System.out.println("[ Chillier Hallway ]");		break;
			case 40:	System.out.println("[ Coal Mines ]");			break;
			case 41:	System.out.println("[ Silent Passageway ]");	break;
			case 42:	System.out.println("[ Guard Station D ]");		break;
			case 43:	System.out.println("[ Room Full of Wires ]");	break;
			case 44:	System.out.println("[ Chilliest Hallway ]");	break;
			case 46:	System.out.println("[ The Inner Sanctum ]");	break;
			case 47:	System.out.println("[ Resting Quarters ]");		break;
			case 48:	System.out.println("[ Mining Lift - B2 ]");		break;
			case 49:	System.out.println("[ Dusty Dead End ]");		break;
			default:	break;
	public String trimspace(String opt) {
		opt = opt.trim();
		opt = opt.toLowerCase();
		return opt;
	public String choose() throws IOException {
		for(int i=0;i<13;i++) {
			if(i%2==0)		System.out.print("\t");
			else			System.out.println();
		System.out.print("\nWhat will you do?\t");
		input = in.readLine();
		for(int j=0;j<13;j++) {
			t = trimspace(choice[j]);
			if(input.compareToIgnoreCase(t)==0) {
				return input.toLowerCase();
		System.out.println("--Invalid choice.");
		return "void";
	public int move(String d) throws IOException {
		int a=-1;
		for(int i=0;i<4;i++) {
			t = trimspace(choice);
			if(d.compareTo(t)==0 && path[room]==1)
				{	a=i;	break;	}
			if(d.compareTo(t)==0 && path[room]==0)
				{	System.out.println(wrongway);	return 0;	}
		switch(a) {
			case 0:		{	score-=5;	return -xaxis;		}
			case 1:		{	score-=5;	return 1;			}
			case 2:		{	score-=5;	return -1;			}
			case 3:		{	score-=5;	return xaxis;		}
			default:	System.out.println("--Invalid direction.");
		return 0;
	public void process(String p) throws IOException {
		if(p.compareTo("pull")==0)			pull();
		if(p.compareTo("push")==0)			push();
		if(p.compareTo("operate")==0)		operate();
		if(p.compareTo("inspect")==0)		inspect();
		if(p.compareTo("take")==0)			take();
		if(p.compareTo("use item")==0)		useitem();
	public void pull() throws IOException {
		System.out.print("What would you like to pull?\t");
		String s=in.readLine();
		if(s.compareTo(items[3])==0 && room==2 && state[2][1]==0) {
			System.out.println("(!)\tThe lever is now in the up position.");
			state[2][1]=1;		path[1][3]=1;		path[6][0]=1;		return;
		if(s.compareTo(items[3])==0 && room==2 && state[2][1]==1) {
			System.out.println("(!)\tThe lever is now in the down position.");
			state[2][1]=0;		path[1][3]=0;		path[6][0]=0;		return;
		if(s.compareTo("exposed wires")==0 && room==43 && state[43][0]==0) {
			if(pitem[4]==29 && pitem[5]==29 && pitem[6]==23) {
			System.out.println("(!)\tPower deactivated.  All B2 activity suspended.");
			path[27][1]=1;		path[27][2]=1;		path[27][3]=1;		score+=75;
			path[28][2]=1;		path[26][1]=1;		path[32][0]=1;
			path[36][1]=1;		path[36][2]=1;		path[36][3]=1;
			path[37][2]=1;		path[35][1]=1;		path[41][0]=1;
			state[8][1]=0;		state[33][0]=0;		state[43][0]=1;
			else		System.out.println("(!)\tYou're missing a few things...");
	public void push() throws IOException {
		System.out.print("What would you like to push?\t");
		String s=in.readLine();
		int i;
		if(s.compareTo("flashing button")==0 && room==4 &&
			object[4][0]==15 && state[8][0]==1) {
			System.out.println("(!)\tThe monitor now reads: 'Adjustment Room open'.");
			object[4][0]=0;		path[8][3]=1;		path[13][0]=1;
			score+=25;			return;
		if(s.compareTo("exposed wires")==0 && room==43 && state[43][0]==1) {
			if(object[27][0]==0 && object[36][0]==0) {
			System.out.println("(!)\tPower reactivated.  All B2 activity resumed.");
			state[8][1]=1;		state[33][0]=1;		state[43][0]=2;		score+=75;
			else		System.out.println("(!)\tYou've still got work to do...");
		if(s.compareTo("red button")==0 && room==13) {
			System.out.print("(?)\tHow far in will you push the button (0-4)?\t");
			if(i<5 && i>-1)			state[13][0]=i;
			else		System.out.println("(!)--Out of range.");
		if(s.compareTo("green button")==0 && room==13) {
			System.out.print("(?)\tHow far in will you push the button (0-5)?\t");
			if(i<6 && i>-1)			state[13][1]=i;
			else		System.out.println("(!)--Out of range.");
		if(s.compareTo("blue button")==0 && room==13) {
			System.out.print("(?)\tHow far in will you push the button (0-3)?\t");
			if(i<4 && i>-1)			state[13][2]=i;
			else		System.out.println("(!)--Out of range.");
		if(s.compareTo("giant door")==0 && room==41) {
			if(state[30][0]==1 && state[43][0]==2) {
				System.out.println("(?)\tYou push the giant door open.");
				path[41][3]=1;		path[46][0]=1;		score+=50;
			else		System.out.println("(!)\tIt's locked.");
	public void operate() throws IOException {
		System.out.print("What would you like to operate?\t");
		String s=in.readLine();
		if(s.compareTo("elevator")==0 && room==8 && state[8][1]==1) {
			System.out.print("(?)\tTake the elevator down?\t");
			if(s.compareToIgnoreCase("yes")==0)	{
				System.out.println("(!)\tGoing down...");		room+=25;
			else		System.out.println("(!)\tElevator ride cancelled.");
		if(s.compareTo("command console")==0 && room==10 && state[10][0]==0) {
			System.out.print("(?)\tEnter a command:\t");
			if(s.compareToIgnoreCase("eject ck")==0 && object[10][1]!=34) {
				System.out.println("(!)\tCard key ejected from console.");
				object[10][1]=27;		state[10][0]=1;			score+=25;
			else		System.out.println("(!)\tCommand not recognized.");
		if(s.compareTo("mining lift")==0 && room==23) {
			System.out.print("(?)\tTake the lift down?\t");
			if(s.compareToIgnoreCase("yes")==0) {
				System.out.println("(!)\tGoing down...");		room+=25;
			else		System.out.println("(!)\tLift riding cancelled.");
		if(s.compareTo("elevator")==0 && room==33 && state[33][0]==1) {
			System.out.print("(?)\tTake the elevator up?\t");
			if(s.compareToIgnoreCase("yes")==0)	{
				System.out.println("(!)\tGoing up...");		room-=25;
			else		System.out.println("(!)\tElevator ride cancelled.");
		if(s.compareTo("mining lift")==0 && room==48) {
			System.out.print("(?)\tTake the lift up?\t");
			if(s.compareToIgnoreCase("yes")==0) {
				System.out.println("(!)\tGoing up...");		room-=25;
			else		System.out.println("(!)\tLift riding cancelled.");
		if(s.compareTo("startup circuit")==0 && room==13 && state[13][0]==3 && 
			state[13][1]==4 && state[13][2]==1 && state[8][1]!=1) {
				System.out.println("(!)\tThe elevator is now operational.");
				state[8][1]=1;		state[33][0]=1;			score+=25;		return;
	public void inspect() throws IOException {
		System.out.print("What would you like to inspect?\t");
		String s=in.readLine();
		if(s.compareTo(items[5])==0 && room==6 && object[6][1]==5 && pitem[0]!=1) {
			System.out.println("(!)\tTurning over the body, you see a rusted key");
			object[6][3]=1;		score+=25;		return;
		if(s.compareTo("cardboard box")==0 && room==7 &&
		 	object[7][0]==7 && pitem[1]!=9) {
			System.out.println("(!)\tUnder a pile of blank paper, you find a fuse");
			object[7][0]=9;		score+=25;		return;
		if(s.compareTo("sunbeam cover")==0 && room==14 && object[14][0]==42) {
			System.out.println("(!)\tPerhaps you can break it with something sharp.");
		if(s.compareTo("chemical a1")==0 && room==9) {
			System.out.println("(!)\tIt's marked 'Cleanser'");
		if(s.compareTo("chemical b2")==0 && room==9) {
			System.out.println("(!)\tIt's marked, 'Brightener'");
		if(s.compareTo("chemical c3")==0 && room==9) {
			System.out.println("(!)\tIt's marked, 'Sharpener'");
		if(s.compareTo("crumbled note")==0 && room==10) {
			System.out.println("(!)\tIt reads, 'eject ck'.");
		if(s.compareTo("red gauge")==0 && room==4) {
			System.out.println("(!)\tThe meter reads, '0.75'.");
		if(s.compareTo("green gauge")==0 && room==4) {
			System.out.println("(!)\tThe meter reads, '0.80'.");
		if(s.compareTo("blue gauge")==0 && room==4) {
			System.out.println("(!)\tThe meter reads, '0.33'.");
		if(s.compareTo("exposed wires")==0 && room==43 && state[43][0]==0) {
			System.out.println("(!)\tPulling these wires would shut down the power.");
		if(s.compareTo("exposed wires")==0 && room==43 && state[43][0]==1) {
			System.out.println("(!)\tPushing these wires would restore the power.");
		if(s.compareTo("coal furnace")==0 && room==30) {
			System.out.println("(!)\tA warning notice reads, 'refined coal only'.");
				System.out.println("(!)\tIt's barely producing any power...");
		if(s.compareTo("giant door")==0 && room==41 && object[41][0]==44) {
			System.out.println("(!)\tDespite its size, you can push this door open.");
			System.out.println("\tThat is, if two sources of power are supplied.");
	public void take() throws IOException {
		System.out.print("What would you like to take?\t");
		String s=in.readLine();
		if(s.compareTo(items[1])==0 && room==6 && object[6][3]==1) {
			System.out.println("(!)\tRusted Key taken.\n");		object[6][3]=0;
			pitem[0]=1;			score+=10;		return;
		if(s.compareTo("fuse")==0 && room==7 && object[7][0]==9) {
			System.out.println("(!)\tFuse taken.\n");			object[7][0]=0;
			pitem[1]=9;			score+=10;		return;	
		if(s.compareTo("rusty pick")==0 && room==49 && object[49][0]==30) {
			System.out.println("(!)\tRusty pick taken.\n");		object[49][0]=0;
			pitem[2]=30;		score+=10;		return;
		if(s.compareTo("card key")==0 && room==10 && object[10][1]==27) {
			System.out.println("(!)\tCard key taken.\n");		object[10][1]=0;
			pitem[3]=27;		score+=10;		return;
		if(s.compareTo("explosives")==0 && room==12 && object[12][0]==29) {
			System.out.println("(!)\tExplosives taken.\n");		object[12][0]=0;
			pitem[4]=29;		score+=10;		return;
		if(s.compareTo("explosives")==0 && room==20 && object[20][0]==29) {
			System.out.println("(!)\tExplosives taken.\n");		object[20][0]=0;
			pitem[5]=29;		score+=10;		return;
		if(s.compareTo("dim rock")==0 && room==3 && object[3][1]==25) {
			System.out.println("(!)\tDim rock taken.\n");		object[3][1]=0;
			pitem[6]=25;		score+=10;		return;
		if(s.compareTo("unrefined coal")==0 && room==40 && object[40][0]==32) {
			System.out.println("(!)\tUnrefined coal taken.\n");	object[40][0]=0;
			pitem[7]=32;		score+=10;		return;
	public boolean useprep() throws IOException {
		int c=0;	int d=0;
		for(int a=0;a<16;a++) {
		if(c>0)		System.out.print("What item would you like to use?\t");
		else		{	
			System.out.print("You don't have any items to use.\n");
			return false;	
		for(int b=0;b<4;b++) {
			if(object[room]>0)	d++;
		if(d>0)		System.out.print("What would you like to use this on?\t");
		else		{
			System.out.print("There's nothing here to try using this with.\n");
			return false;
		return true;
	public void useitem() throws IOException {
		if(useprep()==false)		return;
		if(i.compareTo("rusted key")==0 && o.compareTo("locked door")==0 && 
			room==2 && object[2][0]==2 && pitem[0]==1) {
			System.out.println("(!)\tDoor unlocked with rusted key.\n");
			object[2][0]=0;		path[2][1]=1;		path[3][2]=1;		return;	
		if(i.compareTo("fuse")==0 && o.compareTo("fuse box")==0 && room==8 && 
			object[8][0]==10 && pitem[1]==9) {
			System.out.println("(!)\tThe broken fuse was replaced.\n");
			object[8][0]=0;		state[8][0]=1;		pitem[1]=0;
			score+=25;			return;
		if(i.compareTo("card key")==0 && o.compareTo("security door")==0 &&	
			room==16 && object[16][0]==35 && pitem[3]==27) {
			System.out.println("(!)\tSecurity door unlocked with card key.\n");
			object[16][0]=0;	path[16][2]=1;		path[15][1]=1;
		if(i.compareTo("card key")==0 && o.compareTo("security door")==0 &&	
			room==17 && object[17][0]==35 && pitem[3]==27) {
			System.out.println("(!)\tSecurity door unlocked with card key.\n");
			object[17][0]=0;	path[17][0]=1;		path[12][3]=1;
		if(i.compareTo("card key")==0 && o.compareTo("security door")==0 &&	
			room==19 && object[19][0]==35 && pitem[3]==27) {
			System.out.println("(!)\tSecurity door unlocked with card key.\n");
			object[19][0]=0;	path[19][0]=1;		path[14][3]=1;
		if(i.compareTo("rusty pick")==0 && o.compareTo("chemical a1")==0 &&
			room==9 && pitem[2]==30) {
			System.out.println("(!)\tThe rusty pick has become the dull pick.\n");
			pitem[2]=31;		score+=50;			return;
		if(i.compareTo("dull pick")==0 && o.compareTo("chemical c3")==0 &&
			room==9 && pitem[2]==31) {
			System.out.println("(!)\tThe dull pick has become the sharp pick.\n");
			pitem[2]=36;		score+=50;			return;
		if(i.compareTo("sharp pick")==0 && o.compareTo("luminous rock")==0 &&
			room==3 && pitem[6]!=25 && pitem[2]==36) {
			System.out.println("(!)\tA dim rock breaks off from the larger rock.\n");
			object[3][1]=25;	score+=25;			return;
		if(i.compareTo("sharp pick")==0 && o.compareTo("sunbeam cover")==0 && 
			room==14 && pitem[2]==36 && object[14][0]==42) {
			System.out.println("(!)\tThe sunbeam cover has been broken,");
			System.out.println("\tRevealing a sunbeam path.\n");
			object[14][0]=0;	score+=25;			return;
		if(i.compareTo("dim rock")==0 && o.compareTo("sunbeam path")==0 &&
			room==14 && pitem[6]==25) {
			System.out.println("(!)\tThe dim rock has become a luminous rock.\n");
			pitem[6]=23;		score+=25;			return;
		if(i.compareTo("explosives")==0 && o.compareTo("turret")==0 && 
			room==27 && pitem[4]==29) {
			System.out.println("(!)\tThe turret has been destroyed.\n");
			pitem[4]=0;			object[27][0]=0;	score+=50;		return;
		if(i.compareTo("explosives")==0 && o.compareTo("turret")==0 && 
			room==36 && pitem[5]==29) {
			System.out.println("(!)\tThe turret has been destroyed.\n");
			pitem[5]=0;			object[36][0]=0;	score+=50;		return;
		if(i.compareTo("unrefined coal")==0 && o.compareTo("coal refiner")==0 &&
			room==31 && pitem[7]==32) {
			System.out.println("(!)\tThe refining process yields refined coal.\n");
			pitem[7]=33;		score+=25;			return;
		if(i.compareTo("refined coal")==0 && o.compareTo("coal furnace")==0 &&
			room==30 && pitem[7]==33) {
			System.out.println("(!)\tThe furnace is supplying adequate power.");
			pitem[7]=0;			state[30][0]=1;		score+=25;		return;
	public void inventory() {
		System.out.println("-Items on hand:");
		int c=0;
		for(int i=0;i<16;i++) {
			if(pitem>0) {
				System.out.println("--"+items[pitem]);		c++;
		if(c==0)	System.out.println("--none");
	public void map() {
		int r=0;
		int s=0;
		for(int i=0;i<yaxis;i++) {
			for(int j=0;j<xaxis;j++) {
				else	r=(i*5)+j;
				else	System.out.print("X");
				if(path[r][1]==1 && path[r+1][2]==1)
				if(path[r][1]==1 && path[r+1][2]==0)
				if(path[r][1]==0 && path[r+1][2]==1)
				if(path[r][1]==0 && path[r+1][2]==0)
					System.out.print("  ");
			for(int k=0;k<xaxis;k++) {
				else	s=(i*5)+k;
				if(path[s][3]==1 && path[s+5][0]==1)
					System.out.print("|  ");
				if(path[s][3]==1 && path[s+5][0]==0)
					System.out.print("v  ");
				if(path[s][3]==0 && path[s+5][0]==1)
					System.out.print("^  ");
				if(path[s][3]==0 && path[s+5][0]==0)
					System.out.print("   ");
		System.out.println("'O':current '--':two way '->':one way");
	public void look() {
		System.out.println("Items of interest:");
		int c=0;
		for(int i=0;i<4;i++) {
			if(object[room]!=0) {
				System.out.println("\t*"+items[object[room]]);		c++;
		if(c==0)	System.out.println("\t*none");
	public void intro() {
		System.out.println("\tFor some time, there has been news of travellers");
		System.out.println("disappearing while out on the seas.  Strangely enough,");
		System.out.println("your investigations have led you to a cave near a local");
		System.out.println("lighthouse.  This particular cave has the scent of dead");
		System.out.println("bodies in the air and the atmosphere has a weird - if");
		System.out.println("not terrifying - feel to it.  It is this cave in which");
		System.out.println("your adventure will begin...\n");
	public void conclude() {
		System.out.println("\tUpon entering, something immediately catches your");
		System.out.println("attention - a portal that seems to be trying to suck");
		System.out.println("you in.  Not only that, but there are more dead bodies");
		System.out.println("here than you've seen in all the other rooms combined.");
		System.out.println("The bodies are obviously those of missing travellers,");
		System.out.println("and it appears that a few of them tried to fight off");
		System.out.println("some serious threat or another.  You've definitely");
		System.out.println("found what you were looking for, but the big question");
		System.out.println("is, 'What do you do now?'...\n");
		System.out.println("\t\tTo be continued?");
		System.out.println("\t\tYour score: " + score);
	public void loop() throws IOException {
		while(room>-1) {
			if(room==46) {
				conclude();			return;
			String s=choose();
			for(int a=0;a<4;a++) {
				t = trimspace(choice[a]);
			for(int b=4;b<10;b++) {
				t = trimspace(choice);
			if(s.compareTo("check items")==0)		inventory();
			if(s.compareTo("view map")==0)			map();
			if(s.compareTo("look around")==0)		look();

public class jtest3 {
	public static void main(String[] args) throws IOException{
	areaone a=new areaone();

Share this post

Link to post
Share on other sites
Please use 'source' tags rather than 'code' tags for large blocks of code (Oh, looks like you fixed it :) ). And yeah, definitely look into some OOP design, and data-driven design (reading all of that hard-coded information in from a file instead).

Share this post

Link to post
Share on other sites
Yeah, it looks like it could end up good in the end,
but DEFINATLY needs some DataDriven progaming so that updating your
game levels does not mean a recompile.

Though making it datadriven looks like it also means you need to implement
some sort of state-machine to remove all the variables used to keep track of
button presses/lights/locked doors/ect...

Share this post

Link to post
Share on other sites
I've definetly learned that hard-coding is downright stressful when done on this scale. I'm starting on a way to read info from a text file into the program, but need a bit of help on the theory. I want to do something like have a text file with the following format for npc conversations for a particular location...

npc line 1
npc line 2

...and program code that tests whether the first character in the line is '/' like this:

int c=0;
String npcline[]=new npcline[8];
while(not end of file) {
.if(first character in line is '/')
..go to next line
.else {
..assign string on current line to npcline[c]
..c++ }

The only thing is that I'm not certain what methods there are in Java to move through a file and I find the documentation kinda confusing. For things like weapon/armor stats, could I read the numbers in a series as long as they're separated by a space, or would I have to put one value per line?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!