Sunday, 2 June 2013

Getting out of St. Mungos.

So I tried to program the getting out of St. Mungos part, but nothing worked. Not really sure why. 

But there is a variable on the individual players, which is declared as 1. the other player's variable is set to 3 when they are sent to jail by a room of requirement or "go to st. mungos' card. 

But when I run the code for the replay of the computer, it was an infinite loop. 

So I made a quick decision: don't include the option to stay in St. Mungos thrice, just charge them 50 galleons right when they get in. Those galleons will be added to the pot; so anyone who lands on the tavern will receive it. 

I will also  make changes to the "expansion" of the labels; if they click on it, they can see how much rent it is, and or how much is in the pot (for tavern). 

That way, I don't need a button telling the person where they are. 

doubles?

I just realized that I entirely forgot about the doubles rule. Although I'm thinking I'll just forget about it because a lot of people don't really play by doubles. Some people do, some people don't. 

NoClassDefFound

I just ran into a weird error that crashed my program with a NoClassDefFound. I didn't know what it meant, so I found this article. Which still doesn't make a whole lot of sense. 

So I ran my program again, and it disapparated! :o How? What was the error saying? D; I should be happy I didn't have to solve it, but I kind of want to know why it was there, so I can prevent it next time! -__- 

Anyways, um. My program is almost 6000 lines - not including the computer part. (oops :P). 

I'm done everything for the user - except the staying in jail part, which I think I'm going to program in the computer. 

Advance to the nearest transportation

So, I'm programming the advance to the nearest transportation. It really isn't that big of a deal - it's quite small. But, I used the individual index like square[5].owned rather than square[player[0].col].owned - which makes it a heck lot complicated. So I changed everything to square[player[0].col].owned instead of using individual indexes because that can easily cause mistakes. 

