Question

In: Computer Science

c++ maze game Project Scope – Details of the Project: Sample Maze Layout: User Interface: Data...

c++ maze game

Project Scope – Details of the Project: Sample Maze Layout:
User Interface:
Data Structures:

Data Classes:

Project Details:

Algorithm (flowchart and/or pseudo-code):

Solutions

Expert Solution

User Interface - Command Line Interface

Data Structures - Arrays, Recursion

Data classes - COORD

#include "stdafx.h"
#include <stdio.h>

const int MazeHeight = 9;
const int MazeWidth = 9;

char Maze[MazeHeight][MazeWidth + 1] =
{
    "# #######",
    "#   #   #",
    "# ### # #",
    "# #   # #",
    "# # # ###",
    "#   # # #",
    "# ### # #",
    "#   #   #",
    "####### #",
};

const char Wall = '#';
const char Free = ' ';
const char SomeDude = '*';

class COORD
{
public:
    int X;
    int Y;
    COORD(int x = 0, int y = 0) { X = x, Y = y; }
    COORD(const COORD &coord) { X = coord.X; Y = coord.Y; }
};
COORD StartingPoint(1, 0);
COORD EndingPoint(7, 8);

void PrintDaMaze()
{
    for (int Y = 0; Y < MazeHeight; Y++)
    {
        printf("%s\n", Maze[Y]);
    }
    printf("\n");
}

bool Solve(int X, int Y)
{
    // Make the move (if it's wrong, we will backtrack later.
    Maze[Y][X] = SomeDude;

    // If you want progressive update, uncomment these lines...
    //PrintDaMaze();
    //Sleep(50);

    // Check if we have reached our goal.
    if (X == EndingPoint.X && Y == EndingPoint.Y)
    {
        return true;
    }
// Repeatedly search for our solution.
    if (X > 0 && Maze[Y][X - 1] == Free && Solve(X - 1, Y))
    {
        return true;
    }
    if (X < MazeWidth && Maze[Y][X + 1] == Free && Solve(X + 1, Y))
    {
        return true;
    }
    if (Y > 0 && Maze[Y - 1][X] == Free && Solve(X, Y - 1))
    {
        return true;
    }
    if (Y < MazeHeight && Maze[Y + 1][X] == Free && Solve(X, Y + 1))
    {
        return true;
    }

    // Otherwise we need to backtrack and find another solution.
    Maze[Y][X] = Free;

    // If you want for further continuation, uncomment these lines...
    //PrintDaMaze();
    //Sleep(50);
    return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
    if (Solve(StartingPoint.X, StartingPoint.Y))
    {
        PrintDaMaze();
    }
    else
    {
        printf("Damn\n");
    }

    return 0;
}

Related Solutions

Maze in C++ Simple Maze Program – Project Specifications: 1. Create a simple maze game that...
Maze in C++ Simple Maze Program – Project Specifications: 1. Create a simple maze game that a player must traverse to win. 3. The maze must be text-based and adjustable from 5x5 to 20x20. • Player gets to choose size either as: 1) any size in the range from 5-20 by 5-20. 2) selects from 4 set size options [5x5,10x10,15x15, and 20x20] • the player can choose among different mazes. • You will need to figure out how to denote...
Write a 2-page overview of the project and your participation in the User interface of a...
Write a 2-page overview of the project and your participation in the User interface of a new smartwatch built specifically for athletes... Clearly delineate your role and responsibilities. Discuss what you have learned about Human-Computer Interaction #No plagiarism, please
create a Visual Basic project with the following features: 1. The user interface can display the...
create a Visual Basic project with the following features: 1. The user interface can display the following information, one textbox for one item: 1a. Author, in the form of Lastname, Firstname 1b. Title 1c. Source -- where the paper is published 1d. Abstract 1e. Publication year (This information is in the 1c. Source, but display the publication year separately here) 2. There is a command button "Import". It would allow the user to select the eric.txt as the input file...
In C, build a connect 4 game with no graphical use interface. Build only the text...
In C, build a connect 4 game with no graphical use interface. Build only the text interface. Use a 2D array as the Data structure. The skeleton of the game is provided for you, Build the game based on the guidelines below. The game does NOT need a mode where you play against the computer. It is simply a game of Connect 4 between player 1 and player 2. SKELETON: #include // Initializing constants #define NAME_LENGTH 30 #define BOARD_WIDTH 6...
(C++ program) ***User Interface Write a program that offers an easy way to add items, remove...
(C++ program) ***User Interface Write a program that offers an easy way to add items, remove the last item, look at the last item put in the list. You will write all of the code for processing the stack - do not use any predefined objects in C++.  You decide how the interface will look. A menu driven program is always a good choice. ***Rules for program*** NEVER use break, exit, return, pass, continue or anything to leave a loop (or...
C++ Code ***User Interface Write a program that offers an easy way to add items, remove...
C++ Code ***User Interface Write a program that offers an easy way to add items, remove the last item, look at the last item put in the list. You will write all of the code for processing the stack - do not use any predefined objects in C++.  You decide how the interface will look. A menu driven program is always a good choice. ***Rules for program*** NEVER use break, exit, return, pass, continue or anything to leave a loop (or...
C++ - Checks the relevance of a data structure in terms of following the interface specification...
C++ - Checks the relevance of a data structure in terms of following the interface specification for an ADT that represents a linear data structure: Depending on the ADT of linear data structure, you must create the operations CRUD (Create, Read (search), Update, Delete) elements in the data structure. Some operations do not apply for certain data structures Create: Description: Insert an element in the data structure (create) according to the access policy of the structure Input:Data structure and element...
.Code for a game of Tetris in C# .Short explanation for a first time user, showing...
.Code for a game of Tetris in C# .Short explanation for a first time user, showing them how to use it and pointing out all of the pertinent features. (1 paragraph) .Provide a few screen shots if possible
C++ The program implements the Number Guessing Game. However, in that program, the user is given...
C++ The program implements the Number Guessing Game. However, in that program, the user is given as many tries as needed to guess the correct number. Rewrite the program so that the user has no more than five tries to guess the correct number. Your program should print an appropriate message, such as “You win!” or “You lose!”.
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers. 2.The program must perform the following: a.Uses a Scanner object to ask the user: (The program asks for no other information) i.Full Name (First and Last name only) - stores this Full Name in one String object variable. ii.Age – must be read in as an int. iii.Profession or expected...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT