Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kotlin.math.pow
- import kotlin.math.sqrt
- interface Movable {
- fun move()
- }
- class Player(name: String, strength: Int, x: Double, y: Double, width: Int, hight: Int) : GameObject(x, y, width, hight),
- Movable {
- var name: String = ""
- get() = field
- set(value) {
- field = value
- }
- override fun move() {
- "Car rides"
- }
- }
- class Enemy(name: String, strength: Int, x: Double, y: Double, width: Int, hight: Int) : GameObject(x, y, width, hight),
- Movable {
- var name: String = ""
- get() = field
- set(value) {
- field = value
- }
- override fun move() {
- "Сar rides slow"
- }
- }
- class Block(nature: String, strength: Int, x: Double, y: Double, width: Int, hight: Int) : GameObject(x, y, width, hight) {
- var name: String = ""
- get() = field
- set(value) {
- field = value
- }
- }
- abstract class GameObject(x: Double, y: Double, width: Int, hight: Int) {
- private var x: Int = 0
- get() = field
- set(value) {
- field = value
- }
- private var y: Int = 0
- get() = field
- set(value) {
- field = value
- }
- private var width = 0
- get() = field
- set(value) {
- field = value
- }
- private var hight = 0
- get() = field
- set(value) {
- field = value
- }
- fun isIntersects(anotherObject: GameObject): Boolean {
- var result : Boolean = false
- if (sqrt((this.x - anotherObject.x).toDouble().pow(2) +
- (this.y - anotherObject.y).toDouble().pow(2)) == 0.0) result = true
- return result
- }
- }
- fun main() {
- var one: Player = Player("BMW", 10, 4.0, 1.0, 25, 50)
- var two: Enemy = Enemy("Honda", 30, 3.0, 5.0, 60, 55)
- var wall: Block = Block("wall",0,4.0,3.0,5,80)
- println(one.isIntersects(two))
- println(one.isIntersects(wall))
- }
Advertisement
Add Comment
Please, Sign In to add comment