I made roulette in Java.

The story of creating a roulette game in Java

Introduction

SLP KBIT Advent Calendar 2018 12/5 I made a roulette wheel using Java in a university experiment, so I will introduce it. GitHub. Originally, I was planning to introduce another artifact, but I didn't have enough time to complete it.

What is roulette?

The one in the casino. Wikipedia. There are American style and European style. In the American style, 0/00 exists in addition to the numbers 1 to 36. The European formula is only 0. This time, I chose the American style because I thought that even numbers would be more convenient for programming reasons.

language

We have confirmed the operation with Java> = 9. The reason for using Java is that it was specified in the experiment. heavy.

Original rule

Some rules have been simplified for the sake of simplicity.

Game flow

  1. Set where and how much the player bets
  2. Lottery
  3. Payment processing
  4. Bankruptcy judgment if (bankruptcy) goto 6
  5. goto 1.
  6. Finish

Original design

Roulette has special places such as SMALL and RED. This is expressed as an int type by using the following values. I want to replace it with an enum.

Numbers value
0 0
... ...
36 36
37 00
38 SMALL
39 MIDDLE
40 LARGE
41 LOW
42 HIGH
43 PARILLINEN(Even)
44 PARITON(Odd)
45 RED
46 BLACK

State during operation

  1. Bet table picTable.png

  2. Roulette disc picBall.png

Class design

Progress

InforMation

AnyNumMoney There are the following variables.

Also, as a Static variable, the place where you bet and the number of times you make money are saved separately. By treating this as an array, it is possible to handle where and how much you are betting, and you can obtain the number of the array in which the next value is stored. There is reset as a public method. This initializes all values.

Table

Use the anyNumNomeyNormailize method to normalize the AnyNumMoney array. This is because the element that saves only the place to bet or only the money and does not save the other is useless and is canceled. The public methods are as follows.

  1. void setLock(beelean) You will not be able to bet. In an actual casino, you cannot bet due to the time limit. Realize it.

  2. beelean getLock() Get if you can bet now.

  3. AnyNumMoney[] getNumMoney() Returns an array that stores where and how much you are currently betting.

Number

NumbersTable

  1. public static SpecialNumbers getSpecialNumberByAddress(int)
    Throw a value and take an enum in a special place.

Roulette

  1. int getIntRouletteValue() Take with int.

  2. String getStringRouletteValue() Take with String.

MyColor Returns the Color type.

Ball

Call the BalMain class as Windows. Since the BallMain Window operates in a separate thread, if you call it directly from the Main method, the processing of the Main method will proceed before the roulette is finished. To prevent this, use the ckDoingBallMain () method to check if the animation is currently in progress. When finished, close the Window and return to the Main method.

The following is used as the Private class. Or give me a structure.

dPoint As public, it has double type x and y variables.

iPoint Like dPoint, it has int type x and y variables.

Cast Round x and y in dPoint to make iPoint.

NumOrder Save the disc arrangement. The roulette discs are determined in the order of 5,22,34, ... with less regularity, not 0,1,2, .... The class that saves it.

  1. int search(int)
    A method that returns the number of the argument value. As an example, search (5) returns 0.

BallMain

  1. beelean getThreadStatus()
    Returns by T / F whether the thread is currently running.

Payment Performs monetary processing on users and dealers.

  1. void calcEach(Player, Player, int) Calculate by licking the place where the user bet.

  2. void clac(Player, Player, int, AnyNumMoney) The inside bet and the outside bet are judged for the place where the user bets.

Wallet Save the player's and dealer's money.

  1. Wallet(int) Set the amount of money you have.

  2. int getCache() Get your money.

  3. void Cache(int) Make a payment. The amount of the argument is deducted from the amount of money you have.

  4. boolean isInsolvency() Returns whether it is bankrupt by T / F.

Player Classes about Players and dealers.

Dealer It just inherits Player.

File list

File list


.
├── ButtonIMG/  #Image file to replace the button
├── README.md   
└── roulette/
    ├── Makefile  #Build, for execution
    ├── bin/  #Generated.class is automatically placed
    └── src/  #source file
        ├── AnyNumMoney.java
        ├── Ball.java
        ├── Dealer.java
        ├── InforMation.java
        ├── MyColor.java
        ├── Number.java
        ├── NumbersTable.java
        ├── Payment.java
        ├── Player.java
        ├── Progress.java
        ├── Roulette.java
        ├── Table.java
        ├── Wallet.java
        └── WalletTest.java

Makefile After git clone, move Directory with cd roulette. After that, execute the following for the operation you want to perform.

Both compile and run


$ make

compile


$ make class

Run


$ make exe

Delete the Class file


$ make clean

Generate jar file


$ make jar

Future outlook

Summary

We introduced the created roulette app. I will paste the running image or sometime soon. For the time being, it is possible to play, so please play. I would be very happy if you could give me any reviews.

Recommended Posts

I made roulette in Java.
I made an annotation in Java.
I made a primality test program in Java
I made a rock-paper-scissors game in Java (CLI)
I tried metaprogramming in Java
I made a simple calculation problem game in Java
I sent an email in Java
I created a PDF in Java.
I made a shopify app @java
I wrote Goldbach's theorem in java
I tried using JWT in Java
Age guessing game made in Java
Sample vending machine made in Java
[Beginner] I made a program to sell cakes in Java
I made the "Sunshine Ikezaki game" I saw on Twitter in Java.
[Java] I participated in ABC-188 of Atcorder.
I tried using Elasticsearch API in Java
I made StringUtils.isBlank
Partization in Java
I tried the new era in Java
Changes in Java 11
Rock-paper-scissors in Java
Sample vending machine made in Java (classification)
I did OpenCV camera calibration in Java
I made a new Java deployment tool
Pi in Java
[* Java *] I participated in JJUG CCC 2019 Spring
FizzBuzz in Java
I made a Diff tool for Java files
Refactored GUI tools made with Java8 + JavaFX in 2016
I want to send an email in Java.
I tried to implement deep learning in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I wrote a primality test program in Java
I made a Ruby extension library in C
rsync4j --I want to touch rsync in Java.
What I learned in Java (Part 2) What are variables?
I tried to output multiplication table in Java
I tried to create Alexa skill in Java
I wrote a prime factorization program in Java
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
Combine arrays in Java
I first touched Java ②
"Hello World" in Java
Callable Interface in Java
I first touched Java ③
Comments in Java source
Azure functions in java
I first touched Java ④
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java