Sign in to follow this  

Unity Simple Monopoly Game Help !

This topic is 4724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

/*
  *Simple Monopoly Game , using Singapore MRT Stations to replace countries
  *Created to pass ICP Assignment
  *author : Ronny Liwuh 
  *Version 1.0
*/

import java.applet.*;
import java.awt.*;

class MRTStation
{
    public String itsName; 
    public int itsCost,itsColor;
    char itsOwner;
    
    public MRTStation(String stationName, int stationCost, int colorLine)
    {
        itsName = stationName;
        itsCost = stationCost;
        itsColor = colorLine;
    }
    public String getName()
    {
        return itsName;
    }
    
    public int getPrice()
    {
        return itsCost;
    }
    
    public int getColor()
    {
        return itsColor;
    }
}
public class projectTest2 extends java.applet.Applet 
{
    // 11 MRT station that pass green line
   
    MRTStation BoonLay = new MRTStation("Boon Lay", 1450, 706665989);
    MRTStation Clementi = new MRTStation("Clementi", 1550,706665989);
    MRTStation OutramPark = new MRTStation("Outram Park",1500,706665989);
    MRTStation CityHall = new MRTStation("City Hall",2000,706665989);
    MRTStation Bugis = new MRTStation("Bugis",1750,706665989);
    MRTStation Lavender = new MRTStation("Lavender",1200,706665989);
    MRTStation Tampines = new MRTStation("Tampines",1650,706665989);
    MRTStation ChangiAirport = new MRTStation("Changi Airport",2500,706665989);
    MRTStation PasirRis = new MRTStation("Pasir Ris",2000,706665989);
    MRTStation ChineseGarden = new MRTStation("Chinese Garden",1350,706665989);
    
    // 10 MRT station that pass purple line
    MRTStation DhobyGhaut = new MRTStation("Dhoby Ghaut",3000,300500450);
    MRTStation HarbourFront = new MRTStation("HarbourFront",2000,300500450);
    MRTStation ChinaTown = new MRTStation("China Town",2250,300500450);
    MRTStation ClarkeQuay = new MRTStation("Clarke Quay",1650,300500450);
    MRTStation LittleIndia = new MRTStation("Little India",1200,300500450);
    MRTStation BoonKeng = new MRTStation("Boon Keng",1300,300500450);
    MRTStation Hougang = new MRTStation("Hougang",1350,300500450);
    MRTStation Sengkang = new MRTStation("Sengkang",1250,300500450);
    MRTStation Punggol = new MRTStation("Punggol",1800,300500450);
    MRTStation FarrerPark = new MRTStation("Farrer Park",1600,300500450);
    
    // 11 MRT Station that pass red line
    MRTStation MarinaBay = new MRTStation("Marina Bay",1800,888888889);
    MRTStation Somerset = new MRTStation("Somerset",1950,888888889);
    MRTStation Orchard = new MRTStation("Orchard",3500,888888889);
    MRTStation Newton = new MRTStation("Newton",1200 ,888888889);
    MRTStation Novena = new MRTStation("Novena",2150 ,888888889);
    MRTStation ToaPayoh = new MRTStation("Toa Payoh",2000 ,888888889);
    MRTStation AngMoKio = new MRTStation("Ang Mo Kio",1750,888888889);
    MRTStation YioChuKang = new MRTStation("Yio Chu Kang",1600,888888889);
    MRTStation Admiralty = new MRTStation("Admiralty",1850 ,888888889);
    MRTStation Woodlands = new MRTStation("Woodlands",1600,888888889);
    MRTStation ChoaChuKang = new MRTStation("Choa Chu Kang",2000 ,888888889);
    MRTStation JurongEast = new MRTStation("Jurong East",2750,888888889);
    
    
    static int mouseX, mouseY,TokenPos = 7;
    static int dice1,dice2,diceNumbers,doubleSuccession = 0, playerTurn = 1;
    static int xCurPos1 = 50, yCurPos1 = 160 , xNextPos1 = 50, yNextPos1 = 160; // for player 1
    static int xCurPos2 = 80 ,yCurPos2 = 160, xNextPos2 = 80, yNextPos2 = 160; // for player 2
    static double p1Money = 2500 , p2Money = 2500; 
    static int boxToEnlarge = 0;
    
