• 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.

Archived

This topic is now archived and is closed to further replies.

skreuzer

Reading a File

5 posts in this topic

Hello All, I am sure this is a very simple question, but it has been quite some time since I had to open a file and read it. Anyway, I have a file called levels.ini and it looks like this Level1 128 150 1000 1001 3600 Level2 128 150 1000 1001 7200 Level3 128 150 1000 1001 10800 I want to be able to pass "Level1" to a function that reads the file until it finds "Level1" and then reads the numbers and game grid into variables. Can anyone point me to any reference regarding this. SK skreuzer@mac.com
0

Share this post


Link to post
Share on other sites
Well, you can use the very basics of FILE IO, or you can make it fancy, but to keep it simple you can do it like the following:

FILE * fpInput;
fpInput = fopen ("", "w");

fscanf (fpInput, "<format specifier>", var1, var2);

fclose (fpInput);

The format specifier in this case will change depending on what part of the file you want to read. To handle the first portion of the file you will probably want to have a character, lets say char sInput[30], that takes character data. for int''s, let say iInput.

fscanf (fpInput, "%[^\n]\n", sInput);
fscanf (fpInput, "%d\n", iInput);

the \n at the end will tell scanf to "skip" past that on each line so it may proceed to the next and starts right at the beginning of the next line.

Hopefully this helps you out and the little examples I posted actually work



Cray
0

Share this post


Link to post
Share on other sites
The above poster is on the right track. However, the "Level" name poses a minor problem. First off there is no way to determine when you''ll see "Level" unless your specificaly looking for the whole word. I highly suggest using a special character like ! before you define the word "Level" so it would look like this.. "!Level 1" Then you can search through the file for the specific special character that your using rather than searching for a whole word. This also allows you to determine how many levels you have just by counting the number of special characters in the file...
0

Share this post


Link to post
Share on other sites
Thank you all for your Help. With the above advice, this is what I came up with. It is part of the CLevelManager Class and it works like a charm
  
void CLevelManager::LoadLevel(int BoardNumber)
{
char GridBuffer = '0', LevelString[10];
sprintf(LevelString, "Level%d", BoardNumber);
while(!feof(LevelFile))
{
fscanf(LevelFile, "%s", Buffer);
if(strcmp(Buffer, LevelString) == 0)
{
fscanf(LevelFile, "%d\n", &BackgroundPatternID);
fscanf(LevelFile, "%d\n", &FirstBorderID);
fscanf(LevelFile, "%d\n", &FixedBlockID);
fscanf(LevelFile, "%d\n", &DestructibleBlockID);
fscanf(LevelFile, "%d\n", &GameTime);
}
}
}


Edited by - skreuzer on January 25, 2002 12:53:16 PM
0

Share this post


Link to post
Share on other sites
There''s actually a bunch of Windows functions for dealing with .ini files. You''d simply need to rename each of your sections (from "Level1" to "[Level1]", etc) and place an identifier before each of your values. Then you''d use Get/WritePrivateProfileString(). Look it up in MSDN.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
0

Share this post


Link to post
Share on other sites
Since you are using C++, you could use file streams.

  
#include <fstream.h>
#include <iostream.h>

int main() {
char buf[100];
bool found=false;
int values[5];
fstream in("levelfile.txt");

while(in.getline(buf,100)) {
if(strcmp(buf,"Level1")) {
found=true;
break;
}
}

if(found) {
for(int i=0;i<5;i++) {
in >> values[i];
}
for(int i=0;i<5;i++) {
cout << values[i] << endl;
}
}
return 0;
}



---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
0

Share this post


Link to post
Share on other sites