Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2007, 10:58 PM
Member
 
Join Date: Jul 2007
Posts: 35
silvia is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 04:50 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
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
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-26-2007, 10:25 PM
Member
 
Join Date: Jul 2007
Location: Las Vegas
Posts: 14
Sircedric88 is on a distinguished road
Send a message via AIM to Sircedric88
a hangman game is difficult. One fun game is BlackJack, easy, simple, and fun!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-27-2007, 10:25 AM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
BlackJack needs a GUI don't u think?
how do u play cards without images?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-27-2007, 02:31 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Quote:
how do u play cards without images?
Imagination is the key Represent each card with a specific string...
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-27-2007, 07:06 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
Well, i get it
But still, it's kinda dull playing card in shell environment

Let's simulate it
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-27-2007, 07:58 PM
Member
 
Join Date: Jul 2007
Location: Las Vegas
Posts: 14
Sircedric88 is on a distinguished road
Send a message via AIM to Sircedric88
Here;s the code for my blackjack game.
I used a code called EasyInput to get the user input.

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; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
First Java-game: Containers eastviolence New To Java 0 04-04-2008 07:09 PM
creating a text based game Phobos0001 New To Java 1 02-12-2008 05:35 PM
Java BattleShip game help mars_red Advanced Java 0 02-12-2008 01:58 AM
Implementing "Game Over" in Minesweeper game based on Gridworld framework. JFlash New To Java 0 11-16-2007 12:02 AM
Help with my game in java lenny New To Java 1 07-23-2007 05:40 PM


All times are GMT +3. The time now is 09:19 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org