Commits

Andrew Nguyen committed 0d29a45

fixed ending in mancala at end of game and formatted command output of stones

Comments (0)

Files changed (4)

src/ClassicLayout.java

 		mRects = new Rectangle2D.Double[nPlayers];
 		try {
 		bg = ImageIO.read(new File("resources/classic_bg.png"));
-		System.out.println("DEBUG: Image load was success!");
 		}
 		catch (Exception e) { bg = null; }
 	}
 		g.drawImage(bg, 0, 0, 455, 325, b);
 
 		Graphics2D g2 = (Graphics2D) g;
-		System.out.println("DEBUG: Layout redraw action");
 		
+		// Commandline output of stones
+		System.out.print(" ");
+		for (int p = pits[1].length - 1; p >= 0; p--)
+			System.out.print(" " + pits[1][p]);
+		if (mancalas[1] < 10)
+			System.out.print("\n" + mancalas[1] + "             " + mancalas[0] + "\n ");
+		else
+			System.out.print("\n" + mancalas[1] + "           " + mancalas[0] + "\n ");
 		for (int p = 0; p < pits[0].length; p++)
-			System.out.print(p + ":" + pits[0][p] + " ");
-		System.out.println("P1:" + mancalas[0]);
-
-		for (int p = pits[1].length - 1; p >= 0; p--)
-			System.out.print(p + ":" + pits[1][p] + " ");
-		System.out.println("P2:" + mancalas[1]);
-
+			System.out.print(" " + pits[0][p]);
+		System.out.println("\n");
 
 		// Draw the stones.
 		for (int r = 0; r < pits.length; r++)
 		int ringCenterY = yorigin + boxheight / 2;
 		int stoneCenterX = (int)(ringCenterX + stoneR * Math.cos(a));
 		int stoneCenterY = (int)(ringCenterY + stoneR * Math.sin(a));
-		//System.out.println("DEBUG: R: " + stoneR + " stoneX: " + stoneCenterX +
-		//		" stoneY: " + stoneCenterY + " a: " + a);
 		return new Ellipse2D.Double(stoneCenterX - stoneR * Math.sqrt(2),
 				stoneCenterY - stoneR * Math.sqrt(2), stoneR * 2, stoneR * 2);
 	}
 		{
 			public void actionPerformed(ActionEvent event)
 			{
-				System.out.println("DEBUG: Setting layout to #: " + layoutNumber);
 				layout = layouts[layoutNumber];
 			}
 		};
 					--hand;
 					if (hand <= 0)
 					{
-						// updates board and lets current player have a free turn
+						checkEmpty();
 						freeTurn = true;
 						somethingChanged();
 						return;
 	 */
 	public void somethingChanged()
 	{
-		System.out.println("DEBUG: Change Event Emitted");
 		for (ChangeListener listener : listeners)
       {
          listener.stateChanged(new ChangeEvent(this));
 			 activePlayer = nextSide(activePlayer);
 		}
 
-      // checks if either side is empty and ends the game
+      checkEmpty();
+		
+		somethingChanged();
+	}
+	
+	/**
+	 * Determines if the game is over
+	 * @return whether the game is over or not
+	 */
+	public boolean isGameOver()
+	{
+		return gameOver;
+	}
+	
+	/**
+	 * Checks if either side is empty and ends the game
+	 */
+	private void checkEmpty()
+	{
 		int[][] checkPits = getPits();
 		int empty;
 		for (int i = 0; i < N_PLAYERS; i++)
 					break;
 			 }
 		}
-		somethingChanged();
-	}
-	
-	/**
-	 * Determines if the game is over
-	 * @return whether the game is over or not
-	 */
-	public boolean isGameOver()
-	{
-		return gameOver;
 	}
 	
 	/**

src/MancalaGUI.java

 	 */
 	public void stateChanged(ChangeEvent event)
 	{
-		System.out.println("DEBUG: Change Event Caught");
 		board.setData(game.getPits(), game.getMancalas());
 		board.repaint();
 		if (game.isGameOver())