Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. Software FSMs Beginning with the program dungeon.c from Homework 8, add a new room to the game. Your room can be entered only through

4. Software FSMs

Beginning with the program dungeon.c from Homework 8, add a new room to the game. Your room can be entered only through room 0. Also, it must be possible to do the following:

i. Enter room 0 through your new room (transition 0)

ii. Lose the game in one transition (transition 1)

iii. Enter room 1 through your new room (transition 2)

iv. Enter room 2 through your new room (transition 3)

You cannot win from your room in one transition, however you might enter other rooms through your room to win the game. Draw the expanded state diagram for your new version of the game, then turn in both the diagram and a copy of your code.

Here is the code:

/* * dungeon.c * Douglas L. Jones * University of Illinois at Urbana-Champaign * September 29, 2012 * * (c) 2012 by Douglas L. Jones * This work is made available according to the * Creative Commons "Attribution" license * http://creativecommons.org/licenses/by/3.0/ * * edited by S.S. Lumetta, 11 October 2012 * edited by Yuchen He, March 2015 * * dungeon.c: a simple maze game */ #include  /* Define constants */ int main () { /*********************/ /* Declare variables */ /*********************/ int flag_play; /* indicates whether to play the game again */ int room; /* indicates current room */ int key; /* indicates whether key is found */ int choice; flag_play = 1; while ( flag_play == 1 ) { /***************/ /* Play a game */ /***************/ key = 0; room = 0; while ( room < 3 ) /* Explore the maze */ { if ( room == 0 ) { printf("You wake in a dungeon, chained to the wall! "); printf("The chains are rusty, and you manage to break free. "); printf("You search the room carefully, "); printf("and you discover two hidden exits; "); printf("a tunnel under a large flagstone, "); printf("and an air vent large enough to crawl through. "); printf("Which exit do you wish to explore? "); printf("Enter 0 for flagstone, or 1 for air vent. "); scanf("%d", &choice); if ( choice == 0 ) { room = 3; } if ( choice == 1 ) { room = 1; } } else if ( room == 1 ) { printf("You emerge in what appears to be a large cavern. "); printf("A bat brushes your head as it flies past. "); printf("Groping around in the darkness, you discover a "); printf("crawlway and a fissure you think you can fit through. "); printf("There also seems to be an opening behind a large "); printf("stalagmite. "); printf("Which exit do you wish to explore? "); printf("Enter 0 for crawlway, 1 for fissure, or 2 for behind "); printf("stalagmite. "); scanf("%d", &choice); if ( choice == 0 ) { if (!key) { printf("A locked door stopped you from moving forward."); room = 1; } else { room = 2; } } if ( choice == 1 ) { if (!key) { printf("A locked door stopped you from moving forward."); room = 1; } else { room = 3; } } if ( choice == 2 ) { if (!key) { printf("You found a shiny key on the floor."); key = 1; } room = 1; } } else if ( room == 2 ) { printf("The passage expands into a small cave with an "); printf("underground waterfall. "); printf("The passage continues on, but you feel another passage "); printf("behind the waterfall. "); printf("Enter 0 for behind waterfall, or 1 for continue "); printf("along passage. "); scanf("%d", &choice); if ( choice == 0 ) { room = 1; } if ( choice == 1 ) { room = 4; } } printf(" "); } /* End of game conditions */ if ( room == 3 ) { printf("You feel the passage widening and a draft of fresh air. "); printf("On your next step, you fall into a deep pit and die. "); } if ( room == 4 ) { printf("You see a light in the distance and climb toward it. "); printf("You emerge on the surface in a beautiful forest. "); printf("You have successfully escaped; you are free! "); } printf(" "); printf(" Would you like to play again? Enter 1 for yes, 0 for no. "); scanf("%d", &flag_play); printf(" "); } return 0; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

b. Did you suppress any of your anger? Explain.

Answered: 1 week ago