Skip to content

edited readme #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions FunnyCatchGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package space;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Random;

public class FunnyCatchGame extends JPanel implements ActionListener {
private Timer timer;
private ArrayList<Item> items;
private int playerX = 250;
private final int playerWidth = 70;
private final int playerHeight = 20;
private int score = 0;

Comment on lines +12 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve field encapsulation and constant declarations

  1. Fields should be marked as private for better encapsulation
  2. Magic numbers should be converted to named constants
  3. Consider adding window dimension constants

Apply these improvements:

 public class FunnyCatchGame extends JPanel implements ActionListener {
-    private Timer timer;
-    private ArrayList<Item> items;
-    private int playerX = 250;
-    private final int playerWidth = 70;
-    private final int playerHeight = 20;
-    private int score = 0;
+    private static final int WINDOW_WIDTH = 500;
+    private static final int WINDOW_HEIGHT = 500;
+    private static final int PLAYER_WIDTH = 70;
+    private static final int PLAYER_HEIGHT = 20;
+    private static final int INITIAL_PLAYER_X = WINDOW_WIDTH / 2;
+
+    private final Timer timer;
+    private final ArrayList<Item> items;
+    private int playerX = INITIAL_PLAYER_X;
+    private int score = 0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public class FunnyCatchGame extends JPanel implements ActionListener {
private Timer timer;
private ArrayList<Item> items;
private int playerX = 250;
private final int playerWidth = 70;
private final int playerHeight = 20;
private int score = 0;
public class FunnyCatchGame extends JPanel implements ActionListener {
private static final int WINDOW_WIDTH = 500;
private static final int WINDOW_HEIGHT = 500;
private static final int PLAYER_WIDTH = 70;
private static final int PLAYER_HEIGHT = 20;
private static final int INITIAL_PLAYER_X = WINDOW_WIDTH / 2;
private final Timer timer;
private final ArrayList<Item> items;
private int playerX = INITIAL_PLAYER_X;
private int score = 0;

public FunnyCatchGame() {
timer = new Timer(20, this);
items = new ArrayList<>();
setFocusable(true);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
playerX -= 10;
} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
playerX += 10;
}
playerX = Math.max(0, Math.min(playerX, 500 - playerWidth));
}
});
timer.start();
spawnItems();
}
Comment on lines +20 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve game constants and movement handling

  1. Extract timer refresh rate and movement speed as constants
  2. Use window dimension constants for boundary checking
  3. Consider adding smooth movement with key states instead of direct position changes
+    private static final int REFRESH_RATE_MS = 20;
+    private static final int PLAYER_SPEED = 10;
+
     public FunnyCatchGame() {
-        timer = new Timer(20, this);
+        timer = new Timer(REFRESH_RATE_MS, this);
         items = new ArrayList<>();
         setFocusable(true);
         addKeyListener(new KeyAdapter() {
             @Override
             public void keyPressed(KeyEvent e) {
                 if (e.getKeyCode() == KeyEvent.VK_LEFT) {
-                    playerX -= 10;
+                    playerX -= PLAYER_SPEED;
                 } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
-                    playerX += 10;
+                    playerX += PLAYER_SPEED;
                 }
-                playerX = Math.max(0, Math.min(playerX, 500 - playerWidth));
+                playerX = Math.max(0, Math.min(playerX, WINDOW_WIDTH - PLAYER_WIDTH));
             }
         });

Committable suggestion was skipped due to low confidence.


private void spawnItems() {
Timer itemTimer = new Timer(1000, e -> {
Random rand = new Random();
int x = rand.nextInt(850);
String itemType = rand.nextBoolean() ? "🦆" : "🌮";
items.add(new Item(x, 0, itemType));
});
itemTimer.start();
}
Comment on lines +39 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix spawn mechanics and add resource management

  1. Spawn position uses incorrect width (850 vs window width 500)
  2. itemTimer should be cleaned up when game ends
  3. Spawn frequency should be configurable
