Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Project exclude paths
/.gradle/
/.gradle/
/.idea/
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions src/main/kotlin/builder/Builder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package builder


data class Person(
val name: String,
val email: String,
val phone: Int,
val address: String
)

class PersonBuilder {
private var name: String = "default name"
private var email: String = "default name"
private var phone: Int = 0
private var address: String = "default address"

fun setName(value: String): PersonBuilder {
name = value
return this
}

fun setEmail(value: String): PersonBuilder {
email = value
return this
}

fun setPhone(value: Int): PersonBuilder {
phone = value
return this
}

fun setAddress(value: String): PersonBuilder {
address = value
return this
}

fun build(): Person {
return Person(name, email, phone, address)
}


}

fun main() {
val somePerson =
PersonBuilder().setName("some name").setEmail("some email").setPhone(1111111).setAddress("some address").build()
println(somePerson)
val defaultPerson = PersonBuilder().build()
println(defaultPerson)


}
29 changes: 29 additions & 0 deletions src/main/kotlin/command/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package command
interface Command{
fun execute()
}

class ConcreteCommand(private val receiver: Receiver) : Command{
override fun execute() {
receiver.action()
}
}

class Receiver(){
fun action(){
println("получатель выполняет действия")
}
}

class Initializer(private val command: Command){
fun executeCommand(){
command.execute()
}
}

fun main() {
val receiver = Receiver()
val concreteCommand = ConcreteCommand(receiver)
val initializer = Initializer(concreteCommand)
initializer.executeCommand()
}
58 changes: 58 additions & 0 deletions src/main/kotlin/decorator/Decorator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package decorator

abstract class Lesson {
abstract val title: String
abstract val description: String

abstract fun learn()

}

class EnglishLesson(override val title: String, override val description: String) : Lesson() {
override fun learn() {
println("изучение английского: $title - $description")
}
}

class SpanishLesson(override val title: String, override val description: String) : Lesson() {
override fun learn() {
println("изучение испанского: $title - $description")
}
}

class VocabularyLessonDecorator(private val lesson: Lesson) : Lesson() {
override val description: String
get() = lesson.description
override val title: String
get() = lesson.title

override fun learn() {
lesson.learn()
println("новые слова")
}
}

class GrammarLessonDecorator(private val lesson: Lesson) : Lesson() {
override val description: String
get() = lesson.description
override val title: String
get() = lesson.title

override fun learn() {
lesson.learn()
println("новая грамматика")
}
}


fun main() {
val spanish = SpanishLesson("урок 1", "введение в испанский")

val vocabularySpanish = VocabularyLessonDecorator(spanish)
vocabularySpanish.learn()
val vocabularyAndGrammarSpanish = GrammarLessonDecorator(vocabularySpanish)

vocabularyAndGrammarSpanish.learn()


}
59 changes: 59 additions & 0 deletions src/main/kotlin/decorator/SecondDecorator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package decorator

interface Pizza {
val price: Int

fun getTotalPrice(): Int
fun getDescription(): String
}

class BasicPizza : Pizza {
override val price: Int = 100

override fun getTotalPrice(): Int = price
override fun getDescription(): String = "Базовая пицца"
}

abstract class PizzaDecorator(protected val pizza: Pizza) : Pizza {
abstract override val price: Int
override fun getTotalPrice(): Int = price + pizza.getTotalPrice()
}

class Meat(pizza: Pizza) : PizzaDecorator(pizza){
override val price: Int = 50
override fun getDescription(): String = "${pizza.getDescription()} с мясом"
}

class Cheese(pizza: Pizza) : PizzaDecorator(pizza){
override val price: Int = 100
override fun getDescription(): String = "${pizza.getDescription()} с сыром"
}

class Vegetables(pizza: Pizza) : PizzaDecorator(pizza){
override val price: Int = 150
override fun getDescription(): String = "${pizza.getDescription()} с овощами"
override fun getTotalPrice(): Int = price + this.pizza.getTotalPrice()
}

fun main(){

val badPizza = BasicPizza()
println("${badPizza.getDescription()} ${badPizza.getTotalPrice()}")

val normalPizza = Meat(badPizza)
println("${normalPizza.getDescription()} ${normalPizza.getTotalPrice()}")

val goodPizza = Cheese(normalPizza)
println("${goodPizza.getDescription()} ${goodPizza.getTotalPrice()}")

val awesomePizza = Vegetables(goodPizza)
println("${awesomePizza.getDescription()} ${awesomePizza.getTotalPrice()}")

val allIngredients = Meat(Cheese(Vegetables(pizza = BasicPizza())))
println("${allIngredients.getDescription()} ${allIngredients.getTotalPrice()}")

val veganPizza = Cheese(Vegetables(pizza = BasicPizza()))
println("${veganPizza.getDescription()} ${veganPizza.getTotalPrice()}")


}
29 changes: 29 additions & 0 deletions src/main/kotlin/singleton/Singleton.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package singleton

class GameConfig private constructor(){
private var heroPull : Int = 124;
private var latency: Int = 500;
private var waitingPlayers: Int = 0;
private var matchName: String = "default"

companion object {
val instance : GameConfig by lazy { GameConfig() }
}

fun addPlayers(int: Int){
this.waitingPlayers +=int
}
fun printConfig(){
println("$matchName $heroPull $latency $waitingPlayers")
}
}

fun main(){
val config = GameConfig.instance
val anotherConfig = GameConfig.instance
anotherConfig.addPlayers(23)
config.addPlayers(23)

config.printConfig()

}