Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411505 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 25, 2024, 09:41:02 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Coding Challenge 1: Codeblocks
Pages: 1 2 [3]
Print
Author Topic: Coding Challenge 1: Codeblocks  (Read 24103 times)
Decipher
Guest
« Reply #40 on: July 08, 2008, 11:43:28 PM »

Thanks, I think the reason mouse handling is buggy because it takes the top left of the object as the origin for positioning the object. I guess I might be able to fit a few more bits to center the mouse origin on the object thus create a better gameplay. Trying...

[edit] Okay on a second thought, I think I'm sane enough to not dig into that code again Smiley . In fact the problem is the tile-based movement and I don't really wanna dig it up, hack it and pack it back at this time of the morning.
« Last Edit: July 08, 2008, 11:50:51 PM by Decipher » Logged
Robson
Level 0
**



View Profile WWW
« Reply #41 on: July 12, 2008, 02:11:11 AM »

Here's my game, written as an Excel macro!

Code:
Public Sub Workbook_Open() ' Countdown Numbers Game by Robson
Randomize: Dim C, B, D(5), N, A, E, F(5), G, H: Do
For A = 0 To 5: If Int(2 * Rnd) = 1 And A > 1 Then D(A) = (Int(4 * Rnd) + 1) _
 * 25 Else: D(A) = Int(10 * Rnd) + 1
Next: Erase F: G = 0: E = 0: Do: A = Int(6 * Rnd)
If F(A) = 0 Then
If E = 0 Then
B = D(A): C = D(A)
Else: Select Case Int(3 * Rnd): Case 0: B = B - D(A): C = C & " -": Case 1:
B = B + D(A): C = C & " +": Case 2: B = B * D(A): C = C & " *": End Select
C = C & " " & D(A) & ")": End If: F(A) = 1: E = E + 1
End If: If B >= 1000 Or B <= 0 Then G = 1: DoEvents
Loop Until E - 1 > Int(6 * Rnd) + 1 Or G: If B < 100 Then G = 1: DoEvents
Loop While G: For N = 0 To 5: Cells(2, N + 1) = D(N): Next: C = String(Len(C) _
- (Len(Replace(C, ")", "")) + 1), "(") & C: Cells(3, 1) = Left(C, Len(C) - 1)
Cells(1, 1) = B: Range("A3:A4").Font.ColorIndex = 2: Range("A1:F1").Merge
Cells(1, 1).Font.Bold = 1: Cells(1, 1).Font.Size = 12: Range("A3:F3").Merge
Range("A1:F3").HorizontalAlignment = -4108: Range("A2:F2").Sort Range("A2")
H = Trim(InputBox("Enter your answer as an Excel formula:", , "=(2*2)+2"))
If Left(H, 1) <> "=" Then H = "=" & H
Cells(4, 1).FormulaR1C1 = H: J = "Correct! Play" & " again?": If Val(Cells(4, _
1).Text) <> B Then J = "Failed" & "! [ " & Cells(3, 1) & " ] Play again?"
If MsgBox(J, 4) = 6 Then Workbook_Open
End Sub

It's like the numbers game on Countdown! The macro generates six random numbers and a target. Then you enter a formula that makes the target using the numbers, combined with parentheses, addition, subtraction, division and multiplication.

For example, if I'm given a target of 450 and the numbers available are {6, 2, 25, 1, 3, 2} I can enter the formula =(6+3)*25*2.

An Excel workbook with the macro is attached. I've tested it on Excel 2003. It's incredibly easy to cheat at the game, but you're only cheating yourself Roll Eyes

« Last Edit: September 14, 2020, 11:46:17 AM by Robson » Logged

Current devlog: Infinite Puzzles.
Competition entries: Wall of the Words.
Decipher
Guest
« Reply #42 on: July 12, 2008, 03:29:29 AM »

Hahaha, best use of Excel ever! The game is addictive too. Very nice.
Logged
Cymon
Level 9
****


Computer Kid


View Profile WWW
« Reply #43 on: July 12, 2008, 09:17:51 PM »

Is using only the standard libraries okay?

