[QUOTE=Foxtrot200;42846056]Does anyone here ever organize their code with flowcharts? My grandfather was telling me that when he used to write programs for old machines (like, with punch cards and shit), he'd have to draw up flowcharts with flowchart stencils so he could keep track of what the programs did.
I ask because I'm trying to find ways to organize my workflow and make better habits, but I don't know where to start.[/QUOTE]
I think this is mostly gone now that the feedback rate with programming is much faster and refactoring tools exist.
I very rarely draw something outlining general program structure, but I never write flow diagrams, if anything I let VS generate them.
[QUOTE=Shotgunz;42845595]how do you guys do platformer physics / collision logic effectively?
my implementation involves multiple rectangles placed around the body, similar to the method discussed here ([url]http://games.greggman.com/game/programming_m_c__kids/[/url]). However I'm almost sure that this isn't the most optimal way to do this.[/QUOTE]
Unless your goal is to design a physics engine, I recommend using one that is already well-made like Box2D. Designing even a rudimentary physics engine is a huge task that ultimately distracts you from the main task of designing a game.
[QUOTE=Tamschi;42848825]I think this is mostly gone now that the feedback rate with programming is much faster and refactoring tools exist.
I very rarely draw something outlining general program structure, but I never write flow diagrams, if anything I let VS generate them.[/QUOTE]
Class diagrams are very handy to get a general outline of at least the basic classes your program will need.
[editline]13th November 2013[/editline]
[QUOTE=Foxtrot200;42846056]Does anyone here ever organize their code with flowcharts? My grandfather was telling me that when he used to write programs for old machines (like, with punch cards and shit), he'd have to draw up flowcharts with flowchart stencils so he could keep track of what the programs did.
I ask because I'm trying to find ways to organize my workflow and make better habits, but I don't know where to start.[/QUOTE]
I'm in uni so I have to work with UML etc a lot. UML has two types of diagrams which do what you're asking about. The first is very basic, it's called an activity diagram and it shows every action and every decision point in a use case (work flow) for your program. The second type is called a sequence diagram, which shows the complete timeline of every (up to a reasonable point) method call, and shows the timelines of every class used in a use case.
If you really want to draw your workflows I suggest using activity diagrams as they're much simpler and code independent, you only draw the physical use case (actor presses button, program performs check, if check is false program shows error, etc). When you're drawing sequence diagrams you're basically already writing your complete program, every method call, returns, object creation etc.
I need help on a sprite and spritesheet library in c#. I'm trying to get animations working, I'm just not very good at graphics programming. Does anyone have any tutorials or examples that I could study?
Since my sprites aren't the same sizes, I guess I'm going to have to use an XML file and read it. I'm just not sure how to implement it.
Thanks for that NoFaTe.
I'm getting an error about not being able to convert System.Threading.Tasks.Task<CityApp.City> to CityApp.City.
How can I fix this?
If you want to block the thread until the result is available, just access the [url=http://msdn.microsoft.com/en-us/library/dd321468.aspx]Result[/url]-property.
I posted a question on Stack Overflow I've been stuck on:
[url]http://stackoverflow.com/questions/19967401/c-sharp-adding-json-string-to-a-list?noredirect=1#comment29723662_19967401[/url]
If anybody wants to have a look.
I've literally made like 10 questions on it trying to find answers but I still can't get this shit working
[QUOTE=Over-Run;42856382]I posted a question on Stack Overflow I've been stuck on:
[url]http://stackoverflow.com/questions/19967401/c-sharp-adding-json-string-to-a-list?noredirect=1#comment29723662_19967401[/url]
If anybody wants to have a look.
I've literally made like 10 questions on it trying to find answers but I still can't get this shit working[/QUOTE]
Just replied with a [url=http://stackoverflow.com/a/19977103/2991893]solution[/url].
I should note again though, that having a member have an inconsistent type from a single endpoint is really bad design/practice.
So, If you are the one who created the system that serves that JSON data, I would recommend returning an array with only a single object, instead of returning the object itself.
[QUOTE=mobrockers;42798871]
Your professor probably wants you to get started on using Objects. An Object is a representation of a real world thing. For example for this assignment you would have a Class called Grade, from which you can make a Grade Object. In the Grade class you would have two methods called for example "getGradeLetter()" and "getPercentageLetter()", and a variable called "grade. In these methods you would have your business logic for calculating either the Grade letter or Grade percentage, so this part of your code, but instead of printing the result, you would set the corresponding variable to the result:
[cpp]
public String getGradeLetter() {
if (percentageGrade <= 100 && 90< percentageGrade ) {
return "A";
}
// And so on
}
[/cpp]
[cpp]
public String getGradePercentage() {
if (letterGrade.equals("A") || letterGrade.equals("a")) {
return "100% - 90%";
}
// And so on
}
[/cpp]
If this isn't enough to get you started, let us know.[/QUOTE]
Hey I got it working guys! I didn't exactally use what you guys did but the whole object stuff helped me narrow down what I should look for. Really appreciate it! I'm going to post the code and hopefully it might help someone else too (and also so people can point out things I can do to improve it and make it cleaner code overall)
First Class:
[code]
package grades.com;
import java.util.Scanner;
public class Inputs {
@SuppressWarnings("resource")
public static void main(String[] args) {
Logic grades = new Logic();
while(true) {
System.out.println("Select a Menu Item");
System.out.println("[1]Enter Percentage");
System.out.println("[2]Enter Letter Grade");
System.out.println("[3]Exit");
Scanner scan1 = new Scanner(System.in);
System.out.print("Selection: ");
int menuchoice = scan1.nextInt();
switch (menuchoice) {
case 1:
grades.gradePercentage();
break;
case 2:
grades.gradeLetter();
break;
case 3:
System.exit(1);
default:
System.out.println("Invalid Choice");
}
}
}
}
[/code]
Second Class:
[code]
//Nicholas Adams
//Project 4 Grades
//11/14/2013
//This class does the inputs after a selection has been made, and handles the logic for the the selections.
package grades.com;
import java.util.Scanner;
public class Logic
{
@SuppressWarnings("resource")
public void gradeLetter()
{
Scanner scan3 = new Scanner (System.in);
System.out.print("Enter Letter Grade: ");
String grade = scan3.next();
if (grade.equals("A") || grade.equals("a")) {
System.out.println("");
System.out.println("100% - 90%");
System.out.println("");
} if (grade.equals("B") || grade.equals("b")) {
System.out.println("");
System.out.println("89% - 80%");
System.out.println("");
} if (grade.equals("C") || grade.equals("c")) {
System.out.println("");
System.out.println("79% - 70%");
System.out.println("");
} if (grade.equals("D") || grade.equals("d")) {
System.out.println("");
System.out.println("69% - 60%");
System.out.println("");
} if (grade.equals("F") || grade.equals("f")) {
System.out.println("");
System.out.println("59% - 0%");
System.out.println("");
}
}
@SuppressWarnings("resource")
public void gradePercentage() {
System.out.print("Enter Percentage Grade: ");
Scanner scan1 = new Scanner(System.in);
int percent = scan1.nextInt();
int max = 100;
int min = -1;
if (percent<=100 && 90<percent) {
System.out.println("");
System.out.println("A");
System.out.println("");
} else if (percent<=89 && 80<=percent) {
System.out.println("");
System.out.println("B");
System.out.println("");
} else if (percent<=79 && 70<=percent) {
System.out.println("");
System.out.println("C");
System.out.println("");
} else if (percent<=69 && 60<=percent) {
System.out.println("");
System.out.println("D");
System.out.println("");
} else if (percent<=59 && 1<=percent) {
System.out.println("");
System.out.println("F");
System.out.println("");
} else if (percent>max || percent<=min) {
System.out.println("");
System.out.println("Invalid Entry");
System.out.println("");
} else if (percent == 0) {
System.out.println("");
System.out.println("F");
System.out.println("");
}
}
}
[/code]
[editline]14th November 2013[/editline]
Also can anyone explain @SuppressWarnings("resource") when dealing with the scanners? I tried looking it up online and in my book but I can't find anything about it. Eclipse just put a yellow line under my scanners and recommended suppressing them.
For some reason my content importer doesnt seem to work properly, I have a custom class for a level that is represented by a char array:
[csharp]public class Level
{
protected char [] map ;
public char[] Map { get; private set; }
public Level()
{
}
public void SetMap(char[] mapArr)
{
this.map = mapArr;
}
}[/csharp]
And this level file
[csharp]
.....
.....
.....
.....
.....
.....
.....
.....
.....
.....
.....
[/csharp]
This importer
[csharp][ContentImporter(".lev", DisplayName = "LevelImporter", DefaultProcessor = "LevelProcessor")]
public class LevelImporter : ContentImporter<TImport>
{
public override TImport Import(string filename, ContentImporterContext context)
{
System.Diagnostics.Debugger.Launch();
StreamReader reader = new StreamReader(File.OpenRead(filename));
int size = 0;
List<String> lines = new List<string>();
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (line.Length > size)
size = line.Length;
lines.Add(line);
}
char[] map = new char[size * lines.Count];
int index = 0;
foreach (String line in lines)
{
char[] lineChar = line.ToCharArray();
for (int j = 0; j < line.Length; j++)
{
map[index++] = lineChar[j];
}
}
Level level = new Level();
level.SetMap(map);
return level;
}
}[/csharp]
and call it like:
[csharp]Level l = Content.Load<Level>("level");[/csharp]
The Level instance at the end of the importer is correct but the Content.Load instance returns a null char array in the level
I'm Afk currently and need to know how big is a hello world app in java.
[QUOTE=Gubbygub;42862941]Hey I got it working guys! I didn't exactally use what you guys did but the whole object stuff helped me narrow down what I should look for. Really appreciate it! I'm going to post the code and hopefully it might help someone else too (and also so people can point out things I can do to improve it and make it cleaner code overall)
[/QUOTE]
Instead of doing
[code]
System.out.println("");
System.out.println("A");
System.out.println("");
[/code]
you can change it to
[code]
System.out.println("\nA\n");
[/code]
\n works as a "new line". So, it would work the same as the former one. Also, you don't need the "" inside of the println. You can leave it blank, and it would do the same thing.
[QUOTE=Temioman;42865547]I'm Afk currently and need to know how big is a hello world app in java.[/QUOTE]
[code]class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}[/code]
[QUOTE=Emugod;42865739]Instead of doing
[code]
System.out.println("");
System.out.println("A");
System.out.println("");
[/code]
you can change it to
[code]
System.out.println("\nA\n");
[/code]
\n works as a "new line". So, it would work the same as the former one. Also, you don't need the "" inside of the println. You can leave it blank, and it would do the same thing.[/QUOTE]
Oh wow awesome, thanks for that, makes it look 10x nicer now!
[QUOTE=Richy19;42865460]For some reason my content importer doesnt seem to work properly, I have a custom class for a level that is represented by a char array:
[csharp]public class Level
{
protected char [] map ;
public char[] Map { get; private set; }
// ... codesnip ... //
[/csharp][/QUOTE]
Any particular reason for having two distinct map arrays? It looks like the one with an upper case M is never initialized.
I'm currently creating a storage administration program for my work.
It can scan articles and attach them to a project and employee and also scan them when the employee returns the articles after the project is finished.
All this get stored in Access.
Now they asked me add some other functionalities and if i can make it accessible via web.
What shall i do, create a webservice that handles the local client on the network and web app (ASP.NET or silverlight) or shall both handle the database transactions themself with a common library?
Edit:
I'm going to use MS SQL Express in the new application.
[QUOTE=Ziks;42866476]Any particular reason for having two distinct map arrays? It looks like the one with an upper case M is never initialized.[/QUOTE]
It was just a getter/setter for the private one, turns out my issue was [url]http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.content.contentserializerattribute.aspx[/url]
Probably a simple OpenGL question, but I've been searching for hours and haven't been able to figure this out.
I'm trying to draw a series of 2D boxes onto the screen. I have an orthographic view set up, but I don't know how to set up glVertex to take 0-1024 for the width, and 0-768 for the height. At the moment if I want to draw a square, I have to use numbers between -1 and 1 for the glVertex's. Same if I want to use translatef() as well. Is there any way to change this?
Quick java question. Is there a way for a method or function or whatever to do different things based on the number of parameters? For example if I wanted to calculate the area of a shape, circles only require a radius but rectangles require a length and a width. Can I check both at once? Like GeometricShape as an overall class with a GetArea() and then a Circle/Square class that extends GeometricObject with it's own GetArea (and their own inputs)? Would that work? In my head that would work because if there's one input it would do circle area, and if there were two it would do rectangle.
[QUOTE=st_nick5;42872984]Probably a simple OpenGL question, but I've been searching for hours and haven't been able to figure this out.
I'm trying to draw a series of 2D boxes onto the screen. I have an orthographic view set up, but I don't know how to set up glVertex to take 0-1024 for the width, and 0-768 for the height. At the moment if I want to draw a square, I have to use numbers between -1 and 1 for the glVertex's. Same if I want to use translatef() as well. Is there any way to change this?[/QUOTE]
If i understood correctly, you want to draw a rectangle with custom width/height to screen.
Try adding this to your OpenGL initializing.
[code]
glViewport(0, 0, WIDTH, HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, WIDTH, HEIGHT, 0.0f, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
[/code]
where WIDTH/HEIGHT is size of your window/resolution.
Basically what it does is initialize your viewport and sets correct matrix size for 2D drawing.
[editline]15th November 2013[/editline]
[QUOTE=Zinayzen;42874513]Quick java question. Is there a way for a method or function or whatever to do different things based on the number of parameters? For example if I wanted to calculate the area of a shape, circles only require a radius but rectangles require a length and a width. Can I check both at once? Like GeometricShape as an overall class with a GetArea() and then a Circle/Square class that extends GeometricObject with it's own GetArea (and their own inputs)? Would that work? In my head that would work because if there's one input it would do circle area, and if there were two it would do rectangle.[/QUOTE]
You could overload the GetArea method in the Square class or you could define a GetArea method in the base class that has array inputs and calculate what you need based on passed array length.
[URL="http://stackoverflow.com/questions/837864/java-overloading-vs-overwriting"]This might help.[/URL]
[QUOTE=Zinayzen;42874513]Quick java question. Is there a way for a method or function or whatever to do different things based on the number of parameters? For example if I wanted to calculate the area of a shape, circles only require a radius but rectangles require a length and a width. Can I check both at once? Like GeometricShape as an overall class with a GetArea() and then a Circle/Square class that extends GeometricObject with it's own GetArea (and their own inputs)? Would that work? In my head that would work because if there's one input it would do circle area, and if there were two it would do rectangle.[/QUOTE]
Yes, methods can be overloaded as long as the parameters are different.
I would suggest not calling it getArea though, rather calculateArea or something, as get usually means there's a class variable area which is returned, instead of what you appear to be doing, which is calculate the area upon method call.
[QUOTE=cartman300;42874523]If i understood correctly, you want to draw a rectangle with custom width/height to screen.
Try adding this to your OpenGL initializing.
[code]
glViewport(0, 0, WIDTH, HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, WIDTH, HEIGHT, 0.0f, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
[/code]
where WIDTH/HEIGHT is size of your window/resolution.
Basically what it does is initialize your viewport and sets correct matrix size for 2D drawing.
[/QUOTE]
That worked. Thanks for your help.
[QUOTE=mobrockers;42874655]Yes, methods can be overloaded as long as the parameters are different.
I would suggest not calling it getArea though, rather calculateArea or something, as get usually means there's a class variable area which is returned, instead of what you appear to be doing, which is calculate the area upon method call.[/QUOTE]
Right, that's what I meant. Basically I'm writing a program and the input will be several parameters (for convenience let's just say raidus (or width/height) and a color. if they input "2 blue" it'll make a blue circle with a radius of 2, but if they put in "1 5 red" it'll make a 1x5 red rectangle. I think overloading it is the way to do it but I'm not 100% sure.
[QUOTE=Zinayzen;42875305]Right, that's what I meant. Basically I'm writing a program and the input will be several parameters (for convenience let's just say raidus (or width/height) and a color. if they input "2 blue" it'll make a blue circle with a radius of 2, but if they put in "1 5 red" it'll make a 1x5 red rectangle. I think overloading it is the way to do it but I'm not 100% sure.[/QUOTE]
Overloading will work fine for your use case.
I'm using C#.NET. I have a list of "Thing". "Player" and "Enemy" both extend "Thing". I add a Player to the list of Thing and then an Enemy to the list of Thing. I think try and use a foreach Player in list and foreach Enemy in list to call functions on each object.
This works for Player, but I'm Unable to cast object of type 'Game_Array_New.Player' to type 'Game_Array_New.Enemy'.
I don't know why this is happening, any help? I just tried putting in another Player after the first Enemy and now it's throwing the vice versa of that unhandled exception.
Should I just not be using a List with a base class to store a load of subclass objects?
[QUOTE=The DooD;42877909]I'm using C#.NET. I have a list of "Thing". "Player" and "Enemy" both extend "Thing". I add a Player to the list of Thing and then an Enemy to the list of Thing. I think try and use a foreach Player in list and foreach Enemy in list to call functions on each object.
This works for Player, but I'm Unable to cast object of type 'Game_Array_New.Player' to type 'Game_Array_New.Enemy'.
I don't know why this is happening, any help? I just tried putting in another Player after the first Enemy and now it's throwing the vice versa of that unhandled exception.
Should I just not be using a List with a base class to store a load of subclass objects?[/QUOTE]
You can not cast object of tybe B to C and vice versa if both B and C inhert from A.
Either write a function that will convert B to C (or C to B) or make B inhert from C (or C from B)
Okay I changed it so Player inherits from Enemy and realised that this doesn't work how I thought it would, thanks.
[QUOTE=cartman300;42878143]You can not cast object of tybe B to C and vice versa if both B and C inhert from A.
Either write a function that will convert B to C (or C to B) or make B inhert from C (or C from B)[/QUOTE]
I don't know if .net has instanceof (like java) , but if it does he can do a foreach on 'Thing' and then determine the correct type and cast to it, no?
[QUOTE=mobrockers;42878657]I don't know if .net has instanceof (like java) , but if it does he can do a foreach on 'Thing' and then determine the correct type and cast to it, no?[/QUOTE]
.NET has '[url=http://msdn.microsoft.com/en-us/library/scekt9xw(v=vs.110).aspx]is[/url]'.
[QUOTE=The DooD;42878191]Okay I changed it so [B]Player inherits from Enemy[/B] and realised that this doesn't work how I thought it would, thanks.[/QUOTE]
Something is seriously off with your class hierarchy or naming scheme.
Sorry, you need to Log In to post a reply to this thread.