Worked on Game
This commit is contained in:
parent
4240ac37cd
commit
fdfd1219df
|
@ -6,19 +6,48 @@ import player.Player;
|
|||
// import player.Player1;
|
||||
// import player.Player2;
|
||||
|
||||
/**
|
||||
* Represents a game of Connect Four.
|
||||
*/
|
||||
public class Game {
|
||||
|
||||
/**
|
||||
* Player One
|
||||
*/
|
||||
private final Player p1;
|
||||
|
||||
/**
|
||||
* Player Two
|
||||
*/
|
||||
private final Player p2;
|
||||
|
||||
/**
|
||||
* The board on which is played.
|
||||
* [7] columns, [6] rows
|
||||
* 0 - Empty Space
|
||||
* 1 - Player One
|
||||
* 2 - Player Two
|
||||
*/
|
||||
private int[][] board;
|
||||
|
||||
/**
|
||||
* Is the game still running?
|
||||
*/
|
||||
private boolean gameOn;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Initialize board and save players.
|
||||
*/
|
||||
public Game(Player p1, Player p2) {
|
||||
this.p1 = p1;
|
||||
this.p2 = p2;
|
||||
this.board = new int [7][6];
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the game.
|
||||
*/
|
||||
public void start() {
|
||||
Random ran = new Random();
|
||||
Player first;
|
||||
|
@ -33,15 +62,41 @@ public class Game {
|
|||
|
||||
|
||||
while(gameOn) {
|
||||
makeMove(first);
|
||||
// TODO: Think of another possibility
|
||||
makeMove(first, );
|
||||
}
|
||||
}
|
||||
|
||||
private void makeMove(Player p) {
|
||||
|
||||
/**
|
||||
* Calls a players functions to make a move.
|
||||
*/
|
||||
private void makeMove(Player p, int nr) {
|
||||
boolean invalid = true;
|
||||
int choice;
|
||||
while (invalid) {
|
||||
log(p.getName() + "makes a move!");
|
||||
choice = p.move();
|
||||
if (this.board[choice][0] == 0) {
|
||||
invalid = false;
|
||||
}
|
||||
}
|
||||
int pos = 0;
|
||||
while (this.board[choice][pos + 1] == 0) {
|
||||
pos++;
|
||||
}
|
||||
this.board[choice][pos] = nr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log player actions.
|
||||
*/
|
||||
private void log(String s) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the current board to stdout.
|
||||
*/
|
||||
private void logGame() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
package game;
|
||||
|
||||
import player.Player;
|
||||
// import player.Player1;
|
||||
// import player.Player2;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Player p1 = new Player1();
|
||||
// Player p2 = new Player2();
|
||||
// new Game(p1, p2).start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue