Skip to content

Commit 74f66d0

Browse files
committed
initial snake commit
1 parent c1ca01b commit 74f66d0

File tree

8 files changed

+143
-0
lines changed

8 files changed

+143
-0
lines changed

snake/Zsargul/snake/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snake/Zsargul/snake/.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snake/Zsargul/snake/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snake/Zsargul/snake/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snake/Zsargul/snake/snake.iml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import javax.swing.*;
2+
3+
public class gameFrame extends JFrame {
4+
gameFrame() {
5+
this.add(new gamePanel());
6+
this.setTitle("Snake");
7+
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
8+
this.setResizable(false);
9+
this.pack();
10+
this.setVisible(true);
11+
this.setLocationRelativeTo(null);
12+
}
13+
}
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import javax.swing.*;
2+
import java.awt.*;
3+
import java.awt.event.ActionEvent;
4+
import java.awt.event.ActionListener;
5+
import java.awt.event.KeyAdapter;
6+
import java.awt.event.KeyEvent;
7+
import java.util.Random;
8+
9+
public class gamePanel extends JPanel implements ActionListener {
10+
11+
static final int SCREEN_WIDTH = 600;
12+
static final int SCREEN_HEIGHT = 600;
13+
static final int UNIT_SIZE = 25;
14+
static final int GAME_UNITS = (SCREEN_WIDTH * SCREEN_HEIGHT) / UNIT_SIZE;
15+
static final int DELAY = 75;
16+
17+
final int x[] = new int[GAME_UNITS];
18+
final int y[] = new int[GAME_UNITS];
19+
int bodyParts = 3;
20+
int applesEaten = 0;
21+
int appleX;
22+
int appleY;
23+
24+
/*
25+
R = Right
26+
L = Left
27+
U = Up
28+
D = down
29+
*/
30+
char direction = 'R';
31+
boolean running = false;
32+
Timer timer;
33+
Random random;
34+
35+
gamePanel() {
36+
random = new Random();
37+
this.setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT));
38+
this.setBackground(Color.black);
39+
this.setFocusable(true);
40+
this.addKeyListener(new myKeyAdapter());
41+
42+
start();
43+
}
44+
45+
public void start() {
46+
newApple();
47+
running = true;
48+
timer = new Timer(DELAY, this);
49+
timer.start();
50+
}
51+
52+
public void paintComponent(Graphics g) {
53+
super.paintComponent(g);
54+
}
55+
56+
public void draw(Graphics g) {
57+
58+
}
59+
60+
public void newApple() {
61+
62+
}
63+
64+
public void move() {
65+
66+
}
67+
68+
public void appleCheck() {
69+
70+
}
71+
72+
public void collisionCheck() {
73+
74+
}
75+
76+
public void gameOver(Graphics g) {
77+
78+
}
79+
80+
@Override
81+
public void actionPerformed(ActionEvent e) {
82+
83+
}
84+
85+
public class myKeyAdapter extends KeyAdapter {
86+
@Override
87+
public void keyPressed(KeyEvent e) {
88+
89+
}
90+
}
91+
}

snake/Zsargul/snake/src/snake.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class snake {
2+
public static void main(String[] args) {
3+
new gameFrame();
4+
}
5+
}

0 commit comments

Comments
 (0)