So this is the part for Room of Requirement - I'm posting it for future reference: 




                     int x = (int) ((Math.random()*8)+1);

                            if (x == 0)
                            {
                                player[0].col = 0; 
                                JOptionPane.showMessageDialog(pane, "Advance to go and collect 200 galleons", "Congratulations!", JOptionPane.INFORMATION_MESSAGE);
                            } //end of if statement

                            else if (x == 1)
                            {
                                //player[0].gringottsAccount+=200; 
                                JOptionPane.showMessageDialog(pane, "There is a gringrotts error, and it is in your favour! \n Collect 200 galleons courtesy of us. ", "Good news!", JOptionPane.INFORMATION_MESSAGE);
                                player[0].gringottsAccount+=200; 
                            } //end of if statement

                            else if (x==2)
                            {
                                JOptionPane.showMessageDialog(pane, "You must go to Odin's Land to purchase/interact grain because Camelot is out of food. \n Pay 100 galleons", "Uh oh...", JOptionPane.INFORMATION_MESSAGE);
                                player[0].gringottsAccount-=100; 
                            } //end of if statement

                            else if (x ==3)
                            {
                               int y = JOptionPane.showConfirmDialog(pane, "Your father falls ill, and you must visit the Court Physician, Gaius. \n Under normal circumstances, he wouldn't charge you, but this time, he asks for gold. \n You must provide him with 50 galleons otherwise he'll tell the King that you are a sorceress/sorcerer. \n Do you give him 50 galleons or risk him exposing your secret?", "Uh oh!", JOptionPane.YES_NO_OPTION);

                               if (y ==0)//if the user pressed yes
                               {
                                   player[0].gringottsAccount-=50; 
                                   pot+=50;
                                   JOptionPane.showMessageDialog(pane, "We have taken 50 galleons out of your account.", "Sorry...", JOptionPane.INFORMATION_MESSAGE);
                               } //end of if statement

                               else if (y==1)//if the user pressed no. 
                               {
                                   double p = 0.0; 
                                   int a = (int)(Math.random()*100);

                                   if (a%2 == 0) //if divisible by 2
                                   {
                                       //Gaius rats you out. 
                                       p = (int)((player[0].gringottsAccount)/2);

                                       player[0].gringottsAccount = p; 
                                       
                                       pot += p; 

                                       JOptionPane.showMessageDialog(pane, "Gaius has been possessed by a goblin. He rats you out. You lose half of your total amount of money.", "Bad news...", JOptionPane.INFORMATION_MESSAGE);
                                   } //end of if statement

                                   else //if it is an odd number
                                   {
                                       player[0].gringottsAccount+=50; 
                                       pot -=50; 
                                       JOptionPane.showMessageDialog(pane, "Fortunately, Gaius hasn't said anything to the King! \n In fact, he was possessed by a Goblin, and he apologizes by giving you 50 galleons refund,", "Great news!", JOptionPane.INFORMATION_MESSAGE);
                                   } //end of if statement

                               } //end of if statement

                            } //end of if statement

                            else if (x==4)
                            {
                                player[0].col=9;
                                JOptionPane.showMessageDialog(pane, "Your friends are annoying you, and with a very random thought, \n you try to erase their memory. Your wand backfires and you have no recollection of who you are, what you're doing, or how you got to where you were. Go to St. Mungos, now.", "Bloody Briliat Job..or not", JOptionPane.INFORMATION_MESSAGE);
                                square[9].turn=3;                                
                            } //end of if statement

                            else if (x==5)
                            {
                              JOptionPane.showMessageDialog(pane, "Happy happy birthday! \n Collect 20 galleons from each player and enjoy!", "HAPPY BIRTHDAY!", JOptionPane.INFORMATION_MESSAGE);   
                              player[1].gringottsAccount-=20; 
                              player[0].gringottsAccount+=20; 
                              pot += 40; 

                            } //end of if statement

                            else if (x==6)
                            {
                                JOptionPane.showMessageDialog(pane, "You and all your friends decide to spend money on the Chinese Theatre. \n Yes, that same one that John and his date (plus Sherlock). \n However, Sherlock only has 3 free tickets, no more, no less. \n All other players must pay 50 galleons. \n You, the person who picked up this card must chip in 10 galleons.", "Chinese Theatre", JOptionPane.INFORMATION_MESSAGE);
                                player[1].gringottsAccount-=50;
                                player[0].gringottsAccount-=10; 
                                pot += 60;
                            } //end of if statement

                            else if (x==7) 
                            {
                                int j  = 0; 
                                int index = 0, a = 0 ;
                                int pay = 0; 
                                int b = JOptionPane.showConfirmDialog(pane, "Morgana has declared war on Camelot. \n She is using you to get through to King Arthur. \n You, can use magic and stop her (but then everyone else will know that you have magic); or you can let her do her worst.\n Do you use magic?", "Decisions, decisions", JOptionPane.YES_NO_OPTION);

                                if (b==0) //you use magic. 
                                {
                                    JOptionPane.showMessageDialog(pane, "Good decision! The rent for the Com Pewter landing on your most expensive property will double." , "Good choice!", JOptionPane.INFORMATION_MESSAGE);
                                    
                                    //For Loop to determine most expensive property
                                    for (; index<square.length; index++)
                                    {
                                        //j is originally declared as 0. and so, if the square[i].buy is greater than the j value, j is equal to that starting value. Therefore, J will always be equal to the most expensive properties of the ones that it goes through. 
                                        if (j<square[index].buy)
                                        {
                                            j = square[index].buy;
                                            if (tracing) 
                                                System.out.println("Most Expensive Property: " +j+ " vs. this: square" +index+ ".rent: " +square[index].rent);
                                            
                                            if (tracing) System.out.println("The most expensive property is: " +square[index].name+ " owned by the user. The rent is now: " +square[index].rent);
                                            
                                            //i represents the index. j is used to find the most expensive property - and is equal to the most expensive property. 
                                            square[index].rent *=2;
                                            
                                            if (tracing) System.out.println("The most expensive property is: " +square[index].name+ " owned by the user. The rent is now: " +square[index].rent );
                                        } //end of if statement
                                        
                                    } //end of for loop
                                    
                                    JOptionPane.showMessageDialog(pane, "We made changes to the following property: " +square[index].name+ " . \n The rent for this property is now: " +square[index].rent+ " ." , "Property and Rent Changes", JOptionPane.INFORMATION_MESSAGE);
                                    
                                } //end if statement

                                else if (b==1) //you don't use magic. 
                                {
                                    JOptionPane.showMessageDialog(pane, "Sorry...bad decision. \n The rent of your most expensive property will be cut in half.", "Bad choice...", JOptionPane.INFORMATION_MESSAGE);
                                    
                                    //For Loop to determine most expensive property
                                    for (; index<square.length; index++)
                                    {
                                        //j is originally declared as 0. and so, if the square[i].buy is greater than the j value, j is equal to that starting value. Therefore, J will always be equal to the most expensive properties of the ones that it goes through. 
                                        if (j<square[index].buy)
                                        {
                                            j = square[index].buy;
                                            if (tracing) 
                                                System.out.println("Most Expensive Property: " +j+ " vs. this: square" +index+ ".rent: " +square[index].rent);
                                            
                                            if (tracing) System.out.println("The most expensive property is: " +square[index].name+ " owned by the user. The rent is now: " +square[index].rent);
                                            
                                            //i represents the index. j is used to find the most expensive property - and is equal to the most expensive property. 
                                            square[index].rent/=2;
                                            
                                            if (tracing) System.out.println("The most expensive property is: " +square[index].name+ " owned by the user. The rent is now: " +square[index].rent );
                                        } //end of if statement
                                        
                                    } //end of for loop
                                    
                                    JOptionPane.showMessageDialog(pane, "We made changes to the following property: " +square[index].name+ " . \n The rent for this property is now: " +square[index].rent+ " ." , "Property and Rent Changes", JOptionPane.INFORMATION_MESSAGE);
                                    
                                } //end of if statement (b) 

                            } //end of if statement
                            
                            //************************************************Transportation*

                            else if (x == 8)
                            {
                                JOptionPane.showMessageDialog(pane, "Advance to the nearest transportation spot (Taxi, Tardis, Wardrobe or Hogwarts Express).\n  If it is unowned, you can buy this from the bank. \n If it is owned, roll the dice a second time and pay the owner 10 times the sum of the die. ", "Advance", JOptionPane.INFORMATION_MESSAGE);
                                
                                //If they are in the ranges of after the Hogwarts Express but before the Tardis (or on the tardis).
                                if (player[0].col>= 32 &&player[0].col<=5)
                                {
                                    JOptionPane.showMessageDialog(pane, "You will advance to the Tardis.", "Advance to", JOptionPane.INFORMATION_MESSAGE);
                                    
                                    if (player[0].col == 5)
                                    {
                                        JOptionPane.showMessageDialog(pane, "You are already on this square. Please press 'Go, Com Pewter' when you want the Com Pewter to go", "You're already there.", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of if statement
                                    
                                    if (player[0].col>=32)
                                    {
                                         JOptionPane.showMessageDialog(pane, "You have passed the Start Square - we will provide you with 200 galleons now.", "Passed Start Square", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of if statement
                                    
                                    player[0].col = 5; 
                                    
                                    if (square[player[0].col].owned == false)
                                    {
                                        int answer = JOptionPane.showConfirmDialog(pane, "You have landed on: " +square[player[0].col].name + ". \n Would you like to purchase it? ", "You've landed!", JOptionPane.YES_NO_OPTION);
            
                                            if (answer == 0)
                                            {
                                                square[player[0].col].owner = "User"; 
                                                square[player[0].col].owned=true; 
                                                square[player[0].col].rent *=square[player[0].col].number;
                                                player[0].gringottsAccount-=(square[player[0].col].buy);
                                                JOptionPane.showMessageDialog(pane, "We have taken out: " +square[player[0].col].buy+ " from your Gringotts Account. \n You now have: " + player[0].gringottsAccount+ " galleons.", "Gringotts Account", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of if statement

                                            else
                                            {
                                                JOptionPane.showMessageDialog(pane, "We hope you will consider purchasing the property in the future! \n You now have: " +player[0].gringottsAccount+ " galleons", "Property", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of else statement
                                            
                                    } //end of if statement
                                    
                                    else if (square[player[0].col].owned == true && square[player[0].col].owner.equals("Com Pewter"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You landed on the Com Pewter's Property. \n Please press okay to roll the die.", "Transportation", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        if (square[player[0].col].number<=3)
                                        {
                                            square[player[0].col].number++;
                                            square[player[0].col].rent *= square[player[0].col].number; 
                                        } //end of if statement
                                        
                                        //JOptionPane.showMessageDialog(pane, "", "", "");
                                        
                                        int totalDie = (int)((Math.random()*12)+1); 
                                        
                                        JOptionPane.showMessageDialog(pane, "The result of your die is: " +totalDie+ " . \n You must pay the Com Pewter: " +(int)(totalDie*10)+ " . \n ", "Com Pewter: Thank you!", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        totalDie*=10;
                                        
                                        player[0].gringottsAccount-=totalDie;
                                        player[1].gringottsAccount+=totalDie;
                                        
                                    } //end of if statement
                                    
                                    else if (square[player[0].col].owned && square[player[0].col].owner.equals("User"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You have landed on your own property. Please press the button 'Go, Com Pewter' when you want the computer to go.", "Your own property!", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of else if statement
                                    
                                } //end of if statement
                                
                                /////////////////////////////////////////////////////////////TAAAXI////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                
                                //If they are after the tardis; and on or before the taxi.
                                else if (player[0].col>=6 && player[0].col<=14)
                                {
                                    if (player[0].col == 14)
                                    {
                                        JOptionPane.showMessageDialog(pane, "You are already on this square. Please press 'Go, Com Pewter' when you want the Com Pewter to go", "You're already there.", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of if statement
                                    
                                    JOptionPane.showMessageDialog(pane, "You will advance to the Taxi.", "Advance to", JOptionPane.INFORMATION_MESSAGE);
                                    
                                    player[0].col = 14; 
                                    
                                    if (square[player[0].col].owned == false)
                                    {
                                        int answer = JOptionPane.showConfirmDialog(pane, "You have landed on: " +square[player[0].col].name + ". \n Would you like to purchase it? ", "You've landed!", JOptionPane.YES_NO_OPTION);
            
                                            if (answer == 0)
                                            {
                                                square[player[0].col].owner = "User"; 
                                                square[player[0].col].owned=true; 
                                                //square[player[0].col].number++;
                                                player[0].gringottsAccount-=(square[player[0].col].buy);
                                                JOptionPane.showMessageDialog(pane, "We have taken out: " +square[player[0].col].buy+ " from your Gringotts Account. \n You now have: " + player[0].gringottsAccount+ " galleons.", "Gringotts Account", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of if statement

                                            else
                                            {
                                                JOptionPane.showMessageDialog(pane, "We hope you will consider purchasing the property in the future! \n You now have: " +player[0].gringottsAccount+ " galleons", "Property", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of else statement
                                            
                                    } //end of if statement
                                    
                                    //if the computer owns the property.
                                    else if (square[player[0].col].owned == true && square[player[0].col].owner.equals("Com Pewter"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You landed on the Com Pewter's Property. \n Please press okay to roll the die.", "Transportation", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        int totalDie = (int)((Math.random()*12)+1); 
                                        
                                        JOptionPane.showMessageDialog(pane, "The result of your die is: " +totalDie+ " . \n You must pay the Com Pewter: " +(int)(totalDie*10)+ " . \n ", "Com Pewter: Thank you!", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        totalDie*=10;
                                        
                                        player[0].gringottsAccount-=totalDie;
                                        player[0].gringottsAccount+= totalDie;
                                        
                                        if (square[player[0].col].number<=3)
                                            square[player[0].col].number ++; 
                                        
                                    } //end of if statement
                                    
                                    //if they own the property.
                                    else if (square[player[0].col].owned && square[player[0].col].owner.equals("User"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You have landed on your own property. Please press the button 'Go, Com Pewter' when you want the computer to go.", "Your own property!", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of else if statement
                                    
                                } //end of else if statement
                                
                                //////////////////////////////////////////////////////////WARDROBE////////////////////////////////////////
                                
                                //If they land after the tardis and or before/on the wardrobe.
                                else if (player[0].col>=14 && player[0].col<=22)
                                {
                                    if (player[0].col == 22)
                                    {
                                        JOptionPane.showMessageDialog(pane, "You are already on this square. Please press 'Go, Com Pewter' when you want the Com Pewter to go", "You're already there.", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of if statement
                                    
                                    JOptionPane.showMessageDialog(pane, "You will advance to the Taxi.", "Advance to", JOptionPane.INFORMATION_MESSAGE);
                                    
                                    player[0].col = 22; 
                                    
                                    if (square[player[0].col].owned == false)
                                    {
                                        int answer = JOptionPane.showConfirmDialog(pane, "You have landed on: " +square[player[0].col].name + ". \n Would you like to purchase it? ", "You've landed!", JOptionPane.YES_NO_OPTION);
            
                                            if (answer == 0)
                                            {
                                                square[player[0].col].owner = "User"; 
                                                square[player[0].col].owned=true; 
                                                //square[player[0].col].number++;
                                                player[0].gringottsAccount-=(square[player[0].col].buy);
                                                JOptionPane.showMessageDialog(pane, "We have taken out: " +square[player[0].col].buy+ " from your Gringotts Account. \n You now have: " + player[0].gringottsAccount+ " galleons.", "Gringotts Account", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of if statement

                                            else
                                            {
                                                JOptionPane.showMessageDialog(pane, "We hope you will consider purchasing the property in the future! \n You now have: " +player[0].gringottsAccount+ " galleons", "Property", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of else statement
                                            
                                    } //end of if statement
                                    
                                    //if the computer owns the property.
                                    else if (square[player[0].col].owned == true && square[player[0].col].owner.equals("Com Pewter"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You landed on the Com Pewter's Property. \n Please press okay to roll the die.", "Transportation", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        int totalDie = (int)((Math.random()*12)+1); 
                                        
                                        JOptionPane.showMessageDialog(pane, "The result of your die is: " +totalDie+ " . \n You must pay the Com Pewter: " +(int)(totalDie*10)+ " . \n ", "Com Pewter: Thank you!", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        totalDie*=10;
                                        
                                        player[0].gringottsAccount-=totalDie;
                                        player[1].gringottsAccount+=totalDie;
                                        
                                        if (square[player[0].col].number<=3)
                                                square[player[0].col].number++;
                                        
                                    } //end of if statement
                                    
                                    //if they own the property.
                                    else if (square[player[0].col].owned && square[player[0].col].owner.equals("User"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You have landed on your own property. Please press the button 'Go, Com Pewter' when you want the computer to go.", "Your own property!", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of else if statement
                                    
                                } //end of else if statement    
                                
                                //////////////////////////////////////////////////////////Hogwarts Express////////////////////////////////////////
                                
                                //If they land after the tardis and or before/on the wardrobe.
                                else if (player[0].col>=22 && player[0].col<=31)
                                {
                                    if (player[0].col == 31)
                                    {
                                        JOptionPane.showMessageDialog(pane, "You are already on this square. Please press 'Go, Com Pewter' when you want the Com Pewter to go", "You're already there.", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of if statement
                                    
                                    JOptionPane.showMessageDialog(pane, "You will advance to the Taxi.", "Advance to", JOptionPane.INFORMATION_MESSAGE);
                                    
                                    player[0].col = 31; 
                                    
                                    if (square[player[0].col].owned == false)
                                    {
                                        int answer = JOptionPane.showConfirmDialog(pane, "You have landed on: " +square[player[0].col].name + ". \n Would you like to purchase it? ", "You've landed!", JOptionPane.YES_NO_OPTION);
            
                                            if (answer == 0)
                                            {
                                                square[player[0].col].owner = "User"; 
                                                square[player[0].col].owned=true; 
                                                //square[player[0].col].number++;
                                                player[0].gringottsAccount-=(square[player[0].col].buy);
                                                JOptionPane.showMessageDialog(pane, "We have taken out: " +square[player[0].col].buy+ " from your Gringotts Account. \n You now have: " + player[0].gringottsAccount+ " galleons.", "Gringotts Account", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of if statement

                                            else
                                            {
                                                JOptionPane.showMessageDialog(pane, "We hope you will consider purchasing the property in the future! \n You now have: " +player[0].gringottsAccount+ " galleons", "Property", JOptionPane.INFORMATION_MESSAGE);
                                            } //end of else statement
                                            
                                    } //end of if statement
                                    
                                    //if the computer owns the property.
                                    else if (square[player[0].col].owned == true && square[player[0].col].owner.equals("Com Pewter"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You landed on the Com Pewter's Property. \n Please press okay to roll the die.", "Transportation", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        int totalDie = (int)((Math.random()*12)+1); 
                                        
                                        JOptionPane.showMessageDialog(pane, "The result of your die is: " +totalDie+ " . \n You must pay the Com Pewter: " +(int)(totalDie*10)+ " . \n ", "Com Pewter: Thank you!", JOptionPane.INFORMATION_MESSAGE);
                                        
                                        totalDie*=10;
                                        
                                        player[0].gringottsAccount-=totalDie;
                                        player[1].gringottsAccount+=totalDie;
                                        
                                        if (square[player[0].col].number<=3)
                                                square[player[0].col].number++;
                                        
                                    } //end of if statement
                                    
                                    //if they own the property.
                                    else if (square[player[0].col].owned && square[player[0].col].owner.equals("User"))
                                    {
                                        JOptionPane.showMessageDialog(pane, "You have landed on your own property. Please press the button 'Go, Com Pewter' when you want the computer to go.", "Your own property!", JOptionPane.INFORMATION_MESSAGE);
                                    } //end of else if statement
                                    
                                } //end of else if statement 
                                
                            } //end of if statement

                            JOptionPane.showMessageDialog(pane, "Your gringotts account now has: " +player[0].gringottsAccount+ ". Your opponent, the computer, has: " +player[1].gringottsAccount+" .", "Gringotts Accounts", JOptionPane.INFORMATION_MESSAGE);
                } //end of if statement
                
                else
                {
                                    JOptionPane.showMessageDialog(pane, "Sorry. You are not located on this property. You are unable to purchase/interact with it.", "Invalid", JOptionPane.INFORMATION_MESSAGE);
                } //end of if statement


I've also thought about the JFrames that I was planning to add: the ones that tell the user where they are, how many times the ComPewter has landed on their property, I am thinking  of entirely getting rid of those and just make it so that it shows the number of times the opponent has landed on that