本帖最后由 thefuture 于 2018-11-19 22:50 编辑
Back in the good old days, there were no fancy graphics in computer games; we used text to represent everything. Your task is to draw a room from a family of games called Roguelikes -- the player (represented by the @ symbol) must explore a dungeon.
2x2 room, player at 0,1: +--+
|..|
|@.|
+--+
5x3 room, player at 1,2:
+-----+
|.....|
|.....|
|.@...|
+-----+
14x8 room, player at 8,5:
+--------------+
|..............|
|..............|
|..............|
|..............|
|..............|
|........@.....|
|..............|
|..............|
+--------------+
Your task is to write a function (with extra "helper" functions) to draw such a room.
• How big are the rooms? What is the coordinate system?
• Your int main() must contain only:
- int main() {
- drawRoom(2,2,0,1);
- drawRoom(5,3,1,2);
- drawRoom(14,8,8,5);
- getchar();
- return 0; }
复制代码
• In addition to drawRoom(), write three extra functions. The first draw a horizontal +---+ line, the second draws a line without the player |....|, and the third draws the line with the player |..@.|. The drawRoom function should call those other helper functions when appropriate. (examples of the three extra functions are not drawn to scale) • Use for loops. You may not use if or while in this exercise.
(optional: combine this exercise with keyboard input -- let the player move around in the room, bump into walls, etc. Ask the user to turn on the numlock key and to press enter after every move, then you can read his moves by reading int from the keyboard. Use a while loop for this movement.)
|