• 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.
Sign in to follow this  
Followers 0
SolarChronus

Review of my code

6 posts in this topic

I have been programming for awhile now, but the one thing that seems to always bite me is the design of my code. In college we were taught how to write code, but not how to architect it. I feel as though this .cs file, along with multiple others, could do with some code reviews. I feel like I am at a point where learning concepts and applying them isn't enough anymore and I need my code put through the ringer - something it seems professors don't really have the time to do. I've already found this place really helpful with expanding my knowledge and hope that a few people would take some time to look at it and let me know if there are better/more efficient ways to go about what I am doing!

Below is my CombatUI.cs file. This is used to manage the user interface when the player is inside a combat arena with another ship. The UI will display the players ship, target ship, damage indicators for each subsystem for each ship, and the hull/shield condition for each ship. I use events to update the indicators whenever the subsystems take damage. Everything works perfectly, however, the design feels flawed and cumbersome if I want to add new subsystems. Also checking the owner of the ship (Player vs AI) seems out of place, like there is a better way to implement it.

[CODE]
public class CombatUI
{
public Ship playerShip = null;
public Ship targetShip = null;
public GUIText player_computerCoreDamageIndicator;
public GUIText player_engineCoreDamageIndicator;
public GUIText player_weaponSystemDamageIndicator;
public GUIText player_sensorGridDamageIndicator;
public GUIText player_shieldEmittersDamageIndicator;
public GUIText player_shieldStrengthDamageIndicator;
public GUIText player_hullStrengthDamageIndicator;
public GUIText target_computerCoreDamageIndicator;
public GUIText target_engineCoreDamageIndicator;
public GUIText target_weaponSystemDamageIndicator;
public GUIText target_targetingComputerDamageIndicator;
public GUIText target_shieldEmittersDamageIndicator;
public GUIText target_shieldStrengthDamageIndicator;
public GUIText target_hullStrengthDamageIndicator;

public CombatUI(Ship playerShip, Ship targetShip)
{
this.playerShip = playerShip;
this.targetShip = targetShip;
ObserveShipSystems(playerShip);
//ObserveShipSystems(targetShip);
}

private void ObserveShipSystems(Ship ship)
{
ship.OnShieldChangeCondition += new Ship.ConditionHandler(UpdateShieldConditionIndicator);
ship.OnHullChangeCondition += new Ship.ConditionHandler(UpdateHullConditionIndicator);
ObserveShipSubsystems(ship.Subsystems);
UpdateSubsystemIndicators(ship);
UpdateShieldConditionIndicator(ship);
UpdateHullConditionIndicator(ship);
}

private void ObserveShipSubsystems(Dictionary<SubsystemType, Subsystem> subsystems)
{
foreach (KeyValuePair<SubsystemType, Subsystem> subsystem in subsystems)
{
subsystem.Value.subsystemDamaged += new Subsystem.DamageHandler(UpdateSubsystemIndicators);
}
}

private void UpdateShieldConditionIndicator(Ship ship)
{
float shieldStrength = ((ShieldEmitter)ship.Subsystems[SubsystemType.ShieldEmitter]).ShieldStrength;
player_shieldStrengthDamageIndicator.text = "SS: " + shieldStrength;
}

private void UpdateHullConditionIndicator(Ship ship)
{
float hullStrength = ((HullPlating)ship.Subsystems[SubsystemType.HullPlating]).HullStrength;
player_hullStrengthDamageIndicator.text = "HS: " + hullStrength;
}

private void UpdateSubsystemIndicators(Ship ship)
{
if (ship.Controller == Controller.Player)
{
// Prototype display for showing damage
// TODO: Change from GuiText to a GuiTexture
player_computerCoreDamageIndicator.text = "CC: " + ship.Subsystems[SubsystemType.ComputerCore].DamagePercent().ToString() + "%";
player_engineCoreDamageIndicator.text = "EC: " + ship.Subsystems[SubsystemType.EngineCore].DamagePercent().ToString() + "%";
player_weaponSystemDamageIndicator.text = "WS: " + ship.Subsystems[SubsystemType.WeaponSystem].DamagePercent().ToString() + "%";
player_shieldEmittersDamageIndicator.text = "SE: " + ship.Subsystems[SubsystemType.ShieldEmitter].DamagePercent().ToString() + "%";
player_sensorGridDamageIndicator.text = "SG: " + ship.Subsystems[SubsystemType.SensorGrid].DamagePercent().ToString() + "%";
}
else
{
target_computerCoreDamageIndicator.text = "CC: " + ship.Subsystems[SubsystemType.ComputerCore].DamagePercent().ToString() + "%";
target_engineCoreDamageIndicator.text = "EC: " + ship.Subsystems[SubsystemType.EngineCore].DamagePercent().ToString() + "%";
target_weaponSystemDamageIndicator.text = "WS: " + ship.Subsystems[SubsystemType.WeaponSystem].DamagePercent().ToString() + "%";
target_shieldEmittersDamageIndicator.text = "SE: " + ship.Subsystems[SubsystemType.ShieldEmitter].DamagePercent().ToString() + "%";
player_sensorGridDamageIndicator.text = "SG: " + ship.Subsystems[SubsystemType.SensorGrid].DamagePercent().ToString() + "%";
}
}
}
[/CODE]
0

Share this post


Link to post
Share on other sites
After reading up on MVC as you suggested I look into, I have totally re-designed the combat ui code. I grouped all the major UI elements into frames so they act as my views, created a an overarching HUD file that acts as the controller and let the combat arena scene act as the model. Combined with events I can easily change the hud elements without impacting the way the user interacts with the scene or re-tooling the model. Thanks for the suggestion!

As for those public data members, whoops, that was more a typo then wanting them exposed! I do have another question though on the best way to design out my subsystem installation code. Right now my design would work like this(pseudo-code):

[CODE]
public void InstallSubsystem(Subsystem subsystem)
{
switch(subsystem.Type)
{
case SubsystemType.EngineCore:
InstallEngineCore((EngineCore)subsystem);
break;
}
}


private void InstallEngineCore(EngineCore engineCore)
{
//Stuff associated with installing/replacing a subsystem here.
}
[/CODE]

My one gripe with this is the use of the switch statement. I wanted to encapsulate the installation functionality so that the only thing that needs to be called is InstallSubsystem(...) when a subsystem is to be installed/replaced. I could get rid of that function and expose the individual methods for installing each subsystem but felt like that is just too much exposure. I am butting up against the limits of my knowledge on this one, and wonder if the switch is really the best way to go or would there be an alternative? Edited by SolarChronus
0

Share this post


Link to post
Share on other sites
[quote name='Alpha_ProgDes' timestamp='1351730966' post='4996011']
I know there's a polymorphic solution to your switch statement issue. Unfortunately, I can't think of it right now.
[/quote]
State pattern, or strategy. Take your pick.
1

Share this post


Link to post
Share on other sites
Again, I made this mole hill of a problem into a mountain. Since I am keeping a dictionary of subsystems and using their type as unique keys, I don't need a switch switch statement or polymorphic solution. This function should cover any number of subsystems I intend on implementing on my ship, as the ship will never have duplicate subsystems.


[CODE]public void InstallSubsystem(Subsystem subsystem)
{
if (subsystems.ContainsKey(subsystem.SubsystemType))
{
RemoveSubsystem(subsystems[subsystem.SubsystemType]);
subsystems[subsystem.SubsystemType] = subsystem;
}
else
subsystems.Add(subsystem.SubsystemType, subsystem);
}[/CODE]
0

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  
Followers 0