-
Notifications
You must be signed in to change notification settings - Fork 18
Roulette!
This adds a roulette grid to your game - a graphical random number machine.
It will look like a grid of boxes, two columns and ten rows by default. Calling roulette.roll()
will start a roll, and each cell in turn will be briefly highlighted before moving to the next. It will slow down and eventually stop on the winning number.
You can have each cell coloured, which will then give the player a graphical representation of how likely something is. Probability can be hard to get; some players will assume that a 90% chance of success means it will always work. If they can see two boxes out of twenty are red they are see that that is not the case.
This also gives a bit of tension to the game, as the player has to wait a few second for the outcome.
By default, the roulette grid is not included in a Quest 6 game (though the file is present). The first step, then, is to tell Quest to include this library. To do that, add this line to your settings.js file (and indeed all options that start "settings" should go in that file):
settings.libraries.push('roulette')
You need to give it some cells, enough to fill the grid. Here is a simple example, doing it in a loop; this should be in settings.setup
for (let i = 0; i < roulette.size; i++) {
roulette.setCell(i, new Cell('green', '' + (i + 1)))
}
roulette.redrawSequence()
roulette.afterRoll = function(result) {
msg("Result is " + result)
}
At each iteration, the roulette.setCell()
function is used to set the cell at the i position. It uses a built in class, Cell, which takes a colour and a string.
Once the cells are there, it calls roulette.redrawSequence()
, which draws the cells on the grid one at a time. Alternatively you can call roulette.redraw()
and it will draw it immediately.
It also sets the roulette.afterRoll()
function to fire after a roll. It will be sent the winning number (which counts from zero). If the winning cell has an afterRoll()
function this will also be used.
Use settings.rouletteColumns
and settings.rouletteRows
to set the size of the grid (default to 2 and 10 respectively.
settings.rouletteColumns = 3
To customise the CSS styling of the roulette pane, set settings.roulette.style
. For example:
settings.roulette.style = {
'background-color':'blue',
}
If you are not using the default grid size, you will need to set "height" and "width" and possibly other values too.
Use roulette.show()
and roulette.hide()
to show and hide the pane. You can use roulette.getCell(n)
to retrieve the cell at a certain position, and roulette.setCell(n, cell)
to set the cell there (replacing whatever was there before).
Call roulette.roll()
to make a roll.
Each cell is a JavaScript object (as opposed to a Quest object). It must have a "div" attribute that is an HTML element, plus two functions, "setAlive", and "setHighlight". These are used during a roll - the "setHighlight" function will be called when this is the active cell, and "setAlive" when it is not, so they must visually change the cell to show it is highlighted and not.
This is the minimum:
const myCell = {
setAlive = function() { this.div.style.backgroundColor = 'yellow' },
setHighlight = function() { this.div.style.backgroundColor = 'white' },
}
myCell.div = document.createElement('div')
myCell.div.style.backgroundColor = 'yellow'
myCell.div.style.width = "40px"
myCell.div.style.height = "40px"
myCell.div.style.display = "inline"
myCell.div.style.border = "black 1px solid"
myCell.div.innerHTML = 'MyC'
There is a built-is class, Cell, that does most of the for you, so we could just do this:
const myCell = new Cell('yellow', 'MyC')
You may well want to create your own class for this. Or several classes - you could have one for a hit, one for a critical, one for a miss and one for a fumble. Each can be a different colour, so the player can see his chances at a glance, and react in its own way.
Here is an example to show the basics. This includes an "afterRoll" function.
class Cell {
constructor(c, s) {
this.colour = c
this.div = document.createElement('div')
this.div.style.backgroundColor = this.colour
this.div.style.width = "40px"
this.div.style.height = "40px"
this.div.style.display = "inline"
this.div.style.border = "white 1px solid"
if (s) this.div.innerHTML = s
}
afterRoll() { msg("This cell was picked!")
setAlive() { this.div.style.backgroundColor = this.colour }
setHighlight() { this.div.style.backgroundColor = 'white' }
}
This should be fine, but you need to remember to change everything!
roulette.columnCount
roulette.rowCount
roulette.size
roulette.div.style.width
roulette.div.style.height
There may be other style attributes you need to adjust too. Fill the grid with cells and call roulette.redrawSequence()` when done.
Tutorial
- First steps
- Rooms and Exits
- Items
- Templates
- Items and rooms again
- More items
- Locks
- Commands
- Complex mechanisms
- Uploading
QuestJS Basics
- General
- Settings
- Attributes for items
- Attributes for rooms
- Attributes for exits
- Naming Items and Rooms
- Restrictions, Messages and Reactions
- Creating objects on the fly
- String Functions
- Random Functions
- Array/List Functions
- The
respond
function - Other Functions
The Text Processor
Commands
- Introduction
- Basic commands (from the tutorial)
- Complex commands
- Example of creating a command (implementing SHOOT GUN AT HENRY)
- More on commands
- Shortcut for commands
- Modifying existing commands
- Custom parser types
- Note on command results
- Meta-Commands
- Neutral language (including alternatives to "you")
- The parser
- Command matching
- Vari-verbs (for verbs that are almost synonyms)
Templates for Items
- Introduction
- Takeable
- Openable
- Container and surface
- Locks and keys
- Wearable
- Furniture
- Button and Switch
- Readable
- Edible
- Vessel (handling liquids)
- Components
- Countable
- Consultable
- Rope
- Construction
- Backscene (walls, etc.)
- Merchandise (including how to create a shop)
- Shiftable (can be pushed from one room to another)
See also:
- Custom templates (and alternatives)
Handing NPCs
- Introduction
- Attributes
- Allowing the player to give commands
- Conversations
- Simple TALK TO
- SAY
- ASK and TELL
- Dynamic conversations with TALK TO
- TALK and DISCUSS
- Following an agenda
- Reactions
- Giving
- Followers
- Visibility
- Changing the player point-of-view
The User Experience (UI)
The main screen
- Basics
- Printing Text Functions
- Special Text Effects
- Output effects (including pausing)
- Hyperlinks
- User Input
The Side Panes
Multi-media (sounds, images, maps, etc.)
- Images
- Sounds
- Youtube Video (Contribution by KV)
- Adding a map
- Node-based maps
- Image-based maps
- Hex maps
- Adding a playing board
- Roulette!... in a grid
Dialogue boxes
- Character Creation
- Other example dialogs [See also "User Input"]
Other Elements
- Toolbar (status bar across the top)
- Custom UI Elements
Role-playing Games
- Introduction
- Getting started
- Items
- Characters (and Monsters!)
- Spawning Monsters and Items)
- Systema Naturae
- Who, When and How NPCs Attack
- Attributes for characters
- Attacking and guarding
- Communicating monsters
- Skills and Spells
- Limiting Magic
- Effects
- The Attack Object
- [Extra utility functions](https://github.com/ThePix/QuestJS/wiki/RPG-Library-%E2%80%90-Extra Functions)
- Randomly Generated Dungeon
- Quests for Quest
- User Interface
Web Basics
- HTML (the basic elements of a web page)
- CSS (how to style web pages)
- SVG (scalable vector graphics)
- Colours
- JavaScript
- Regular Expressions
How-to
Time
- Events (and Turnscripts)
- Date and Time (including custom calendars)
- Timed Events (i.e., real time, not game time)
Items
- Phone a Friend
- Using the USE verb
- Display Verbs
- Change Listeners
- Ensembles (grouping items)
- How to spit
Locations
- Large, open areas
- Region,s with sky, walls, etc.
- Dynamic Room Descriptions
- Transit system (lifts/elevators, buses, trains, simple vehicles)
- Rooms split into multiple locations
- Create rooms on the fly
- Handling weather
Exits
- Alternative Directions (eg, port and starboard)
- Destinations, Not Directions
Meta
- Customise Help
- Provide hints
- Include Achievements
- Add comments to your code
-
End The Game (
io.finish
)
Meta: About The Whole Game
- Translate from Quest 5
- Authoring Several Games at Once
- Chaining Several Games Together
- Competition Entry
- Walk-throughs
- Unit testing
- Debugging (trouble-shooting)
Releasing Your Game
Reference
- The Language File
- List of settings
- Scope
- The Output Queue
- Security
- Implementation notes (initialisation order, data structures)
- Files
- Code guidelines
- Save/load
- UNDO
- The editor
- The Cloak of Darkness
- Versions
- Quest 6 or QuestJS
- The other Folders
- Choose your own adventure