Skip to content

jdiep1034/Text-Adventure-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The header files for room, item, and character all declare the proper functions which are implemented for use in adventure.c. item contains "add_item" and "drop_item" functions for adding and removing an item from a link list. rooms have a linked item list as well as a linked character list. character contains "move_character" function which moves a character to an assigned room while also removing them from the previous room. In adventure.c, a helper function is made for most of the commands. Others I found it to be easier to  do in the while loop. The game runs continuously until either all 10 clues are used or the player correctly matches the correct room, character, and item. In main, an array is made for room structs, character structs, and item structs which is used when some commands are inputted by the player. There are 9 room structs, 5 character structs, and 6 item structs. The room struct array is randomized through a random shuffle. I then link the rooms by having the first 3 elements be the top third of the map, the next 3 elements being the middle third, and the last 3 elements being the bottom third of the map. Characters are randomly assigned using a for loop and rand(). Same for items except I make sure that there is only 1 item per room. The player is randomly assigned to a room. Avatar is also given an inventory which is a linked list of items. winning Set is also randomly determnined at the beginning in main. When 'help' is inputted, help() function is called which prints the table of commands and what they do. When 'list' is inputted, list() function is called which prints a list of all the rooms, all the characters, and all the items in the game. 'look' input calls look function which takes a room struct as a parameter. Rooms in each direction is displayed (Nothing if no room in that direction). Also displays all items and all characters in the room. 'go DIRECTION' calls the respective go__() functions i made which finds the room in the direction requested using the room's pointers and assigns the new room to the player's room struct, representing where they are. Both 'take_ITEM' and 'drop_ITEM' utilize the add_Item and drop_Item functions in the item files to either take item from a room or drop item from player inventory to the room. 'inventory' input simply calls showInventory function which displayed all items in the players inventory. 'clue CHARACTER' first checks to see if character is a valid character. if so, it used move_character to move the character to the room the player is in. It then checks if the current room matches the room in winning set. Then does the same for all characters in the room and all items in the room and in the player's inventory. The while loop is exited when all three match the winning set or when all 10 clues are used.

Youtube link:
https://youtu.be/GIT3IByg2Mw

About

Text adventure game using C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published