diff --git a/README.md b/README.md index 6f03192..b3a5105 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,17 @@ # HellsGamers -Pong Game developed by Eren Esen, Berkan Sarp, Justin Senn, Brice Tchoumi +"3-Games" developed by Eren Esen, Berkan Sarp, Justin Senn, Brice Tchoumi Pong game is a two-player table tennis-themed console game. The game involves two paddles and a moving ball. The players have to move paddles in an upwards or downwards direction and save the ball from getting hit onto the wall. If the ball hits the wall then it’s a score for another player. The game ends at 20 Points. + +Battleship is a strategy type guessing game for two players. It is played on ruled grids on which each +player's fleet of warships are marked. The locations of the fleets are concealed from the other player. Players +alternate turns calling "shots" at the other player's ships, and the objective of the game is to destroy the +opposing player's fleet. + +Snake is an action video game in which the player maneuvers the end of a growing snake, often represented as a snake. +The objective of the game is to pick up the randomly appearing "apples" that are offered as food. As the snake grows +with each bite, maneuvering becomes increasingly difficult as the playing field becomes more crowded. You lose as soon +as you collide with yourself. \ No newline at end of file diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 7756d31..5a9b32a 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -1,5 +1,10 @@ package BattleShip; +import javax.swing.*; +import javax.swing.border.Border; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Random; @@ -9,8 +14,13 @@ public class GridGUI { ArrayList allShips = new ArrayList(); int[] testLocations; int numOfGuesses = 0; + String text = ""; int rows; int columns; + boolean clicked = false; + boolean endGame = false; + Color darkRed = new Color(100, 0, 0); + Border loweredBevel = BorderFactory.createLoweredBevelBorder(); Ship destroyer = new Ship(2, "destroyer"); Ship cruiser = new Ship(3, "cruiser"); @@ -63,4 +73,63 @@ public class GridGUI { } } } -} \ No newline at end of file + public boolean getClicked() {return clicked;} + public void setClicked() { + clicked = false; + } + public boolean getEndGame() { + return endGame; + } + public void setEndGame() { + for(JButton j : buttons){ + j.setEnabled(false); + } + } + public class MyCellListener implements ActionListener { + public void actionPerformed(ActionEvent a) { + if(!clicked) { + BSButton cell = (BSButton) a.getSource(); + Ship s = cell.getCellContents(); + boolean killed = false; + numOfGuesses++; + boolean gameOver = true; + cell.setEnabled(false); + cell.setBorder(loweredBevel); + + if(s == null) { + //Mark cell as missed. + text = "You missed. Other player's turn..."; + cell.setBackground(Color.lightGray); + } else { + killed = s.counter(); + if(killed) { + //Mark all of the ship's cells as killed. + text = "You sunk the " + s.getName() + "! Other player's turn..."; + for(BSButton bu : buttons) { + if(bu.getCellContents() == s) { + bu.setBackground(darkRed); + } + } + } else { + //Mark cell as hit. + text = "You got a hit. Other player's turn..."; + cell.setBackground(Color.red); + } + } + for(Ship sh : allShips) { + if(!sh.isKilled()) { + gameOver = false; + } + } + if(gameOver) { + text = "You win! You took " + numOfGuesses + " guesses."; + endGame = true; + } + + clicked = true; + } + } + } +} + +