Skip to content

Instantly share code, notes, and snippets.

@jonas747
Created November 2, 2016 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonas747/8fc01f9bae6d0b9293e4ef20bccbb1be to your computer and use it in GitHub Desktop.
Save jonas747/8fc01f9bae6d0b9293e4ef20bccbb1be to your computer and use it in GitHub Desktop.
package main
import (
"crypto/rand"
"fmt"
"math/big"
"strings"
"time"
)
var (
steps = []Step{
NewSimpleStep("Launching super duper extraordinary virus version 1377.69 build infinity", "\nLaunched! If you encounter any issues or bugs with this virus please report them to me, thanks!"),
NewSimpleStep("Finding core system lamps and plants...", " Found a pretty cheap ikea lamp, virus might buy it."),
NewSimpleStep("Finding out what we should do with this computer...", " Hack it sounds like a good idea"),
NewSimpleStep("HAcking computer...", " Uh oh how do i hack?"),
NewSimpleStep("Reading a book about hacking computers...", " mhm i understand"),
NewSimpleStep("Prepares an axe (can't read books heh...)", " Can't find axe"),
&SimpleStdInStep{prompt: "Where is the axe? ", out: "Found an axe in %s!"},
NewSimpleStep("Hacking your computer with axe...", " why is nothing happening"),
NewSimpleStep("Pondering about the meaning of virus life...", " I don't want to hack no more!"),
NewSimpleStep("Thinking about what to do...", "oooo rock paper scissors sure sounds fun"),
&RockPaperScissorsStep{},
NewSimpleStep("That was fun but beep boop im sleepy, seeya! -love virus"),
}
)
func main() {
for _, v := range steps {
v.Process()
}
}
type Step interface {
Process()
}
// Will print each message after after delay until all have been printed
type SimpleStep struct {
msgs []string
}
func NewSimpleStep(msgs ...string) *SimpleStep {
return &SimpleStep{
msgs: msgs,
}
}
func (s *SimpleStep) Process() {
for _, m := range s.msgs {
fmt.Print(m)
time.Sleep(time.Second * 3)
}
time.Sleep(time.Second)
fmt.Print("\n")
}
type RandomNumberStep struct{}
func (r *RandomNumberStep) Process() {
fmt.Print("Generating a random number...")
time.Sleep(time.Second * 2)
n, _ := rand.Int(rand.Reader, big.NewInt(1337))
fmt.Println(" Generated this super neato number:", n)
}
type RockPaperScissorsStep struct{}
var RPSMoves = [][]string{
[]string{"rock", "scissors"},
[]string{"paper", "rock"},
[]string{"scissors", "paper"},
}
func (r *RockPaperScissorsStep) Process() {
fmt.Println("Playing rock paper scissors...")
for {
fmt.Print("Please enter your move (one of rock, paper, scissors): ")
move := ""
_, err := fmt.Scan(&move)
if err != nil {
fmt.Println("The virus encountered an error, please try again:", err)
continue
}
virusMoveN, _ := rand.Int(rand.Reader, big.NewInt(3))
virusMove := RPSMoves[int(virusMoveN.Int64())]
moveI := -1
switch strings.ToLower(move) {
case "rock":
moveI = 0
case "paper":
moveI = 1
case "scissors":
moveI = 2
}
if moveI == -1 {
fmt.Println("Thats not a valid move! this virus is too smart for that!")
continue
}
playerMove := RPSMoves[moveI]
winner := "???"
playerWon := false
if playerMove[0] == virusMove[0] {
winner = "Tie!?!?!"
} else if playerMove[1] == virusMove[0] {
winner = "You won! (this isnt the end of the virus though)"
playerWon = true
} else if playerMove[0] == virusMove[1] {
winner = "Virus won! you fucking stupid idiot loser!"
}
fmt.Printf("You picked %s, Virus picked %s, Result: %s! Holy sht!\n", playerMove[0], virusMove[0], winner)
if playerWon {
break
}
}
}
type SimpleStdInStep struct {
prompt string
out string
}
func (s *SimpleStdInStep) Process() {
fmt.Print(s.prompt)
str := ""
fmt.Scan(&str)
fmt.Printf(s.out+"\n", str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment