Text Based game into a window

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 609 Views - Last Post: 29 October 2017 - 11:17 AM Rate Topic: -----

#1 Smuge316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-October 17

Text Based game into a window

Posted 25 October 2017 - 08:24 AM

I've made a little text base game for my a course and now if got it working. I would like to make it open into a window or separate console, instead of the IDE's console.

Any links on how to do this or any help is much appreciated.

Thanks in advance.
Is This A Good Question/Topic? 0
  • +

Replies To: Text Based game into a window

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3447
  • View blog
  • Posts: 15,614
  • Joined: 20-September 08

Re: Text Based game into a window

Posted 25 October 2017 - 08:51 AM

That's not necessarily as easy as one might think it should be. We won't know until you post your code
Was This Post Helpful? 0
  • +
  • -

#3 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 590
  • View blog
  • Posts: 2,487
  • Joined: 13-June 14

Re: Text Based game into a window

Posted 25 October 2017 - 08:52 AM

Run the program outside the IDE, as you normally would in a console - i.e. with java MainClass, where MainClass should be replaced with the (fully qualified) name of the class containing your main method.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3447
  • View blog
  • Posts: 15,614
  • Joined: 20-September 08

Re: Text Based game into a window

Posted 25 October 2017 - 09:11 AM

Ah - i think i might have misunderstood your question. If you're happy to have it run in the OS's console then that's easy - a shortcut or script will do it

This post has been edited by g00se: 25 October 2017 - 09:11 AM
Reason for edit:: typo

Was This Post Helpful? 0
  • +
  • -

#5 Smuge316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-October 17

Re: Text Based game into a window

Posted 25 October 2017 - 01:23 PM

/*
@author Alex Chadwick
*/
package monsterrun;

import java.util.Random;
import java.util.Scanner;


public class MonsterRun {
    public static void main(String[] args) {
       
        //system objects
        Scanner in = new Scanner(System.in);
        Random rand = new Random();
        
        // Game variables
        String[] enemies = { "Skeleton",
            "goblin", "Assassin", "Wolves" , "Bats" };
        int maxEnemyHealth = 80;
        int enemyAttackDamage = 10;
        
        //boss variable
        String[] boss = { "balrog",
          "Dragon", "Master Assassin", "DireWolf", "Vampire" 
        };
        int maxBossHealth = 300;
        int minBossHealth = 100;
        int maxBossAttackDMG = 50;
        int minBossAttackDMG = 10;
                
                
        //player variables
        int health = 101;
        int attackDamage = 24;
        int numHealthPots = 12; // number of potion you start with
        int healthPotionHealAmount = 30;
        int healthPotiondropChance = 70; //drop chance/percentage
        
        Boolean running = true;
        
        System.out.println(" MonsterRun Dungeon");
        System.out.println("#############################################################################");
        System.out.println("#                                                                           #");
        System.out.println("#                                Welcome To                                 #");
        System.out.println("#                                                                           #");
        System.out.println("#  #     #                                          ######                  #");
        System.out.println("#  ##   ##  ####  #    #  ####  ##### ###### #####  #     # #    # #    #   #");
        System.out.println("#  # # # # #    # ##   # #        #   #      #    # #     # #    # ##   #   #");
        System.out.println("#  #  #  # #    # # #  #  ####    #   #####  #    # ######  #    # # #  #   #");
        System.out.println("#  #     # #    # #  # #      #   #   #      #####  #   #   #    # #  # #   #");
        System.out.println("#  #     # #    # #   ## #    #   #   #      #   #  #    #  #    # #   ##   #");
        System.out.println("#  #     #  ####  #    #  ####    #   ###### #    # #     #  ####  #    #   #");
        System.out.println("#                                                                           #");
        System.out.println("#############################################################################");
        
        
        GAME:
        while(running) {
            System.out.println("-----------------------------------------------------------");
            
            int enemyHealth = rand.nextInt(maxEnemyHealth);
            String enemy = enemies[rand.nextInt(enemies.length)];
            System.out.println("\t# " + enemy + " has appeared! #\n");
            //  #skeleton has appeared
            while(enemyHealth > 0){
                System.out.println("\t Your HP is:" + health);
                System.out.println("\t" + enemy + "'s HP is:" +enemyHealth);
                System.out.println("\n\t What would you like to do?");
                System.out.println("\t1. Attack!");
                System.out.println("\t2. Drink health portion");
                System.out.println("\t3. Run Away!");
                
                String input = in.nextLine();
                if (input.equals("1")){
                    int damageDealt = rand.nextInt(attackDamage);
                    int damageTaken = rand.nextInt(enemyAttackDamage);
                    
                    enemyHealth -= damageDealt;
                    health -= damageTaken;
                    
                    System.out.println("\t> You strike the " + enemy + " for " + damageDealt + " damage.");
                    System.out.println("\t> You recieve " + damageTaken + " in retalliation!");
                    
                    if(health < 1) {
                        System.out.println("\t> You have taken too much damage, you are to weak too continue!");
                    }
                    
                }
                else if(input.equals("2")) {
                    if(numHealthPots > 0) {
                        health += healthPotionHealAmount;
                        numHealthPots--;
                        System.out.println("\t> You drink a health potion, healing yourself for " +healthPotionHealAmount + "."
                                            + "\n\t> You now have " + health + " HP "
                                            + "\n\t> You have" +numHealthPots + " health potions left. \n");
                    }
                    else {
                        System.out.println("\t> You don't have any health potions left, defeat an enemy for a chance to get one");
                    }
                }
                else if(input.equals("3")){
                    System.out.println("\tYou run away from" + enemy );
                    continue GAME;
                    
                }
                else {
                    System.out.println("\tInvalid Command");
                }
            }   
            
            if(health < 1){
                System.out.println("You Crawl out of the dungeon, bearly escaping with your life.");
                break;
            }
            
            System.out.println("---------------------------------------------");
            System.out.println("#" + enemy + " was defeated! #");
            System.out.println(" # You have " + health + " Hp left. #");
            if(rand.nextInt(100) < healthPotiondropChance) {
                numHealthPots++;
                System.out.println("# The " + enemy + " dropped a health potion #");
                System.out.println(" # You now have " + numHealthPots + " health potion(s). #");
            }
            System.out.println("---------------------------------------------");
            System.out.println("What would you like to do now?");
            System.out.println("1. Continue fighting");
            System.out.println("2. Exit Dungeon");
           
            String input = in.nextLine();
             
            while(!input.equals("1") && !input.equals("2")) {
                System.out.println("Invalid Command!");
                input = in.nextLine();
            }
            
            if(input.equals("1")){
                System.out.println("You continues on your advanture!");
            }
            else if (input.equals("2")) {
                System.out.println("You exit the dungeon, successful from your adventure");
                break;
            }
            
        }
        
        System.out.println("########################");
        System.out.println("# THANKS FOR PLAYING ! #");
        System.out.println("########################");
        
    }
    
}


