CS1101C Lab 1 (Odd Week)

BZFlag #1

The deadline for this lab question is Friday 15 February 2008, 23:59:59 hours.

The name of your C program file must be called tank1.c, files with any other name will not be marked.

Preliminary

Battle Zone capture Flag is a free multi-player online tank game where players try to kill as many opponents as possible.

Each tank has a unique tank number and is named Tank 1 to Tank 20. Furthermore, each tank belongs to one of twenty teams which are named Team 1 to Team 20.

When a tank x kills another tank y (where x and y are the tank numbers), there are three possible scenarios:

  1. x and y are tanks on different teams. This is the ideal situation because you want to kill only enemy tanks.

  2. x and y are tanks on the same team. This is not ideal because you do not want to kill your teammates.

  3. x and y are the same tank (x is equal to y); i.e. tank x kills itself. Stupid, but possible, since bullets can bounce off walls.

Write a program that asks the user to input the tank and team numbers for two tanks: the shooting tank and the tank being hit, and print out the correct scenario above.

Sample Runs

Assuming that the executable is tank1, sample runs of the program are shown below. User input is denoted in bold.

$ gcc -Wall tank1.c -o tank1

$ ./tank1

Enter tank number of shooter (1-20): 5
Enter team number of shooter (1-20): 6
Enter tank number of tank being hit (1-20): 7
Enter team number of tank being hit (1-20): 8
Tank 5 from team 6 shot enemy tank 7 on team 8. Well done!

$ ./tank1

Enter tank number of shooter (1-20): 5
Enter team number of shooter (1-20): 6
Enter tank number of tank being hit (1-20): 7
Enter team number of tank being hit (1-20): 6
Tank 5 from team 6 shot teammate tank 7. Oops.

$ ./tank1

Enter tank number of shooter (1-20): 5
Enter team number of shooter (1-20): 6
Enter tank number of tank being hit (1-20): 5
Enter team number of tank being hit (1-20): 6
Tank 5 shot itself. Major oops.

$

Note and Ponder

  1. Assume that all user input is valid. For example, each tank can only belong to exactly one team.

  2. If your program does not work as you expect (logical errors), use extra printf statements to print out all the values of your variables to aid in your debugging.

  3. Most importantly, have lots of fun programming!


This document, index.html, has been accessed 15 times since 25-Jun-24 11:57:13 +08. This is the 1st time it has been accessed today.

A total of 8 different hosts have accessed this document in the last 445 days; your host, nsrp-source.comp.nus.edu.sg, has accessed it 5 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.