Skip to content

Commit 03fdff2

Browse files
author
Joe O'Regan
committed
Comment Game File
1 parent 7286d92 commit 03fdff2

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/com/jor/con5/Game.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/*
22
* Joe O'Regan
3+
*
4+
* Game.java
35
* 09/01/2018
6+
*
47
* Connect5
5-
* Text based 5 in row game
8+
* Works with text and graphics based 5 in row games
69
*/
10+
711
package com.jor.con5;
812

913
public class Game {
@@ -32,6 +36,9 @@ public void setPlayer(int player) {
3236
this.player = player;
3337
}
3438

39+
/*
40+
* Game constructor
41+
*/
3542
public Game() {
3643
player = 1;
3744
board = new int[Var.ROWS][Var.COLS];
@@ -40,6 +47,9 @@ public Game() {
4047
setBoard(winBoard);
4148
}
4249

50+
/*
51+
* Print the game board to the console window
52+
*/
4353
public void displayBoard(int[][] board) {
4454
for (int i = 1; i < 10; i++) {
4555
System.out.print(i + " ");
@@ -55,6 +65,9 @@ public void displayBoard(int[][] board) {
5565
}
5666
}
5767

68+
/*
69+
* Set all board cells to 0
70+
*/
5871
public void setBoard(int[][] board) {
5972
for (int row = 0; row < Var.ROWS; row++) {
6073
for (int col = 0; col < Var.COLS; col++) {
@@ -63,6 +76,9 @@ public void setBoard(int[][] board) {
6376
}
6477
}
6578

79+
/*
80+
* Check for 5 in a row diagonal, horizontal, and vertical, and highlight the winning move if winner found
81+
*/
6682
public void checkWin() {
6783
for (int row = 0; row <= Var.ROWS - Var.CONNECT; row++) {
6884
// Diagonal /
@@ -117,8 +133,11 @@ public void checkWin() {
117133
}
118134
}
119135

136+
/*
137+
* If the column is not full, add the move to the game board
138+
*/
120139
public void checkCol(int col) {
121-
if (board[0][col] != 0) {
140+
if (board[0][col] != 0) { // top row full
122141
System.out.println("\nERROR: Column " + col + " is full\n");
123142
player = (player == Var.PLAYER_1) ? Var.PLAYER_2 : Var.PLAYER_1;
124143
}
@@ -131,6 +150,9 @@ public void checkCol(int col) {
131150
}
132151
}
133152

153+
/*
154+
* Highlight the winning 5 in a row
155+
*/
134156
public void show5InARow() {
135157
for (int i = 0; i < 10; i += 2) {
136158
winBoard[fiveInARow[i]][fiveInARow[i + 1]] = 1; // Highlight winning line

0 commit comments

Comments
 (0)