none
How to make a maze game? RRS feed

  • Question

  • Hello again!

    I am wanting to get better at programming. so, i thought: "i'll get better the more i do it!" which is working. but, i have ran into a problem. i have no idea how to make a maze game! It's my next project i'm working on, while i'm taking a break from my text adventure. Any, to the point!

    I have not gotten very far... i only have 1 line drawn, and i don't think i'll get much farther than that.

    If you can maybe direct me to a handy tutorial, or a example, or just help me directly, it will be great.

    Please note, that i am only a beginner, and i know very little. (but i know how to use pretty basic commands)

    Thank you again, and sorry for all my questions. *.*


    Small Basic Beginner. :3

    Monday, April 15, 2013 9:40 PM

Answers

  • Hello 8Bit Pony!

    There's nothing wrong with asking questions =)

    Maze games can get pretty tricky. What you want to do is store your maze in a 2D array with one character (such as 'S') representing the start and another (such as 'F') representing the finish. Then, use another character (such as '*") to represent walls and one more (such as '.') to represent places the player can go.

    Then, iterate (with a double for loop) through the array elements and draw them in a TextWindow and use two number variables to hold the player's X and Y positions (and another two to represent the length and width of the maze). You can use TextWindow.ReadKey() to get the last key pressed and handle each arrow key like so (pseudocode):

    If LastKey = RightArrow If PlayerX > 0 And PlayerY > 0 'make sure we are not at the top If PlayerX < MazeWidth 'make sure we are in the bounds of the maze If Maze[PlayerX + 1][PlayerY] = "." 'check if this is not a wall PlayerX = PlayerX + 1 'move the player to the right EndIf EndIf EndIf EndIf

    '...other arrow key actions

    You will also need to add checks to see if the player is at the finish point or any other special points you may want to add.

    Also, if you want to get really fancy, you can solve the maze with recursion and Djikstra's Alogrithm!


    Please mark any answers and "vote as helpful" any posts that help you!



    • Edited by gungan37Editor Monday, April 15, 2013 10:59 PM
    • Marked as answer by 8Bit Pony Wednesday, April 17, 2013 2:24 AM
    Monday, April 15, 2013 10:57 PM
    Answerer
  • These are Maze programs  .  PLZ refer.

    Packman         BFN681         
    Packman maze drawing program CWQ839l
    Maze game (Player) HZG550   
    Maze game (Background) QDF403   
    Maze game CWC005-0 
    Maze Game XHL585-5
    Maze resolved by Turtle    PNC833  
    3D maze         RCS876          
    MazePackman     ZWD466   

    • Marked as answer by 8Bit Pony Wednesday, April 17, 2013 2:24 AM
    Monday, April 15, 2013 11:56 PM
    Answerer
  • Hello 8BiT PoNy

    Chapters 4.1 to 4.4 in the curriculum give an introduction to writing games. There's also chapters on Shapes, Arrays, Interactivity and Controls etc.

    If you haven't already got a copy you can download from here: http://sdrv.ms/YX494K

    Let me know if the download doesn't work for you.

    I've been gradually working through the curriculum (after 4 months i'm upto 3.4 Events) and find that some of the projects I put aside were worth starting, as they exposed me to new stuff, and after working through more chapters and challenges could come back to them and write them with more ease. One thing I've learnt so far is that when I get stuck with a program, there's a reason and an answer can be found, eventually.

    Hey, I posted this link on programming a couple of months ago. It's a bit off your topic bit you might like it.

    http://www.youtube.com/watch?v=nKIu9yen5nc

    Enjoy :)


    Tuesday, April 16, 2013 6:18 AM
    Moderator

All replies

  • Hello 8Bit Pony!

    There's nothing wrong with asking questions =)

    Maze games can get pretty tricky. What you want to do is store your maze in a 2D array with one character (such as 'S') representing the start and another (such as 'F') representing the finish. Then, use another character (such as '*") to represent walls and one more (such as '.') to represent places the player can go.

    Then, iterate (with a double for loop) through the array elements and draw them in a TextWindow and use two number variables to hold the player's X and Y positions (and another two to represent the length and width of the maze). You can use TextWindow.ReadKey() to get the last key pressed and handle each arrow key like so (pseudocode):

    If LastKey = RightArrow If PlayerX > 0 And PlayerY > 0 'make sure we are not at the top If PlayerX < MazeWidth 'make sure we are in the bounds of the maze If Maze[PlayerX + 1][PlayerY] = "." 'check if this is not a wall PlayerX = PlayerX + 1 'move the player to the right EndIf EndIf EndIf EndIf

    '...other arrow key actions

    You will also need to add checks to see if the player is at the finish point or any other special points you may want to add.

    Also, if you want to get really fancy, you can solve the maze with recursion and Djikstra's Alogrithm!


    Please mark any answers and "vote as helpful" any posts that help you!



    • Edited by gungan37Editor Monday, April 15, 2013 10:59 PM
    • Marked as answer by 8Bit Pony Wednesday, April 17, 2013 2:24 AM
    Monday, April 15, 2013 10:57 PM
    Answerer
  • These are Maze programs  .  PLZ refer.

    Packman         BFN681         
    Packman maze drawing program CWQ839l
    Maze game (Player) HZG550   
    Maze game (Background) QDF403   
    Maze game CWC005-0 
    Maze Game XHL585-5
    Maze resolved by Turtle    PNC833  
    3D maze         RCS876          
    MazePackman     ZWD466   

    • Marked as answer by 8Bit Pony Wednesday, April 17, 2013 2:24 AM
    Monday, April 15, 2013 11:56 PM
    Answerer
  • Hello 8BiT PoNy

    Chapters 4.1 to 4.4 in the curriculum give an introduction to writing games. There's also chapters on Shapes, Arrays, Interactivity and Controls etc.

    If you haven't already got a copy you can download from here: http://sdrv.ms/YX494K

    Let me know if the download doesn't work for you.

    I've been gradually working through the curriculum (after 4 months i'm upto 3.4 Events) and find that some of the projects I put aside were worth starting, as they exposed me to new stuff, and after working through more chapters and challenges could come back to them and write them with more ease. One thing I've learnt so far is that when I get stuck with a program, there's a reason and an answer can be found, eventually.

    Hey, I posted this link on programming a couple of months ago. It's a bit off your topic bit you might like it.

    http://www.youtube.com/watch?v=nKIu9yen5nc

    Enjoy :)


    Tuesday, April 16, 2013 6:18 AM
    Moderator
  • Hello 8BiT PoNy

    Chapters 4.1 to 4.4 in the curriculum give an introduction to writing games. There's also chapters on Shapes, Arrays, Interactivity and Controls etc.

    If you haven't already got a copy you can download from here: http://sdrv.ms/YX494K

    Let me know if the download doesn't work for you.

    I've been gradually working through the curriculum (after 4 months i'm upto 3.4 Events) and find that some of the projects I put aside were worth starting, as they exposed me to new stuff, and after working through more chapters and challenges could come back to them and write them with more ease. One thing I've learnt so far is that when I get stuck with a program, there's a reason and an answer can be found, eventually.

    Hey, I posted this link on programming a couple of months ago. It's a bit off your topic bit you might like it.

    http://www.youtube.com/watch?v=nKIu9yen5nc

    Enjoy :)


    Thanks! that curriculum will help me alot. Thank you again! i downloaded it, so as soon as i'm done school, i'll dive in! :3 i'll watch that video too.

    Small Basic Beginner. :3

    Tuesday, April 16, 2013 4:56 PM