Game program - simon sez

I have a simple game program call simon sez. I have the code completely
written, but i cant figure out why its not working. I have the area
in the program that is not working right and have add ********* where
the problem area is. Can anyone figure out what ive done wrong here???
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
import sun.audio.*; //import the sun.audio package
import java.io.*;
public class SimonMain extends Applet implements ActionListener {
SimonButton[] simonb = new SimonButton[4];
SimonButton[] navb = new SimonButton[2];
SimonButton gob = new SimonButton("GO");
Label level;
int levelc;
int[] levelarray = new int[10];
int playmode = 1;
int arraycount=0;
int whichbutton=0;
AudioClip snd1;
AudioClip snd2;
AudioClip snd3;
AudioClip snd4;
AudioClip right;
AudioClip wrong;
     //Initialize the applet
public void init() {
levelc=1;
snd4=getAudioClip(getDocumentBase(), "three.wav");
snd3=getAudioClip(getDocumentBase(), "two.wav");
snd2=getAudioClip(getDocumentBase(), "one.wav");
snd1=getAudioClip(getDocumentBase(), "zero.wav");
right=getAudioClip(getDocumentBase(), "right.wav");
wrong=getAudioClip(getDocumentBase(), "wrong.wav");
level = new Label("Choose Level: "+Integer.toString(levelc) );
add(level);
for(int count=0; count<4;count++)
simonb[count] = new SimonButton(Integer.toString(count));
simonb[count].ColorButton(Color.black );
simonb[count].ColorFont(Color.white);
simonb[count].addActionListener(this);
add(simonb[count]);
for(int count=0; count<2;count++)
if(count==0)
navb[count] = new SimonButton("<");
if(count==1)
navb[count] = new SimonButton(">");
navb[count].addActionListener(this);
add(navb[count]);
gob.addActionListener(this) ;
add(gob);
public void paint(Graphics g) {
g.drawString ("Simon Sez: Choose your level using arrow buttons and click go to play.Have FUN!!!",10,50);
public void actionPerformed(ActionEvent event) {
//test.setText("Button number is " + buttonCaption);
String command = event.getActionCommand();
     //if (command.equals("Push")){
if (command == "GO")
playmode=3;
switch(playmode)
case 1: //This is choose level mode
if (command == "<" )
if(levelc==1);
else
levelc--;
level.setText("Level: "+Integer.toString(levelc) );
if (command == ">" )
if(levelc==10);
else
levelc++;
level.setText("Level: "+Integer.toString(levelc) ) ;
break;
case 2: //This is play mode
//This is where it wont get past my if statement???????????????????????????
if ( "0"==command)
     {     level.setText("WORKIng"+command);
simonb[0].ColorFont(Color.red);
for(int count=0;count<100000000;count++)
          snd1.play();
simonb[0].ColorFont(Color.white );
whichbutton=1;
if((levelarray[arraycount]==whichbutton))
if(arraycount+1==levelc)
{ right.play();
playmode=1;
break;
arraycount++;
else
{   wrong.play();
arraycount=0;
if ("1" == command)
simonb[1].ColorFont(Color.yellow);
for(int count=0;count<100000000;count++)
          snd2.play();
simonb[1].ColorFont(Color.white );
whichbutton=2;
if((levelarray[arraycount]==whichbutton))
if(arraycount+1==levelc)
{ right.play();
playmode=1;
break;
arraycount++;
else
{   wrong.play();
arraycount=0;
if (command == "2" )
simonb[2].ColorFont(Color.blue);
for(int count=0;count<100000000;count++)
          snd3.play();
simonb[2].ColorFont(Color.white );
whichbutton=3;
if((levelarray[arraycount]==whichbutton))
if(arraycount+1==levelc)
{ right.play();
playmode=1;
break;
arraycount++;
else
{   wrong.play();
arraycount=0;
if (command == "3" )
simonb[3].ColorFont(Color.pink);
for(int count=0;count<100000000;count++)
          snd4.play();
simonb[3].ColorFont(Color.white );
whichbutton=4;
if((levelarray[arraycount]==whichbutton))
if(arraycount+1==levelc)
{ right.play();
playmode=1;
break;
arraycount++;
else
{   wrong.play();
arraycount=0;
level.setText(command ) ;
break;
case 3: //This is generate mode
arraycount=0;
whichbutton=0;
playmode=2;
for(int count=0;count<levelc;count++)
levelarray[count]=1+ (int) (Math.random() *4);
level.setText(Integer.toString(levelarray[count]) );
for(int count=0;count<levelc;count++)
if(levelarray[count]==1)
simonb[0].ColorFont(Color.red);
for(int countr=0;countr<100000000;countr++)
          snd1.play();
simonb[0].ColorFont(Color.white );
if(levelarray[count]==2)
simonb[1].ColorFont(Color.yellow);
for(int county=0;county<100000000;county++)
snd2.play();
simonb[1].ColorFont(Color.white );
if(levelarray[count]==3)
simonb[2].ColorFont(Color.blue);
for(int countb=0;countb<100000000;countb++)
          snd3.play();
simonb[2].ColorFont(Color.white );
if(levelarray[count]==4)
simonb[3].ColorFont(Color.pink);
for(int countp=0;countp<100000000;countp++)
          snd4.play();
simonb[3].ColorFont(Color.white );
playmode=2;
} //end of for loop
playmode=2;
break;
     //Get Applet information
public String getAppletInfo() {
          return "Applet Information";
     //Get parameter info
public String[][] getParameterInfo() {
          return null;
import java.awt.*;
import java.awt.event.*;
public class SimonButton extends Button implements ActionListener{
public SimonButton(String label) {
this.setLabel(label) ;
public void actionPerformed(ActionEvent event) {
public void ColorButton(Color color){
this.setBackground(color);
public void ColorFont(Color color) {
this.setForeground(color );
public void paint(Graphics g) {

you need to replace all occurrances in your code of:
if(".." == command)....
with:
if("..".equalsIngnoreCase(command))...
When doing string comparison, the equality operator doesn't work. Use the provided method instead

Similar Messages

  • I recently downloaded a 10.6.8 update and a game program has now been reduced in size.  It's specifications are set for full screen, but it is about 1/4 of the size.  Any ideas how to fix?

    I recently downloaded a 10.6.8 update and a game program has now been reduced in size.  It's specifications are set for full screen, but it is about 1/4 of the size.  Any ideas how to fix?

    Hi, I have got the same problem but all is 1/4 the size have you fixed it?

  • Applet Game Programming - player movement

    HI Java Experts,
    I have a very simple question applet game programming - jdk 1.02.
    Let's say you have a player on the applet window. He can move right and left.
    Naturally you have an image representing the player. When the player moves left you present an image loop with him running left. And vice versa for running right.
    Of course when he stops moving you just want to show a still image.
    What do you guys feel is the best technique for that situation ?
    Stephen

    Hi Thanks for the advice.
    I'm under the impression that if I used jdk1.4
    everybody who wanted to play the game would have to go
    through the trouble of downloading something . If
    that is so, then i would like to stick with 1.02 to
    have the widest possible audience.Use Java Web Start to deploy it as an application instead of an Applet. If your program is really cool, people will download the JDK 1.4 to use it. Then we will have more java users in the world :)
    By the way i have a URL perhaps someone could look > at the source code and give additional suggestions
    you can make sonic the hedge hog run and jump
    http://www.swebdev.com/Adventure.html
    That code has some good points. I like the nice object oriented flow of it. However, the way he sets up the Thread is all wrong. He uses yield and sleep, you would want to set up this using wait() and notifyAll() calls if you want to make it more interesting.
    Right now i'm trying to address the issue of how to
    reverse the image for when the player is running the
    opposite way -- ? perhaps a separate thread in 1.02
    might be an answer? I would be glad to hear all kinds
    of suggestions on the sample code seen thereYou shouldn't need a separate thread just to reverse the image. If your little guy is already in his own thread, just switch the image that is displayed when the player hits the opposite direction key.
    Think of threads like puppets, and you are the puppet master. Your little guys is a puppet, so he should be in his own thread. You can make him do whatever you want from your thread (the master) by pulling strings (changing globals, and message passing)
    Wow... Thats a really good analogy... I just thought that up :)

  • Timer for game program.

    Hello all,
    I am making a game program and I need a way to implement a timer so that it the game will end if the time expires.
    Is there any easy function to help me with this task?

    Thanks for the reply and I just found that class.
    Thanks

  • J2ME game programming

    Helo everyone,
    I am working in j2me game programming plz if
    any one know how make image as small as possible
    in our game program.?
    I am using *.png format of image which is working well
    in game but my game size is very big so plz help me to get
    out of this problem
    Thank u
    Aman Gautam

    hi,
    if you want to do any kind of game programming in J2ME, i suppose you would require to use the Canvas class, well there are a few good resources.. try out
    www.billday.com
    www.javamobiles.com..
    that ought to get u started.
    cheerz
    ynkrish

  • J2Me game programming plz help

    Helo everyone,
    I am working in j2me game programming plz if
    any one know how make image as small as possible
    in our game program.?
    I am using *.png format of image which is working well
    in game but my game size is very big so plz help me to get
    out of this problem
    Thank u
    Aman Gautam

    I solved the same problem by using indexed color images instead of true color.
    So, for example, if you have a colorful background you can convert it to a 256 color image.
    Depending on your specific image and the devices you'll see it on you may or may not notice the difference, but the file size is generally smaller.
    Then you can push further for smaller elements, like, say, a moving object like a pointer or a starship, you can reduce it to 60 or 30 colors, or even less.
    Another technique is to use tiles to build up the background instead of big images. With MIDP2.0 there's the TiledLayer, but you can implement the same with some code also on MIDP1.0 if backward compatibility is of concern.

  • I want to learn 2D game programming. But, I am confused!

    I want to make a 2D game in C#. I have begun learning C# on my own. But, I am confused sbout what to learn after c# to make a game. I hear many things like XNA, MDX, Monogame, SlimDX, SharpDX, Frameworks, game engines, IDE's etc. To me all of this has
    caused a great confusion. The C# game tutorial I am learning is based on MDX (Managed DirectX). Now, I realise that MDX and XNA is dead. I am confused if I want to change my tutorial itself. Can anyone clear things out for me and tell what i need to learn
    step by step?
    I really don't even know what all the sh*t (.NET ,XNA, Monogame, SharpDX, xxx, xxxx, xxxx etc.) really is or what it does or which is better or even what the differences are. So please explain everything to me. Please help!

    Hi,
    You can refer to the Books:
    Beginning .NET Game Programming
    Beginning C# Game Programming
    Few other useful links:
    Coding 4 Fun is a great .NET resource that has quite a few user-created games. They also have a
    book and a
    2-D game primer
    Tutorial Listing at C# corner
    C# Game Tutorial for Beginners (video)
    Link to more game programming e-books
    Advanced Topics
    The Farseer Physics Engine on Codeplex would be a good next step once you get comfortable with programming games.
    Please mark as answer or vote as helpful if my reply does

  • About game programming.. please....help

    How to define game map for java midlet
         If I see the rpg game, it have default map. I want to know how to translate it to code
         in midlet? The map will be existed image or dynamicly generated?
         Like Prince of Persia Midlet version, I wonder how to generate the environment?
         Is it pixel generated or immutable image?
    detect collision
         SO if the map is image and the sprite game is draw over the map, how can we detect the
         collision?
         Please hellp me.... because I want to be game programmer for midlet but I
         didn't know about game programming before

    to write a small game in midl is already a hard work. to make a big one, take a look of a team of programers.
    about maping, there is no such thing. wire every thing by yourself. by books or read tutorials.
    as i already said. no easy task.
    but keep on trying. if you need some help write me a mail.
    [email protected]
    jeliel
    (sebastian)

  • Mobile Game Programming

    Hey All,
    I am a decent Java programmer but in last few days I found Java Game Programming intresting and has strong future for ones career.
    I wanted to know what do Expert over here have to say about this ?
    and
    Where do I need to start In order to get to know about it ?(I mean under Java).
    Thanx
    Messy

    I suggest you move to this forum and ask your question again.
    http://forum.java.sun.com/category.jspa?categoryID=23

  • Multiplayer game programming - Code of a basic server

    I'm a beginner in multiplayer game programming and I'm looking for the code of a basic server for a multiplayer game. I don't mind which kind of game (I mean: chess, ping-pong, battlenet...) The important thing is the code pattern abnd the server structure.
    Could anyone help me?

    If you want to have a look at a generic multi-threaded server, check out the Java networking tutorial.. there's a basic example server that responds to a "Knock knock, who's there?" conversation.. you can start off with it..
    Of course it's not a game server but you could try sticking in a game engine to maintain the game world and change the user sessions to a proper game protocol.. e.g. sending key strokes or joystick movements. You could also get the server to send player and enemy positions etc...
    Good luck!

  • TS1702 I have installed a game program on both my I phone and I pod mini....I want to remove it on both items how to I do this????

    How to removed a game program from both my Iphone and Ipad mini??

    Tap and hold any app icon until they all wiggle.  Press the black x to delete the app.  Press the home button when done.
    Note that when they are wiggling, you can drag then around to position as desired.
    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf

  • Game Programming on Mac?

    Dear Apple,
    My cousin Jesse is wondering why all the game programming tutorials on the internet are made using the PC. Doesn’t Apple have the ability to make games on their operating system?
    Just wondering,
    Craig

    You can write games for the iPhone on a Mac
    Also, there are many games that run on a Mac
    Mihalis.
    Message was edited by: Mihalis Tsoukalos

  • Game programming

    I am new to game programming and J2ME. how can i integrate animated clips and application using J2ME>

    Well thats kinda general... In my opinion java is a great language. Just not for games usually. Also what kind of game? 2d or 3d? I would recommend checking out unity for 3D games. I have used it and it is a great tool for people looking to make 3D games without as much work. Plus it supports execution in a browser like an applet kindof. For 2D i usually use flash as it greatly simplifies the process. If your hearts set on Java start off with this- http://www.tutorialized.com/view/tutorial/2D-Java-Platform-Game/10145

  • Complete beginner: Creating Card Game program

    I am brand new to object oriented programming, i'm trying to write a simple card game program, without using arrays or importing packages or vectors (whatever they all are?). can someone please help me?

    First of all, arrays are a very good idea, as are other datastructures such as the hashtable. But you can also use a String, which is basically an array of characters.
    The initial hurdle you will have in writing a card game will be modelling a single playing card. Your program will likely understand the sequence of cards as 2,3,4,5,6,7,8,9,10,11,12,13, even tho you will want to present this to your user as 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A. Computers deal well with the numbers, Humans like to refer to cards using the familiar symbolic references (J, Q, K, A). Suits likewise will probably be stores as integers (0-3).
    Your program will have to determine whether one playing card is less than or greater than another, whether it is in the same suit, what value the card will have (for BlackJack, for instace). All of these behaviors can be engineered into your PlayingCard class.
    To get going with your card game, you must thus begin an abstraction of the real-word PlayingCard. Start with a class such as this:
    class PlayingCard {
    final static String nums = "234567891JQKA" ;
    final static String [] suits = "DCHS";
    private int num, suit; // i.e. of this instance
    public PlayingCard (String card) { // constructor
    num = values.indexOf(card.charAt(0)) ;
    suit = suits.indexOf(card.charAt(card.length()-1);
    public String toString() {
    return nums.charAt(value)+((num==8)?"0":"")+suits.charAt(suit);
    int value() { return suit*4+num; }
    boolean compareValue(PlayingCard first, PlayingCard second) {
    return first.value() - second.value();
    boolean sameSuitAs(PlayingCard p) {
    return (this.suit == p.suit);
    // etc.
    For a BlackJackPlayingCard, extend PlayingCard and add/override specific behaviors such as counting (i.e. face cards = 10, Ace's two values, etc).
    Have fun. Java is a great language.

  • About server in game programming

    hi,
    from what i know, we need a web server like tomcat or blazix to make other people can access our web. but my problem is like this..... i develop a game programming that need a server to control the player, so that mean now i have 2 server...... but when people acces my web, they cannot connect with my game server, so they cannot play the game..... so what should i do to make people can access my web and play the game?

    I presume this is about how to have a game run in the background on the server, outside of the web requests the user made to get to the game in the first place.
    What it comes down to is, you need some way to get the data back, asynchronously or pseudo-asynchronously. You have a few options...
    (1) Run a process on the server separate to the web server, which opens the game server socket, and does all the game stuff. Simplest solution.
    (2) Make a little servlet which initialises when your webapp starts up, and the init() method starts a thread, which opens the game server socket, and does all the game stuff. A little harder, but better because it will work even if you don't have a shell to the web server (e.g. if you're on a hosting provider who has given you just an FTP.)
    (3) Make a little servlet to perform the actual game functions, and either poll at regular intervals or have the servlet itself send the data back as a continuous stream. I personally like this solution the best, and it doesn't require a thread to sit there on the server wasting a thread, but it does make a single HTTP request last for a rather long time and also proxies can screw around with the data.
    Hope this helped somehow...

Maybe you are looking for

  • I cannot install iTunes 7

    I have been using itunes for a very long time, and today i was installing iTunes 7, and I recieved an error message saying, Link to error message > http://img45.imageshack.us/my.php?image=itunescrashqc5.jpg so then I said oh well.. I cannot download

  • Bb tour 9630 used with hyperterminal or procomm plus as an out dial modem

    Trying to use Balckberry Tour 9630 tethered with usb cable to laptop as a regular dial out modem.  I am using hyper terminal and Procomm Plus.  This connection is not to an ISP but to modems connected to other equipment.  Any input to make it work wo

  • Cannot access web using hostname

    Hi, I am not able to access web in hotjava webbrowser using hostname like www.sun.com. But it is possible to access using IP address. I am using solaris 2.6, hotjava 1.0 . I am new to unix. I do not know what to be configured to get it right. Your he

  • Only part of page was printed when accessing Canon website

    When printing or print previewing the indicated page on affected website http://www.usa.canon.com/cusa/support/consumer/eos_slr_camera_systems/eos_digital_slr_cameras/eos_rebel_xsi_ef_s_18_55is_kit#DriversAndSoftware only the first pages are printed

  • UDT - This Entry already exists

    Hi, When trying to add a new record in a UDT, the system shows the error "This entry already exists in the following table..." We tried deleting the last record and then add it again...and it did'nt work, now we are missing more records to add. The k