Search Results

Search found 13 results on 1 pages for 'tietyt'.

Page 1/1 | 1 

  • How do I make good guy attacks only hit bad guys and vice versa?

    - by tieTYT
    My game has many different type of good guys and many different type of bad guys. They will all be firing projectiles at each other but I don't want any accidental collateral damage to occur for either alignment. So bad guys should not be able to hit/damage other bad guys and good guys should not be able to hit/damage other good guys. The way I'm thinking of solving this is by making it so that the Unit instance (this is javascript, btw), has an alignment property that can be either good or bad. And I'll only let collision happen if the class Attack boolean didAttackCollideWithTarget(target) return attack.source.alignment != target.alignment and collisionDetected(attack.source, target) This is pseudo-code, of course. But I'm asking this question because I get the sense that there might be a much more elegant way to design this besides adding yet another property to my Unit class.

    Read the article

  • What kind of code would Kent Beck avoid unit testing?

    - by tieTYT
    I've been watching a few of the Is TDD Dead? talks on youtube, and one of the things that surprised me is Kent Beck seems to acknowledge that there are just some kinds of programs that aren't worth unit testing. For example, right here DHH says that Kent Beck is ... very happy to say "Well, TDD doesn't fit in this case, I'm just going to bail" It's frustrating to me that Kent Beck seems to acknowledge this, but nobody asks him to elaborate on it or give concrete examples. I'd like to know the situations where Kent Beck thinks TDD is a bad fit. Nobody can read his mind or speak for him, but I'm hoping he's been transparent enough through his books/tweets/whatever for someone to be able to answer. I'm not necessarily going to take what he says as gospel, but it would be useful to know that the times I've tried TDD and it just felt impossible/useless are situations that he would have bailed on it himself. Or, if it turned out he would have tested that code it'd suggest to me that I was approaching the process very wrong. I also think it would be enlightening to understand why he would bail on such projects. My opinion on why this is not a duplicate of "When is it appropriate to not unit test?" After skimming those answers I'm not satisfied. For example, look at UncleBob's answer. He doesn't even acknowledge that such a situation exists. I really think there's value in understanding Kent Beck's position, not just a general, "What's your opinion?" type of question. After all, he's the father of TDD.

    Read the article

  • I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?

    - by tieTYT
    My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. For example, their input may describe a person but they may say their age is "apple". Correct behavior in that case is roll back the transaction and to tell the user an error occurred and they'll have to try again. There may be a requirement to report on every error we can find in the input, not just the first. In this case, I argued we should throw an exception. He disagreed, saying, "Exceptions should be exceptional: It's expected that the user may input invalid data, so this isn't an exceptional case" I didn't really know how to argue that point, because by definition of the word, he seems to be right. But, it's my understanding that this is why Exceptions were invented in the first place. It used to be you had to inspect the result to see if an error occurred. If you failed to check, bad things could happen without you noticing. Without exceptions every level of the stack needs to check the result of the methods they call and if a programmer forgets to check in one of these levels, the code could accidentally proceed and save invalid data (for example). Seems more error prone that way. Anyway, feel free to correct anything I've said here. My main question is if someone says Exceptions should be exceptional, how do I know if my case is exceptional?

    Read the article

  • How do I separate model positions from view positions in MVC?

    - by tieTYT
    Using MVC in games (as opposed to web apps) always confuses me when it comes to the view. How am I supposed to keep the model agnostic of how the view is presenting things? I always end up giving the Model a position that holds x and y but invariably, these values end up being in units of pixels and that feels wrong. I can see the advantage* of avoiding that but how am I supposed to? This idea was suggested: Don't think of it in units of pixels, think of them in arbitrary distance units that just happen map to pixels at a 1:1 ratio. Oh, the resolution is half of what it was? We are now taking the x/y coordinates at 50% value for screen display, and your spells casting range is still 300 units long, which now is 150 pixels. But those numbers conveniently work out. What do I do if the numbers divide in such a way that I get decimal places? Floating points are unsafe. I think allowing decimal places would eventually cause really weird bugs in my game. *It'd let me write the model once and write different views depending on the device.

    Read the article

  • What are some techniques I can use to refactor Object Oriented code into Functional code?

    - by tieTYT
    I've spent about 20-40 hours developing part of a game using JavaScript and HTML5 canvas. When I started I had no idea what I was doing. So it started as a proof of concept and is coming along nicely now, but it has no automated tests. The game is starting to become complex enough that it could benefit from some automated testing, but it seems tough to do because the code depends on mutating global state. I'd like to refactor the whole thing using Underscore.js, a functional programming library for JavaScript. Part of me thinks I should just start from scratch using a Functional Programming style and testing. But, I think refactoring the imperative code into declarative code might be a better learning experience and a safer way to get to my current state of functionality. Problem is, I know what I want my code to look like in the end, but I don't know how to turn my current code into it. I'm hoping some people here could give me some tips a la the Refactoring book and Working Effectively With Legacy Code. For example, as a first step I'm thinking about "banning" global state. Take every function that uses a global variable and pass it in as a parameter instead. Next step may be to "ban" mutation, and to always return a new object. Any advice would be appreciated. I've never taken OO code and refactored it into Functional code before.

    Read the article

  • Is the Entity Component System architecture object oriented by definition?

    - by tieTYT
    Is the Entity Component System architecture object oriented, by definition? It seems more procedural or functional to me. My opinion is that it doesn't prevent you from implementing it in an OO language, but it would not be idiomatic to do so in a staunchly OO way. It seems like ECS separates data (E & C) from behavior (S). As evidence: The idea is to have no game methods embedded in the entity. And: The component consists of a minimal set of data needed for a specific purpose Systems are single purpose functions that take a set of entities which have a specific component I think this is not object oriented because a big part of being object oriented is combining your data and behavior together. As evidence: In contrast, the object-oriented approach encourages the programmer to place data where it is not directly accessible by the rest of the program. Instead, the data is accessed by calling specially written functions, commonly called methods, which are bundled in with the data. ECS, on the other hand, seems to be all about separating your data from your behavior.

    Read the article

  • Foreign Key constraint violation when persisting a many-to-one class

    - by tieTYT
    I'm getting an error when trying to persist a many to one entity: Internal Exception: org.postgresql.util.PSQLException: ERROR: insert or update on table "concept" violates foreign key constraint "concept_concept_class_fk" Detail: Key (concept_class_id)=(Concept) is not present in table "concept_class". Error Code: 0 Call: INSERT INTO concept (concept_key, description, label, code, concept_class_id) VALUES (?, ?, ?, ?, ?) bind = [27, description_1, label_1, code_1, Concept] Query: InsertObjectQuery(com.mirth.results.entities.Concept[conceptKey=27]) at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:3728) at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3576) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1354) ... 101 more Here is the method that tries to persist it. I've put a comment where the line is: @Override public void loadConcept(String metaDataFilePath, String dataFilePath) throws Exception { try { ConceptClassMetaData conceptClassMetaData = (ConceptClassMetaData) ModelSerializer.getInstance().fromXML(FileUtils.readFileToString(new File(metaDataFilePath), "UTF8")); em.executeNativeQuery(conceptClassMetaData.getCreateStatement()); ConceptClassRow conceptClassRow = conceptClassMetaData.getConceptClassRow(); ConceptClass conceptClass = em.findByPrimaryKey(ConceptClass.class, conceptClassRow.getId()); if (conceptClass == null) { conceptClass = new ConceptClass(conceptClassRow.getId()); } conceptClass.setLabel(conceptClassRow.getLabel()); conceptClass.setOid(conceptClassRow.getOid()); conceptClass.setDescription(conceptClassRow.getDescription()); conceptClass = em.merge(conceptClass); DataParser dataParser = new DataParser(conceptClassMetaData, dataFilePath); for (ConceptModel conceptModel : dataParser.getConceptRows()) { ConceptFilter<Concept> filter = new ConceptFilter<Concept>(Concept.class); filter.setCode(conceptModel.getCode()); filter.setConceptClass(conceptClass.getLabel()); List<Concept> concepts = em.findAllByFilter(filter); Concept concept = new Concept(); if (concepts != null && !concepts.isEmpty()) { concept = concepts.get(0); } concept.setCode(conceptModel.getCode()); concept.setDescription(conceptModel.getDescription()); concept.setLabel(conceptModel.getLabel()); concept.setConceptClass(conceptClass); concept = em.merge(concept); //THIS LINE CAUSES THE ERROR! } } catch (Exception e) { e.printStackTrace(); throw e; } } ... Here are how the two entities are defined: @Entity @Table(name = "concept") @Inheritance(strategy=InheritanceType.JOINED) @DiscriminatorColumn(name="concept_class_id", discriminatorType=DiscriminatorType.STRING) public class Concept extends KanaEntity { @Id @Basic(optional = false) @Column(name = "concept_key") protected Integer conceptKey; @Basic(optional = false) @Column(name = "code") private String code; @Basic(optional = false) @Column(name = "label") private String label; @Column(name = "description") private String description; @JoinColumn(name = "concept_class_id", referencedColumnName = "id") @ManyToOne private ConceptClass conceptClass; ... @Entity @Table(name = "concept_class") public class ConceptClass extends KanaEntity { @Id @Basic(optional = false) @Column(name = "id") private String id; @Basic(optional = false) @Column(name = "label") private String label; @Column(name = "oid") private String oid; @Column(name = "description") private String description; .... And also, what's important is the sql that's being generated: INSERT INTO concept_class (id, oid, description, label) VALUES (?, ?, ?, ?) bind = [LOINC_TEST, 2.16.212.31.231.54, This is a meta data file for LOINC_TEST, loinc_test] INSERT INTO concept (concept_key, description, label, code, concept_class_id) VALUES (?, ?, ?, ?, ?) bind = [27, description_1, label_1, code_1, Concept] The reason this is failing is obvious: It's inserting the word Concept for the concept_class_id. It should be inserting the word LOINC_TEST. I can't figure out why it's using this word. I've used the debugger to look at the Concept and the ConceptClass instance and neither of them contain this word. I'm using eclipselink. Does anyone know why this is happening?

    Read the article

  • Foreign Key constraint when persisting a many-to-one class

    - by tieTYT
    I'm getting an error when trying to persist a many to one entity: Internal Exception: org.postgresql.util.PSQLException: ERROR: insert or update on table "concept" violates foreign key constraint "concept_concept_class_fk" Detail: Key (concept_class_id)=(Concept) is not present in table "concept_class". Error Code: 0 Call: INSERT INTO concept (concept_key, description, label, code, concept_class_id) VALUES (?, ?, ?, ?, ?) bind = [27, description_1, label_1, code_1, Concept] Query: InsertObjectQuery(com.mirth.results.entities.Concept[conceptKey=27]) at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:3728) at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3576) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1354) ... 101 more Here is the method that tries to persist it. I've put a comment where the line is: @Override public void loadConcept(String metaDataFilePath, String dataFilePath) throws Exception { try { ConceptClassMetaData conceptClassMetaData = (ConceptClassMetaData) ModelSerializer.getInstance().fromXML(FileUtils.readFileToString(new File(metaDataFilePath), "UTF8")); em.executeNativeQuery(conceptClassMetaData.getCreateStatement()); ConceptClassRow conceptClassRow = conceptClassMetaData.getConceptClassRow(); ConceptClass conceptClass = em.findByPrimaryKey(ConceptClass.class, conceptClassRow.getId()); if (conceptClass == null) { conceptClass = new ConceptClass(conceptClassRow.getId()); } conceptClass.setLabel(conceptClassRow.getLabel()); conceptClass.setOid(conceptClassRow.getOid()); conceptClass.setDescription(conceptClassRow.getDescription()); conceptClass = em.merge(conceptClass); DataParser dataParser = new DataParser(conceptClassMetaData, dataFilePath); for (ConceptModel conceptModel : dataParser.getConceptRows()) { ConceptFilter<Concept> filter = new ConceptFilter<Concept>(Concept.class); filter.setCode(conceptModel.getCode()); filter.setConceptClass(conceptClass.getLabel()); List<Concept> concepts = em.findAllByFilter(filter); Concept concept = new Concept(); if (concepts != null && !concepts.isEmpty()) { concept = concepts.get(0); } concept.setCode(conceptModel.getCode()); concept.setDescription(conceptModel.getDescription()); concept.setLabel(conceptModel.getLabel()); concept.setConceptClass(conceptClass); concept = em.merge(concept); //THIS LINE CAUSES THE ERROR! } } catch (Exception e) { e.printStackTrace(); throw e; } } ... Here are how the two entities are defined: @Entity @Table(name = "concept") @Inheritance(strategy=InheritanceType.JOINED) @DiscriminatorColumn(name="concept_class_id", discriminatorType=DiscriminatorType.STRING) public class Concept extends KanaEntity { @Id @Basic(optional = false) @Column(name = "concept_key") protected Integer conceptKey; @Basic(optional = false) @Column(name = "code") private String code; @Basic(optional = false) @Column(name = "label") private String label; @Column(name = "description") private String description; @JoinColumn(name = "concept_class_id", referencedColumnName = "id") @ManyToOne private ConceptClass conceptClass; ... @Entity @Table(name = "concept_class") public class ConceptClass extends KanaEntity { @Id @Basic(optional = false) @Column(name = "id") private String id; @Basic(optional = false) @Column(name = "label") private String label; @Column(name = "oid") private String oid; @Column(name = "description") private String description; .... And also, what's important is the sql that's being generated: INSERT INTO concept_class (id, oid, description, label) VALUES (?, ?, ?, ?) bind = [LOINC_TEST, 2.16.212.31.231.54, This is a meta data file for LOINC_TEST, loinc_test] INSERT INTO concept (concept_key, description, label, code, concept_class_id) VALUES (?, ?, ?, ?, ?) bind = [27, description_1, label_1, code_1, Concept] The reason this is failing is obvious: It's inserting the word Concept for the concept_class_id. It should be inserting the word LOINC_TEST. I can't figure out why it's using this word. I've used the debugger to look at the Concept and the ConceptClass instance and neither of them contain this word. I'm using eclipselink. Does anyone know why this is happening?

    Read the article

  • Can someone explain the ivy.xml dependency's conf attribute?

    - by tieTYT
    I can't find any thorough explanation of the ivy dependency tag's conf attribute: <dependency org="hibernate" name="hibernate" rev="3.1.3" conf="runtime, standalone -> runtime(*)"/> See that conf attribute? I can't find any explanation (that I can understand) about the right hand side of the - symbol. PLEASE keep in mind I don't know the first thing about maven so please explain this attribute with that consideration. Yes, I've already looked at this: http://ant.apache.org/ivy/history/latest-release/ivyfile/dependency.html Thanks, Dan

    Read the article

  • Can I use JPA/EJB3 on a table that was created at runtime?

    - by tieTYT
    This is weird and probably not possible but I'll ask anyway. I'm making this app that reads in a meta file and creates some tables then populates them with data. I was wondering if I could somehow use JPA to populate those tables. Obviously, there's no way I could have an entity with annotations on it since the table didn't exist at compile time. But perhaps JPA or the entity manager has a way to load data into a nameless table? If possible, I'd expect a method like entityManager.update("myTableName", hashMapOfColumnNamesAndColumnDataValues);

    Read the article

  • In Intellij, how can I get a List on the left hand side when I extract a variable that's an ArrayList?

    - by tieTYT
    As an example, if I extract a variable from this: return new ArrayList<CrudTestData<Foo>>(); It will turn the code into this: ArrayList<CrudTestData<Foo>> list = new ArrayList<CrudTestData<Foo>>(); return list; How can I automatically get a list on the left hand side like this? List<CrudTestData<Foo>> list = new ArrayList<CrudTestData<Foo>>(); return list; Theoretically, Intellij should know to use a List instead of a Collection because the method returns a List.

    Read the article

1