Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


HELP: java game in command line


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Mochy Tanauan   Members   -  Reputation: 101

Like
0Likes
Like

Posted 10 April 2012 - 05:22 AM

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!

Sponsor:

#2 falconmick   Members   -  Reputation: 80

Like
0Likes
Like

Posted 10 April 2012 - 11:26 AM

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.

#3 Mochy Tanauan   Members   -  Reputation: 101

Like
0Likes
Like

Posted 10 April 2012 - 05:41 PM

Thanks falconmick. Actually I've already learned C. I'm a little bit confuse in making the said game, on how I code to built floors with different types. BTW thanks for the post it really helps.

#4 falconmick   Members   -  Reputation: 80

Like
0Likes
Like

Posted 10 April 2012 - 09:34 PM

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...

#5 Mochy Tanauan   Members   -  Reputation: 101

Like
0Likes
Like

Posted 10 April 2012 - 11:19 PM

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.

#6 rip-off   Moderators   -  Reputation: 8515

Like
2Likes
Like

Posted 11 April 2012 - 03:42 AM

Your posts so far don't indicate that you have even started on this project yourself. What have you tried?

#7 Mochy Tanauan   Members   -  Reputation: 101

Like
0Likes
Like

Posted 11 April 2012 - 07:58 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS