• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
    6
  • comments
    2
  • views
    10389


1 Comment


Well I took a Room-centric approach to my solution. I'm convinced that this is not the THE WAY or an optimal way. But it works [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[spoiler]
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CW_Project1
{
class Program
{
static void Main(string[] args)
{
MazeCreator mc = new MazeCreator();
mc.createMaze(4, 4);
mc.createPerfectMaze();
mc.displayMaze();
}
}
class Room
{
int roomNumber;
int[] wallArray;
public Room()
{
}
public Room(int roomNum, int[] walls)
{
roomNumber = roomNum;
wallArray = walls;
}
public int RoomNumber
{
get
{
return roomNumber;
}

set
{
roomNumber = value;
}
}
public int[] WallArray
{
get
{
return wallArray;
}
set
{
wallArray = value;
}
}

}
class MazeCreator
{
int rows;
int columns;
int topOffset;
int leftOffset;
int rightOffset;
int bottomOffset;
int rowOffset;
List<int> knockedDownRooms;
Room[,] initialRooms;
int[] wallsToKnockDown;
public void createMaze(int rows, int columns)
{
this.rows = rows;
this.columns = columns;
initialRooms = new Room[rows, columns];
int numOfRooms = rows * columns;
int rowOfWalls = (columns - 1) + columns;
int totalNumberOfWalls = (rowOfWalls * rows) - columns;

for (int i = 0; i < rows; ++i)
{
adjustRowOffsets(i, columns, rowOfWalls);
for (int j = 0; j < columns; ++j)
{
int roomNum = (i * columns) + j;
int tO = roomNum + topOffset;
int lO = roomNum + leftOffset;
int rO = roomNum + rightOffset;
int bO = roomNum + bottomOffset;
setWallsToRoom(rowOfWalls, ref tO, ref lO, ref rO, ref bO);
checkOverflowOfBottomFloors(totalNumberOfWalls, ref bO);
initialRooms[i,j] = new Room(roomNum, new int[] {tO, lO, rO, bO});
}
}
}
public void createPerfectMaze()
{
int rowOfWalls = (columns - 1) + columns;
int totalNumberOfWalls = (rowOfWalls * rows) - columns;
knockedDownRooms = new List<int>();
wallsToKnockDown = wallToKnockDownArray(totalNumberOfWalls);
int[] roomsAndFloorType;
for (int i = 0; i < wallsToKnockDown.Length; ++i)
{
roomsAndFloorType = getRoomsFromWall(wallsToKnockDown[i], rowOfWalls, columns);
// rowNum * columns + cell
int y = roomsAndFloorType[0] / columns;
int x = roomsAndFloorType[0] % columns;
int floorType = roomsAndFloorType[2];
if (knockedDownRooms.Contains(roomsAndFloorType[0]) &&
knockedDownRooms.Contains(roomsAndFloorType[1]))
continue;
for (int j = 0; j < initialRooms[y, x].WallArray.Length; ++j)
{
if (initialRooms[y, x].WallArray[j] == wallsToKnockDown[i])
{
initialRooms[y, x].WallArray[j] = -2;

if (!knockedDownRooms.Contains(roomsAndFloorType[0]))
knockedDownRooms.Add(roomsAndFloorType[0]);
break;
}
}

if (floorType == 0)
{
int y0 = y + 1;
for (int j = 0; j < initialRooms[y0, x].WallArray.Length; ++j)
{
if (initialRooms[y0, x].WallArray[j] == wallsToKnockDown[i])
{
initialRooms[y0, x].WallArray[j] = -2;
if (!knockedDownRooms.Contains(roomsAndFloorType[1]))
knockedDownRooms.Add(roomsAndFloorType[1]);
break;
}
}
}
else if (floorType == 1)
{
int x0 = x + 1;
for (int j = 0; j < initialRooms[y, x0].WallArray.Length; ++j)
{
if (initialRooms[y, x0].WallArray[j] == wallsToKnockDown[i])
{
initialRooms[y, x0].WallArray[j] = -2;
if (!knockedDownRooms.Contains(roomsAndFloorType[1]))
knockedDownRooms.Add(roomsAndFloorType[1]);
break;
}
}
}
}
}
public void displayMaze()
{
int totalRooms = initialRooms.Length;
for (int j = 0; j < rows; ++j)
{
for (int i = 0; i < columns; ++i)
{
Console.Write(" ");
if (initialRooms[j, i].WallArray[0] == -1)
Console.Write("-");
else if (initialRooms[j, i].WallArray[0] >= 0)
Console.Write("-");
else if (initialRooms[j, i].WallArray[0] == -2)
Console.Write(" ");
}
Console.Write(" ");
Console.WriteLine();
for (int i = 0; i < columns; ++i)
{
if (initialRooms[j, i].WallArray[1] == -1)
Console.Write("|");
else if (initialRooms[j, i].WallArray[1] >= 0)
Console.Write("|");
else if (initialRooms[j, i].WallArray[1] == -2)
Console.Write(" ");
Console.Write(" ");
}
Console.Write("|");
Console.WriteLine();
if (j == rows - 1)
{
for (int i = 0; i < columns; ++i)
{
Console.Write(" ");
if (initialRooms[j, i].WallArray[3] == -1)
Console.Write("-");
else if (initialRooms[j, i].WallArray[3] >= 0)
Console.Write("-");
else if (initialRooms[j, i].WallArray[3] == -2)
Console.Write(" ");
}
Console.Write(" ");
Console.WriteLine();
}
}
}
public Room[,] getInitialRooms()
{
return initialRooms;
}
private int[] getRoomsFromWall(int wallNumber, int rowOfWalls, int columns)
{
int x = (wallNumber % rowOfWalls);
int y = (wallNumber / rowOfWalls);
int colLimit = columns - 1;
int roomA = -1;
int roomB = -1;
int floorOrWall = -1;
if (0 <= x && x < colLimit)
{
roomA = (y * columns) + x;
roomB = roomA + 1;
floorOrWall = 1;
}
else if (colLimit <= x && x < rowOfWalls)
{
roomA = (y * columns) + (x - colLimit);
roomB = roomA + columns;
floorOrWall = 0;
}
int[] knockDownRooms = new int[3];
knockDownRooms[0] = roomA;
knockDownRooms[1] = roomB;
knockDownRooms[2] = floorOrWall;
return knockDownRooms;
}
private int[] wallToKnockDownArray(int totalNumberOfWalls)
{
int[] wallsArray = new int[totalNumberOfWalls];
for (int i = 0; i < totalNumberOfWalls; ++i)
{
wallsArray[i] = i;
}
shuffle(wallsArray);
return wallsArray;
}
private void shuffle(int[] array)
{
//Fisher-Yates algorithm, gotten from Stack Overflow
Random rng = new Random(); // i.e., java.util.Random.
int n = array.Length; // The number of items left to shuffle (loop invariant).
while (n > 1)
{
int k = rng.Next(n); // 0 <= k < n.
n--; // n is now the last pertinent index;
int temp = array[n]; // swap array[n] with array[k] (does nothing if k == n).
array[n] = array[k];
array[k] = temp;
}
}
private void adjustRowOffsets(int indexedRow, int columns, int rowOfWalls)
{
rowOffset = -columns + (indexedRow * (columns - 1));
topOffset = rowOffset;
leftOffset = (topOffset + (columns - 1));
rightOffset = leftOffset + 1;
bottomOffset = topOffset + rowOfWalls;
}
private void setWallsToRoom(int rowOfWalls, ref int tO, ref int lO, ref int rO, ref int bO)
{
tO = (columns - 1) <= (tO % rowOfWalls) && (tO % rowOfWalls) < rowOfWalls ? tO : -1;
lO = 0 <= (lO % rowOfWalls) && (lO % rowOfWalls) < (columns - 1) ? lO : -1;
rO = 0 <= (rO % rowOfWalls) && (rO % rowOfWalls) < (columns - 1) ? rO : -1;
bO = (columns - 1) <= (bO % rowOfWalls) && (bO % rowOfWalls) < rowOfWalls ? bO : -1;
}
private void checkOverflowOfBottomFloors(int totalNumberOfWalls, ref int bO)
{
int wallLimit = totalNumberOfWalls - 1;
if (bO > wallLimit)
bO = -1;
}
}
}
[/CODE][/spoiler]
0

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now