Results 1 to 7 of 7
  1. #1
    silvia is offline Member
    Join Date
    Jul 2007
    Posts
    35
    Rep Power
    0

    Default Help with java text game

    Hi, I was wondering if JAVA was any good for programming text-games.
    Or if I should stick with C++.
    I know JAVA is a little slower... But has anyone here coded a text-game in JAVA?
    Thanks.

  2. #2
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    What kinda textgame?
    A hangman sorta?
    The answer depends on what text game ur trying to make i think
    Besides, from previous experience it wont be that much slower if it's just a text game, a couple nanoseconds slower maybe :D
    It's a bit slow if u store the text game variables in array though, but as just i had said, maybe just a cumulative nanoseconds slower :D

  3. #3
    Sircedric88 is offline Member
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    14
    Rep Power
    0

    Default

    a hangman game is difficult. One fun game is BlackJack, easy, simple, and fun!

  4. #4
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    BlackJack needs a GUI don't u think?
    how do u play cards without images?:confused:

  5. #5
    levent Guest

    Default

    how do u play cards without images?
    Imagination is the key :) Represent each card with a specific string...

  6. #6
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    Well, i get it :p
    But still, it's kinda dull playing card in shell environment:D

    Let's simulate it
    Java Code:
    C:\java BlackJack
     Welcome to the BlackJack game =)
     Let's start shall we...
    
     Shuffle cards...
     Deal cards...
    
     Dealer hands u a card it's an Ace of Hearts
     Dealer hands opponent a flipped card
     Dealer hands u a card, it's a Jack of Spades
     Dealer hands opponent a card, its an King of Spades
    
     Action?
    ...thinking ur action...
    
     Open the cards...
     U got a BlackJack
     Opponent got a King of Spades and a King of Diamonds
    
     Result....
     U win, yay!:D
    Hmm..that could be fun, but still, a little GUI would feel nice ;)

  7. #7
    Sircedric88 is offline Member
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    14
    Rep Power
    0

    Default

    Here;s the code for my blackjack game.
    I used a code called EasyInput to get the user input.

    Java Code:
    import java.util.*;
    
    public class Program
    {
    	public static void main(String[] args)
    	{
    		int total = 0;// player's total
    		int comp = 0; // computer's total
    		int choice = 0;
    		char playagain = 'y';
    
    		while (playagain == 'y')
    		{
    			System.out.print("Here are your first two cards: ");
    			total += drawcard(); // first card
    
    			System.out.print("and ");
    
    			total += drawcard();
    			System.out.println("");
    
    			System.out.print("Computer cards: ");
    			comp += drawcard(); //computer draws first card
    			//System.out.print(comp); //shows first card drawn
    			comp += computerdrawcard(comp);
    
    
    
    
    			while (total <= 21)//loop to ask for another card -		PLAYER TURN BEGINS
    			{
    				System.out.print("\nWould you like a hit (1) or to stay (2)");
    				choice = EasyInput.getInt();
    				EasyInput.getln();
    				if (choice == 1)
    				{
    					total += drawcard();
    				}
    				else
    				{
    					break;
    				}
    
    
    				if (total > 21)
    				{
    					System.out.println("Busted!"); break;
    
    				}
    			}
    
    			while (comp <= 18)
    			{
    				comp += computerdrawcard(comp);
    			}
    
    
    			System.out.print("Your score: ");
    			System.out.println(total);
    			System.out.print("Computer Score: ");
    			System.out.print(comp + "\n");
    
    			System.out.println("Would you like to play again? (y/n)");
    			playagain = EasyInput.getChar();
    			EasyInput.getln();
    
    			
    
    			if (playagain == 'y')
    			{
    				total = 0;
    				comp = 0;
    				choice = 0;
    			}
    			else
    				break;
    		}
    	}
    
    		
    
    
    	// Player drawcard
    	public static int drawcard()
    	{
    		int cards = (int)(Math.random() * 12)+1; 
    		
    		switch (cards)
    		{
    			case 1: {System.out.print("King ");
    					return 10;}
    		
    			case 2: {System.out.print("Queen ");
    					return 10;}
    			
    			case 3: {System.out.print("Jack ");
    					return 10;}
    			
    			case 4: {System.out.print("Ten ");
    					return 10;}
    			
    			case 5: {System.out.print("Nine ");
    					return 9;}
    			
    			case 6: {System.out.print("Eight "); 
    					return  8;}
    			
    			case 7: {System.out.print("Seven ");
    					return 7;}
    			
    			case 8: {System.out.print("Six ");
    					return 6;}
    			
    			case 9: {System.out.print("Five ");
    					return 5;}
    			
    			case 10:{System.out.print("Four ");
    					return 4;}
    			
    			case 11:{System.out.print("Three ");
    					return 3;}
    			
    			case 12:{System.out.print("Two ");
    					return 2;}
    			
    			case 13:{System.out.print("Ace ");
    			System.out.print("Do you want 1 or 11?");
    			int ace = EasyInput.getInt ();
    				if (ace == 1) {return 1;}
    				else {return 11;}
    			}
    			
    			default: {System.out.print(""); }
    				break;
    				
    		}
    		return 0;
    	}
    
    
    	// Computer draw card
    	public static int computerdrawcard(int compscore)
    	{
    		int cards = (int)(Math.random() * 12) + 1;
    
    		switch (cards)
    		{
    			case 1:
    				{
    					return 10;
    				}
    
    			case 2:
    				{
    			
    					return 10;
    				}
    
    			case 3:
    				{
    					
    					return 10;
    				}
    
    			case 4:
    				{
    				
    					return 10;
    				}
    
    			case 5:
    				{
    					
    					return 9;
    				}
    
    			case 6:
    				{
    					
    					return 8;
    				}
    
    			case 7:
    				{
    					
    					return 7;
    				}
    
    			case 8:
    				{
    					
    					return 6;
    				}
    
    			case 9:
    				{
    					
    					return 5;
    				}
    
    			case 10:
    				{
    					
    					return 4;
    				}
    
    			case 11:
    				{
    					
    					return 3;
    				}
    
    			case 12:
    				{
    					
    					return 2;
    				}
    
    			case 13:
    				{
    				if (compscore + 11>21) { //if 11 will bust the computer, then it will choose 1
    					return 1;}
    
    					else { return 11; }
    	
    				}
    
    			default: { System.out.print(""); }
    				break;
    
    		}
    		return 0;
    	}
    }

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. First Java-game: Containers
    By eastviolence in forum New To Java
    Replies: 0
    Last Post: 04-04-2008, 06:09 PM
  3. creating a text based game
    By Phobos0001 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 04:35 PM
  4. Java BattleShip game help
    By mars_red in forum Advanced Java
    Replies: 0
    Last Post: 02-12-2008, 12:58 AM
  5. Help with my game in java
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 04:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •