Game Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesGame Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 4th, 2008, 10:36 AM
Brass_monkey Brass_monkey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 Brass_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 52 sec
Reputation Power: 0
Creating a Checkers game using NetBeans

Hello,

I'm currently studying Netbeans for an assignment, i have been given the task to create a multiplayer game that can be played across two mobiles. We have been given three options of different games we can create, i have chosen the easiest option of creating a 'Checkers' game

Unfortunately my Java skills are not to a high standard and for the past three days i've become stuck on the same problem.

I've created a board and have managed to create two different coloured checker pieces using 'sprites', my main concern at the moment is how to move on from having just one checker each to having three rows of checkers for each player. At the moment i can only think of creating multiple amounts of the checker pieces by having 24 sprites (bad practice?) and then moving on by coding the movement of the pieces. Is there another way of generating 24 pieces onto the board without having 24sprite images?

Many thanks for any feedback, if i'm in the wrong place i apologize.

James

Reply With Quote
  #2  
Old March 4th, 2008, 02:52 PM
paulscode paulscode is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 43 paulscode User rank is Sergeant (500 - 2000 Reputation Level)paulscode User rank is Sergeant (500 - 2000 Reputation Level)paulscode User rank is Sergeant (500 - 2000 Reputation Level)paulscode User rank is Sergeant (500 - 2000 Reputation Level)paulscode User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 30 m 17 sec
Reputation Power: 9
The good thing about Java, is that objects in Java behave a little like pointers in C++. For example:
Code:
obj2 = obj1;

This makes obj2 and obj1 handles to the same object (in other words, changing one will change the other).

SO what this means for you, is you can pass the handle to a single "sprite" on to multiple checkers.
For example, you could first create a Checker class:
Code:
import java.awt.image.BufferedImage;

public class Checker
{
    private BufferedImage mySprite;

    // Constructor: gets passed a handle to the sprite:
    public Checker( BufferedImage s )
    {
        // Point "mySprite" to the given handle:
        mySprite = s;
    }
}

Then, create a Checker Manager class, which loads the sprite once, then creates the individual Checkers and passes them a handle to the loaded sprite:
Code:
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.lang.System;

public class CheckerManager
{
    private BufferedImage redCheckerSprite;
    private BufferedImage blackCheckerSprite;
    private Checker[] redCheckers;
    private Checker[] blackCheckers;

    // Constructor: load the sprites, and create the checkers
    public CheckerManager()
    {
        String redCheckerFilename = "redchecker.jpg";
        String blackCheckerFilename = "blackchecker.jpg";

        // Use whatever way you want to load your sprites:
        try
        {
            redCheckerSprite = ImageIO.read( getClass().getClassLoader().getResourceAsStream( redCheckerFilename ) );
            blackCheckerSprite = ImageIO.read( getClass().getClassLoader().getResourceAsStream( blackCheckerFilename ) );
        }
        catch( IOException e )
        {
            System.err.println( "Error loading a sprite" );
        }

        // Create 12 of each type of checkers:
        redCheckers = new Checker[12];
        blackCheckers = new Checker[12];
        for( int c = 0; c < 12; c++ )
        {
            // Create the individual checkers, each gets a handle to one of the two loaded sprites:
            redCheckers[c] = new Checker( redCheckerSprite );
            blackCheckers[c] = new Checker( blackCheckerSprite );
        }
    }    
}


Hope this helps!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesGame Development > Creating a Checkers game using NetBeans


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway