This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 29 May 2007 03:06:15 pm    Post subject:

Yo! Yesterday I was really not feeling like writing my History essay, so instead I wrote my Computer Science final project! It's a Connect Four game written in Java. I had to figure out the graphics libraries myself while I was programming the game (never used graphics in Java before) so the graphics are pretty simplistic, but they work. Play the game, and let me know if you find any bugs! Sorry about the ads...it's free web hosting.

http://magicdanw.fortunecity.com/ConnectFour.html

The final project was only to make a two-player version, but if anyone knows about any simple Connect Four strategies or algorithms, let me know, because it might be fun to try my hand at a computer AI opponent!
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 29 May 2007 03:16:48 pm    Post subject:

Post the source, I don't feel like decompiling it.

[EDIT] - Too late, I got bored. Looking through it now.


Last edited by Guest on 29 May 2007 03:18:12 pm; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 29 May 2007 03:19:51 pm    Post subject:

Here's the source. It can probably be optimized a lot. If you want to know what any part of it does, just ask.

Last edited by Guest on 29 May 2007 03:21:13 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 29 May 2007 03:32:21 pm    Post subject:

When the New Game button appears, clicking on it doesn't refresh the game board, yet any actions performed after clicking on it will. When the screen doesn't clear immediately, it makes this button seem unresponsive, and clicking on it twice can make the first player drop his piece unintentionally. Also, at a tie game, I'd rather that no one gets a point instead of having both players each receive one.

Finally, I'm not really fond of the green. Yellow would be easier on the eyes. Smile
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 29 May 2007 03:40:33 pm    Post subject:

Just random suggestions as I look through the code:

Make the player names, colors, and board sizes constants.

Get rid of all the blank methods.

Could refactor it a lot. Have a board class, player class, stuff like that. Not object oriented at all. Of course it's a small program, and it works fine as it is. Just from a design perspective, it could be changed a lot.

Could use double buffering to get rid of the flickers.

[EDIT]

In reply to weregoose's bug, if you just add a repaint() as the last line of newGame(), it'll fix it.


Last edited by Guest on 29 May 2007 03:47:10 pm; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 29 May 2007 03:59:43 pm    Post subject:

Weregoose:

I added the repaint() line to newGame() (I thought I already had; guess I forgot). As for color scheme and point system, I'll ask around in my CS class, see what other people think.

JoeImp:

I didn't make the variables constants because at first I thought I might let the user choose the names, colors, etc. I could make them constants now, I guess. I can't take out the blank methods because implementing the mouse input routines requires implementing all the methods. If I take out the blank methods, it won't compile. I didn't make the game OOP because it was just a quick project and it seemed simpler to use a basic array with ints for pieces. A board class with piece objects seemed overkill. Finally, what is double buffering, and how do you do it?
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 29 May 2007 04:05:04 pm    Post subject:

Google, my friend.

Weird that you have to extend every one of those methods. Don't remember doing that in the past.
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 29 May 2007 04:08:20 pm    Post subject:

It's quite possible that there's a way to not extend every method. As I said, this is the first time I've used a GUI in Java, and I basically taught myself using the api at java.sun.com.

I'll check out double buffering. I assume you mean creating a graphics buffer and then copying that to the display in one command. That makes sense, I just have to find out how to do it in Java. I'll be back later.
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 29 May 2007 04:21:30 pm    Post subject:

I see you looking, arcane. Finally beat you to a thread Very Happy
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 29 May 2007 04:24:43 pm    Post subject:

All methods of interfaces (MouseListener and MouseMotionListener in this case) MUST be overriden.

edit: lols @ JoeImp. I'm browsing on my failtop/laptop, on which I have just installed Ubuntu with Beryl and the fancy 3D effects where a little too much causing firefox to start swapping like mad. Which is not fun on a 4200rpm harddrive. Didn't get to fix it untill after I was done with firefox and could fix+restart it. I guess Beryl without Emerald is fine too.


Last edited by Guest on 29 May 2007 04:28:21 pm; edited 1 time in total
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 29 May 2007 04:44:04 pm    Post subject:

The default beryl installation that comes with the new version of ubuntu, or did you install it yourself? I've heard the included one is really limited with not all the features, though I have yet to check it out myself. Gentoo + beryl = love.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 29 May 2007 04:53:20 pm    Post subject:

