Jump to content

Image of the Day

#QuestOfDungeons is an old-fashioned dungeon crawler. #ScreenshotSaturday  #PS4share

https://t.co/1mztLegxeN https://t.co/DpYimg3MZb
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

AI and Interfaces + Inheritance

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Frogggg   Members   

132
Like
0Likes
Like

Posted 16 May 2012 - 08:28 PM

Upon creating the AI for the small console game that I am creating, I was a little bummed out by the thought of creating simple AI through only If statements and came across a thought. I know that if a Class inherits an Interface, the class must implement methods from that interface, sort of how abstract classes work (according to my knowledge). Seeing as classes can inherit multiple interfaces, I was wondering if I could use the interfaces to apply certain actions to all monsters from the parent Monster class. For example:

interface IAttack {}
interface IDefend {}

interface IBrain : IAttack, IDefend {} //The parent classes would generally define the characteristics of the monster in battle

class Soul {} //Parent to the Hero class as well.

class Monster : Soul, IBrain {}

class Slime : Monster {}
class Bat : Monster {}

I admit, I haven't done too much research on AI for games, but seeing as how I might be able to make something like this work, I thought I'd ask the question.

Edited by Frogggg, 16 May 2012 - 08:31 PM.


#2 Jebbs   Members   

280
Like
2Likes
Like

Posted 16 May 2012 - 09:23 PM

You're definitely on the right track, but you need to work on the implementation. Studying and practicing interfaced and inheritance is going to be the key to getting this down.
In case you were wondering about it though, here's kind of how I would put this together.
interface Creature //base class that provides methods for interaction and AI
{
	   Attack();
	   Defend();
	   Run();
}
class Monster : Creature
{
	 //this would be where you define the actual behavior
}
class Player : Creature
{
	 //likewise
}


More or less

#3 codeToad   Members   

142
Like
1Likes
Like

Posted 17 May 2012 - 08:18 PM

You are on the right track. Polymorphism can be a great way to implement special cases without having complex if-else logic.

#4 Frogggg   Members   

132
Like
0Likes
Like

Posted 18 May 2012 - 11:01 AM

It's good to know I am doing at least something right.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.