    //Arrays of MRTStation
    MRTStation leftMost[] = { ChangiAirport,Lavender,Tampines,ChinaTown,LittleIndia,Newton,Somerset };
    MRTStation bottom[] = { Punggol,Admiralty,OutramPark,DhobyGhaut,ToaPayoh,ChoaChuKang,PasirRis };
    MRTStation rightMost[] = { ClarkeQuay,Bugis,Hougang,Orchard,Novena,Clementi,Woodlands };
    MRTStation top[] = { JurongEast,FarrerPark,AngMoKio,CityHall,MarinaBay,HarbourFront,BoonLay };
    
    public void init()
    {
        
    }
    
    public boolean mouseDown(Event evt, int x , int y)
    {
        if(x > 700 && x < 850 && y > 10 && y < 50)//to check the mouse position
        {
            dice1 = (int)Math.floor(Math.random()*6)+1;
            dice2 = (int)Math.floor(Math.random()*6)+1;
            diceNumbers = dice1 + dice2;
            
            // % 2 if return 0 then player 2 , return 1 mean player 1
            if(playerTurn % 2 == 1)
            {
                TokenPos = 25;
                moving1(diceNumbers);
                checkBoxToEnlarge_1(xCurPos1,yCurPos1);
                repaint();
            }
            else
            {
                TokenPos = 7;
                moving2(diceNumbers);
                checkBoxToEnlarge_2(xCurPos2,yCurPos2);
                repaint();
            }
            
            if(dice1 == dice2)
            {
                playerTurn += 0;
                if(playerTurn % 2 == 1)//maintain the position of token 
                {
                    TokenPos = 7;
                }
                else
                {
                    TokenPos = 25;
                }
                
            }
            else
            {
                playerTurn++;
            }
            
            return true;
        }
        return false;
    }
    
    void moving1(int diceNumber)
    {
        
        //leftmost, down vertical movement
        if(xCurPos1 == 50 && yCurPos1 < 790)
        {
            xNextPos1 = 50;
            yNextPos1 = yCurPos1 + diceNumber * 70;
            
            if(yNextPos1 >= 790) //so that P1 doesn't stuck at the end of the box
            {
                xNextPos1 = xCurPos1 + (yNextPos1 - 790);
                if(xNextPos1 > 680) // for case the dice give 12 and make player1 exceeds the 1 row movement
                {
                    yNextPos1 = 790 - (680 - xNextPos1);
                    xNextPos1 = 680;
                    
                }
                else // player 1 just ended in any boxes on bottom row
                {
                    yNextPos1 = 790;
                    
                }
            }
            xCurPos1 = xNextPos1;
            yCurPos1 = yNextPos1;
           
        }
        //bottom, right horizontal movement
        else if(yCurPos1 == 790 && xCurPos1 < 680)
        {
            yNextPos1 = 790;
            xNextPos1 = xCurPos1 + diceNumber * 70;
           
            if(xNextPos1 >= 680)
            {
                yNextPos1 = yCurPos1 - (xNextPos1 - 680);
                if(yNextPos1 < 160)
                {
                    xNextPos1 = 680 - (160 - yNextPos1);
                    yNextPos1 = 160;
                    
                }
                
                else
                {
                    xNextPos1 = 680;
                    
                }
                
                //check whether player1 ended up in go to jail box
                if(xNextPos1 == 680 && yNextPos1 == 160)
                {
                    p1GoToJail();
                }
            }
            xCurPos1 = xNextPos1;
            yCurPos1 = yNextPos1;
            
        }
        //rightmost, up vertical movement
        else if(xCurPos1 == 680 && yCurPos1 > 160)
        {
            xNextPos1 = 680;
            yNextPos1 = yCurPos1 - diceNumber * 70;
            
            if(yNextPos1 <= 160)
            {
                xNextPos1 = xNextPos1 - (160 - yNextPos1);
                if(xNextPos1 < 50)
                {
                    yNextPos1 = 160 + (50 - xNextPos1);
                    xNextPos1 = 50;
                    
                }
                else
                {
                    yNextPos1 = 160;
                    
                }
                
                //check whether player1 ended up in go to jail box
                if(xNextPos1 == 680 && yNextPos1 == 160)
                {
                    p1GoToJail();
                }
                
            }
            xCurPos1 = xNextPos1;
            yCurPos1 = yNextPos1;
            
        }
        //top ,left vertical movement
        else  if(yCurPos1 == 160 && xCurPos1 > 50)
        {
            yNextPos1 = 160;
            xNextPos1 = xCurPos1 - diceNumber * 70;
            
            if(xNextPos1 <= 50)
            {       
                yNextPos1 = yCurPos1 + 50 - xNextPos1;
                if(yNextPos1 > 790)
                {
                    xNextPos1 = 50 + (yNextPos1 - 790);
                    yNextPos1 = 790;
                    
                }
                else
                {
                    xNextPos1 = 50;
                    
                }
            }
            xCurPos1 = xNextPos1;
            yCurPos1 = yNextPos1;
            
        }
        
    }
    
