DominoGame.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * DominoesGame.java
  3. *
  4. * This is where the Domino game will be played
  5. *
  6. * Stephen Stengel
  7. * Jose Rodriquez
  8. *
  9. */
  10. public class DominoGame
  11. {
  12. public static void main (String args[])
  13. {
  14. System.out.println("This is going to be a dominoes game!\n");
  15. //create the table
  16. Table myTable= new Table();
  17. //print inital state of table and players
  18. System.out.println("State of table:\n\n" + myTable.toString());
  19. //run the game
  20. myTable.placeFirstDomino( myTable.highestDomino() );
  21. //print state of table after first domino is placed
  22. System.out.println( "\n\nNew State:\n" + myTable.toString() + "\nEnd new state print.\n");
  23. //winning player will be winnerValue+1
  24. int winnerValue = myTable.playGame();
  25. System.out.println("\n\n##################################"
  26. + "\nBoard state: \n" + myTable.toString() );
  27. //System.out.println("Value of winnerValue: " + winnerValue);
  28. if (winnerValue <= -1)
  29. {
  30. System.out.println("The game was blocked by Player " + (winnerValue * -1) + "! Player with fewest dots wins!");
  31. System.out.println("Player 1 has: " + myTable.players[0].getNumberOfDots() + " dots!");
  32. System.out.println("Player 2 has: " + myTable.players[1].getNumberOfDots() + " dots!");
  33. if ( myTable.players[0].getNumberOfDots() == myTable.players[1].getNumberOfDots() )
  34. {
  35. System.out.println("It's a tie! Each player has the same number of dots!");
  36. }
  37. else if ( myTable.players[0].getNumberOfDots() > myTable.players[1].getNumberOfDots() )
  38. {
  39. System.out.println("Player 2 wins!");
  40. }
  41. else
  42. {
  43. System.out.println("Player 1 wins!");
  44. }
  45. }
  46. else if (winnerValue == 0 || winnerValue == 1)
  47. {
  48. System.out.println("The winner is Player" + (winnerValue + 1) + "!");
  49. }
  50. else
  51. {
  52. System.out.println("ERROR in main!");
  53. }
  54. }
  55. }