Example #1
0
func acceptScore(score uint8, name string) {
	records = vanity.Insert(records, score, name)
	err := vanity.WriteToFile(records)
	setMode(modeVanity)
	if err != nil {
		teletype.Print(err.Error())
	}
}
Example #2
0
func (context) KeyDown(k nimble.Key) {
	switch k {
	case nimble.KeyEscape:
		switch currentMode {
		case modeSplash, modeVanity:
			nimble.Quit()
		case modeTraining, modeGame:
			youLose()
		case modeName:
			// FIXME - ask for confirmation
			nimble.Quit()
		}
	}
	if currentMode == modeName {
		if 0x20 <= k && k < 0x7F {
			teletype.PrintCharUpper(rune(k))
		} else {
			switch k {
			case nimble.KeyReturn:
				acceptScore(uint8(universe.NKill()), teletype.CursorLine())
			case nimble.KeyBackspace, nimble.KeyDelete:
				teletype.Backup()
			}
		}
	}

	if devConfig {
		// Shortcuts for debugging
		switch k {
		case 'b':
			// Begin game
			bootSequencePeriod = 0
			setMode(modeGame)
		case 'e':
			// End game
			youLose()
		case 'r':
			// Reset score file
			records = make([]vanity.Record, 0)
			vanity.WriteToFile(records)
		case 's':
			// Score a point
			universe.TallyKill()
		case 't':
			// Begin training
			bootSequencePeriod = 0
			setMode(modeTraining)
		}
	}
}