Created
March 27, 2021 06:00
-
-
Save zapkub/eb8ddb2d5a715fdac5a5df0315bfff7d to your computer and use it in GitHub Desktop.
level1.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
class GameObject { | |
// Coordinate | |
public int x; | |
public int y; | |
// Dimension | |
public int width; | |
public int height; | |
} | |
class Vehicle extends GameObject { | |
public int wheels; | |
public int seats; | |
public String engineType; | |
public float speed; | |
public void Accelerate(float howfast) { | |
this.speed = howfast; | |
System.out.println("speed of this vehicle change to " + this.speed + " driving by " + this.driver.name); | |
} | |
public Player driver; | |
public void AssignDriver(Player driver) { | |
this.driver = driver; | |
} | |
} | |
class SedanCar extends Vehicle { | |
public String radio; | |
} | |
class Motorcycle extends Vehicle { | |
public int handBreak; | |
} | |
class Player extends GameObject { | |
public String name; | |
public Player(String name) { | |
this.name = name; | |
} | |
public void drive(Vehicle car) { | |
car.AssignDriver(this); | |
car.Accelerate(10.0f); | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
SedanCar sedanCar1 = new SedanCar(); | |
Motorcycle motorcycle = new Motorcycle(); | |
Player player1 = new Player("my player 1"); | |
player1.drive(sedanCar1); | |
player1.drive(motorcycle); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment