Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to get the walls from input?

how to get the walls from input?

Scheduled Pinned Locked Moved C / C++ / MFC
game-devdata-structureshelptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hasani2007
    wrote on last edited by
    #1

    Hello all; I'm a beginner in c. I should program a game(it's maze). So I am dealing with this problem that can't get the walls from input. because user should be able to put the walls by using an array. Apologise me because bad English writing.

    S _ 2 Replies Last reply
    0
    • H hasani2007

      Hello all; I'm a beginner in c. I should program a game(it's maze). So I am dealing with this problem that can't get the walls from input. because user should be able to put the walls by using an array. Apologise me because bad English writing.

      S Offline
      S Offline
      Software_Developer
      wrote on last edited by
      #2

      For example, this code generates a random maze. Its a console application

      #include <iostream.h>
      #include <conio.h>
      #include <time.h>
      #include <stdlib.h>

      int main()
      {
      system("color 1F");
      int rows,columns,r,k;
      int center,c;
      int random_it;
      char someCharacter;
      char lgt1='\xB3';
      char lgt3='\xBF';
      char lgt10='\xD9';
      srand(time(0));

      //system("color 1F")
      cout<<"Maze generator ver 0.000000000001 beta \\n\\n";
      cout<<"Input columns (x)  > ";
      cin>>columns;
      
      cout<<"Input rows    (y)  > ";
      cin>>rows;
      
      center=38-(columns/2);
      
      cout<<'\\n';
      for (r=0;r<rows;r++)
      {
      	for (c=0;c<center;c++) cout<<" ";//cout<<"|";
      	for(k=0;k<columns;k++)
      	{
      		random\_it=rand() % 20;
      		if (random\_it==0) someCharacter=random\_it+lgt1;
      		if (random\_it==1) someCharacter=random\_it+lgt1;
      		if (random\_it==2) someCharacter=random\_it+lgt3-2;
      		if (random\_it==3) someCharacter=random\_it+lgt3-2;
      		if (random\_it==4) someCharacter=random\_it+lgt3-2;
      		if (random\_it==5) someCharacter=random\_it+lgt3-2;
      		if (random\_it==6) someCharacter=random\_it+lgt3-2;
      		if (random\_it==7) someCharacter=random\_it+lgt3-2;
      		if (random\_it==8) someCharacter=random\_it+lgt3-2;
      		if (random\_it==9) someCharacter=random\_it+lgt10-9;
      		if (random\_it==10) someCharacter=random\_it+lgt10-9;
      		if (random\_it>10) someCharacter='\\x20';			
      	    cout<<(char)someCharacter;
      
      	}
      	//cout<<"|\\n";
      	  cout<<"\\n";
      }
      
      
      
      
      cout<<"\\n";
      return 0;
      

      }

      ...

      1 Reply Last reply
      0
      • H hasani2007

        Hello all; I'm a beginner in c. I should program a game(it's maze). So I am dealing with this problem that can't get the walls from input. because user should be able to put the walls by using an array. Apologise me because bad English writing.

        _ Offline
        _ Offline
        _beauw_
        wrote on last edited by
        #3

        This question reminds me of one of my articles, Fast Generation of Single-Solution Mazes[^]. Of course, one big difference is that in the article I deal with automatically generated mazes. I think you are wanting to let the user of the program input the maze. Maybe the article can still give you some ideas about certain things, e.g. data structures. Personally, if I needed to allow the user to enter a "wall" character from the console, I would use the | character, perhaps in conjunction with the _ character. Or, you could use menus of some sort. Even in a text-based application, it's possible to have a menu, e.g. 1....File 2....Print 3....About

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups