Sign in to follow this  

AI and Interfaces + Inheritance

Recommended Posts

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 [i]If[/i] statements and came across a thought. I know that if a [i]Class[/i] inherits an [i]Interface[/i], 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 [i]Monster[/i] class. For example:

[CODE]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 {}[/CODE]

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

Share this post

Link to post
Share on other sites
jdehaan    280
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
class Monster : Creature
//this would be where you define the actual behavior
class Player : Creature

More or less

Share this post

Link to post
Share on other sites

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

Sign in to follow this