Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Tidbits and Tricks for programming
Index -> Programming, Turing -> Turing Tutorials
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AsianSensation




PostPosted: Fri Nov 21, 2003 5:29 pm   Post subject: Tidbits and Tricks for programming

Here is just a collection of tricks and shortcuts you can use when programming, I knew it helped me alot. Anyways, anyone else with anything to add, please share too.

Declaring Picture Files

I constantly see alot of people declaring picture files like this:
code:
var picID: array 1..20 of int

picID (1) := Pic.FileNew ("Apple.bmp")
picID (2) := Pic.FileNew ("Orange.bmp")
picID (3) := Pic.FileNew ("Strawberry.bmp")
picID (4) := Pic.FileNew ("Starfruit.bmp")
.
.
.
picID (5) := Pic.FileNew ("Avocado.bmp")

this is really a waste of time, I mean who cares if your name your picture strawberry? It's the program that they care about, so next time you need to import tons of pictures do it like this:

first, name all your pictures "pic1.bmp", "pic2.bmp", "pic3.bmp", "pic4.bmp" ... "pic35.bmp"
then declare an array of variables:
code:
var picID :array 1..35 of int

and run a for loop like this:
code:
for i : 1 .. 35
   picID := Pic.FileNew ("pic" + intstr(i) + ".bmp")
end for


this cuts all your picture declaring into 4 lines total. Just make sure you have a textfile or some sort to tell you what each picture is.
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Fri Nov 21, 2003 6:14 pm   Post subject: (No subject)

Emulating two dimensional dynamic arrays in Turing
(there are no two dimensional dynamic arrays in turing)

assumptions:
the array begins with 0 for row and column index
the two dimensional array we are to emulate is not of an irregular shape (this is possible in languages like Java) but of a rectangular (matrix) shape.

solution:
let y be the index for the row count
let x be the index for the column count

then the location of [y][x] in a one dimensional array:
y * NumberOfColumns + x

what does this mean?

var arr : flexible array 0 .. 0 of int
new arr, 99

- notice the total # of elements (or area) in the 2 dimensional array is 100 = the # elements in the one dimensional array

now to get the [2][5] element from this array

x := 5
y := 2

value := arr(y * 10 + x)
Andy




PostPosted: Fri Nov 21, 2003 7:06 pm   Post subject: (No subject)

u lucky turing kids with lower boundry of arrays...
Dan




PostPosted: Sat Nov 22, 2003 1:27 am   Post subject: (No subject)

dodge_tomahawk wrote:
u lucky turing kids with lower boundry of arrays...


why whould you need that? i think you are refuring to how C and othe languges only have [num] for array. but if you think about it you realy dont need a starting and end point for them, since realy they are just the same but with difrent numbers for the index.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Mazer




PostPosted: Sat Nov 22, 2003 8:47 am   Post subject: (No subject)

i thought dodge meant to say upper boundary of arrays. like, in turing you could say
code:

put upper (myArray)

to see how high the array went. but in c++ you need a variable to keep track of the upper boundary, or just remember it yourself. (unless there's some other way that i was not made aware of)
rizzix




PostPosted: Sat Nov 22, 2003 2:50 pm   Post subject: (No subject)

actually there is another way Smile

sizeof(arr) / sizeof(arr[0])

that should give u the # of elements
Dan




PostPosted: Sun Nov 23, 2003 2:41 pm   Post subject: (No subject)

oOo, i thougth he was talking about the rang thing turing has.

java has the thing to tell how big an array is too.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Andy




PostPosted: Sun Nov 23, 2003 3:41 pm   Post subject: (No subject)

in turing, you can just pass an array through a function and use upper to how big it is, in c, you have to shove the size in as well, kinda annoying
rizzix




PostPosted: Sun Nov 23, 2003 7:22 pm   Post subject: (No subject)

well u'll love java then Smile

suppose u have an array of type x called element[10] <-- yea 10 elements

in java all u need to do is element.length yep thats right an array is an object in java, just ask it its size!
Tony




PostPosted: Sun Nov 23, 2003 7:32 pm   Post subject: (No subject)

everything is an object in java Very Happy java kicks ass 8)

and methods such as .toString make debugging really easy Very Happy
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
AsianSensation




PostPosted: Sun Nov 30, 2003 9:27 pm   Post subject: (No subject)

OK, this has been bugging me for too much.

Here is the best programming trick you will ever need when programming in turing.

Press either F8, F9, or F10
Andy




PostPosted: Sun Nov 30, 2003 9:44 pm   Post subject: (No subject)

F8 is awsome it tells you what to type
Cervantes




PostPosted: Fri Jan 23, 2004 2:53 pm   Post subject: (No subject)

ooh cool never new that one Razz
AsianSensation




PostPosted: Thu Mar 18, 2004 8:36 pm   Post subject: (No subject)

Another programming trick. Don't use processes unless you are really really good and can handle it. So far, only Mazer has successfully used processes for his Evasive Maneuvers game (even then he had to create a draw-check procedure to handle it).

I am seeing way too many kids with action games that are full of processes. They are inaccurate, messes up your View.Update, messes up your collision detection, especially those done with whatdotcolor, and God forbid if you based any part of your program on Time.Elapsed. Processes will ruin it all.

Try a normal loop once in a while. Guess what, the computer draws really really fast, I bet you can't tell that one thing is actually happening before another.
Flashkicks




PostPosted: Fri May 07, 2004 7:47 am   Post subject: (No subject)

Its funny that you say that-bcuz I thought of processes to be really handy so far... but i do indeed see where you are coming from.. The only thing with only sticking to procedures is that you cant really have multiple things happening at once. Hence; i always used a process. I could keep my original procedure running and have a process at the same time.. Unless I am just gonig about things All Wrong Shocked ..lol.

Process werk GREAT for keeping music in a game as well Wink
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 29 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: