1 Replies - 751 Views - Last Post: 16 April 2009 - 07:28 PM Rate Topic: -----

#1 A2ZOMG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-March 09

I would like suggestions for this project

Post icon  Posted 15 April 2009 - 09:39 PM

The requirements here

I am doing a slot machine project. It is close to completion and as far as I know runs perfectly, as I took great care in checking for and eliminating bugs (one thing that may arguably be a bit sloppy is the fact it is possible to get a 3 in a row of more than one type of value). However, there are a few requirements I have yet to complete, and these requirements merely are to demonstrate that I know material from previous chapters.

Requirements I would appreciate help with said:

5. At least ONE interface and THREE classes (One of which MUST be abstract), Not including the driver, which brings the total to FIVE.
9. Polymorphism must be implemented with the student designed classes.
10. Class Array List must be used in at least ONE student designed class and it MUST be traversed through AND accessed via an Iterator.
12. Animation OR Graphical Interface are optional for extra points
Probably the most important thing I need help with is a GOOD idea for an Abstract class and polymorphism. I originally made an Abstract "Slots" class, but it seems kinda silly to me at this point making more than one kind of slot machine. I wonder for example, if making an abstract class for different slot icons that could replace the number values be viable (aka switching the numbers with a string such as 'Bar'. Also, nub question. Are there any other common icons besides, '7', the 'Bar' variations, and the Cherries?).

