CSaveGameDateAndTime

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

CSaveGameDateAndTime

Post by belfegor »

code wrote:/***** CSaveGameDateAndTime.h *****/

#ifndef __SAVE_GAME_DATE_AND_TIME_HEADER_INCLUDED__
#define __SAVE_GAME_DATE_AND_TIME_HEADER_INCLUDED__

#include <irrlicht.h>
using namespace irr;

class CSaveGameDateAndTime
{
private:
int year, month, day, hour, minute, second;
char* monthString[12];
int getYear() { return year;}
int getMonth() { return month; }
int getDay() { return day; }
int getHour() { return hour;}
int getMinute() { return minute;}
int getSeconds() { return second;}
char* getMonthString() { return monthString[month]; }
core::stringw sDate, sTime;
public:
CSaveGameDateAndTime();
const wchar_t* getDate();
const wchar_t* getTime();
};

#endif

/***** CSaveGameDateAndTime.cpp *****/

#include <time.h>
#include "dateAndTime.h"

CSaveGameDateAndTime::CSaveGameDateAndTime()
{
time_t timeDate;
struct tm* currentDate;
timeDate = time(NULL);
currentDate = localtime(&timeDate);
year = currentDate->tm_year + 1900;
month = currentDate->tm_mon;
day = currentDate->tm_mday;
hour = currentDate->tm_hour;
minute = currentDate->tm_min;
second = currentDate->tm_sec;

monthString[0] = "Jan";
monthString[1] = "Feb";
monthString[2] = "Mar";
monthString[3] = "Apr";
monthString[4] = "May";
monthString[5] = "Jun";
monthString[6] = "Jul";
monthString[7] = "Aug";
monthString[8] = "Sep";
monthString[9] = "Oct";
monthString[10] = "Nov";
monthString[11] = "Dec";
}

const wchar_t* CSaveGameDateAndTime::getDate()
{
if(getDay() < 10)
{
sDate += "0";
sDate += getDay();
}
else
sDate += getDay();
sDate += " / ";
sDate += getMonthString();
sDate += " / ";
sDate += getYear();
sDate += " ";
return sDate.c_str();
}

const wchar_t* CSaveGameAndTime::getTime()
{
if(getHour() < 10)
{
sTime += "0";
sTime += getHour();
}
else
sTime += getHour();
sTime += " : ";
if(getMinute() < 10)
{
sTime += "0";
sTime += getMinute();
}
else
sTime += getMinute();
sTime += " : ";
if(getSeconds() < 10)
{
sTime += "0";
sTime += getSeconds();
}
else
sTime += getSeconds();
return sTime.c_str();
}

/***** main.cpp *****/

#include <irrlicht.h>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")

#include "dateAndTime.h"

const s32 winWidth = 800;
const s32 winHeight = 600;

IrrlichtDevice* device = 0;

class MyEventReceiver : public IEventReceiver
{
public:
bool OnEvent(SEvent event)
{
if(event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_ESCAPE &&
!event.KeyInput.PressedDown)
{
device->closeDevice();
}
return false;
}
};

