Jump to content
MakeWebGames

Basic Engine on Laravel


krballard94

Basic Engine on Laravel  

11 members have voted

  1. 1. Basic Engine on Laravel



Recommended Posts

I've been planning on starting a project using the Symfony framework for sometime, just haven't got round to it. I wonder if there are many games out there using MVC frameworks?

Mine is

[MENTION=70715]krballard94[/MENTION]

If you do this, make sure to have a basic user table at the very least, a login/register/forgot password system.

Have it so that its easy to implement mods etc, without leaving the database or file system clustered.

For me personally, objects and classes are your best friend when using MVC.

So like for me, I'd have an Item class and an ItemLoader class. The item class would have functions and variables that store information from the database. Item loader creates a bunch Items and makes them accessible when you need them, that way you can get information easily, readily and without rewriting code all over the place in your game. That can be done for anything then:

Shops - have a purchase function which accepts an Item as a parameter and it does all the checks then adds the item to your inventory and removes the money etc. Have it use the ItemLoader and Item class to list the items it sells.

In other words... I love obejcts and classes :P

Edited by Coly010
Link to comment
Share on other sites

I think it would be fun. I don't know laravel and always kind of wanted to dig into it

I've been using it quite a bit since I've come back to development and I think it is very good!

 

Decent framework, needs better error handling, me thinks!

Laravel encourages people to extend the framework to how they see fit!

 

I've been planning on starting a project using the Symfony framework for sometime, just haven't got round to it. I wonder if there are many games out there using MVC frameworks?

I believe that MVC is a good approach and we should start using it as it gives us great ability to separate our application logic.

Link to comment
Share on other sites

If you do this, make sure to have a basic user table at the very least, a login/register/forgot password system.

Have it so that its easy to implement mods etc, without leaving the database or file system clustered.

The best thing about this, is Laravel ships with this.

 

Don't gear the engine to any specific game genre, that way people can be more open minded.

I'm open to suggestions on ideas through out. I don't plan on making a specific genre because it gets way to boring. So if you have any ideas, please let me know!

To even avoid every game having the same currency, I've simply put currency and special and in the settings table I've made fields called game_currency, game_currency_sign and game_special.

I even made it so when you reference the currency column all the formatting has been done already with the help of accessors from Eloquent

$user->stats->currency // output: £1,234.56
Edited by krballard94
Link to comment
Share on other sites

I'd recommend a minor change
$user->stats->currency // output: 1234.56
$user->stats->currency_formatted // output: [symbol]1,234.56 | output: [symbol][local currency formatting system]

Eloquent has a function to output the original state before the accessor touched it.

$user->stats->currency // output: 1,234.56
$user->stats->getOriginal('currency') // output: 1234.56
Link to comment
Share on other sites

I'd recommend a minor change
$user->stats->currency // output: 1234.56
$user->stats->currency_formatted // output: [symbol]1,234.56 | output: [symbol][local currency formatting system]

Yep, cause that way you can use the un formatted version in game logic :)

Link to comment
Share on other sites

I love Laravel, I think this will be an awesome project. Excited to see what you create.

I think it's very good to! I might even create a GitHub repo after I have the basics so the source is easily accessible.. Then people will also be able to fork it and make adjustments to make the whole engine better.

Link to comment
Share on other sites

I think it's very good to! I might even create a GitHub repo after I have the basics so the source is easily accessible.. Then people will also be able to fork it and make adjustments to make the whole engine better.

If you do and I have any free time I'll try and help out!

Link to comment
Share on other sites

Decent framework, needs better error handling, me thinks!

After seeing some of your code, in which you prepend every damn class with mtg_. How on earth can you see it needs better error handling? It's fine, I assume you know about environments in which to turn on and off errors right?

Laravel is beautiful, full of everything you need to get started with a framework.

- - - Updated - - -

 

The best thing about this, is Laravel ships with this.

 

I'm open to suggestions on ideas through out. I don't plan on making a specific genre because it gets way to boring. So if you have any ideas, please let me know!

To even avoid every game having the same currency, I've simply put currency and special and in the settings table I've made fields called game_currency, game_currency_sign and game_special.

I even made it so when you reference the currency column all the formatting has been done already with the help of accessors from Eloquent

$user->stats->currency // output: £1,234.56

-1 in my opinion, you should always return the raw output. Then in blade or twig, write an extension which formats it correctly imo, you will only ever use the formatted amount a few times, but the original you would use across all mods surely that use cash?

Link to comment
Share on other sites

