Jump to content
  • Advertisement
Sign in to follow this  
Mochy Tanauan

HELP: java game in command line

This topic is 2262 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

i want to make a commad line type of game like tiny towers in java. just in command line. the gameplay is, a player can add floor and choos whatever type they like, once they choose the type, the player may choose what kind of business it will be. minimum of 6 choices per floorr type. And at the end of the day tenant will pay 100 coins to the player for rent,should be 3 tenants per floor.

Game Play
Players should have access at all times on the status of the tower, floors and the bitizens. A player can add a floor, add bitizens and restock. The game should notify the player if an item is up for restocking so that the player can restock a specific item. A player can choose to end the current day to move to the next one.


please help! thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
I would assume that if you are asking this that your knowledge in programming is fairly little (or maybe, you have never done Java)

As much as we would all love to start with the fun, I would recommend first learning C (if you don't already know it), not C++, but C.
after that, Java is a good language as it is an easy language to start with object orientation. this is some good theory, for learning java you can look at this... finally, once you know how to program in java to a high enough level maybe look into the theory behind the design of a game.. I was inable to find out how difficult making this would be, so I assumed it would be hard enough that making a proper design would be beneficial. you can look at that here

you could also have a look at this:

import java.io.*;
class RockPaperScissors {
BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) {
RockPaperScissors RPS = new RockPaperScissors();
System.out.println("Welcome to Rock, Paper, or Scissors!");
System.out.print("Please enter the number of rounds you would like to play : ");
int round = RPS.rounds();
int user = 0;
int computer = 0;
for (int i = 0; i < round; i++) {
if (RPS.choose(i + 1))
user++;
else
computer++;
}
RPS.result(user, computer);
}

void result(int user, int computer) {
System.out.println("RESULTS:");
System.out.println("User wins : " + user);
System.out.println("Computer wins : " + computer);
if (user > computer)
System.out.println("User wins the game!\n");
else
System.out.println("Computer wins the game!\n");
}

int rounds() {
try {
int temp = Integer.parseInt(BR.readLine());
if (temp % 2 == 0)
throw new Exception();
return temp;
}
catch (Exception err) {
System.out.print("Sorry, you need to enter an odd number. Please try again : ");
return rounds();
}
}

boolean choose(int val) {
System.out.print("[Round " + val + "] Rock, Paper, or Scissors? : ");
String input = "";
try {
input = BR.readLine();
}
catch(Exception err) {
}
if (input.equals("Rock"))
return process(1, val);
else if (input.equals("Paper"))
return process(2, val);
else if (input.equals("Scissors"))
return process(3, val);
else {
System.out.println("Sorry, \"" + input + "\" is not a valid entry!\n");
return choose(val);
}
}

boolean process(int user, int val) {
String[] hand = {"", "Rock", "Paper", "Scissors"};
int comp = (int)(Math.random() * 3) + 1;
if (user == comp) {
System.out.println("Computer chooses " + hand[user] + ". It's a tie.\n");
return choose(val);
}
else if (user == 1 && comp == 3) {
System.out.println("Computer chooses " + hand[comp] + ". You win!\n");
return true;
}
else if (user == 2 && comp == 3) {
System.out.println("Computer chooses " + hand[comp] + ". You lose!\n");
return false;
}
else if (user == 1 && comp == 2) {
System.out.println("Computer chooses " + hand[comp] + ". You lose!\n");
return false;
}
else if (user == 3 && comp == 2) {
System.out.println("Computer chooses " + hand[comp] + ". You win!\n");
return true;
}
else if (user == 2 && comp == 1) {
System.out.println("Computer chooses " + hand[comp] + ". You win!\n");
return true;
}
else {
System.out.println("Computer chooses " + hand[comp] + ". You lose!\n");
return false;
}
}
}

source

I can't say if it works or not, but it is a good example as it shows nested loops and an easily implemented game.
I tend to find looking at someone else code easier to make my own.

Share this post


Link to post
Share on other sites
break it down into it's smallest pieces..

so, you would have a class called buildingLevel, of which the game at one time would have 6 stored in an array (maybe a map just to speed things up).

once you have done that you break down building level more. split it into it's diferent components, turn each component into a class, then use buildingLevel to link all of the other components into the single buildingLevel component...

Share this post


Link to post
Share on other sites
can you give a sample code for building the floors, sorry im just a beginner in java. i need a Floor class, that has an array [] of floor types. Floors can be Residential, Food, Service, Recreation, Retail, or Creative. and what kind of business it will be.

Share this post


Link to post
Share on other sites
I actually started the project, creating a class for building floors, but I'm really confuse, thinking that I'm doing it wrong. I'm not really good in java, I'm just a beginner in this language so I'm hoping for help. Thanks in advance!

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!