Learn Java with Progate → I will explain because I made a basic game myself

What I learned in Progate's Java course

I used the paid version of Progate to clear all Java courses. Java courses are divided into two types. (As of 06/03/2018) The learning course is a course to understand the basics while having the slides explain how Java works. The dojo course uses what you learned in the learning course while looking at the minimum explanation. This is a course to make one work. These are the three features that I found amazing about Java.

--Method ... A mechanism to create an action by yourself and issue a command to a program ――Object-oriented ... A mechanism to create characters (classes) with actions in the world of programs --Inheritance ... When creating a lot of characters (classes), a mechanism to combine information and actions common to them into one

In Java, one character is called a class. I decided to make one game by myself using these three functions.

Capital theory game

The theory of capital was thought by an uncle named Marx, "In this world, servants and office workers are poor, and those who own their own company or product become rich." The idea is.

To confirm this, I created a class called Capitalist (People with products / Cap. Below) and Worker (Wor. Below), and made a game to see the movement of their second money. ..

Basic information of two people

These two are made up of four statuses (name, HP, money, product).

Capitalist person1 = new Capitalist("Capitalist", 10, 500000, 0);
Worker person2 = new Worker("Worker", 10, 500000, 0);

Both have the same initial status.

Superclass Person

In this game, we created a class called Person that Cap. And Wor. Inherit.

class Person {
	protected String name;
	 protected int health;
	 protected int money;
	 protected double product;
	 
	 Person(String name, int health, int money, double product){
	     this.name = name;
	     this.health = health;
	     this.money = money;
	     this.product = product;
	 }
	 
	 public String getName() {
	    return this.name;
	  }
	  public int getHealth() {
	    return this.health;
	  }
	  public int getMoney() {
	    return this.money;
	  }
	  public double getProduct() {
	    return this.product;
	  }
	 
	 public void printData(){
	     System.out.println("name:" + this.name);
	     System.out.println("Physical strength:" + this.health);
	     System.out.println("savings:" + this.money);
       System.out.println("Product" + this.product);
	 }
	 }

The status of the two is encapsulated so that they can only be retrieved from a class that inherits from this class. The method common to both is the PrintOut () method that prints the status.

Class Worker

class Worker extends Person{
	 public Worker(String name, int health, int money, double product){
	        super(name, health, money, product);
	    }
	    public void work(){
	     if(this.health == 5){
	         this.health += 5;
	         this.money -= 20000;
	     }else if(this.health > 0){
	        this.health-= 2;
	        this.money+= 10000;
	     }else{
	         this.health += 5;
	         this.money -= 20000;
	     }
	 }
}

Wor. Works 5 days and rests 2 days repeatedly. I work when I have HP, and when I don't have HP, I rest until I'm completely recovered. In this game "Working" means reducing HP by 2 and increasing money by 10,000. "Resting" means increasing your HP by 5 and reducing your money by 20000.

In other words, Wor. Earns about 200,000 yen in a month and spends about 160,000 yen, so You can collect about 40,000 yen every month.

Class Capitalist

class Capitalist extends Person{
	public Capitalist(String name, int health, int money, double product){
        super(name, health, money, product);
    }
 
    
    public void manage(){
     invest();
     harvest();
 }
 
 public void invest(){
      if(this.health == 5){
         this.health += 5;
         this.money -= 20000;
     }else if(this.health > 0){
        this.health -= 2;
        this.money -= 10000;
        this.product += 0.02;
     }else{
         this.health += 5;
         this.money -= 20000;
     }
 }
 public void harvest(){
     if(this.product >= 1){
         this.money += (int)product*1000;
     }
 }
}

Cap. Invests 5 days and rests 2 days repeatedly. Invest when you have HP, and rest until you're completely recovered when you don't have HP. In this game "Working" means that your HP is reduced by 2, your money is reduced by 10,000, and your product status is increased by 0.02. "Resting" means increasing your HP by 5 and reducing your money by 20000. In other words, Cap. Saves about 360,000 yen in one month.

Another Cap. Has an action called harvest. When Cap. Makes a product (product> = 1), you will receive the number of the product * 1000 yen every day. One product is finally completed in 50 days.

result

Repeating the actions of Cap. And Wor., Wor. Made more money in the first few years, but decades later Cap. Became richer.

image.png

image.png

Of course this game is not accurate. Wor. May have salary increases, bonuses, job change events, Cap. May have investment failures and investment efficiency events.

However, I found from this graph that what is said in the theory of capital is roughly correct. I'll aim to be a capitalist!

Recommended Posts

Learn Java with Progate → I will explain because I made a basic game myself
I made a rock-paper-scissors game in Java (CLI)
I made a simple calculation problem game in Java
I made a shopify app @java
I made a GUI with Swing
I made a risky die with Ruby
I made a rock-paper-scissors app with kotlin
I made a new Java deployment tool
I made a rock-paper-scissors app with android
[LINE BOT] I made a ramen BOT with Java (Maven) + Heroku + Spring Boot (1)
I made a Diff tool for Java files
I made a primality test program in Java
I tried to make Basic authentication with Java
04. I made a front end with SpringBoot + Thymeleaf
I made a mosaic art with Pokemon images
I made a LINE bot with Rails + heroku
I tried to break a block with java (1)
I made a portfolio with Ruby On Rails
[Ruby] I made a crawler with anemone and nokogiri.
I tried OCR processing a PDF file with Java
I made a Wrapper that calls KNP from Java
I made a program in Java that solves the traveling salesman problem with a genetic algorithm
I tried to create a java8 development environment with Chocolatey
I made a server side of an online card game ⑤
I made a server side of an online card game ③
I made a development environment with rails6 + docker + postgreSQL + Materialize.
I tried to modernize a Java EE application with OpenShift.
parquet-tools gives java.lang.ExceptionInInitializerError, so I made it work with java8
[Beginner] Try to make a simple RPG game with Java ①
I made a plugin to execute jextract with Gradle task
[Beginner] I made a program to sell cakes in Java
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I made a mod that instantly calls a vehicle with Minecraft
I made a server side of an online card game ④
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I made a server side of an online card game ②
I tried OCR processing a PDF file with Java part2
I made a Dockerfile to start Glassfish 5 using Oracle Java