Results 1 to 5 of 5
  1. #1
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default My semester proj.

    So. I was given a semester project to do. and it was going to be checked weekly on updates to the code. and at the end of the semester well turn it in for the points...

    but what i didn't know was that he was gonna give points based eff each week he checked..

    i need to keep adding stuff to the code to make it better but god damit im out of ideas! so. i was hoping for some feed back on how i should change/add to me code. all feed back is appreciated.
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import javax.swing.*;
    
    public class GUITAR_HERO extends Applet implements ActionListener, MouseListener, KeyListener
    {
        // instance variables:
        Timer timer;
        private int difficulty;
        private int money;
        
        private boolean leftbool=true;
        private boolean upbool=true;
        private boolean downbool=true;
        private boolean rightbool=true;
        
        private int key;
        
        private Button easybutton; 
        private Button mediumbutton;
        private Button hardbutton;
        
        private int lefty=75;
        private int upy=75;
        private int downy=75;
        private int righty=75;
        
        private int leftspeed=1;
        private int upspeed=1;
        private int downspeed=1;
        private int rightspeed=1;
        
        private int scorex=50;
        private int scorey=400;
        
        private boolean start=true;
        
        public void init()
        { 
            easybutton = new Button("Easy");       
            add(easybutton);                               
            easybutton.addActionListener(this);
            
            mediumbutton = new Button("Medium");       
            add(mediumbutton);                               
            mediumbutton.addActionListener(this);
            
            hardbutton = new Button("Hard");       
            add(hardbutton);                               
            hardbutton.addActionListener(this);
            
            
            timer = new Timer(15, this);
            //timer.start();  //timers
            
            addMouseListener(this);
            addKeyListener(this);
            setFocusable(true);
            
            
            
            
            
        }
        
        public void mouseEntered(MouseEvent me){}
        public void mouseExited(MouseEvent me){}
        public void mousePressed(MouseEvent me){} 
        public void mouseReleased(MouseEvent me){}
        public void mouseClicked(MouseEvent me)           
        { 
            
        }
        
        public void keyPressed(KeyEvent ke)
        {
            key = ke.getKeyCode();//returns the interger coe of the key taht was pressed
            
            if (key==KeyEvent.VK_LEFT)//left key listener
            {
                if ( ((500-lefty) <= 110) && ((500-lefty) >= 90))//awards 100 points if 20 pixals near perfect
                {
                    money+=100;
                    lefty=75;
                    repaint();
                }
                
                else if ( ((500-lefty) <= 130) && ((500-lefty) >= 70))//awards 50 points if 60 pixals near
                {
                    money+=50;
                    lefty=75;
                    repaint();
                }  
                else
                {
                    money-=100;
                    lefty=75;
                    repaint();
                }
            }
            
            if (key==KeyEvent.VK_UP)//left key listener
            {
                if ( ((500-upy) <= 110) && ((500-upy) >= 90))//awards 100 points if 20 pixals near perfect
                {
                    money+=100;
                    upy=75;
                    repaint();
                }
                
                else if ( ((500-upy) <= 130) && ((500-upy) >= 70))//awards 50 points if 60 pixals near
                {
                    money+=50;
                    upy=75;
                    repaint();
                }  
                else
                {
                    money-=100;
                    upy=75;
                    repaint();
                }
            }
            
            if (key==KeyEvent.VK_DOWN)//left key listener
            {
                if ( ((500-downy) <= 110) && ((500-downy) >= 90))//awards 100 points if 20 pixals near perfect
                {
                    money+=100;
                    downy=75;
                    repaint();
                }
                
                else if ( ((500-downy) <= 130) && ((500-downy) >= 70))//awards 50 points if 60 pixals near
                {
                    money+=50;
                    downy=75;
                    repaint();
                }  
                else
                {
                    money-=100;
                    downy=75;
                    repaint();
                }
            }
            
            if (key==KeyEvent.VK_RIGHT)//left key listener
            {
                if ( ((500-righty) <= 110) && ((500-righty) >= 90))//awards 100 points if 20 pixals near perfect
                {
                    money+=100;
                    righty=75;
                    repaint();
                }
                
                else if ( ((500-righty) <= 130) && ((500-righty) >= 70))//awards 50 points if 60 pixals near
                {
                    money+=50;
                    righty=75;
                    repaint();
                }  
                else
                {
                    money-=100;
                    righty=75;
                    repaint();
                }
            }
            
            if (key==KeyEvent.VK_P)//left key listener
            {
                timer.stop();
                repaint();
                
            }
            
             if (key==KeyEvent.VK_S)//left key listener
            {
                timer.start();
                repaint();
                
            }
            
            
            
        }
        public void keyReleased(KeyEvent ke){}
        public void keyTyped(KeyEvent ke){}
        
        
        
        public void actionPerformed(ActionEvent ae)
        {
            Object source = ae.getSource(); //allows buttons
            
            if (source.equals(easybutton))                
            {
                timer.stop();
                difficulty=1000;
                start=true;
                timer= new Timer(50, this);
                timer.start();
                
                
                
            }
            
            if (source.equals(mediumbutton))                
            {
                timer.stop();
                difficulty=50;
                start=true;
                timer= new Timer(25, this);
                timer.start();
                
                
            }
            
            if (source.equals(hardbutton))                
            {
                timer.stop();
                difficulty=10;
                start=true;
                timer=new Timer(12, this);
                timer.start();
                
            }
            easybutton.setFocusable(false);
            mediumbutton.setFocusable(false);
            hardbutton.setFocusable(false);
            repaint(); 
                         
        }
        
        //public void update(Graphics g)
        //{
            //super.update(g);
            
           // paint(g);
            //money(g);
           
        //}
        
        public void paint(Graphics g)
        {
            
            
            if (start==true)
            {  
                left(g); 
                up(g);
                down(g);
                right(g);      
            }
            money(g);
            target(g);
            running(g);
            
        }
        
        public void left(Graphics g)
        {
            Polygon pleft = new Polygon();
            pleft.addPoint(75,lefty);
            pleft.addPoint(75,lefty+20);
            pleft.addPoint(100,lefty+20);
            pleft.addPoint(100,lefty+30);
            pleft.addPoint(75,lefty+30);
            pleft.addPoint(75,lefty+50);
            pleft.addPoint(50,lefty+25);
            g.fillPolygon(pleft);
            
            if (lefty==75)
            {
                leftspeed = (int) (Math.random()*4);
                    if (money>=7000)
                    {
                        leftspeed +=2;
                    }
                        
            }
            
            lefty+=leftspeed;
            
            if (lefty>=450)
            {
                lefty=75;
                money-=200;
                leftbool=true;
            }
            
            
        }
        
        public void up(Graphics g)
        {
            Polygon pup = new Polygon();
            pup.addPoint(175,upy);
            pup.addPoint(200,upy+25);
            pup.addPoint(180,upy+25);
            pup.addPoint(180,upy+50);
            pup.addPoint(170,upy+50);
            pup.addPoint(170,upy+25);
            pup.addPoint(150,upy+25);
            g.fillPolygon(pup);
            
            if (upy==75)
            {
                upspeed = (int) (Math.random()*4);
                if (money>=7000)
                {
                    upspeed +=2;
                }
            }
            upy+=upspeed;
            
            if (upy>=450)
            {
                upy=75;
                money-=200;
                upbool=true;
            }
            
        }
        
        public void down(Graphics g)
        {
            Polygon pdown = new Polygon();
            pdown.addPoint(275,downy+50);
            pdown.addPoint(300,downy+25);
            pdown.addPoint(280,downy+25);
            pdown.addPoint(280,downy);
            pdown.addPoint(270,downy);
            pdown.addPoint(270,downy+25);
            pdown.addPoint(250,downy+25);
            g.fillPolygon(pdown);
            
            if (downy==75)
            {
                downspeed = (int) (Math.random()*4);
                if (money>=7000)
                    {
                        downspeed +=2;
                    }
            }
            downy+=downspeed;
            
            if (downy>=450)
            {
                downy=75;
                money-=200;
                downbool=true;
            }
        }
        
        public void right(Graphics g)
        {
           Polygon pright = new Polygon();
           pright.addPoint(350,righty+20);
           pright.addPoint(350,righty+30);
           pright.addPoint(375,righty+30);
           pright.addPoint(375,righty+50);
           pright.addPoint(400,righty+25);
           pright.addPoint(375,righty);
           pright.addPoint(375,righty+20);
           g.fillPolygon(pright);
           
            if (righty==75)
            {
                rightspeed = (int) (Math.random()*4);
                if (money>=7000)
                    {
                        rightspeed+=2;
                    }
            }
            righty+=rightspeed;
            
            if (righty>=450)
            {
                righty=75;
                money-=200;
                rightbool=false;
            }
            
        }
        
        public void target(Graphics g)
        {
                g.setColor(Color.GREEN);
                
                Polygon pleft2 = new Polygon();     // bottom left arrow
                pleft2.addPoint(75,400);            //******************
                pleft2.addPoint(75,420);            //******************
                pleft2.addPoint(100,420);           //******************
                pleft2.addPoint(100,430);           //******************
                pleft2.addPoint(75,430);            //******************
                pleft2.addPoint(75,450);            //******************
                pleft2.addPoint(50,425);            //******************
                g.drawPolygon(pleft2);              // bottom left arrow
                
                Polygon pright2 = new Polygon();    // bottom right arrow
                pright2.addPoint(350,420);          //*******************
                pright2.addPoint(350,430);          //*******************
                pright2.addPoint(375,430);          //*******************
                pright2.addPoint(375,450);          //*******************
                pright2.addPoint(400,425);          //*******************
                pright2.addPoint(375,400);          //*******************
                pright2.addPoint(375,420);          //*******************
                g.drawPolygon(pright2);             // bottom right arrow
                
                Polygon pdown2 = new Polygon();     // bottom down arrow
                pdown2.addPoint(275,450);           //******************
                pdown2.addPoint(300,425);           //******************
                pdown2.addPoint(280,425);           //******************
                pdown2.addPoint(280,400);           //******************
                pdown2.addPoint(270,400);           //******************
                pdown2.addPoint(270,425);           //******************
                pdown2.addPoint(250,425);           //******************
                g.drawPolygon(pdown2);              // bottom down arrow
                
                Polygon pup2 = new Polygon();       // bottom up arrow
                pup2.addPoint(175,400);             //****************
                pup2.addPoint(200,425);             //****************
                pup2.addPoint(180,425);             //****************
                pup2.addPoint(180,450);             //****************
                pup2.addPoint(170,450);             //****************
                pup2.addPoint(170,425);             //****************
                pup2.addPoint(150,425);             //****************
                g.drawPolygon(pup2);                // bottom up arrow
        }
        
        public void money(Graphics g)
        {
            g.setColor(Color.BLACK);
            String pmoney = Integer.toString(money);
            
            g.drawString(pmoney, 405, 50);
            
        }
        
        public void running(Graphics g)
        {
            boolean pause;
            
            pause = timer.isRunning();
            
            if (pause==false)
            {
                g.drawString("Applet paused press S to start", 5, 490);
            }
            else
            {
                g.drawString("Press P to pause", 5, 490);
            }
            
        }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    1) Upgrade from 2000: use Swing rather than AWT.

  3. #3
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    its a school project man.. i do what they tell me and what they teach me.. its jsut a highschool class

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Write the XxxListener functionality each in its own class.

  5. #5
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

Similar Threads

  1. Half a semester into java
    By apfroggy0408 in forum New To Java
    Replies: 3
    Last Post: 12-17-2007, 10:05 AM

Posting Permissions

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