int main()
{
MyEventReceiver receiver;
SIrrlichtCreationParameters param;
param.DriverType = video::EDT_DIRECT3D9;
param.EventReceiver = &receiver;
param.WindowSize.Width = winWidth;
param.WindowSize.Height = winHeight;
device = createDeviceEx(param);

video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* gui = device->getGUIEnvironment();

video::SColor dateColor(255, 128, 0, 0);
video::SColor timeColor(255, 0, 0, 128);

gui::IGUIFont* font = gui->getFont(
"../02_Media/06_Fonts/fontBrock_14_800x600.bmp");

CSaveGameDateAndTime dat;

gui::IGUIStaticText* dateText = gui->addStaticText(
dat.getDate(),
core::rect<s32>(20, 20, 220, 50),
false,
false
);
dateText->setOverrideFont(font);
dateText->setOverrideColor(dateColor);

gui::IGUIStaticText* timeText = gui->addStaticText(
dat.getTime(),
core::rect<s32>(20, 60, 220, 90),
false,
false
);
timeText->setOverrideFont(font);
timeText->setOverrideColor(timeColor);

while(device->run())
{
driver->beginScene(
true,
true,
video::SColor(255, 128, 128, 128));
smgr->drawAll();
gui->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Hope i didnt overseen something.
Happy new year.

edit: it has some typos now its corrected
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Tabs FTW!!!
Image
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

Sorry i didnt understand (my english isnt good enough).
What is "Tabs FTW"?
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

It means "tabs for the win", as in tabs is the prefered way to go about this. I think.. :) (After looking at your code however I still dont understand what he really means..)

Oh right tabs haha, I thot spintz was refering to the GUI element.. :oops:
Last edited by BlindSide on Wed Jan 03, 2007 3:04 pm, edited 1 time in total.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Yeah, Tabs FTW = Tabs for the win. It means we all win if your code looks like this -

Code: Select all

/***** CSaveGameDateAndTime.h *****/ 

#ifndef __SAVE_GAME_DATE_AND_TIME_HEADER_INCLUDED__ 
#define __SAVE_GAME_DATE_AND_TIME_HEADER_INCLUDED__ 

#include <irrlicht.h> 
using namespace irr; 

class CSaveGameDateAndTime 
{ 
private: 
	int year, month, day, hour, minute, second; 
	char* monthString[12]; 
	int getYear() { return year;} 
	int getMonth() { return month; } 
	int getDay() { return day; } 
	int getHour() { return hour;} 
	int getMinute() { return minute;} 
	int getSeconds() { return second;} 
	char* getMonthString() { return monthString[month]; } 
	core::stringw sDate, sTime; 
public: 
	CSaveGameDateAndTime(); 
	const wchar_t* getDate(); 
	const wchar_t* getTime(); 
}; 

#endif 

/***** CSaveGameDateAndTime.cpp *****/ 

#include <time.h> 
#include "dateAndTime.h" 

CSaveGameDateAndTime::CSaveGameDateAndTime() 
{ 
1
} 

const wchar_t* CSaveGameDateAndTime::getDate() 
{ 
if(getDay() < 10) 
{ 
sDate += "0"; 
sDate += getDay(); 
} 
else 
sDate += getDay(); 
sDate += " / "; 
sDate += getMonthString(); 
sDate += " / "; 
sDate += getYear(); 
sDate += " "; 
return sDate.c_str(); 
} 

const wchar_t* CSaveGameAndTime::getTime() 
{ 
	if(getHour() < 10) 
	{ 
		sTime += "0"; 
		sTime += getHour(); 
	} 
	else 
	{
		sTime += getHour(); 
	}
	
	sTime += " : "; 
	if(getMinute() < 10) 
	{ 
		sTime += "0"; 
		sTime += getMinute(); 
	} 
	else 
	{
		sTime += getMinute(); 
	}

	sTime += " : "; 
	if(getSeconds() < 10) 
	{ 
		sTime += "0"; 
		sTime += getSeconds(); 
	} 
	else
	{
		sTime += getSeconds(); 
	}

	return sTime.c_str(); 
} 

/***** main.cpp *****/ 

#include <irrlicht.h> 
using namespace irr; 
#pragma comment(lib, "Irrlicht.lib") 

#include "dateAndTime.h" 

const s32 winWidth = 800; 
const s32 winHeight = 600; 

IrrlichtDevice* device = 0; 

class MyEventReceiver : public IEventReceiver 
{ 
public: 
	bool OnEvent(SEvent event) 
	{ 
		if( event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key == KEY_ESCAPE && !event.KeyInput.PressedDown )  
		{ 
			device->closeDevice(); 
		} 
		return false; 
	} 
}; 

int main() 
{ 
	MyEventReceiver receiver; 
	SIrrlichtCreationParameters param; 
	param.DriverType = video::EDT_DIRECT3D9; 
	param.EventReceiver = &receiver; 
	param.WindowSize.Width = winWidth; 
	param.WindowSize.Height = winHeight; 
	device = createDeviceEx(param); 

	video::IVideoDriver* driver = device->getVideoDriver(); 
	scene::ISceneManager* smgr = device->getSceneManager(); 
	gui::IGUIEnvironment* gui = device->getGUIEnvironment(); 

	video::SColor dateColor(255, 128, 0, 0); 
	video::SColor timeColor(255, 0, 0, 128); 

	gui::IGUIFont* font = gui->getFont( "../02_Media/06_Fonts/fontBrock_14_800x600.bmp"); 

	CSaveGameDateAndTime dat; 

	gui::IGUIStaticText* dateText = gui->addStaticText( dat.getDate(), core::rect<s32>(20, 20, 220, 50), false, false ); 
	dateText->setOverrideFont(font); 
	dateText->setOverrideColor(dateColor); 

	gui::IGUIStaticText* timeText = gui->addStaticText( dat.getTime(), core::rect<s32>(20, 60, 220, 90), false, false ); 
	timeText->setOverrideFont(font); 
	timeText->setOverrideColor(timeColor); 

	while(device->run()) 
	{ 
		driver->beginScene( true, true, video::SColor(255, 128, 128, 128)); 
		smgr->drawAll(); 
		gui->drawAll(); 
		driver->endScene(); 
	} 

	device->drop(); 
	return 0; 
}
Image
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

MSVC tip: Ctrl-A to select all. Alt-F8 to format selection. Source file should now be nicely formatted, with tabs inserted.
ErUs
Posts: 165
Joined: Thu Oct 07, 2004 6:13 pm

Post by ErUs »

MSVC FTW :D
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

This isnt my computer, and it dont have compiler.
I was copying it from notepad.
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

sio2 thanks for the tip.
But what word processing program to use that will hold formating.
I think notepad cant do that.

spinz how do i get rid of the word "wrote".

Sorry i dont have internet on my PC.
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
Post Reply