That's really a hard way to implement the algorithm, when your field is a grid. Prim's algorithm for a grid can be much more easily expressed. Rather than study what you did wrong with your code, I'll tell you the easy way.
Create your grid, and number all the cells with consecutive numbers from zero. Each cell has two boundary walls it can break; up and left, or down and right, or some other combination, it doesn't matter as long as you choose one of (left/right) and one of (up/down).
Now choose any cell, and choose one of its walls. If the cell on the other side of that wall has a different number (one higher and one lower), break that wall, and then throughout the maze, renumber all occurrences of the higher number to the lower one. If you choose a cell and a wall that already has the same number on the other side, don't try the other wall, instead move to the next cell in order, repeating across each row and down (perhaps cycling almost all the way around) until you find a cell with a wall that you can break.
If you have N cells, you have to repeat this wall-breaking exercise exactly N-1 times until the last time all cells are numbered zero (because each time you break, you remove the higher number from the field), and you have a complete maze.
If you want a maze whose paths are more often left-right than up-down, then bias your random choice of which wall to break in that direction. This also works for 3D mazes, where you might not want many ladders; just don't choose to break so many ceilings/floors.
After I described this algorithm, my 14yo son implemented it in Turbo-Pascal in 3D, so I know that the algorithm and this description actually work. This is actually a version of Prim's algorithm, except where all arcs have the same cost (or all left-right ones do, and all up-down ones do, etc). The neat thing about it is the way the numbering works to figure out which cells are already reachable from which others.