Arcane Wizard wrote:
All methods of interfaces (MouseListener and MouseMotionListener in this case) MUST be overriden.[post="105967"]<{POST_SNAPBACK}>[/post]
Technically not overriding, since an interface cannot provide code for its methods, and overriding implies there's existing code which is ignored in favor of the new code - implementing would be a better word.
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 29 May 2007 06:17:39 pm    Post subject:

Technically overriding since a method excist wether it's body is empty or not and implementing is class level.
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 29 May 2007 07:40:10 pm    Post subject:

Edit: Ignore the post below. I got it to work (not sure why it wasn't working before). I'll upload the non-flickering version momentarily.

Hi! I've looked around online, and I found out how to make a BufferedImage object, draw to it, and then copy it to the screen at the end of the paint() method. However, then everything flickers at once. I assume I'm only supposed to draw new objects to the BufferedImage (so, only draw and copy the green board once), but if I do that then they disappear after a split second. What am I supposed to do?


Last edited by Guest on 29 May 2007 07:44:16 pm; edited 1 time in total
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 29 May 2007 08:52:42 pm    Post subject:

I like the tutorials from this site:

http://www.cokeandcode.com/info/tut2d.html

See if that helps you out.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 29 May 2007 08:56:04 pm    Post subject:

Arcane Wizard wrote:
Technically overriding since a method excist wether it's body is empty or not and implementing is class level.
[post="105989"]<{POST_SNAPBACK}>[/post]


"implementing a method of an interface"
"overriding a method of an interface"

Google doesn't lie.
Back to top
Super Speler
Super Awesome Dude


Calc Guru


Joined: 28 Nov 2005
Posts: 1391

Posted: 29 May 2007 08:58:49 pm    Post subject:

Quote:
Your search - "overriding a method of an interface" - did not match any documents.


:P


Last edited by Guest on 29 May 2007 08:59:12 pm; edited 1 time in total
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 30 May 2007 06:14:32 am    Post subject:

magicdanw wrote:
Edit:  Ignore the post below.  I got it to work (not sure why it wasn't working before).  I'll upload the non-flickering version momentarily.

Hi!  I've looked around online, and I found out how to make a BufferedImage object, draw to it, and then copy it to the screen at the end of the paint() method.  However, then everything flickers at once.  I assume I'm only supposed to draw new objects to the BufferedImage (so, only draw and copy the green board once), but if I do that then they disappear after a split second.  What am I supposed to do?
[post="106013"]<{POST_SNAPBACK}>[/post]

You can post your code again if you want.

If you followed whatever example you had correctly you should:
1) create a backbuffer Image with Component's [url="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html#createImage(int,%20int)"]createImage[/url] method probably via Applet which extends Component.
2) create a Graphics object of that backbuffer Image with it's [url="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Image.html#getGraphics()"]getGraphics[/url] method.
3) do whatever drawing you want to that Graphics object.
4) copy the buffer to the screen by drawing it's Image with Graphics' [url="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20java.awt.Color,%20java.awt.image.ImageObserver)"]drawImage[/url] method.
5) repeat

Quote:
Google doesn't lie.
Hehe, yeah but let's agree that I'm right anyway.

Last edited by Guest on 30 May 2007 06:16:44 am; edited 1 time in total
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 30 May 2007 10:10:42 am    Post subject:

http://www.googlefight.com/index.php?lang=...2=Arcane+Wizard

No, google doesnt lie

:D
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 30 May 2007 01:13:04 pm    Post subject:

Yup! That's what I did. Unfortunately, today the teacher handed out the "official" assignment, and there's a few more "features" that I have to add, all of which seem to distort the game from the classic Connect Four that we all know. Oh well. I have to read up on how to use a timer object (if you take too long to make a move, it makes a random move for you). Also, every time you place a piece, it checks if that piece potentially blocked a win for the other team (so, it pretends the other person put a piece there and checks if it would have won that way), and each player keeps a counter of how many wins he/she blocked, and then at the end, two points are awarded for winning, and one point is awarded for blocking more wins before the end of the game. I intend on letting the person choose at the beginning whether they want to play the "Classic" version or the "Insane: designed for the discomfort of both the programmer and the players" version. Smile
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement