0% found this document useful (0 votes)
11 views19 pages

Matrix - Gun Game

The document outlines a series of programming tasks for a game development project involving a 9x9 matrix. It includes instructions for placing a gun and two players in random positions, ensuring they do not overlap, and implementing movement functionality for the players. The final task introduces a two-player game where the first player to reach the gun wins.

Uploaded by

Siva Raman K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views19 pages

Matrix - Gun Game

The document outlines a series of programming tasks for a game development project involving a 9x9 matrix. It includes instructions for placing a gun and two players in random positions, ensuring they do not overlap, and implementing movement functionality for the players. The final task introduces a two-player game where the first player to reach the gun wins.

Uploaded by

Siva Raman K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

This document contains set of questions for a game development, each being an

enhancement for the game.

Zip the program as you solve each question and upload them separately in the
answers submission form.

1. Write a program to fill up the matrix size of 9*9 with 0 . Generate random number for
position x and position y and place '5' in that generated (x,y) position. Here, 5 is gun.
Note : Random number should be generated between 1 to 9. Assume matrix position
starts as (1,1)

Input :
0 - Filled matrix :
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Generated random number for 'x' : 9


Generated random number for 'y' : 1

Output :
Gun placed matrix :
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0

2. For the previous program, now add player '1', position him in the location by generating
'x' and 'y' by random number.
Note : random number generated for gun position (x,y) and player position (x,y)
should not be same. In case of generating same values, regenerate for new position. Player
1 denote as '1'

0 - Filled matrix :
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Placing Gun :
Generated random number for 'x' : 3
Generated random number for 'y' : 4
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Placing player '1' :


Generated random number for 'x' : 3
Generated random number for 'y' : 4
as already Gun ( 5 ) placed in same location. Generate new position values for
player '1' :
Generated random number for 'x' : 9
Generated random number for 'y' : 1

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0

3. Moving operation : Now introduce moving functionality to the player. Finish the game
when reaching gun [ 5 ] position
1 - Choosing left direction
2 - Choosing right direction
3 - Choosing up direction
4 - Choosing down direction.
For each move generate number from 0-3 to move forward number of position. Forward
0 means no move.
0 - Filled matrix :
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Placing Gun :
Generated random number for 'x' : 3
Generated random number for 'y' : 4
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Placing player '1' :


Generated random number for 'x' : 9
Generated random number for 'y' : 1

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0

Enter the direction you want to move : 2


Number of move (random number: 0-3) : 1
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0

Enter the direction you want to move : 3


Number of move (random number: 0-3) : 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Enter the direction you want to move : 3


Number of move (random number: 0-3) : 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 1 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Enter the direction you want to move : 2
Number of move (random number: 0-3) : 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Game Over !!!

4. Two Player game : Now introduce player '2' . Player who gets gun (reaching gun
position) is winner
Note : Generated position of player '2' should not be same as player '1' and gun [5]
position.

0 - Filled matrix :
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Placing Gun :
Generated random number for 'x' : 3
Generated random number for 'y' : 4
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Placing player '1' :


Generated random number for 'x' : 9
Generated random number for 'y' : 1
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0

Gun Holder : -
Placing player '2' :
Generated random number for 'x' : 1
Generated random number for 'y' : 4
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0

Gun Holder : -
Player '1' move :
Enter the direction you want to move : 3
Number of move (random number: 0-3) : 3
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : -
Player '2' move :
Enter the direction you want to move : 4
Number of move (random number: 0-3) : 2

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Player 2 Picked Gun - So He is the winner !!!

5. Add below functionality. Player who gets gun can shoot other person when
facing/meet opponent in the same row or column.
i) Player who gets gun should kill opponent in 3 tries (moves) , if so he is the
winner
ii) If player who gets gun was not able to shoot the opponent in 3 tries (moves),
then opponent is the winner.
iii) If player who gets gun is in same row/column in the opponent , before move
shooting is possible. For shooting , enter option '5'

Test case : follow the previous program (4) test case. So, now player '2' gets gun.
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '1' move :
Enter the direction you want to move : 4
Number of move (random number: 0-3) : 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '2' move :
Enter the direction/shooting option : 4
Number of move (random number: 0-3) : 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '1' move :
Enter the direction/shooting option : 2
Number of move (random number: 0-3) : 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '2' move :
Enter the direction/shooting option : 5

Player 2 shoot the opponent - So He is the winner !!!

6. Now, Instead of finishing game, in case of missing opponent to shoot. If the player
who gets gun was not able to shoot the opponent, then gun is freed from the player and
will be placed randomly in some other places [ x,y - randomly generated position ]. Now,
both the player having chance to pick the Gun and game will be continued till some one
gets shooted.
Condition : Freed gun should be placed in new position which is within the radius
of distance 2 from the Player who is holding gun. Ex. Assume Player '1' holding gun at
position (3,4) and his tries are over. Now, Gun could be placed in following positions:
(1,2), (1,3,), (1,4), (1,5) , (1,6)
(2,2), (2,3,), (2,4), (2,5) , (2,6)
(3,2), (3,3), , (3,5), (3,6)
(4,2), (4,3,), (4,4), (4,5) , (4,6)
(5,2), (5,3,), (5,4), (5,5) , (5,6)

Test case : follow the program - 4 test case. So, now player '2' gets gun.
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '1' move :
Enter the direction you want to move : 4
Number of move (random number: 0-3) : 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '2' move :
Enter the direction/shooting option : 4
Number of move (random number: 0-3) : 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '1' move :
Enter the direction/shooting option : 2
Number of move (random number: 0-3) : 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '2' move :
Enter the direction/shooting option : 1
Number of move (random number: 0-3) : 3

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '1' move :
Enter the direction/shooting option : 3
Number of move (random number: 0-3) : 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player '2' move :
Enter the direction/shooting option : 4
Number of move (random number: 0-3) : 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

As player '2' tries ( 3 moves over ), now gun is freed. So new position for gun in
radius 2 of Player '2'.

Gun Holder : -
Placing Gun :
Generated random number for 'x' : 5
Generated random number for 'y' : 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2 0 5 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Gun Holder : Player 1
Player '1' move :
Enter the direction/shooting option : 1
Number of move (random number: 0-3) : 1
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 1


Player '2' move :
Enter the direction/shooting option : 1
Number of move (random number: 0-3) : 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Player '1' move :


Enter the direction/shooting option : 5

Player 1 shoot the opponent - So He is the winner !!!


7. Now add 2 life survival power as '6', Place life survival power randomly in some
position. So, Player who still be alived after shoot if he has consumed survival power.
Each survival will give one life chance.

Test case :
0 - Filled matrix :
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Life Survival Power placing :


Power 1 :
Generated random number for 'x' : 6
Generated random number for 'y' : 4
Power 2 :
Generated random number for 'x' : 9
Generated random number for 'y' : 9

Placing Gun :
Generated random number for 'x' : 3
Generated random number for 'y' : 4
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 6 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 6

Placing player '1' :


Generated random number for 'x' : 7
Generated random number for 'y' : 4
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 6 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Placing player '2' :


Generated random number for 'x' : 1
Generated random number for 'y' : 4
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 6 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : -
Player 1' Survival Power : 0
Player 2 Survival Power : 0

Player '1' move :


Enter the direction/shooting option : 3
Number of move (random number: 0-3) : 1
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : -
Player 1' Survival Power : 1
Player 2 Survival Power : 0

Player '2' move :


Enter the direction/shooting option : 4
Number of move (random number: 0-3) : 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player 1' Survival Power : 1
Player 2 Survival Power : 0

Player '1' move :


Enter the direction/shooting option : 4
Number of move (random number: 0-3) : 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player 1' Survival Power : 1
Player 2 Survival Power : 0
Player '2' move :
Enter the direction/shooting option : 5
Player 1 survived .
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Gun Holder : Player 2


Player 1 Survival Power : 0
Player 2 Survival Power : 0
Player '1' move :
Enter the direction/shooting option : 2
Number of move (random number: 0-3) : 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

and so on....

You might also like