+    private static final int SPAWN_INTERVAL_MS = 1000;
+    private Timer itemTimer;
+
     private void spawnItems() {
-        Timer itemTimer = new Timer(1000, e -> {
+        itemTimer = new Timer(SPAWN_INTERVAL_MS, e -> {
             Random rand = new Random();
-            int x = rand.nextInt(850);
+            int x = rand.nextInt(WINDOW_WIDTH - 20); // Subtract emoji width
             String itemType = rand.nextBoolean() ? "🦆" : "🌮"; 
             items.add(new Item(x, 0, itemType));
         });
         itemTimer.start();
     }
+
+    public void stopGame() {
+        timer.stop();
+        itemTimer.stop();
+    }

Committable suggestion was skipped due to low confidence.


@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.GREEN);
g.fillRect(playerX, 450, playerWidth, playerHeight);
g.setColor(Color.RED);
for (Item item : items) {
g.drawString(item.type, item.x, item.y);
}
g.setFont(new Font("Arial", Font.BOLD, 20));
g.drawString("Score: " + score, 10, 20);
}

@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < items.size(); i++) {
Item item = items.get(i);
item.y += 5; // Fall speed
if (item.y > 500) {
items.remove(i);
i--;
} else if (item.y >= 450 && item.x >= playerX && item.x <= playerX + playerWidth) {
// Catching the item
score += item.type.equals("🦆") ? 1 : 2; // Duck = 1 point, Taco = 2 points
items.remove(i);
i--;
}
}
repaint();
}
Comment on lines +62 to +78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve game loop and collision detection safety

  1. Use Iterator or CopyOnWriteArrayList to safely modify collection
  2. Extract magic numbers to constants
  3. Consider adding game over condition
