Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit e553a26

Browse files
author
Davide
committed
Updated GameGrid and added full comments to Tile class.
1 parent 9da0bc0 commit e553a26

File tree

6 files changed

+128
-2
lines changed

6 files changed

+128
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist/

build/classes/forza4/GameGrid.class

1.79 KB
Binary file not shown.

build/classes/forza4/Tile.class

-129 Bytes
Binary file not shown.

nbproject/private/private.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
44
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
55
<group>
6+
<file>file:/C:/Users/AdSumPro/Documents/NetBeansProjects/Forza4/src/forza4/GameGrid.java</file>
67
<file>file:/C:/Users/AdSumPro/Documents/NetBeansProjects/Forza4/src/forza4/GameScreen.java</file>
78
<file>file:/C:/Users/AdSumPro/Documents/NetBeansProjects/Forza4/src/forza4/Tile.java</file>
89
<file>file:/C:/Users/AdSumPro/Documents/NetBeansProjects/Forza4/src/forza4/Game.java</file>
10+
<file>file:/C:/Users/AdSumPro/Documents/NetBeansProjects/Forza4/src/forza4/GameManager.java</file>
11+
<file>file:/C:/Users/AdSumPro/Documents/NetBeansProjects/Forza4/src/forza4/ButtonListener.java</file>
912
</group>
1013
</open-files>
1114
</project-private>

src/forza4/GameGrid.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ public class GameGrid {
1515
public static final int VOID=0;
1616
public static final int PLAYER_1=1;
1717
public static final int PLAYER_2=2;
18+
public static final int TIE=0;
19+
public static final int PLAYER_1_WIN=1;
20+
public static final int PLAYER_2_WIN=2;
21+
public static final int NO_WIN=3;
1822
private int grid[][];
23+
private int left;
1924

2025
public GameGrid(){
2126
grid=new int[X_SIZE][Y_SIZE];
27+
left=X_SIZE*Y_SIZE;
2228
}
2329

2430
public int insert(int column,int player){
2531
boolean ris;
2632
int y=deepestPiece(column);
2733
if(y!=-1){
2834
grid[column][y]=player;
35+
left-=1;
2936
}
3037
return y;
3138
}
@@ -40,4 +47,78 @@ private int deepestPiece(int column){
4047
}
4148
return found ? y-1 : y;
4249
}
50+
51+
public int checkVictory(int column,int row,int player){
52+
if(left!=0){
53+
if(grid[column][row]==player){
54+
int right=checkRight(column,row,player);
55+
if(right>=3){
56+
return player;
57+
}
58+
59+
int left=checkLeft(column,row,player);
60+
if(right+left>=3){
61+
return player;
62+
}
63+
64+
int up=checkUp(column,row,player);
65+
if(up>=3){
66+
return player;
67+
}
68+
69+
int down=checkDown(column,row,player);
70+
if(up+down>=3){
71+
return player;
72+
}
73+
74+
int upRight=checkUpRight(column,row,player);
75+
if(upRight>=3){
76+
return player;
77+
}
78+
79+
int downLeft=checkDownLeft(column,row,player);
80+
if(downLeft+upRight>=3){
81+
return player;
82+
}
83+
84+
int upLeft=checkUpLeft(column,row,player);
85+
if(upLeft>=3){
86+
return player;
87+
}
88+
int downRight=checkDownRight(column,row,player);
89+
if(downRight+upLeft>=3){
90+
return player;
91+
}
92+
}
93+
return NO_WIN;
94+
}else{
95+
return TIE;
96+
}
97+
}
98+
99+
private int checkRight(int column,int row,int player){
100+
101+
102+
}
103+
104+
private int checkLeft(int column,int row,int player){
105+
}
106+
107+
private int checkUp(int column,int row,int player){
108+
}
109+
110+
private int checkDown(int column,int row,int player){
111+
}
112+
113+
private int checkUpLeft(int column,int row,int player){
114+
}
115+
116+
private int checkUpRight(int column,int row,int player){
117+
}
118+
119+
private int checkDownLeft(int column,int row,int player){
120+
}
121+
122+
private int checkDownRight(int column,int row,int player){
123+
}
43124
}

src/forza4/Tile.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,64 @@
1313
* @author AdSumPro
1414
*/
1515
public class Tile extends JPanel {
16+
/**
17+
* The ratio between the circle radious and the square.
18+
*/
1619
private static final float CIRCLE_RATIO=0.9f;
20+
/**
21+
*
22+
*/
1723
private static final float DISTANCE_RATIO= ((1-CIRCLE_RATIO)/2);
24+
/**
25+
* The tile is void.
26+
*/
1827
public static final int STATUS_VOID=0;
28+
/**
29+
* The tile is occuped by the Player1.
30+
*/
1931
public static final int STATUS_PLAYER1=1;
32+
/**
33+
* The tile is occuped by the Player2.
34+
*/
2035
public static final int STATUS_PLAYER2=2;
36+
/**
37+
* Current status.
38+
*/
2139
private int status;
40+
/**
41+
* Create a void Tile with no name.
42+
*/
2243
public Tile(){
2344
super();
2445
status=STATUS_VOID;
2546
}
2647

48+
/**
49+
* Create a Tile with a specific name.
50+
* @param name the name of the tile.
51+
*/
2752
public Tile(String name){
2853
super();
2954
this.setName(name);
3055
status=STATUS_VOID;
3156
}
3257

58+
/**
59+
* Paint the tile with the colors associated with the actual status of the tile and the configuration.
60+
* @param g the graphics of the tile.
61+
*/
3362
@Override
3463
public void paintComponent(Graphics g){
3564
super.paintComponent(g);
36-
System.out.println("TAAC");
3765
drawCircle(g,getWidth(),getHeight());
3866
}
3967

68+
/**
69+
* Draw the disc hole or the player disc depending on the current status of the tile.
70+
* @param g the graphics of the tile.
71+
* @param width the width of the tile.
72+
* @param height the height of the tile.
73+
*/
4074
private void drawCircle(Graphics g,int width,int height){
4175
switch(status){
4276
case STATUS_PLAYER1:
@@ -52,10 +86,17 @@ private void drawCircle(Graphics g,int width,int height){
5286
g.fillOval((int)(width*DISTANCE_RATIO),(int)(height*DISTANCE_RATIO), (int)(width*CIRCLE_RATIO),(int)(height*CIRCLE_RATIO));
5387
}
5488

89+
/**
90+
* Get the actual status.
91+
* @return The actual status.
92+
*/
5593
public int getStatus() {
5694
return status;
5795
}
58-
96+
/**
97+
* Set the actual status.
98+
* @param status The status to set.
99+
*/
59100
public void setStatus(int status) {
60101
this.status = status;
61102
}

0 commit comments

Comments
 (0)