Here's mine. The code fits in the window allowed, but that's because it's actually designed to be <1k, which it is sans the comments. However game relies on running in a 80x24 console to format the output as it scrolls to clear the screen. It's a game that most people know as "Doctor Who", but I call Robot Escape. An expanded version that is a little less restrictive (and includes borders) was one of the first games I chose to feature on my site. But when I write that version I thought of the IOCCC and some cool entries I saw there, so I decided to give this a go.

(From the notes I typed up a while back) RobotEscape1k is played using the number key pad (be sure num-lock is on). 8 is up, 2 is down, 4 and 6 are left and right respectively, and 7, 9, 1, and 3 are diagonals. Use 5 to stand still for a turn. If you are in a safe spot and want to just wait to the end of the level use the period (.) key. 0 activates your teleport-a-matic but remember that it might teleport you into your enemies. Use it with caution.
Code:
#define q(a)(a)*(a)                        /* RobotEscape in 1K by Joe Larson*/
#define f(u,v) if((p[n]->l u 79)v(l->l u 79))p[n]->l  /* www.cymonsgames.com */
typedef struct{int l,t;}z;z*p[99];int y;k(){int a=0,b,c=0,d=0;z*e;for(;a<=y;a++
){for(b=y;a<y&&b>a;b--)if(p[b]->l<p[b-1]->l){e=p[b];p[b]=p[b-1];p[b-1]=e;}if(a)
{if(p[a]->l==p[a-1]->l)p[a]->t=p[a-1]->t=3;else do{if(!(c%79))puts("");putchar(
" O+#"[(p[a-1]->l==c)?p[a-1]->t:0]);}while(++c<p[a]->l&&c<=1817);d+=(p[a-1]->t
==2);}}return d;}main(){int n=0,m,w,e=0,d[9],i;z*l;srand(time(0));for(;n<99;n++
){if(n<9)d[n]=79*(1-n/3)+(n%3-1);p[n]=malloc(sizeof(z));p[n]->l=1976;}do{y=m=7+
++e*4;n=rand()%m;w=1817;while(m-->0){p[m]->l=w-=rand()%(w/(m+1))+1;p[m]->t=(n!=
m)+1;}l=p[n];printf("\nLevel %d",e);m=k();do{if(m){do i=getche ();while(iscntrl
(i));if(i=='.')m=0;else if(!(i-'0'))l->l=rand()%1817;else if(i>'0'&&i<='9'){n=l
->l + d[i-'1'];if(q((n%79)-(l->l%79))<2&&n<1817&&n>=0)l->l=n;}}for(n=0;n<y;n++)
if(p[n]->t==2){f(%,>)-=1;else f(%,<)+=1;f(/,>)-=79;else f(/,<)+=79;}w=k();}
while(w&&l->t==1);}while(!w);if(w)printf("Ended on %d\n",e);}

Code monkeys may be amused to discover that this uses a modified bubble sort to handle collision detection and screen drawing. Since the bubble sort insures that you can, as you're sorting, keep the next one on top, after each loop through the sort I can take a second to do the housekeeping and output.

Executable Here.

And since I'm only using the standard library I'll spruce up your expectations with an illustration:
Logged

Cymon's Games, free source code, tutorials, and a new game every week!
Follow me on twitter
muku
Level 10
*****


View Profile
« Reply #44 on: July 13, 2008, 03:42:15 AM »

Some very cool entries here. I wouldn't have the nerve to try and pack as much into one screen of code Wink Incidentally, surely there must be a program somewhere that, much like those Javascript compressors, takes a C source file and packs it up as tightly as possible? Then these codeblocks would be much more convenient to write.
Logged
Cymon
Level 9
****


Computer Kid


View Profile WWW
« Reply #45 on: July 13, 2008, 10:07:14 AM »

I forgot to mention. When I read the title of this thread I thought you meant Code::Blocks.
Logged

Cymon's Games, free source code, tutorials, and a new game every week!
Follow me on twitter
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #46 on: July 20, 2008, 01:00:31 PM »

Ok, I think we better wrap this up - nice work everyone, some really cool stuff here! :D I'll post a new one in a couple of minutes.
Logged

Pages: 1 2 [3]
Print
Jump to:  

Theme orange-lt created by panic