Jump to content
  • Advertisement
Sign in to follow this  
JavaSharingan

Unity Simple Monopoly Game Help !

This topic is 4914 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.getColor()));
                if(leftMost.getName().length() > 13)
                {
                    g.drawString(leftMost.getName(),42,posVar);
                }
                else if(leftMost.getName().length() > 9)
                {
                    g.drawString(leftMost.getName(),45,posVar);
                }
                else
                {
                    g.drawString(leftMost.getName(),50,posVar);
                }
                g.drawString("$"+leftMost.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.getColor()));
                
                if(bottom.getName().length() == 13)
                {
                    g.drawString(bottom.getName(),posVar-10,750);
                }
                
                else if(bottom.getName().length() > 9)
                {
                    g.drawString(bottom.getName(),posVar-5,750);
                }
                else
                {
                    g.drawString(bottom.getName(),posVar,750);
                }
                
                g.drawString("$"+bottom.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.getColor()));
                
                if(rightMost.getName().length() > 8)
                {
                    g.drawString(rightMost.getName(),680,posVar);
                }
                else
                {
                    g.drawString(rightMost.getName(),685,posVar);
                }
                
                g.drawString("$"+rightMost.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.getColor()));
                
                if(top.getName().length() > 11)
                {
                    g.drawString(top.getName(),posVar-15,120);
                }
                else if(top.getName().length() > 8)
                {
                    g.drawString(top.getName(),posVar-10,120);
                }
                
                else
                {
                    g.drawString(top.getName(),posVar-5,120);
                }
                
                g.drawString("$"+top.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
Advertisement
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
Quote:

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


No, as long as you understand what they are.[/quote]

And have a good reason for using them ;).

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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By Alexander_Vovk
      Hello Guys!
      Please share your experience, where is it better to find sales manager  specialists for indie team of 6 + people(remotely)?
      Maybe someone has a good experience of cooperation with finding projects through sale managers(USA and Canada)?
      Thank you
      Best Regards
      Alex Vovk
      Co-Founder of Sixteen Squares
      Alexander_Vovk@outlook.com
       
    • By RoKabium Games
      Been a bit quiet recently, but we've been busy bug fixing and tweaking things... Now we have lots more 'Particle effects' in the game, specifically here the Flamethrower and Enemy attacks!
    • By JoshuaFraser
      Hi and thanks for reading, I have an issue with this reactive crosshair script, everything works fine until I start changing the offset. Give the script a go and you will see what I mean, when I do SetOffset(0f); it doesnt always set back to the origional state, if anyone can spot a fix I'd be super appreciative!
      using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReactiveCrosshair : MonoBehaviour { [SerializeField] GameObject c_limb_prefab; private float center_offset = 0f; private float current_offset = 0f; private float max_offset = .5f; private int number_of_limbs = 4; private float limb_length = .05f; private float limb_width = .005f; private List<GameObject> c_limbs = new List<GameObject>(); public void SetupCrosshair(){ for (int i = 0; i < number_of_limbs; i++) { GameObject line_go = (GameObject)Instantiate (c_limb_prefab); line_go.transform.SetParent (this.transform); Vector3 limb_pos = new Vector3 (0f,0f,0f); //line_go.transform.position = limb_pos; line_go.transform.localPosition = limb_pos; LineRenderer line = line_go.GetComponent<LineRenderer>(); line.startWidth = limb_width; line.positionCount = 2; line.SetPosition (0, line_go.transform.localPosition + new Vector3(center_offset, 0f, 0f)); line.SetPosition (1, line_go.transform.localPosition + new Vector3(center_offset + limb_length, 0f, 0f)); line.useWorldSpace = false; c_limbs.Add(line_go.gameObject); } if (c_limbs != null) { OrientLimbs (); SetOffset (0f); } } public void OrientLimbs(){ for (int i = 0; i < c_limbs.Count; i++) { float rotation_step = 360f / (float)c_limbs.Count; c_limbs [i].transform.RotateAround (c_limbs[i].transform.position, c_limbs[i].transform.forward, 90f + (rotation_step * (float)i)); } } public void SetOffset(float _current_spread){ float offset = Mathf.Lerp (0f, max_offset, _current_spread); for (int i = 0; i < number_of_limbs; i++) { if (offset > current_offset) { Vector3 pos = c_limbs [i].transform.position + (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } if (offset < current_offset) { Vector3 pos = c_limbs [i].transform.position - (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } } Debug.Log ("SetOffset() offset: " + offset.ToString () + " _current_spread: " + _current_spread.ToString() + " localPos: " + c_limbs[1].transform.localPosition); current_offset = offset; } }  
    • By Erik Nivala
      So, as the title says i am trying to figure out a good way sync all that information with other players in Unity. My problem is that i can't come up with a good solution since i am used to creating classes for everything e.g. attachments are its own class and then the weapon would save a reference to that attachment. But since you can't send custom classes over [Command] & [ClientRPC] i am a little stuck. A solution for this would be giving each attachment for a slot a unique ID and then passing the ID to other player but i feel like that is very error prone if other ppl add a new attachment or the IDs get mixed up.
      Is there a "standard" way that this is usually done that i am missing?
      I am fairly new to programming so any help is appreciated!
    • By MintyLyton
      I'm looking for any team / people that need a programmer for their project. I'm looking to expand my portfolio which you can see Here. I'm more experienced with Unity but I can spend the time to learn new Engines if that's your preference. I have worked on Unreal Engine 4 before but I might take some time to re-learn it, if the project requires it. Feel free to DM here or use the contact info on my website. 
    • By ethancodes
      I'm working on a system for my game that will allow the player to stack pick ups in a queue. As one pick up expires, the next automatically activates. I'm having an issue though where if I pick up the first one, it activates fine, but if i pick up a second directly after it, it overrides the first one, activates the second one, and then once it has run it's course, everything goes back to normal gameplay, no first pick up. I'm not sure why this is happening. Hopefully someone can spot what I'm doing wrong in my code.
      Here is the code for the pick up manager:
      // Update is called once per frame void Update () { if (pickUpQueue.Count != 0 && !pickUpActive) { pickUpActive = true; pickUpQueue[0].ActivatePickUp(); } DeactivatePickUp(); } void DeactivatePickUp () { if (pickUpQueue.Count != 0 && pickUpActive) { Destroy (pickUpQueue [0]); pickUpQueue.RemoveAt (0); pickUpActive = false; } } And here is the PickUp:
      public override void ActivatePickUp () { ball.GetComponent<Ball>().Speed = 2.0f; //increase ball speed... ball.GetComponent<Ball>().StartCoroutine(timer); //...set time that power up is active }  
      There is also a Base Pick Up:
      public void OnCollisionEnter2D (Collision2D collision) { Vector2 tweak = new Vector2 (Random.Range(0f, 0.2f),Random.Range(0f, 0.2f)); this.gameObject.GetComponent<Rigidbody2D>().velocity += tweak; //if the pickup makes contact with the paddle or ball.... if (collision.gameObject.tag == "Paddle" || collision.gameObject.tag == "Ball") { GameObject.FindObjectOfType<GameManager>().GetComponent<PickUpManager>().pickUpQueue.Add(this); Destroy(gameObject); //...and finally destroy power up object } } As a side note, I am trying to find a solution to this that will work for all of my pickups. Some pickups are ammo based, some are timed. 
    • By D34DPOOL
      Edit Your Profile D34DPOOL 0 Threads 0 Updates 0 Messages Network Mod DB GameFront Sign Out Add jobEdit jobDeleteC# Programmer for a Unity FPS at Anywhere   Programmers located Anywhere.
      Posted by D34DPOOL on May 20th, 2018
      Hello, my name is Mason, and I've been working on a Quake style arena shooter about destroying boxes on and off for about a year now. I have a proof of concept with all of the basic features, but as an artist with little programming skill I've reached the end of my abilities as a programmer haha. I need someone to help fix bugs, optomize code, and to implent new features into the game. As a programmer you will have creative freedom to suggest new features and modes to add into the game if you choose to, I'm usually very open to suggestions :).
      What is required:
      Skill using C#
      Experience with Unity
      Experience using UNET (since it is a multiplayer game), or the effort and ability to learn it
      Compensation:
      Since the game currently has no funding, we can split whatever revenue the game makes in the future. However if you would perfer I can create 2D and/or 3D assets for whatever you need in return for your time and work.
      It's a very open and chill enviornment, where you'll have relative creative freedom. I hope you are interested in joining the team, and have a good day!
       
      To apply email me at mangemason@yahoo.com
    • By davejones
      Is there a way to automatically change the start position of an animation? I have a bunch of animations set up on 3D models in unity. The issue is that I need to move the 3D models, however when I do so the animation start positions are not updated and I have to do it manually.

      Changing the transform of key frames is time consuming with the amount of animations I have, so I was wondering if there was a way to do it automatically?
    • By MoreLion
      hey all! We are looking for members for our Unity horror game! 
      Here’s the story:
      After a deadly virus plunges the world into chaos killing 85% of the human population there are now what they call “zones” these zones are watched very closely by the surviving government, people are checked every day for the virus, even if you touch the spit or any human waste or fluids of the victim who is infected, you will die. But one day, people in the west zone start to go missing, 1 woman goes outside the walls to uncover the mystery, is there more to the virus than meets the eye?, That is where your story starts.
      This game is not a long development game, I have loads other game ideas,
      I will also allow you to have a bit of creative freedom if you wish to add or share a idea!
      And no, it’s not a zombie game lol I feel like zombie games are too generic, in this game you will encounter terrifying beasts!
      There is some concept art one of our concept artists have made
      If interested email liondude12@gmail.com
    • By Canadian Map Makers
      GOVERNOR is a modernized version of the highly popular series of “Caesar” games. Our small team has already developed maps, written specifications, acquired music and performed the historical research needed to create a good base for the programming part of the project.

      Our ultimate goal is to create a world class multi-level strategic city building game, but to start with we would like to create some of the simpler modules to demonstrate proof of concept and graphical elegance.

       

      We would like programmers and graphical artists to come onboard to (initially) create:

      A module where Province wide infrastructure can be built on an interactive 3D map of one of the ancient Roman Provinces.
      A module where city infrastructure can be built on a real 3D interactive landscape.
      For both parts, geographically and historically accurate base maps will be prepared by our team cartographer. Graphics development will be using Blender. The game engine will be Unity.

       

      More information, and examples of the work carried out so far can be found at http://playgovernor.com/ (most of the interesting content is under the Encyclopedia tab).

       

      This project represents a good opportunity for upcoming programmers and 3D modeling artists to develop something for their portfolios in a relatively short time span, working closely with one of Canada’s leading cartographers. There is also the possibility of being involved in this project to the point of a finished game and commercial success! Above all, this is a fun project to work on.

       

      Best regards,

      Steve Chapman (Canadian Map Makers)

       
  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631396
    • Total Posts
      2999784
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!