    void moving2(int diceNumber)
    {
        
        //leftmost, down vertical movement
        if(xCurPos2 == 80 && yCurPos2 < 790)
        {
            xNextPos2 = 80;
            yNextPos2 = yCurPos2 + diceNumber * 70;
            
            if(yNextPos2 >= 790)//so that P2 doesn't stuck at the end of the box
            {
                xNextPos2 = xCurPos2 + yNextPos2 - 790;
                if(xNextPos2 > 710) // for case the dice give 12 and make player2 exceeds the 1 row movement
                {
                    yNextPos2 = 790 -  (xNextPos2 - 710);
                    xNextPos2 = 710;
                    
                }
                else
                {
                    yNextPos2 = 790;
                    
                }
               
            }
            xCurPos2 = xNextPos2;
            yCurPos2 = yNextPos2;
            
        }
        //bottom, right horizontal movement
        else if(yCurPos2 == 790 && xCurPos2 < 710)
        {
            yNextPos2 = 790;
            xNextPos2 = xCurPos2 + diceNumber * 70;
            
            if(xNextPos2 >= 710)
            {
                yNextPos2 = yCurPos2 - (xNextPos2 - 710);
                if(yNextPos2 < 160)
                {
                    xNextPos2 = 710 - (160 - yNextPos2);
                    yNextPos2 = 160;
                    
                }
                else
                {
                    xNextPos2 = 710;
                    
                }
                
                //check whether player 2 hit the go to jail box
                if(xNextPos2 == 710 && yNextPos2 == 160)
                {
                    p2GoToJail();
                }
                    
            }
            xCurPos2 = xNextPos2;
            yCurPos2 = yNextPos2;
           
        }
        //rightmost, up vertical movement
        else if(xCurPos2 == 710 && yCurPos2 > 160)
        {
            xNextPos2 = 710;
            yNextPos2 = yCurPos2 - diceNumber * 70;
            
            if(yNextPos2 <= 160)
            {
                xNextPos2 = xNextPos2 - (160 - yNextPos2);
                 if(xNextPos2 < 80)
                {
                    yNextPos2 = 160 + (50 - xNextPos2);
                    xNextPos2 = 80;
                    
                }
                else
                {
                    yNextPos2 = 160;
                    
                } 
                
                //check whether player 2 hit the go to jail box
                if(xNextPos2 == 710 && yNextPos2 == 160)
                {
                    p2GoToJail();
                }
            }
            xCurPos2 = xNextPos2;
            yCurPos2 = yNextPos2;
            
        }
        //top ,left vertical movement
        else  if(yCurPos2 == 160 && xCurPos2 > 80)
        {
            yNextPos2 = 160;
            xNextPos2 = xCurPos2 - diceNumber * 70;
            
            if(xNextPos2 <= 80)
            {
                yNextPos2 = yCurPos2 + 80 - xNextPos2;
                if(yNextPos2 > 790)
                {
                    xNextPos2 = 80 + (yNextPos2 - 790);
                    yNextPos2 = 790;
                    
                }
                else
                {
                    xNextPos2 = 80;
                    
                }
                
            }
            xCurPos2 = xNextPos2;
            yCurPos2 = yNextPos2;
            
        }
        
    }
    
