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

Game Play

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.

Question List

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

Scoring

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.

Game Over

The game over when all stacks are full.

Quit Game

The game will quit when user input the position -1

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.