This post has been edited by andrewsw: 25 October 2017 - 01:28 PM
Reason for edit:: no need to quote yourself, use the REPLY button

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • Joined: 12-December 12

Re: Text Based game into a window

Posted 25 October 2017 - 01:30 PM

Do you have a further question? Don't just post code without comment.
Was This Post Helpful? 0
  • +
  • -

#7 Smuge316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-October 17

Re: Text Based game into a window

Posted 25 October 2017 - 01:32 PM

[quote name='Smuge316' date='25 October 2017 - 01:23 PM' timestamp='1508963027' post='2340954']

View PostSmuge316, on 25 October 2017 - 08:24 AM, said:

I've made a little text base game for my a course and now if got it working. I would like to make it open into a window or separate console, instead of the IDE's console.

Any links on how to do this or any help is much appreciated.

Thanks in advance.

just to clarify i wanna know how to open this program in to a separate program like zork. or pretty much most games.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • Joined: 12-December 12

Re: Text Based game into a window

Posted 25 October 2017 - 01:38 PM

There is no need to keep quoting yourself. There is a Reply button further down the page, or a Fast Reply box.
Was This Post Helpful? 0
  • +
  • -

#9 Smuge316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-October 17

Re: Text Based game into a window

Posted 25 October 2017 - 01:51 PM

okay didn't see it kind of new to the website, total noob at this
Was This Post Helpful? 0
  • +
  • -

#10 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 590
  • View blog
  • Posts: 2,487
  • Joined: 13-June 14

Re: Text Based game into a window

Posted 25 October 2017 - 02:05 PM

Perhaps I've misunderstood your question. Are you looking to run your application in a console window (in which case see my post above) or are you looking to make a graphical user interface?
Was This Post Helpful? 0
  • +
  • -

#11 Smuge316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-October 17

Re: Text Based game into a window

Posted 26 October 2017 - 05:10 PM

Okay i'm reading over this trying to understand what you mean. since i'm not exactly proficient with java
what part do you mean replace the MainClass with what cause i only have two classes i can see which are
public class MonsterRun and public static void main(String[] args) correct em if i'm wrong

This post has been edited by ndc85430: 26 October 2017 - 10:32 PM
Reason for edit:: Removed quote of previous post.

Was This Post Helpful? 0
  • +
  • -

#12 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 590
  • View blog
  • Posts: 2,487
  • Joined: 13-June 14

Re: Text Based game into a window

Posted 26 October 2017 - 10:34 PM

You only have one class, MonsterRun and that's the one containing your main method.

Also, there's no need to quote the previous post in its entirety. Please use the "Reply" button as andrewsw asked.
Was This Post Helpful? 0
  • +
  • -

#13 Smuge316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-October 17

Re: Text Based game into a window

Posted 28 October 2017 - 11:22 AM

im still really confused. so you said that

Quote

with java MainClass, where MainClass should be replaced with the (fully qualified) name of the class containing your main method.
so my only class is monsterRun and monsterRun contains my main method so the name of the class containing my main method is MonsterRun. right?
Was This Post Helpful? 0
  • +
  • -

#14 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3447
  • View blog
  • Posts: 15,614
  • Joined: 20-September 08

Re: Text Based game into a window

Posted 28 October 2017 - 11:44 AM

Quote

right?
Yes
Was This Post Helpful? 0
  • +
  • -

#15 Smuge316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-October 17

Re: Text Based game into a window

Posted 28 October 2017 - 12:14 PM

But how would that do anything cause your just replacing monsterRun with monsterRun.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2