    void checkBoxToEnlarge_1(int x,int y)
    {
        if(y == 160 || y == 790)//160 for top limit and 790 for bottom limit
        {
            boxToEnlarge = ((x - 50)/70)-1;
        }
        
        if(x == 50 || x == 680 )
        {
            boxToEnlarge = ((y - 160)/70)-1;
        }
        
    }
    
    void checkBoxToEnlarge_2(int x, int y)
    {
        if(y == 160 || y == 790)
        {
            boxToEnlarge = ((x-80)/70)-1;
            
        }
        
        if(x == 80 || x == 710 )
        {
            boxToEnlarge = ((y - 160)/70)-1;
        }
    }
  
    
    void p1GoToJail()
    {
       xNextPos1 = 50;
       yNextPos1 = 790;
       
    }
    
    void p2GoToJail()
    {
       xNextPos2 = 80;
       yNextPos2 = 790;
       
    }
    void freePark()
    {
        
    }
    
    public void paint(Graphics g)
    {
        try
        {
            //draw the players name on the top left
            g.setFont(new Font("Verdana",Font.BOLD,16));
            g.drawString("Player 1 : P1" , 20,20);
            g.drawString("Player 2 : P2" , 20,40);

            //draw the token to show which player's turn
            g.fillOval(140,TokenPos,15,15);

            //draw the "roll dice" button
            g.drawRect(700,10,150,40);
            g.drawString("Roll the Dice",725,35);

            //draw the box to display dice number
            g.drawRect(860,10,40,40);
            g.drawString(""+dice1,875,35);
            g.drawRect(910,10,40,40);
            g.drawString(""+dice2,925,35);


            //draw the map of the monopoly
            //----------------------------

            //draw the first box
            g.drawRect(40,100,70,70);

            //draw the leftmost veritical boxes
            for(int i = 170; i < 800 ; i += 70)
            {
                g.drawRect(40,i,70,70);
            }


            //draw the first horizontal boxes
            for(int i = 110; i < 740 ; i += 70)
            {
                g.drawRect(i,100,70,70);
            }

            //draw the rightmost horizontal boxes
            for(int i = 170; i < 800 ; i += 70)
            {
                g.drawRect(670,i,70,70);
            }

            //draw the bottom horizontal boxes
            for(int i = 110; i < 740 ; i += 70)
            {
                g.drawRect(i,730,70,70);
            }
            
            //draw the enlarged box of the picture
            g.drawRect(850,340,300,300);

            //draw the player movement on the boxes
            g.drawString("P1",xNextPos1,yNextPos1);
            g.drawString("P2",xNextPos2,yNextPos2);
            
            //draw GO on the first box
            g.setFont(new Font("Arial",Font.BOLD,24));
            g.setColor(Color.CYAN);
            g.drawString("G O",52,125);
            
            //draw the MRT Stations on leftmost row
            g.setFont(new Font("Arial",Font.BOLD,9));
           
            int posVar = 190; //Position Variable to help drawing the name and price
            for(int i=0 ; i < 7; i++)
            {
                g.setColor(new Color(leftMost[i].getColor()));
                if(leftMost[i].getName().length() > 13)
                {
                    g.drawString(leftMost[i].getName(),42,posVar);
                }
                else if(leftMost[i].getName().length() > 9)
                {
                    g.drawString(leftMost[i].getName(),45,posVar);
                }
                else
                {
                    g.drawString(leftMost[i].getName(),50,posVar);
                }
                g.drawString("$"+leftMost[i].getPrice(),55,posVar+20);
                    
                if(i==2)//save a space for chance box
                {
                    posVar+=140;
                }
                else
                {
                    posVar+=70;
                }
                    
            }
            
            //draw the chance box on the leftmost row
            g.setFont(new Font("Arial",Font.BOLD,12));
            g.setColor(Color.PINK);
            g.drawString("?Chance?",45,400);
            
            //draw JAIL on the bottom left corner
            g.setFont(new Font("Arial",Font.BOLD,16));
            g.setColor(Color.magenta);
            g.drawString("J A I L",50,760);
            
            //draw the MRT Stations on bottom row
            posVar = 120;
            g.setFont(new Font("Arial",Font.BOLD,9));
            for(int i = 0 ; i < 7 ; i++)
            {
                g.setColor(new Color(bottom[i].getColor()));
                
                if(bottom[i].getName().length() == 13)
                {
                    g.drawString(bottom[i].getName(),posVar-10,750);
                }
                
                else if(bottom[i].getName().length() > 9)
                {
                    g.drawString(bottom[i].getName(),posVar-5,750);
                }
                else
                {
                    g.drawString(bottom[i].getName(),posVar,750);
                }
                
                g.drawString("$"+bottom[i].getPrice(),posVar+10,760);
                if(i==1)//for Community Chest
                {
                    posVar+=140;
                }
                else
                {
                    posVar+=70;
                }
                
            }
            
            //draw the Community Chest on bottom row
            g.setFont(new Font("Arial",Font.BOLD,12));
            g.setColor(Color.GREEN);
            g.drawString("Community",254,750);
            g.drawString("Chest",270,760);
            
            //draw the Free Park
            g.setFont(new Font("Arial",Font.BOLD,15));
            g.setColor(Color.BLUE);
            g.drawString("FREE",683,750);
            g.drawString("RIDE",683,770);
            
            //draw the MRT Stations on the rightmost row
            posVar = 680;
            g.setFont(new Font("Arial",Font.BOLD,9));
            for(int i = 0 ; i < 7 ; i++)
            {
                g.setColor(new Color(rightMost[i].getColor()));
                
                if(rightMost[i].getName().length() > 8)
                {
                    g.drawString(rightMost[i].getName(),680,posVar);
                }
                else
                {
                    g.drawString(rightMost[i].getName(),685,posVar);
                }
                
                g.drawString("$"+rightMost[i].getPrice(),690,posVar+20);
                if(i==4)//for Community Chest
                {
                    posVar-=140;
                }
                else
                {
                    posVar-=70;
                }
                
            }
            
            //draw the chance box on the leftmost row
            g.setFont(new Font("Arial",Font.BOLD,12));
            g.setColor(Color.darkGray);
            g.drawString("?Chance?",675,330);
            
            //draw the "GO TO JAIL" on the top right corner
            g.setFont(new Font("Arial", Font.BOLD,12));
            g.setColor(Color.orange);
            g.drawString("Go To",690,120);
            g.drawString("JAIL",690,140);
            
            //draw the MRT Stations on the top row
            posVar = 620;
            g.setFont(new Font("Arial",Font.BOLD,9));
            for(int i = 0 ; i < 7 ; i++)
            {
                g.setColor(new Color(top[i].getColor()));
                
                if(top[i].getName().length() > 11)
                {
                    g.drawString(top[i].getName(),posVar-15,120);
                }
                else if(top[i].getName().length() > 8)
                {
                    g.drawString(top[i].getName(),posVar-10,120);
                }
                
                else
                {
                    g.drawString(top[i].getName(),posVar-5,120);
                }
                
                g.drawString("$"+top[i].getPrice(),posVar,140);
                if(i==0)//for Community Chest
                {
                    posVar-=140;
                }
                else
                {
                    posVar-=70;
                }
                
            }
            
            //draw the Community Chest on top row
            g.setFont(new Font("Arial",Font.BOLD,12));
            g.setColor(Color.yellow);
            g.drawString("Community",534,120);
            g.drawString("Chest",550,130);
            
            //finsihed drawing the monopoly map
            //---------------------------------
            
            g.setColor(Color.black);
            //draw the player1 status box
            g.drawRect(800,100,200,200);
            
            //draw the player2 status box
            g.drawRect(1000,100,200,200);
            
            //draw the player1 status
            g.setFont(new Font("Courier New",Font.BOLD,18));
            g.setColor(Color.blue);
            g.drawString("Player 1 ",850,125);
            g.drawString("Money   : ",820,165);
            g.drawString("MRT ",820,205);
            g.drawString(": ",910,215);
            g.drawString("Stations",820,225);
            
            //draw the player2 status
            g.drawString("Player 2 ",1050,125);
            g.drawString("Money   : ",1020,165);
            g.drawString("MRT ",1020,205);
            g.drawString(": ",1110,215);
            g.drawString("Stations",1020,225);
            
            //draw the community chest in the center
            g.setColor(Color.green);
            g.fillRect(180,200,200,100);
            
            //draw the chance in the center
            g.setColor(Color.magenta);
            g.fillRect(400,550,200,100);
            
            //draw MRT-Monopoly in the center
            g.setColor(Color.black);
            g.setFont(new Font("Monotype Corsiva",Font.BOLD,24));
            g.drawString("Community Chest",200,250);
            g.drawString("Chance",470,600);
            
            g.setFont(new Font("ARIAL", Font.BOLD,42));
            g.drawString("MRT - Monopoly", 250,430);
            
            //draw the String of the enlargedBox
            g.setFont(new Font("Arial Black",Font.BOLD,20));
            
            
            if(playerTurn % 2 == 1)//the large box shows player 1 pos
            {
                //for leftmost row
                if(xCurPos1 == 50 && (yCurPos1 > 160 && yCurPos1 < 790))
                {
                    if(boxToEnlarge == 3)
                    {
                        //draw the chance
                    }
                    else if(boxToEnlarge >= 4)
                    {
                        g.setColor(new Color(leftMost[boxToEnlarge-1].getColor()));
                        g.drawString(""+leftMost[boxToEnlarge-1].getName(),870,360);
                        g.drawString(""+leftMost[boxToEnlarge-1].getPrice(),880,390);
                    }
                    else
                    {
                        g.setColor(new Color(leftMost[boxToEnlarge].getColor()));
                        g.drawString(""+leftMost[boxToEnlarge].getName(),870,360);
                        g.drawString(""+leftMost[boxToEnlarge].getPrice(),880,390);
                    }
                }
                //for rightmost row
                else if (xCurPos1 == 680 && (yCurPos1 > 160 && yCurPos1 < 790))
                {
                    if(boxToEnlarge < 3)
                    {
                        g.setColor(new Color(rightMost[6-boxToEnlarge].getColor()));
                        g.drawString(""+rightMost[6-boxToEnlarge].getName(),870,360);
                        g.drawString(""+rightMost[6-boxToEnlarge].getPrice(),880,390);
                    }
                    if(boxToEnlarge == 3)
                    {
                        //draw the chance
                    }
                    else
                    {
                        g.setColor(new Color(rightMost[7-boxToEnlarge].getColor()));
                        g.drawString(""+rightMost[7-boxToEnlarge].getName(),870,360);
                        g.drawString(""+rightMost[7-boxToEnlarge].getPrice(),880,390);
                    }

                }

                //for top row
                else if(yCurPos1 == 160 && (xCurPos1 > 50 && xCurPos1 < 680))
                {
                    if(boxToEnlarge < 6)
                    {
                        g.setColor(new Color(top[6-boxToEnlarge].getColor()));
                        g.drawString(""+top[6-boxToEnlarge].getName(),870,360);
                        g.drawString(""+top[6-boxToEnlarge].getPrice(),880,390);
                    }
                    else if (boxToEnlarge == 6)
                    {
                        //draw the community chest
                    }
                    else
                    {
                        g.setColor(new Color(top[7-boxToEnlarge].getColor()));
                        g.drawString(""+top[7-boxToEnlarge].getName(),870,360);
                        g.drawString(""+top[7-boxToEnlarge].getPrice(),880,390);
                    }
                }
                else
                {
                    if(boxToEnlarge == 1)
                    {
                        //draw the chance
                    }
                    else if(boxToEnlarge >= 2)
                    {
                        g.setColor(new Color(bottom[boxToEnlarge-1].getColor()));
                        g.drawString(""+bottom[boxToEnlarge-1].getName(),870,360);
                        g.drawString(""+bottom[boxToEnlarge-1].getPrice(),880,390);
                    }
                    else
                    {
                        g.setColor(new Color(bottom[boxToEnlarge].getColor()));
                        g.drawString(""+bottom[boxToEnlarge].getName(),870,360);
                        g.drawString(""+bottom[boxToEnlarge].getPrice(),880,390);
                    }
                }
            }
            else // the large box shows player2 position
            {
                if(xCurPos2 == 80 && (yCurPos2 > 160 && yCurPos2 < 790))
                {
                    if(boxToEnlarge == 3)
                    {
                        //draw the chance
                    }
                    else if(boxToEnlarge >= 4)
                    {
                        g.setColor(new Color(leftMost[boxToEnlarge-1].getColor()));
                        g.drawString(""+leftMost[boxToEnlarge-1].getName(),870,360);
                        g.drawString(""+leftMost[boxToEnlarge-1].getPrice(),880,390);
                    }
                    else
                    {
                        g.setColor(new Color(leftMost[boxToEnlarge].getColor()));
                        g.drawString(""+leftMost[boxToEnlarge].getName(),870,360);
                        g.drawString(""+leftMost[boxToEnlarge].getPrice(),880,390);
                    }
                }
                //for rightmost row
                else if(xCurPos2 == 710 && (yCurPos2 > 160 && yCurPos2 < 790))
                {
                    if(boxToEnlarge < 3)
                    {
                        g.setColor(new Color(rightMost[6-boxToEnlarge].getColor()));
                        g.drawString(""+rightMost[6-boxToEnlarge].getName(),870,360);
                        g.drawString(""+rightMost[6-boxToEnlarge].getPrice(),880,390);
                    }
                    if(boxToEnlarge == 3)
                    {
                        //draw the chance
                    }
                    else
                    {
                        g.setColor(new Color(rightMost[7-boxToEnlarge].getColor()));
                        g.drawString(""+rightMost[7-boxToEnlarge].getName(),870,360);
                        g.drawString(""+rightMost[7-boxToEnlarge].getPrice(),880,390);
                    }

                }

                //for top row
                else if(yCurPos2 == 160 && (xCurPos2 > 80 && xCurPos2 < 680))
                {
                    if(boxToEnlarge < 6)
                    {
                        g.setColor(new Color(top[6-boxToEnlarge].getColor()));
                        g.drawString(""+top[6-boxToEnlarge].getName(),870,360);
                        g.drawString(""+top[6-boxToEnlarge].getPrice(),880,390);
                    }
                    else if (boxToEnlarge == 6)
                    {
                        //draw the community chest
                    }
                    else
                    {
                        g.setColor(new Color(top[7-boxToEnlarge].getColor()));
                        g.drawString(""+top[7-boxToEnlarge].getName(),870,360);
                        g.drawString(""+top[7-boxToEnlarge].getPrice(),880,390);
                    }
                }
                else
                {
                    if(boxToEnlarge == 1)
                    {
                        //draw the chance
                    }
                    else if(boxToEnlarge >= 2)
                    {
                        g.setColor(new Color(bottom[boxToEnlarge-1].getColor()));
                        g.drawString(""+bottom[boxToEnlarge-1].getName(),870,360);
                        g.drawString(""+bottom[boxToEnlarge-1].getPrice(),880,390);
                    }
                    else
                    {
                        g.setColor(new Color(bottom[boxToEnlarge].getColor()));
                        g.drawString(""+bottom[boxToEnlarge].getName(),870,360);
                        g.drawString(""+bottom[boxToEnlarge].getPrice(),880,390);
                    }
                }
            }
            
        }
        catch(RuntimeException e) {};
    }
    
   
    
    
}

