What we did here is, using the OOPs concepts abstract and interface we change the face of the project
Help us to do simple modification in future so as to add new games using the same matrix.
You have to go through the previous tutorials to fully understand the concepts.
Change in Tic Tac Toe class
public class TicTacToe implements IGameChanges in Main class
import com.cfed.matrix.tictactoe.IGame;
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
* Copyright (c) 1997-2017 Javabelazy and/or its affiliates. All rights reserved.
*
*/
/**
* @author konzernites
* @since 1.0
*
*/
public class Main extends AbstractGame {
private static final long serialVersionUID = 8683452581122892182L;
/**
* @param args
* @throws IllegalAccessException
*/
public static void main(String[] args) throws IllegalAccessException {
Main mainClass = new Main();
mainClass.execute();
}
private void execute() throws IllegalAccessException {
Matrix<Character> matrix = new Matrix<>(3, 3);
System.out.println(" **** INSTRUCTIONS **** ");
System.out.println(" User has to enter row and column ");
System.out.println(" Postion starts from (0,0) to (2,2) ");
IGame game = new TicTacToe(matrix);
TicTacToe.isTwoPlayer = true;
playGame(game);
System.out.println(" ***** GAME OVER ***** ");
System.out.println(" Developed by consumerfed I T Section ");
}
}
AbstractGame.java
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
* Copyright (c) 1997-2017 Javabelazy and/or its affiliates. All rights reserved.
*
*/
import com.cfed.matrix.tictactoe.IGame;
/**
*
*/
/**
* @author Konzernites
*
*/
public abstract class AbstractGame {
public void playGame(IGame game) throws IllegalAccessException {
game.startGame();
}
}
IGame Interface in java
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
* Copyright (c) 1997-2017 Javabelazy and/or its affiliates. All rights reserved.
*
*/
/**
*
*/
package com.cfed.matrix.tictactoe;
/**
* @author jwalian walla bag
*
*/
public interface IGame {
public void startGame() throws IllegalAccessException;
}
No comments:
Post a Comment
Your feedback may help others !!!