Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Silx · Apr 04, 2012 at 07:31 PM · c#arraysobjectsarraylist

Getting data from Arraylist within Arraylist

I'm sure the first response will be 'wtf, don't use arraylists!', but I'm really just trying to get this working in any way that I can.

It's basically the 'match looker' for a match 3 game. I'm having trouble getting access to the match data within the match list. See below..

     public void FindAndRemoveMatches() {
 
     ArrayList foundMatches = LookForMatches();
     
     //just checking if we're getting the right amount for now
     Debug.Log("We found " + foundMatches.Count + " 'Match 3's");
     
     foreach(Object el in foundMatches){
        //    Debug.Log(el.ToString());
     }
     
 }
 
 ArrayList LookForMatches(){
 
     //List<int> matchList = new List<int>();
     ArrayList matchList = new ArrayList();
     
     // search for horizontal matches
     // note that we're subtracting two rows here.
     // We don't need to check the last two rows because we're matching 3.
     for (int i = 0; i < BOARD_WIDTH; i++){
         for (int j = 0; j < BOARD_HEIGHT-2; j++){
             ArrayList match = GetMatchHoriz(i,j);
             if (match.Count > 2) {
                 matchList.Add(match);
                 i += match.Count-1;
             }
         }
     }
     
     // search for vertical matches
     for (int i = 0; i < BOARD_WIDTH; i++){
         for (int j = 0; j < BOARD_HEIGHT-2; j++){
             ArrayList match = GetMatchVert(i,j);
             if (match.Count > 2) {
                 matchList.Add(match);
                 j += match.Count-1;
             }
                 
         }
     }
     
     
     return matchList;
 }
 
 
 // look for horizontal matches starting at this point
 ArrayList GetMatchHoriz(int col,int row){
     ArrayList match = new ArrayList();
     match.Add(mBoard[col,row]);
     
     for(int i = 1; (col+i)<8; i++) {
         if (mBoard[col,row] == mBoard[col+i,row]) {
             if(mBoard[col+i,row] > mPieces.GetNumPieceTypes()) match.Add(mBoard[col+i,row]);
         } else {
             return match;
         }
     }
     return match;
 }    
 
 // look for horizontal matches starting at this point
 ArrayList GetMatchVert(int col,int row){
     ArrayList match = new ArrayList();
     match.Add(mBoard[col,row]);
     
     for(int i = 1; (row+i)<8; i++) {
         if (mBoard[col,row] == mBoard[col,row+i]) {
             if(mBoard[col,row+i] > mPieces.GetNumPieceTypes()) match.Add(mBoard[col,row+i]);
         } else {
             return match;
         }
     }
     return match;
 }    

Good news is, I know that it's finding the matches correctly. The number of matches it's finding using the debug log correlates with what's happening on the screen. Yay! But, I need to get access to that data so I can compare it to the board (mBoard[col,row]) and remove those objects from the game board.

The 'foreach' loop in findandremovematches gives an error about casting. Any help with this?

thanks!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Apr 04, 2012 at 09:20 PM 2
Share

wtf, don't use ArrayList. ;) Seriously, why? Just use List, then you won't have any errors about casting.

avatar image cregox · Apr 04, 2012 at 10:05 PM 0
Share

@Eric maybe that's supposed to be the answer?! :P

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Array empties values on RunTime? 1 Answer

Using a Parameterized arraylist (C#)??? 1 Answer

Identifier Expected Error ArrayList -1 Answers

odd error in c# script when working with arrays 2 Answers

Sequence Scripting 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges