Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit #210

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

137 changes: 134 additions & 3 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,134 @@
fun main(args: Array<String>) {
println("Hello World!")
}
data class Note(val title: String, val content: String)

class Archive(val name: String) {
val notes = mutableListOf<Note>()
}

class NoteManager {
val archives = mutableListOf<Archive>()

fun addArchive(archive: Archive) {
archives.add(archive)
}
}


fun main() {
val noteManager = NoteManager()
val mainMenu = MainMenu(noteManager)
mainMenu.show()
}

class MainMenu(private val noteManager: NoteManager) {
fun show() {
while (true) {
println("Главное меню:")
println("1. Выбор архива")
println("2. Создание архива")
println("0. Выход")

when (readLine()) {
"1" -> {
val archiveMenu = ArchiveMenu(noteManager)
archiveMenu.show()
}
"2" -> {
val createArchiveMenu = CreateArchiveMenu(noteManager)
createArchiveMenu.show()
}
"0" -> return
else -> println("Неверный выбор. Попробуйте снова.")
}
}
}
}

class ArchiveMenu(private val noteManager: NoteManager) {
fun show() {
while (true) {
println("Выбор архива:")
noteManager.archives.forEachIndexed { index, archive ->
println("${index + 1}. ${archive.name}")
}
println("0. Назад")

when (readLine()) {
"0" -> return
else -> {
val index = readLine()?.toIntOrNull()
if (index != null && index in 1..noteManager.archives.size) {
val noteMenu = NoteMenu(noteManager.archives[index - 1])
noteMenu.show()
} else {
println("Неверный выбор. Попробуйте снова.")
}
}
}
}
}
}

class CreateArchiveMenu(private val noteManager: NoteManager) {
fun show() {
println("Создание архива:")
print("Введите название архива: ")
val name = readLine() ?: ""
noteManager.addArchive(Archive(name))
println("Архив создан! Нажмите любую клавишу для продолжения...")
readLine()
}
}

class NoteMenu(private val archive: Archive) {
fun show() {
while (true) {
println("Заметки в архиве '${archive.name}':")
archive.notes.forEachIndexed { index, note ->
println("${index + 1}. ${note.title}")
}
println("0. Назад")
println("2. Создать заметку")

when (readLine()) {
"0" -> return
"2" -> {
val createNoteMenu = CreateNoteMenu(archive)
createNoteMenu.show()
}
else -> {
val index = readLine()?.toIntOrNull()
if (index != null && index in 1..archive.notes.size) {
val noteDisplayMenu = NoteDisplayMenu(archive.notes[index - 1])
noteDisplayMenu.show()
} else {
println("Неверный выбор. Попробуйте снова.")
}
}
}
}
}
}

class CreateNoteMenu(private val archive: Archive) {
fun show() {
println("Создание заметки:")
print("Введите заголовок: ")
val title = readLine() ?: ""
print("Введите текст заметки: ")
val content = readLine() ?: ""

archive.notes.add(Note(title, content))

println("Заметка создана! Нажмите любую клавишу для продолжения...")
readLine()
}
}

class NoteDisplayMenu(private val note: Note) {
fun show() {
println("Заметка: ${note.title}")
println(note.content)
println("Нажмите любую клавишу для возвращения...")
readLine()
}
}