After seeing some of your code, in which you prepend every damn class with mtg_. How on earth can you see it needs better error handling? It's fine, I assume you know about environments in which to turn on and off errors right?

Laravel is beautiful, full of everything you need to get started with a framework.

[...]

Prepending my classes with "mtg_" is just a personal preference. It makes no difference in the usage itself.

And yes, I know about error handling. I've wrote and used many different error handlers for different projects.

I like Laravel, never stated I don't. I just don't like the stock error handling system. There's normally far too much information being displayed to repair the more common errors.

Whilst the highly-verbose output does come in handy, I find it a little overkill personally. I like clear and concise.

Link to comment
Share on other sites

Prepending my classes with "mtg_" is just a personal preference. It makes no difference in the usage itself.

And yes, I know about error handling. I've wrote and used many different error handlers for different projects.

I like Laravel, never stated I don't. I just don't like the stock error handling system. There's normally far too much information being displayed to repair the more common errors.

Whilst the highly-verbose output does come in handy, I find it a little overkill personally. I like clear and concise.

The amount of times I get hardly any information from an error and I cry a lot. You can never have too much information about an error, especially in agency life, even more so especially when it's not your code you're debugging.

Link to comment
Share on other sites

-1 in my opinion, you should always return the raw output. Then in blade or twig, write an extension which formats it correctly imo, you will only ever use the formatted amount a few times, but the original you would use across all mods surely that use cash?

I want to keep my view files as clean and with minimal logic inside them so I disagree with this (And I'm not a fan of blade, but I am using it). However, as I'm going along I'm slowing documenting what I add. Personally for me, I know that I'll be using accessors in this project so I know that the getOrignal function will return the raw output.

I've since added some methods to my logic in the model, and in my opinion it will make it easier update stats and currency in mods.

 

// Within UserStat model
public function decreaseStat($stat, $value)
{
   return $this->attributes[$stat] = parent::getOriginal($stat) - $value;
}

public function increaseStat($stat, $value)
{
   return $this->attributes[$stat] = parent::getOriginal($stat) + $value;
}

//Examples
$user->stats->increaseStat('endurance', 10.10);
$user->stats->decreaseStat('currency', .50);
$user->stats->save();

 

So now, upon displaying the information it is still formatted but overall the editting of the stats are done with ease.

Link to comment
Share on other sites

I want to keep my view files as clean and with minimal logic inside them so I disagree with this (And I'm not a fan of blade, but I am using it). However, as I'm going along I'm slowing documenting what I add. Personally for me, I know that I'll be using accessors in this project so I know that the getOrignal function will return the raw output.

I've since added some methods to my logic in the model, and in my opinion it will make it easier update stats and currency in mods.

 

// Within UserStat model
public function decreaseStat($stat, $value)
{
   return $this->attributes[$stat] = parent::getOriginal($stat) - $value;
}

public function increaseStat($stat, $value)
{
   return $this->attributes[$stat] = parent::getOriginal($stat) + $value;
}

//Examples
$user->stats->increaseStat('endurance', 10.10);
$user->stats->decreaseStat('currency', .50);
$user->stats->save();

 

So now, upon displaying the information it is still formatted but overall the editting of the stats are done with ease.

Just a suggestion, you could have it in one function and allow an extra parameter which takes the math operator, instead of having two functions. So + (add on to current value) = (overwrite value) etc. I'm sure you get what I mean, so adjustStat("currency", .50, "+");. Named adjust stat as it's neutral to what is going to happen. That might help keeping the files clean.

Link to comment
Share on other sites

Just a suggestion, you could have it in one function and allow an extra parameter which takes the math operator, instead of having two functions. So + (add on to current value) = (overwrite value) etc. I'm sure you get what I mean, so adjustStat("currency", .50, "+");. Named adjust stat as it's neutral to what is going to happen. That might help keeping the files clean.

I did actually toy with that idea just before I previously posted, but i decided against it. I believe the method names are more clear and concise.

Link to comment
Share on other sites

I did actually toy with that idea just before I previously posted, but i decided against it. I believe the method names are more clear and concise.

Fair enough, although I do wonder why you have to call the save function for it save? And why it is not called when a stat is adjusted.

Edited by Script47
Link to comment
Share on other sites

Fair enough, although I do wonder why you have to call the save function for it save? And why it is not called when a stat is adjusted.

Because that's the way Eloquent is intended to be used.

However for example, if it would update on each reference... What if you wanted to do more than one adjustment? That could be multiple queries!

So why do more, when less is good?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...