本文整理汇总了Scala中scala.io.StdIn.readLine类的典型用法代码示例。如果您正苦于以下问题:Scala readLine类的具体用法?Scala readLine怎么用?Scala readLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了readLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SevenSteps
//设置package包名称以及导入依赖的类
package de.htwg.se.SevenSteps
import com.google.inject.Guice
import de.htwg.se.SevenSteps.aview.gui.SwingGui
import de.htwg.se.SevenSteps.aview.tui._
import de.htwg.se.SevenSteps.controller.IController
import scala.io.StdIn.readLine
object SevenSteps {
def main(args: Array[String]): Unit = {
// val con = FactoryBasic.state.newController
val injector = Guice.createInjector(new SevenStepsModule)
var con = injector.getInstance(classOf[IController])
val tui = new Tui(con)
val gui = new SwingGui(con)
while (tui.processInputLine(readLine())) {}
}
}
示例2: Game
//设置package包名称以及导入依赖的类
package de.htwg.se.menschaergerdichnicht
import com.google.inject.Guice
import de.htwg.se.menschaergerdichnicht.aview.gui.SwingGui
import de.htwg.se.menschaergerdichnicht.aview.tui.Tui
import de.htwg.se.menschaergerdichnicht.controller.controllerComponent.ControllerInterface
import de.htwg.se.menschaergerdichnicht.controller.controllerComponent.controllerBaseImpl.Controller
import de.htwg.se.menschaergerdichnicht.model.fieldComponent.fieldBaseImpl.Dice
import de.htwg.se.menschaergerdichnicht.model.playerComponent.playerBaseImpl.Player
import scala.collection.mutable.Map
import scala.io.StdIn.readLine
// should try idea ultimate for worksheets
// datenstrukturen sollten runterskalieren, auf skalierbarkeit achten
// fuer einfache testfaelle
object Game {
val injector = Guice.createInjector(new MenschAergerDichNichtModule)
val controller = injector.getInstance(classOf[ControllerInterface])
val tui = controller.tui
val gui = controller.gui
gui.visible = true
def main(args: Array[String]): Unit = {
var input: String = ""
tui.update
do {
input = readLine()
tui.processInputLine(input)
} while (input != "q")
gui.dispose()
}
}
示例3: Sudoku
//设置package包名称以及导入依赖的类
package de.htwg.se.sudoku
import com.google.inject.Guice
import de.htwg.se.sudoku.aview.Tui
import de.htwg.se.sudoku.aview.gui.SwingGui
import de.htwg.se.sudoku.controller.controllerComponent.ControllerInterface
import scala.io.StdIn.readLine
object Sudoku {
val injector = Guice.createInjector(new SudokuModule)
val controller = injector.getInstance(classOf[ControllerInterface])
val tui = new Tui(controller)
val gui = new SwingGui(controller)
controller.createNewGrid
def main(args: Array[String]): Unit = {
var input: String = ""
do {
input = readLine()
tui.processInputLine(input)
} while (input != "q")
}
}
示例4: ClientCommandsLoop
//设置package包名称以及导入依赖的类
package commands.runner
import akka.actor.ActorRef
import com.typesafe.scalalogging.StrictLogging
import commands.ClientCommands._
import commands.entities._
import utils.{HelpPrinter, UserInformer}
import scala.io.StdIn.readLine
import scala.util.Try
class ClientCommandsLoop(executor: ActorRef, exitCallback: (Int) => Unit) extends StrictLogging with UserInformer {
def start(): Unit = {
informUserCallback(
"Hey, welcome to fun-chat! \n" +
"Type 'help' to show demo client commands.")
Try {
do {
val input: String = readLine()
input match {
case cmd if cmd.startsWith(HELP) => HelpPrinter.print()
case cmd if cmd.startsWith(SIGN_IN) => executor ! SignInCommand(cmd)
case cmd if cmd.startsWith(SIGN_UP) => executor ! SignUpCommand(cmd)
case cmd if cmd.startsWith(SIGN_OUT) => executor ! SignOutCommand(cmd)
case cmd if cmd.startsWith(UPDATE_CREDENTIALS) => executor ! UpdateCredentialsCommand(cmd)
case cmd if cmd.startsWith(ONLINE_USERS) => executor ! ListOnlineUsersCommand(cmd)
case cmd if cmd.startsWith(USER_INFO) => executor ! GetUserInfoCommand(cmd)
case cmd if cmd.startsWith(SEND_MESSAGE) => executor ! SendMessageCommand(cmd)
case cmd if cmd.startsWith(EXIT) => exitCallback(0)
case other => informUserCallback(s"Unsupported command ! $other")
}
} while (true)
}.recover {
case ex: Exception =>
informUserCallback("Unexpected error occurred!")
logger.error("Unexpected error occurred!", ex)
}
}
}
示例5: Hello
//设置package包名称以及导入依赖的类
package de.htwg.sa.connectfour
import de.htwg.sa.connectfour.model.{Matchfield, Player}
import de.htwg.sa.connectfour.controller.Controller
import de.htwg.sa.connectfour.view.Tui
import scala.io.StdIn.readLine
object Hello extends App{
val (rows, columns) = (6,7)
val player1 = Player(1, "player1")
val player2 = Player(2, "player2")
val controller = new Controller(new Matchfield(rows, columns), player1, player2)
val tui = new Tui(controller)
controller.notifyObservers()
var input: String = ""
do {
input = readLine()
tui.processInputLine(input)
} while (input != "q")
}
示例6: Main
//设置package包名称以及导入依赖的类
package calculator
import scala.io.StdIn.readLine
import calculator.parser.Trees._
object Main {
// Interpretation Memory
var memory: Map[Identifier, ExprTree] = Map()
// Execution Memory
var memory_double: Map[String, Double] = Map()
var memory_reference: Map[String, String] = Map()
def main(args: Array[String]) {
println("Welcome to the Scala calculator !")
console
}
def console: Unit = {
val pattern = "i (.*)".r
readLine match {
case "quit" => println("Bye !")
case "usage" => {
usage
console
}
// allows interpretation only, without execution (to see the parsing result)
case pattern(s) => {
(new Calculator(s)).interpret
console
}
// interpretation and execution, result is printed
case s => {
(new Calculator(s)).execute
console
}
}
}
def usage = {
println("Welcome to the help.")
println(" Type 'i expr' to see the interpretation (the parsing result) but not the execution and result.")
println("Supports only POSITIVE INTEGERS as inputs, but any float for a result")
println(" Use substraction and/or fraction to generate negative/fractionnal numbers")
println(" a = (0 - 1)/2; a will take value -0.5")
println("Supported Operators: +, -, *, /, % (modulo), ˆ (power), ! (factorial)")
println(" expr1 <op> expr2, except expr! ")
println("Keywords : GCD SQRT PRIME (in capitals!)")
println(" prime returns 1 for false, 0 for true.")
println(" SQRT PRIME: KEY(expr); GCD: KEY(expr1, expr2)")
println(" result of PRIME(term) cannot be used! (not allowing 2*PRIME(term)")
println("Memory: affectation var = expr, access: var, (var names only a-z, A-Z, not a keyword)")
}
}
示例7: E57
//设置package包名称以及导入依赖的类
package fi.kajstrom.efpscala.E57
import scala.io.StdIn.readLine
object E57 extends App{
val questionService = new QuestionService("E57_questions.json")
val game = new Game(questionService.getQuestions)
game.start()
promptQuestion()
def promptQuestion(): Unit = {
val question = game.nextQuestion()
println("Question: " + question.text)
var nth = 0
question.answers.foreach((answer: Answer) => {
println(nth + ". " + answer.answer)
nth += 1
})
val selectedAnswer = readLine("What is your answer? ")
if (game.answer(selectedAnswer.toInt)) {
println("Correct! Your current score is: " + game.getScore)
promptQuestion()
} else {
gameOver()
}
}
def gameOver(): Unit = {
println("Game over! Your score is: " + game.getScore)
}
}
示例8: StatisticsClient
//设置package包名称以及导入依赖的类
package fi.kajstrom.efpscala.E36Actor
import akka.actor.{Actor, ActorRef}
import scala.io.StdIn.readLine
class StatisticsClient(manager: ActorRef) extends Actor{
var requests = 0
def receive = {
case start: Start => {
requests += 1
manager ! RequestStatistics(requests, promptNumbers())
requests += 1
manager ! RequestStatistics(requests, promptNumbers())
}
case statistics: StatisticsCalculated => {
println(s"Results for request: ${statistics.requestId}")
println(s"The average is ${statistics.average}.")
println(s"The minimum is ${statistics.minimum}.")
println(s"The maximum is ${statistics.maximum}.")
println(s"The standard deviation is ${statistics.standardDeviation}")
}
}
def promptNumbers(): Vector[Int] = {
var numbers = Vector[Int]()
var running = true
while (running) {
val input = readLine("Enter a number: ")
if (input != "done") {
try {
numbers = numbers :+ input.toInt
} catch {
case nfe: NumberFormatException => println("That's not a valid number...")
case _ => println("What seems to be the officer, problem?")
}
} else {
running = false
}
}
numbers
}
}
case class Start()
示例9: WillsQuest
//设置package包名称以及导入依赖的类
package de.htwg.se.wills_quest.a_WillsQuest
import de.htwg.se.wills_quest.d_model.impl.JsonParser
import de.htwg.se.wills_quest.c_controller.impl.Controller
import de.htwg.se.wills_quest.d_model.impl.Person
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn.readLine
import com.google.inject.Guice
import de.htwg.se.wills_quest.b_ui.impl.{Gui, Tui}
import de.htwg.se.wills_quest.util.WillsQuestInjector
object WillsQuest {
val injector = Guice.createInjector(new WillsQuestInjector)
val will_pics = Array("Will_combat.png", "Will_auffordern.png", "Will_frozen.png")
val will = PersonFactory("will", "Will", "Default.png", 120, null)
val putzfrau_pics = Array("putzfrau_intro.png", "Putzfrau_Combat.png", "putzfrau_frozen.png")
val putzfrau_attacks = AttackFactory(Map("Mobwirbel" -> 20, "Wischen" -> 10))
val putzfrau = PersonFactory("enemy", "Putzfrau", "Default.png", 120, putzfrau_attacks)
val buecherwurm_pics = Array("Bucherwurm_Intro.png", "Bucherwurm_combat.png", "Buecherwurm_frozen.png")
val buechderwurm_attacks = AttackFactory(Map("Buecherwurf" -> 30, "Klausurvorbereitung" -> 35, "Prüfungsstress" -> 40))
val buecherwurm = PersonFactory("enemy", "Bücherwurm", "Default.png", 120, buechderwurm_attacks)
val bauingenieur_pics = Array("Bauingenieur_Intro.png", "Bauingenieur_combat.png", "Bauingenieur_frozen.png")
val bauingenieur_attacks = AttackFactory(Map("Bellen" -> 20, "Wetttrinken" -> 38))
val bauingenieur = PersonFactory("enemy", "Bauingenieur", "Default.png", 120, bauingenieur_attacks)
val erstsemester_pics = Array("Erstsemester_Intro.png", "Erstsemester_combat.png", "Erstsemester_frozen.png")
val erstsemester_attacks = AttackFactory(Map("Nasepudern" -> 30))
val erstsemester = PersonFactory("enemy", "Erstsemester", "Default.png", 120, erstsemester_attacks)
val professor_pics = Array("Professor_Intro.png", "Professor_combat.png", "Professor_frozen.png")
val professor_attacks = AttackFactory(Map("Laiserpointer" -> 40, "Redetalent" -> 50))
val professor = PersonFactory("enemy", "Professor", "Default.png", 120, professor_attacks)
val persons = new ArrayBuffer[Person]
persons.append(will, putzfrau, buecherwurm, bauingenieur, erstsemester, professor)
val jsonParser = new JsonParser
val controller = new Controller(persons, jsonParser, 1, injector)
val tui = new Tui(controller)
val gui = new Gui(controller)
def main(args: Array[String]): Unit = {
while (tui.processInputLine(readLine())) {}
System.exit(0)
}
}
示例10: DateFile
//设置package包名称以及导入依赖的类
package churchscreen.shell
import java.io.File
import java.util.Calendar
import java.text.SimpleDateFormat
import scala.io.StdIn.readLine
object DateFile
{
def apply(dir : File, ext : String) : DateFile =
{
val fileDate = promptForDate
new DateFile(dir, fileDate, ext)
}
def apply(dir : File, fileName : String, ext : String) : DateFile =
{
new DateFile(dir, fileName, ext)
}
private def promptForDate : String =
{
val defaultAnswer = nextSunday
print("Enter the service date [%s]:".format(defaultAnswer))
readLine() match
{
case s if s.matches("\\d{4}-\\d{2}-\\d{2}") => s
case d if "".equals(d) => defaultAnswer
case _ => promptForDate
}
}
private def nextSunday : String =
{
val formatString = "yyyy-MM-dd"
val cal = Calendar.getInstance
val dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)
if (dayOfWeek != Calendar.SUNDAY)
{
cal.add(Calendar.DAY_OF_WEEK, 1 + 7 - dayOfWeek)
}
new SimpleDateFormat(formatString) format cal.getTime
}
}
class DateFile(val dir : File, val fileName : String, val fileExtension : String)
{
def file : File =
{
val dateName = "%s.%s".format(fileName, fileExtension)
new File(dir, dateName)
}
def path = file.getAbsolutePath
}
示例11: Reading
//设置package包名称以及导入依赖的类
package churchscreen.show
import java.awt.{Rectangle, Dimension, Point}
import scala.io.StdIn.readLine
object Reading
{
def readPassage =
{
println("Enter passage:")
readLine()
}
def readPageNumber =
{
println("Enter page number:")
readLine()
}
def bibleReadingTitleAnchor = new Rectangle(new Point(51, 129), new Dimension(921, 260))
def bibleReadingTextAnchor = new Rectangle(new Point(51, 396), new Dimension(921, 320))
}
示例12: run
//设置package包名称以及导入依赖的类
package coalgebraz
package driver
import scala.io.StdIn.readLine
import Coalgebraz._
trait MooreDriver {
def run[I, O, X](m: Moore[I, O, X])(x: X): List[I] => O = unfoldMoore(m)(x)
def runIO[I: Read, O, X](m: Moore[I, O, X])(x: X, e: O => Unit): Unit =
runFunctionIO(unfoldMoore(m)(x))(e)
def runFunctionIO[I: Read, O](
f: List[I] => O)(
e: O => Unit): Unit = {
val s = readLine("z> ")
val oi = Read[I].read(s)
oi.fold(s match {
case "" => runFunctionIO(f)(e)
case "exit" => println("Bye!")
case _ => {
println(s"unknown input: '$s'")
runFunctionIO(f)(e)
}
}) { i =>
e(f(List(i)))
runFunctionIO((i2: List[I]) => f(List(i) ++ i2))(e)
}
}
def unfoldMoore[I, O, X](m: Moore[I, O, X])(x: X): List[I] => O =
anaMoore(m)(x)
def anaMoore[I, O, X](s: Moore[I, O, X]): X => List[I] => O =
s andThen (_ map anaMoore(s)) andThen (mf => xs =>
if (xs.isEmpty) mf.output else mf.next(xs.head)(xs.tail))
}
示例13: runMealy
//设置package包名称以及导入依赖的类
package coalgebraz
package driver
import scala.io.StdIn.readLine
import scalaz._, Scalaz._
import Coalgebraz._
trait MealyDriver {
def runMealy[I, O, X](m: Mealy[I, O, X])(x: X): NonEmptyList[I] => O =
unfoldMealy(m)(x)
def runIOMealy[I: Read, O, X](m: Mealy[I, O, X])(x: X, e: O => Unit): Unit =
runNelFunctionIO(unfoldMealy(m)(x))(e)
def runNelFunctionIO[I: Read, O](
f: NonEmptyList[I] => O)(
e: O => Unit): Unit = {
val s = readLine("z> ")
val oi = Read[I].read(s)
oi.fold(s match {
case "" => runNelFunctionIO(f)(e)
case "exit" => println("Bye!")
case _ => {
println(s"unknown input: '$s'")
runNelFunctionIO(f)(e)
}
}) { i =>
e(f(i.wrapNel))
runNelFunctionIO((i2: NonEmptyList[I]) => f(i.wrapNel append i2))(e)
}
}
def unfoldMealy[I, O, X](m: Mealy[I, O, X])(x: X): NonEmptyList[I] => O =
anaMealy(m)(x)
def anaMealy[I, O, X](m: Mealy[I, O, X]): X => NonEmptyList[I] => O =
m andThen (_ map anaMealy(m)) andThen (mf => {
case NonEmptyList(x, INil()) => mf.next(x)._1
case NonEmptyList(x1, ICons(x2, xs)) =>
mf.next(x1)._2(NonEmptyList.nel(x2, xs))
})
}
示例14: runObject
//设置package包名称以及导入依赖的类
package coalgebraz
package driver
import scala.io.StdIn.readLine
import scalaz._, Scalaz._
import Coalgebraz._
trait ObjectDriver {
def runObject[I, O, E, X](
ob: Object[I, O, E, X])(x: X): NonEmptyList[I] => (E \/ O) =
unfoldObject(ob)(x)
def runIOObject[I: Read, O, E, X](
ob: Object[I, O, E, X])(x: X, efe: E => Unit, efo: O => Unit): Unit =
runFunctionIOObject(unfoldObject(ob)(x))(efe, efo)
def runFunctionIOObject[I: Read, O, E](
f: NonEmptyList[I] => (E \/ O))(
efe: E => Unit,
efo: O => Unit): Unit = {
val s = readLine("z> ")
val oi = Read[I].read(s)
oi.fold(s match {
case "" => runFunctionIOObject(f)(efe, efo)
case "exit" => println("Bye!")
case _ => {
println(s"unknown input: '$s'")
runFunctionIOObject(f)(efe, efo)
}
}) { i =>
f(i.wrapNel).fold(
efe,
o => {
efo(o)
runFunctionIOObject(
(i2: NonEmptyList[I]) => f(i.wrapNel append i2))(efe, efo)
})
}
}
def unfoldObject[I, O, E, X](
ob: Object[I, O, E, X])(
x: X): NonEmptyList[I] => (E \/ O) =
anaObject(ob)(x)
def anaObject[I, O, E, X](
ob: Object[I, O, E, X]): X => NonEmptyList[I] => (E \/ O) =
ob andThen (_ map anaObject(ob)) andThen (obf => {
case NonEmptyList(i, INil()) => obf.method(i).map(_._1)
case NonEmptyList(i1, ICons(i2, t)) => obf.method(i1).fold(
e => e.left,
ox => ox._2(NonEmptyList.nel(i2, t)))
})
}
示例15: runCCSIO
//设置package包名称以及导入依赖的类
package coalgebraz
package driver
import scala.collection.immutable.{ Stream => LazyList }
import scala.io.StdIn.readLine
import scalaz._, Scalaz._
import Coalgebraz._
trait CCSDriver {
def runCCSIO[A, X](
m: CCS[A, X])(
x: X,
el: A => Unit,
er: A => Unit)(implicit
ev0: Read[A \/ A]): Unit =
runLTSIO(unfoldCCS(m)(x))(el, er)
def runLTSIO[A](
dt: LTS[A])(
el: A => Unit, er: A => Unit)(implicit
ev0: Read[A \/ A]): Unit = {
if (dt.branches.isEmpty)
println("deadlocked!")
else {
dt.branches.foreach(b => b._1.fold(el, er))
val s = readLine("z> ")
val oa = Read[A \/ A].read(s)
oa.fold(s match {
case "" => runLTSIO(dt)(el, er)
case "exit" => println("bye!")
case _ => {
println(s"unknown input: '$s'")
runLTSIO(dt)(el, er)
}
}) { a =>
dt.branches.find(_._1 == a).fold {
println(s"invalid transition: '$s'")
runLTSIO(dt)(el, er)
} { case (_, dt2) => runLTSIO(dt2)(el, er) }
}
}
}
def unfoldCCS[A, X](m: CCS[A, X])(x: X): LTS[A] = anaCCS(m)(x)
def anaCCS[A, X](m: CCS[A, X]): X => LTS[A] =
m andThen (_ map anaCCS(m)) andThen (mf => LTS(mf.next))
class LTS[A](_branches: => LazyList[(A \/ A, LTS[A])]) {
def branches: LazyList[(A \/ A, LTS[A])] = _branches
}
object LTS {
def apply[A](branches: => LazyList[(A \/ A, LTS[A])]): LTS[A] =
new LTS(branches)
}
}