loop y 5
platform at 100, 100 * y
ladder at 100 + rnd 100, 100 * y
end
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
There are three kinds of actuaries: those who can count, and those who can't.
SCJP, SCWCD, SCJD
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:I normally have just one huge class and stuff everything into it.
I need some sort of structure that holds various types ie integers, some strings and a few boolean values. I just want to pass the program "string" to the compiler bit and get an array of these structures back.
GameObject: Unfortunately the program can define new objects at any time so a platform is defined as
[code=java]define platform
image brick.png
tile 10 by 1
action stand
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I know, hence my questionWinston Gutkowski wrote:
Mich Robinson wrote:I normally have just one huge class and stuff everything into it.
Well that's a really bad idea for a start.
I've created quite a few languages and the compilers or interpreters to go with them. They're not as difficult as you think and if you're the one designing the language then you can make the language easier to process.Winston Gutkowski wrote:for something as complex as this, if you end up with less than twenty classes, I'll be surprised. You're creating a language, man.
The user's program is just a long string of commands. The compiler parses this string and currently turns it into a set of parallel arrays that mostly contain integers (but there are some string arrays as well). Another aspect of the program uses these arrays to draw the users game on screen and allow the user to play it. I'd like to kow if I can combine these arrays into a class and then have a method that can pass back this "structure" to the calling program.Winston Gutkowski wrote:
I need some sort of structure that holds various types ie integers, some strings and a few boolean values. I just want to pass the program "string" to the compiler bit and get an array of these structures back.
Sorry, but that's all very "woolly". What exactly do you need?
There were a class of games called platform games - here's an example of one called Donkey Kong.Winston Gutkowski wrote:What is a "platform"?
My program allows them to write the game and then allow their mates to play it as well. The aim is to give kids a way of creating games simply and hopefully getting them interested in programming. My younger son (13) is quite capable of knocking out games using the language.Winston Gutkowski wrote:Imagine you had to explain it to one of the kids who is hopefully going to play your game.
I'm at a stage where most of this works but I'm trying to change things so I can make the Java program more understandable by other Java programmers. The idea being that I might share the project with others. It's difficult knowing where to split the program into classes. Obviously I'd like to do this if it makes the program better but my first attempt at splitting the compileGame class out of the main program is proving difficult. I'm currently trying to split the program into the following classes:Winston Gutkowski wrote:You may find the WhatNotHow (←click) page useful to read
I have no problems designing the language or writing the "compiler". In fact it works fine on my PC. My issue is just how to pass the various arrays back to the calling program and how to split things into classes. This part is proving quite difficult for me to understandWinston Gutkowski wrote:About the only other thing I can say is that this is NOT a simple problem.
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:I'm currently trying to split the program into the following classes:
compileGame editGame playGame
Mich Robinson wrote:My issue is just how to pass the various arrays back to the calling program and how to split things into classes. This part is proving quite difficult for me to understand
Oddly enough, that sounds exactly like the way the program was organised before ;)Stuart A. Burkett wrote:That sounds wrong. I would think it is more likely you want a class called Game that contains all the information about the game and that class should have methods called edit, compile and play.*
It's funny, no matter how I read your comment it just comes across as a little bit insulting. I was going to respond with a simple 3 letter acronym but instead I'll suggest you have a look at a few of the apps I have in my signature and let you decide for yourself whether you've done anything better.Stuart A. Burkett wrote:In that case you should stop programming now and do some study on object oriented design/programming. Spending some time on that now will make you are a far better programmer in the long term (assuming you're using an object oriented language) and will also save you time in the future when you have to maintain the code you've written
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
There are three kinds of actuaries: those who can count, and those who can't.
This is my attempt. Please correct me where I've made mistakes.Piet Souris wrote:to make the language specification better readable, I suggest to put the key-words between angled brackets,
to make the meaning more clear. Are you familiar with the Backus--Naur notation?
Both are just entries in the array "structure". They would both have different images associated with them while the ladder is likely to be tiled vertically and the action associated with it would be "climb". The ball might have the action "die" which would mean the player might want to keep out the way of any balls. So a definition of ladder and a bouncing killer ball might be:Piet Souris wrote:If you have defined a platform and say a ladder, or a ball, or whatever, what are the
similarities and what are the specific differences between these?
Everything that appears in the game are just entries in the arrays. The user can create new definitions like the ladder above but this is still an entry in the arrays. There are no new classes created as that would mean compiling the script into a java program and then compiling that - which is quite a bit more complex. In fact some of the "keywords" that appear in the BN above are actually only defined in an initial script that's run before the users script iePiet Souris wrote:Can you define different classes with different properties, or are they only treated different in the game code?
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:It's funny, no matter how I read your comment it just comes across as a little bit insulting.
Mich Robinson wrote:I'm at a stage where most of this works but I'm trying to change things so I can make the Java program more understandable by other Java programmers.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
OKStuart A. Burkett wrote:
Mich Robinson wrote:It's funny, no matter how I read your comment it just comes across as a little bit insulting.
It wasn't meant to be
Perhaps you can just pretend that I fully agree with you and I'll pretend that you're fully experienced with building compilers ;)Winston Gutkowski wrote:What you've written..
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:Perhaps you can just pretend that I fully agree with you and I'll pretend that you're fully experienced with building compilers ;)
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:I am after help but being told to totally completely rewrite your (working) code is not helpful.
Doing this takes far too much time and will just introduce bugs.
The end result may be easier for you to read but it will be more difficult for me.
Being told I should stop programming until I've learnt a little more also gets pretty short thrift from me.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
It takes time to re-code. All coding introduces bugs. The end benefit of your proposed re-write offers no discernible functional improvement over what I have and actually makes it worse for me personally to maintain. My point is put far better in this piece by Joel Spolsky.Winston Gutkowski wrote:
Mich Robinson wrote:Doing this takes far too much time and will just introduce bugs.
Why should it? If you'd actually read my previous post instead of reacting to it, you'll notice that I said that you probably CAN re-use some of your code - maybe even quite a bit.
Nearly all programs can do with improvement but not all need a complete rewrite just to keep some architecture astronaut happy.However, I don't understand your reaction, since it was you who seems to understand that what you've got is not where you want to be.
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:Can someone close this thread?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:very disappointing, the outcome. I was looking forward to gain some experience in a topic I am totally unfamiliar with. Hoping to extract the characteristics of all objects appearing in a game and how that could result in nice classes, with data and methods, and how that
would relate to compilers.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I couldn't see where it states this - I tried clicking the FAQ a couple of times but it crashed each time. My impression was simply that the idea was to vilify anyone that doesn't code in the same manner as you.Winston Gutkowski wrote:This is a Java forum, designed to help people (especially beginners) to write good Java code.
I'll be the 1st to admit that I'm not an OO programmer. I tend to identify data structures first and then program around those. It works for me and I've managed to create a fair number of interesting applications (though most aren't Java based). I don't know if this approach has a name and nor do I try to force this methodology on anyone else. It simply works for me.Winston Gutkowski wrote:Object-Orientation
Glad you liked it. He wrote a very influential book called Joel on Software which is well worth reading. The important bit in that particular article was "the single worst strategic mistake that any software company can make: They decided to rewrite the code from scratch". Which I believe is what you were suggesting.Winston Gutkowski wrote:Loved the Spolsky article so much I've bookmarked it; but I think you've missed the whole point of it
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
The code is already written, it's currently in Java and works fine. I have better things to do than to rewrite it all in C.Campbell Ritchie wrote:I haven't followed this whole discussion, but I think you are trying to write procedural code. Porting the code to Java would entail a complete redesign, so to follow Spolsky's suggestion, I suggest you consider keeping the code in a procedural language, e.g. C.
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
If it ain't broke, don't fix it.Mich Robinson wrote: . . . The code is already written, it's currently in Java and works fine. . . .
I'm a bit confused by your post.Campbell Ritchie wrote:
If it ain't broke, don't fix it.Mich Robinson wrote: . . . The code is already written, it's currently in Java and works fine. . . .
I suggest you try a combination of JFlex and CUP for a compiler. Or ANTLR.
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:I couldn't see where it states this - I tried clicking the FAQ a couple of times but it crashed each time. My impression was simply that the idea was to vilify anyone that doesn't code in the same manner as you.
I'll be the 1st to admit that I'm not an OO programmer. I tend to identify data structures first and then program around those. It works for me and I've managed to create a fair number of interesting applications (though most aren't Java based). I don't know if this approach has a name and nor do I try to force this methodology on anyone else. It simply works for me.
I find it difficult picturing classes for a compiler - the suggestions for classes so far are just items or types of things that a user "could" create in their program but they're certainly not understood by the language as it stands.
my suspicion is that this is easier to do by putting the definitions into data which by it's very nature is extensible.
He wrote a very influential book called Joel on Software which is well worth reading. The important bit in that particular article was "the single worst strategic mistake that any software company can make: They decided to rewrite the code from scratch". Which I believe is what you were suggesting.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:I'd certainly like to read your essay but please don't expect any major sea changes from me - can you PM it?
Can you suggest any classes that might go into such my (or any) compiler? I just wondered please keep in mind that the users program isn't being compiled into java and that the concept of platforms, ladders etc is just something that I created in order to illustrate the language (it's not a part of the language per se).
Can you just (very) briefly point out how the compiler would be better with classes as well? You mention that some compilers have been written in an OO fashion but I'm guessing that if OO gave a major advantage to their construction then wouldn't all compilers would be done that way?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Mich Robinson wrote:I'd certainly like to read your essay but please don't expect any major sea changes from me - can you PM it?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Mich Robinson wrote:Interesting reading. You asked for comments so here's a few that came to mind while I was reading it :
Your code illustrates the compactness of the overall design but doesn't have the actual logic and rules - surely this bit is quite important.
How do you decide what rules can be applied to a given file - I assume by file type but I don't see this logic either.
Would all the rules be repeated for languages that share common quoting conventions etc?
I didn't think you could nest comments in Java - does you system cope with that?
Could you supply the original awk program for us to compare against?
I'm reasonably competent with awk and must admit I'd of used it for this problem - why didn't you?
It seems like a fairly interesting problem - was it done for work or personal interest?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here