CS1411 - 160 - Programming Principles I, Spring 2005

Programming project 1

Mandatory work

In this programming project you will write a simple treasure-hunting game. An evil computer troll has hidden a treasure in a field

What the program should do

Before the game starts, it should give the user an option to enter the field size. The field should be anywhere between 5x5 and 26x26 spaces large (Make sure you only allow correct input!).

The game will then randomly hide a treasure somewhere (see example code for random).

During the game, the computer displays the whole field with A-Z coordinates, and where the user has guessed before

It will give the user an option to guess, and display how far (s)he is from the actual treasure

All this is done until the treasure has been found

Example transcript

An example of how a program run could look can be found in the example run transcript. This is only a suggestion, though, your program may look much different!

How it should be written

  • Your program should include your name in a comment!
  • The program should be written in C++ using only standard libraries (as we had in class)
  • The program should not use any global variables. (Global types are ok)
  • The program should be modularized. It should contain many small functions. (No function should be more than 20 lines!)
  • The program should make use of two-dimensional arrays
  • The program should make use of a struct for coordinate handling
  • Every function should have a comment (about 1-5 lines) what it does
  • The program must be your unique work. There should be no code sharing between students!


Mail your code to jing. and also bring a printout to class on March 10 2005. If you cannot come to class either hand in the assignment early or make some arrangements with me. I will not accept just emailed programs or programs in my mailbox unless I have told you that it is ok to do so!


  • To convert num from 0-25 to A-Z: static_cast<char>('A'+num)
  • To convert ch from A-Z to 0-25: static_cast<int>(toupper(ch)-'A')
  • To calculate distance, #include<math.h> and use the following formula: dist = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ) (Hint: It would make a lot of sense to make a distance function that takes two coordinates as parameters)


Please ask me if you have any


Please ask me if you have any

Q: when the user finds the treasure do you want all of the tries to dissapear off the field and just show the treasure or would you like to show all the tries also?

A: This is totally up to you.

Optional work

The following things are for you to try, please pass your project in before you do them:

  • Try hiding multiple treasures
  • Kepp the user from probing the same spot again
  • Instead of just X display the distance to the spot on the field


Please check the labs page on how to get started. There are instructions for visual studio (use version 6) and XCode

Please give the Macs a try. If you simply cannot work with them, go to PE 119, but let your TA know.

Sample programs

have moved to the examples page


Use the TA HELP Desk. M-F afternoon in CS 201!

For help: ask your TA! He is here to help you!

If the instructions are unclear or you have any other questions, please email me