Hi everyone, I'm a new java game programmer, I have a project to make a simple monopoly game. I decided to make one using java language and create it with applet. Above is my source code.. There is 1 problem I need a help : I got problem to display the enlarged box of the small box where the player is on after he/she rolled the dice in the down right of the applet. My previous logic is in the variable boxToEnlarge, you may either ignore or help to improve my logic. I will gladly accept any constructive comments on the way I write the source code Thank you very much for your attention...

Share this post


Link to post
Share on other sites
Quote:
Original post by JavaSharingan
how is it everyone ?
is it too troublesome to read my source code ?


Yes. There is a huge amount of it and it is full of unexplained numbers and seeming redundancies. Please read up on data-driven design. Also, consider having the MRTStations keep track of their screen locations and neighbours; and consider having a class to represent players (with an object being created for each player).

Quote:

anyway, is there too much harm for using static variable ?


No, as long as you understand what they are.

Share this post


Link to post
Share on other sites
Ya I think there is too much redundancy, I don't have programming experience.. and the school taught me only C Programming (which are scanf and printf) and javascript, yet the assignment comes to make monopoly game... I barely wrote the source codes above by reading java books for 2 weeks.. by the way I have solved the problem with lousy writing style though..
I think I will have to look back at OOP books..

thanks for the guidance..

Share this post


Link to post
Share on other sites

This topic is 4724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this