+    private static final int FALL_SPEED = 5;
+
     @Override
     public void actionPerformed(ActionEvent e) {
-        for (int i = 0; i < items.size(); i++) {
-            Item item = items.get(i);
-            item.y += 5; // Fall speed
-            if (item.y > 500) {
-                items.remove(i);
-                i--;
-            } else if (item.y >= 450 && item.x >= playerX && item.x <= playerX + playerWidth) {
+        items.removeIf(item -> {
+            item.y += FALL_SPEED;
+            if (item.y > WINDOW_HEIGHT) {
+                return true;
+            }
+            if (item.y >= WINDOW_HEIGHT - PLAYER_HEIGHT && 
+                item.x >= playerX && 
+                item.x <= playerX + PLAYER_WIDTH) {
                 // Catching the item
-                score += item.type.equals("🦆") ? 1 : 2; // Duck = 1 point, Taco = 2 points
-                items.remove(i);
-                i--;
+                score += item.type.equals("🦆") ? 1 : 2;
+                return true;
             }
-        }
+            return false;
+        });
         repaint();
     }

Committable suggestion was skipped due to low confidence.


public static void main(String[] args) {
JFrame frame = new JFrame("Funny Catch Game");
FunnyCatchGame game = new FunnyCatchGame();
frame.add(game);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
Comment on lines +80 to +87
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve window initialization

  1. Use constants for window dimensions
  2. Set minimum window size
  3. Center window on screen
     public static void main(String[] args) {
         JFrame frame = new JFrame("Funny Catch Game");
         FunnyCatchGame game = new FunnyCatchGame();
         frame.add(game);
-        frame.setSize(500, 500);
+        frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
+        frame.setMinimumSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
+        frame.setLocationRelativeTo(null); // Center on screen
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setVisible(true);
     }

Committable suggestion was skipped due to low confidence.


class Item {
int x, y;
String type;

Item(int x, int y, String type) {
this.x = x;
this.y = y;
this.type = type;
}
}
Comment on lines +89 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve Item class encapsulation and documentation

The Item class needs better encapsulation and documentation.

-    class Item {
-        int x, y;
-        String type;
+    /**
+     * Represents a falling item in the game.
+     */
+    private static class Item {
+        private int x, y;
+        private final String type;
 
         Item(int x, int y, String type) {
             this.x = x;
             this.y = y;
+            if (type == null || (!type.equals("🦆") && !type.equals("🌮"))) {
+                throw new IllegalArgumentException("Invalid item type");
+            }
             this.type = type;
         }
+
+        public int getX() { return x; }
+        public int getY() { return y; }
+        public String getType() { return type; }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class Item {
int x, y;
String type;
Item(int x, int y, String type) {
this.x = x;
this.y = y;
this.type = type;
}
}
/**
* Represents a falling item in the game.
*/
private static class Item {
private int x, y;
private final String type;
Item(int x, int y, String type) {
this.x = x;
this.y = y;
if (type == null || (!type.equals("🦆") && !type.equals("🌮"))) {
throw new IllegalArgumentException("Invalid item type");
}
this.type = type;
}
public int getX() { return x; }
public int getY() { return y; }
public String getType() { return type; }
}

}
74 changes: 24 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,69 @@
<img width="1280" alt="readme-banner" src="https://github.com/user-attachments/assets/35332e92-44cb-425b-9dff-27bcf1023c6c">

# [Project Name] 🎯
# [Duck and Dock] 🎯


## Basic Details
### Team Name: [Name]
### Team Name: [DevelopMental]


### Team Members
- Team Lead: [Name] - [College]
- Member 2: [Name] - [College]
- Member 3: [Name] - [College]
- Team Lead: [Kevin B John] - [College of engineering perumon]
- Member 2: [Hiba P N] - [College of engineering perumon]


### Project Description
[2-3 lines about what your project does]
[Its a simple game to based on java.]

### The Problem (that doesn't exist)
[What ridiculous problem are you solving?]
[There are a lot of games, i just want to enjoy some time making my own version , or would i say i didnt like most the designs of such games :]

### The Solution (that nobody asked for)
[How are you solving it? Keep it fun!]
[Created a fun game in java, theres a lot of games there in the internet, adding my own pile to the ocean , or should i say its useless :)]

## Technical Details
### Technologies/Components Used
For Software:
- [Languages used]
- [Frameworks used]
- [Libraries used]
- [Tools used]
- [java]
- [jdk IDE]


For Hardware:
- [List main components]
- [List specifications]
- [List tools required]

### Implementation
For Software:
# Installation
[commands]
For Software: Eclipse IDE

# Run
[commands]

### Project Documentation
For Software:

# Screenshots (Add at least 3)
# Screenshot![Screenshot 2024-10-26 091235](https://github.com/user-attachments/assets/5ae08857-da29-424c-9929-31aa6373b8d8)
s (Add at least 3)
![Screenshot1](Add screenshot 1 here with proper name)
*Add caption explaining what this shows*

![Screenshot2](Add screenshot 2 here with proper name)
*Add caption explaining what this shows*
*Add caption ex![Screenshot 2024-10-26 091251](https://github.com/user-attachments/assets/c0a58390-a9a4-4635-acbf-389b2846a65a)
plaining what this shows*

![Screenshot3](Add screenshot 3 here with proper name)
![Screenshot3![Screenshot 2024-10-26 091335](https://github.com/user-attachments/assets/b9384fc5-7e3b-4d61-84f1-2fefb47ecd79)
](Add screenshot 3 here with proper name)
*Add caption explaining what this shows*

# Diagrams
![Workflow](Add your workflow/architecture diagram here)
*Add caption explaining your workflow*

For Hardware:

# Schematic & Circuit
![Circuit](Add your circuit diagram here)
*Add caption explaining connections*
### Project Demo
# Video

![Schematic](Add your schematic diagram here)
*Add caption explaining the schematic*
https://github.com/user-attachments/assets/713bf604-988c-41a9-bd3e-ed338664f840

# Build Photos
![Components](Add photo of your components here)
*List out all components shown*

![Build](Add photos of build process here)
*Explain the build steps*
[Add your demo video link here]

![Final](Add photo of final product here)
*Explain the final build*

### Project Demo
# Video
[Add your demo video link here]
*Explain what the video demonstrates*

# Additional Demos
[Add any extra demo materials/links]

## Team Contributions
- [Name 1]: [Specific contributions]
- [Name 2]: [Specific contributions]
- [Name 3]: [Specific contributions]
- [HIBA P N]: [IDEA And support]
- [KEVIN B JOHN]: [IMPLEMENTATION]

---
Made with ❤️ at TinkerHub Useless Projects
Expand Down