hi i need help with my class assignment we're suppose to create a 4*5 grid, two player and three enemies. the grid is made up of coordinates and i am not allowed to use arrays. To start the game the players must enter their names and then go to (0,0). the aim of the game is for the players to reach (4,3) end of grid without being eatten from the enemies who are randomly place on the grid.If eatten game over you lose, if player reaches(4,3) you won. How would you approach this assignment. (not allowed to use arrays) Thanks in advance :)

Make each player a struct with say a Name,Xcoord and Ycoord.

My approach would be to tell the instructor that this is a poor example of an assignment.

If you are learning something other than arrays then perhaps this makes sense (but I am still skeptical). Otherwise an arbitrary restriction on the use of arrays (which is the appropriate way to do this) is just wrong.

Is there a reason behind the restiction? Are you learning other mechanisms that are not arrays (a list, for example)?

You could probably use a file (one file per player, if more than one player can occupy the same location) Then use getc (or fgetc) and putc (or fputc).

See the following:
getc and fgetc

Create a file format for yourself. Here is an example:

P0*00
0*000
00!00
00*00

In the above, "0" is an open position. The asterisk is an enemy. And the exclamation (!) is the winner. "P" is the player's location.

When a user chooses to move to a location, check if the location is "open", an enemy, or the finish point. Update the user's location in the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.