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 {
- override fun move() {
- println("Car rides")
- }
- }
- class Enemy(name: String, strength: Int, x: Double, y: Double, width: Int, hight: Int) : GameObject(x, y, width, hight),
- Movable {
- override fun move() {
- println("С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 = ""
- }
- abstract class GameObject(x: Double, y: Double, width: Int, hight: Int) {
- var x: Int = 0
- var y: Int = 0
- var width = 0
- var hight = 0
- 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))
- PrintMove(one)
- PrintMove(two)
- }
- fun PrintMove (printMove: Movable) {
- printMove.move()
- }
Advertisement
Add Comment
Please, Sign In to add comment