You are required to write a game called "Push and Pop" which is a single player game with a 3 x 3 game board (in basic version). The game board consists of 3 x 3 stacks of size 5, which are numbered as follow:
0 1 2
3 4 5
6 7 8
During the game, only the top element of the stack is shown to the player. If the stack is empty, '-' is shown. For ease of playing, the size of the stack will be displayed too. The expected output of the game should look somewhat like this:
D:PPGjava PushPopGame q1.txt
-------------------------------
QUESTION: [0 1 2] SCORE: 0
-------------------------------
Game Size
---- ----
- - - | 0 0 0
- - - | 0 0 0
- - - | 0 0 0
Please enter the position (-1 to quit):
As you can see from the screen capture above, a question preview of size 3 is provided. Player is asked to push the first number in the question preview to one of nine stacks (if it is not full) by the numbering mentioned in the first paragraph.
At the start of each game, a question list is read from a file (e.g. ql.txt) which contains a set of number (range from 0 - 9) in space delimited format. The list repeats from start again if all numbers Page 2 are placed to the board. A question preview of size 3 is provided which perform like a sliding window after each move. For example:
Question List
0 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
Game preview when the game starts
[0 1 2] 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
After player placed 0 to the game board, game preview slides to the next element
0 [1 2 3] 4 5 6 7 8 9 8 7 6 5 4 3 2 1
Your Java program should be able to handle the inputs for the question list file (e.g. q1.txt) through command line input as follows:
java PushPopGame ql.txt
Player's score is starting from 0 and increases when any of the following patterns is found horizontal, vertical or diagonal row
1. same number (+10)
2. sequential number in either increasing or decreasing manner (+30)
Note that, multiple rows may take into account in one single move, as see in the example below
5 5 5
- 4 7
2 2 3
If 5 is placed at position 0, 10 marks is obtained by pattern (5,5,5) found in position [0,1,2] and 30 marks is obtained by pattern (5,4,3) found in position [0,4,8], therefore 40 marks will be added to total, and involved elements will be popped. And the new state of the game board is formed, for example:
- 9 -
- - 7
2 2 2
The new state of the game board will be considered again as combo. For example, a 10 marks pattern is found in position [6, 7, 8] and the score obtained in the new state will be multiplied by the combo count. In this case, 10 x 2 = 20 and added to total score, in other words 40 + 20 marks in this single push. The process repeat until the state become stable, i.e. no pattern is found and no element is needed to be popped.
The game over when all stacks are full.
The game will quit when user input the position -1