However, I would also appreciate help understanding how to do graphics. I guess I have one simple fundamental question about Java and graphics. Like, say you have some images saved on your computer that you want to apply (probably as slot icons I'd assume). How do you apply those images onto like a Java applet? On a related note, I believe this is why I can't get this code (not related to the project) to work. Tiled Pictures Java, aka there are supposed to be pictures that are displayed getting progressively smaller from the lower right to the upper left.

Now, I'll show what code I'm using.
public interface InsertCredits
{
    public void SetCost (int cost);
    public void DepositCredits();
}

import java.util.Random;
public class ClassicSlots implements InsertCredits
{
public int slotvalues;
public int display[][];
public int wheel1[], wheel2[], wheel3[];
public int credits, maxCost, pay;
public boolean win;
public int position1, position2, position3;
Random generator = new Random();
String response = "y";
public ClassicSlots (int num, int cash)
{
slotvalues = num;
credits = cash;
if (slotvalues < 5)
slotvalues = 5;

display = new int[3][3];
for (int index = 0; index < 3; index++)
{
for (int index2 = 0; index2 < 3; index2++)
{
display[index][index2] = index2 + 1;
}
}

wheel1 = new int[slotvalues + 1]; ////the first reel is meant to have values 1,2,3,4,3,5,6 in this order
for (int index1 = 0; index1 < slotvalues; index1++)
{
wheel1[index1] = index1 + 1;
}
for (int index1 = 5; index1 < slotvalues + 1; index1++)
{
wheel1[index1] = index1;
}
wheel1[4] = 3;
wheel2 = new int[slotvalues]; ////the second reel is meant to have values 1,2,3,4,5,6 in this order
for (int index1 = 0; index1 < slotvalues; index1++)
{
wheel2[index1] = index1 + 1;
}
wheel3 = new int[slotvalues + 1]; ////the third reel is meant to have values 3,2,3,4,5,6,1 in this order
for (int index1 = 0; index1 < slotvalues + 1; index1++)
{
wheel3[index1] = index1 + 1;
}
wheel3[0] = 3;
wheel3[slotvalues] = 1;

}
public void SetCost (int cost) //// This should be set to 3 (check the driver). There is no case to handle any larger maximum cost to play.
{
maxCost = cost;
if (maxCost > 3) //// In case some sadistic person has any bright ideas, this ensures things stay simple.
maxCost = 3;
pay = cost + 1;
}

public void DepositCredits()
{
while (pay < 1 || pay > maxCost)
{
System.out.print ("\f");
if (pay < 1)
{
System.out.println("That is not a valid amount.");
}
System.out.println("You have " + credits + " credits.");
System.out.print("Insert 1-"+maxCost+" credits: ");
pay = Keyboard.readInt();

if (pay >= maxCost)
pay = maxCost;
if (pay > credits)
pay = 0;
}
}

public void Play()
{
System.out.print ("\f");
credits -= pay;
System.out.println("You have " + credits + " credits.");
for (int index = position1; index < generator.nextInt(10) + 5; index++) ////this simulates the spinning of the first reel
{
display[0][0] = wheel1[index % (slotvalues+1)];
display[1][0] = wheel1[(index + 1) % (slotvalues+1)];
display[2][0] = wheel1[(index + 2) % (slotvalues+1)];
position1 = index % (slotvalues + 1);
}
for (int index = position2; index < generator.nextInt(10) + 8; index++) ////this simulates the spinning of the second reel
{
display[0][1] = wheel2[index % slotvalues];
display[1][1] = wheel2[(index + 1) % slotvalues];
display[2][1] = wheel2[(index + 2) % slotvalues];
position2 = index % slotvalues;
}
for (int index = position3; index < generator.nextInt(10) + 11; index++) ////this simulates the spinning of the third reel
{
display[0][2] = wheel3[index % (slotvalues+1)];
display[1][2] = wheel3[(index + 1) % (slotvalues+1)];
display[2][2] = wheel3[(index + 2) % (slotvalues+1)];
position3 = index % (slotvalues + 1);
}
System.out.println (display[0][0] + "\t" + display[0][1] + "\t" + display[0][2]);
System.out.println (display[1][0] + "\t" + display[1][1] + "\t" + display[1][2]);
System.out.println (display[2][0] + "\t" + display[2][1] + "\t" + display[2][2]);

if (pay == 1) //only the middle row is checked for wins
{
if (display[1][0] == display[1][1] && display[1][0] == display[1][2])
win = true;
else
win = false;
}
if (pay == 2) //all three rows are only checked horizontally
{
if (display[0][0] == display[0][1] && display[0][0] == display[0][2]
|| display[1][0] == display[1][1] && display[1][0] == display[1][2]
|| display[2][0] == display[2][1] && display[2][0] == display[2][2])
win = true;
else
win = false;
}
if (pay == 3) //all three rows are checked horizontally and diagonally
{
if (display[0][0] == display[0][1] && display[0][0] == display[0][2]
|| display[1][0] == display[1][1] && display[1][0] == display[1][2]
|| display[2][0] == display[2][1] && display[2][0] == display[2][2]
|| display[0][0] == display[1][1] && display[0][0] == display[2][2]
|| display[2][0] == display[1][1] && display[2][0] == display[0][2]
|| display[2][0] == display[1][1] && display[2][0] == display[2][2]
&& display[2][0] == display[0][0] && display[2][0] == display[0][2])
win = true;
else
win = false;
}
if (win == true)
{
if (display[2][0] == display[1][1] && display[2][0] == display[2][2]
&& display[2][0] == display[0][0] && display[2][0] == display[0][2] && display[2][0] == 3)
{
credits += 100; // if the number '3' is found in the formation of an 'X'
System.out.println("Jackpot! You just won 100 credits and you now have " + credits + " credits!");
win = false;
}
}
if (win == true)
{
if (display[0][0] == display[0][1] && display[0][0] == display[0][2] && display[0][0] == 3
|| display[1][0] == display[1][1] && display[1][0] == display[1][2] && display[1][0] == 3
|| display[2][0] == display[2][1] && display[2][0] == display[2][2] && display[2][0] == 3
|| display[0][0] == display[1][1] && display[0][0] == display[2][2] && display[0][0] == 3
|| display[2][0] == display[1][1] && display[2][0] == display[0][2] && display[2][0] == 3)
{
credits += 50; // the number '3' is given priority over others and is worth more credits
System.out.println("Wow! You just won 50 credits and you now have " + credits + " credits!");
}
else
{
credits += 15; // this is when you get 3 in a row of anything other than a '3'
System.out.println("Nice. You won 15 credits and you now have " + credits + " credits.");
}
}
pay = 4;
if (credits >= 1)
{
System.out.print ("Play again? (enter \"y\" or \"n\" or enter your next credit deposit from 1-3) ");
response = Keyboard.readString();
if (response.equals("1") || response.equals("2") || response.equals("3"))
{ //these statements allow you to skip pressing 'y' in order to reinitiate the DepositCredits() method
if (response.equals("1"))
pay = 1;
if (response.equals("2"))
pay = 2;
if (response.equals("3"))
pay = 3;
response = "y";

if (pay > credits)
pay = 0;
}
}
else
{
System.out.print ("Ha ha ha, the house wins. Better luck next time with the one-armed bandit!");
response = "Game Over. Loop terminates here.";
}
}
public String Response() //this enables the driver to check the user's response for its 'while' loop
{
return response;
}


}

public class Driver
{
	public static void main (String args[])
    {
        String answer = "y";
        ClassicSlots Slot1 = new ClassicSlots(6, 100);        
        Slot1.SetCost(3);
        while (answer.equalsIgnoreCase("y"))
        {
        Slot1.DepositCredits();
        Slot1.Play();
        answer = Slot1.Response();
        }
    }
}

This post has been edited by A2ZOMG: 15 April 2009 - 09:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: I would like suggestions for this project

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8030
  • View blog
  • Posts: 31,176
  • Joined: 06-March 08

Re: I would like suggestions for this project

Posted 16 April 2009 - 07:28 PM

View PostA2ZOMG, on 15 Apr, 2009 - 08:39 PM, said:

I originally made an Abstract "Slots" class, but it seems kinda silly to me at this point making more than one kind of slot machine.

I actually program slot machine from 08h00 to 17h00 everyday
Yes you need an abstarct class slot to hold: number or wheels, number of displayed lines, number of winning lines

View PostA2ZOMG, on 15 Apr, 2009 - 08:39 PM, said:

Are there any other common icons besides


Yes there are usualy a slot machines has between 9 to 12 symbols (you change thse symbol by themeatic: party, western, UFO, Old Irish, ...

View PostA2ZOMG, on 15 Apr, 2009 - 08:39 PM, said:

Winning patterns:

CHERRY_MODE: from lest to Right
CHERRY_MODE_END from Rigth to Left
LINE_MODE (full line... 5 of a kind or 7 of a kind depending of number of wheels)
SCATTERED: ususaully bonus are scattered
....
And the slots machines usually have bnetween 1 to 40 lines selectable by the user. The primary nbet applies to all lines.
Very old games allow you to select a different bet for every line but this feature seems to disappear.

View PostA2ZOMG, on 15 Apr, 2009 - 08:39 PM, said:

However, I would also appreciate help understanding how to do graphics. I guess I have one simple fundamental question about Java and graphics. Like, say you have some images saved on your computer that you want to apply (probably as slot icons I'd assume). How do you apply those images onto like a Java applet?

Never tried in Java.... I doubt you will be able to spin wheels in Java fast enought, the language is not efficient enough

Hope you have fun

Question for you, if you have the time to answer:
- How many lines of C/C++ code in an average slot machine game ? let assume that Java would need 3/4 of these line

This post has been edited by pbl: 16 April 2009 - 07:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1