1. CSC-141 Introduction to Computer Programming Spring-2013
Assignment 2
CSC-141 Introduction to Computer Programming
Instructor: Saba Anwar
Class: FA12-BPH-A
Total Marks: 50
Assignment Date Saturday May 18, 2013
Submission Date and Time: Monday May 25, 2013 by 11:55 PM
Submission Guidelines:
This is an individual assignment. For collaboration rules, please consult academic rules /honor code
(placed at website).Your submitted work will be compared with that of your friends, and copied work will
lead you to strict penalty.
When you are done with both questions, place your name and roll number in comments at start of each
program. Save each file with filename of this pattern: FA12BPH-0XX-1.c and FA12-0XX-2.c. XX is your
ID and 1, 2 represent Task number.
Send both files in a single mail with subject FA12-BPH-A [Assignment1] to
ciitsubmissions@gmail.com
Any violation may misplace your assignment and you will be marked as “Absent” in assignment.
You may submit it late as well. 20% marks will be deducted for late submission of one day and 40%
marks will be deducted for late submission of two days. No assignment will be accepted after 48 hours.
__________________________________________________________________________________
Task 1
A possible 2D array is given below
You can see that its last cell is empty. Implement the following program:
Numbers should be displayed in the above fashion. Allow the user to hit any of the arrow
keys (up, down, left or right). If user hits up key, then the piece with number 4 and blank
piece will be swapped, and this table will look like:
2. CSC-141 Introduction to Computer Programming Spring-2013
After that if user hits left key, then the piece with number 43 and blank piece will be swapped
and table will look like:
If user hits left key and there is no column on left, then it should give appropriate message. With every
hit, it will check whether numbers are sorted in ascending order or not. When all 15 integers are sorted
and blank is at last position, then it should stop by giving success message, and this table will look like:
To keep track of keys, use getch() and identify each key by its ASCII codes as follows:
Up arrow key: 72
Down arrow key: 80
Right arrow key: 75
Left arrow key: 77
It should also show number of moves at each step. It may also be stopped by press ‘q’ somewhere to
quit the program.
Task 2
3. CSC-141 Introduction to Computer Programming Spring-2013
In this task you will be implementing a simple board game called Dungeon Crawl. It will use a simple 2D
string array to draw the game board. The board should be like following:
… P ………
…… E ……
…… E ……
……… E …
… E ………
……… E …
………… $
P is the player, E’s are enemies, and $ is the treasure. Objective of the game is to safely steal the hidden
treasure in the dungeon. Following are the rules of game
1. P can move in any direction but it should not go beyond the board boundary, if it goes he dies
and game will be lost.
2. If P collides with any enemy, its life points are decreased by 1. The total points are 3 at start.
Display life points along with board throughout the game.
3. Enemies can be placed anywhere on board randomly, every time game starts, But player’s
position can be fixed in 1st
row where ever you want. You can set number of enemies yourself,
but minimum they should be 5
Use arrows keys to move the player on board
Bonus point: you can move enemies in random directions with every move of player.
___________________________________________