initial commit
parent
fb537f3ae4
commit
13eddceb4b
|
@ -0,0 +1,32 @@
|
|||
Copyright (c) 2013, Brett O'Donnell http://cornernote.github.io
|
||||
All rights reserved.
|
||||
_____ _____ _____ _____ _____ _____
|
||||
| |___| __ | | |___| __ | | |___|_ _|___
|
||||
| --| . | -| | | | -_| -| | | | . | | | | -_|
|
||||
|_____|___|__|__|_|___|___|__|__|_|___|___| |_| |___|
|
||||
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the organization nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
53
README.md
53
README.md
|
@ -1,4 +1,51 @@
|
|||
minetest-rpsls_lc
|
||||
=================
|
||||
# Rock Paper Scissors Lizard Spock - LuaController for Minetest
|
||||
|
||||
Rock Paper Scissors Lizard Spock - LuaController for Minetest
|
||||
Create a game of Rock Paper Scissors Lizard Spock
|
||||
|
||||
|
||||
## Depends
|
||||
|
||||
* [mesecons](https://github.com/Jeija/minetest-mod-mesecons)
|
||||
* [digilines](https://github.com/Jeija/minetest-mod-digilines)
|
||||
|
||||
|
||||
## Items Required
|
||||
|
||||
- 12x LuaController (mesecons_luacontroller:luacontroller)
|
||||
- 11x Button (mesecons_button:button_off)
|
||||
- 3x LCD (digilines_lcd:lcd)
|
||||
- 1x Player Detector (mesecons_detector:object_detector_off)
|
||||
- 20x (approx) Digilines Wire (digilines:wire_std)
|
||||
- 10x (approx) Mesecons Wire (mesecons:wire)
|
||||
|
||||
|
||||
## How-To
|
||||
|
||||
- Place 5 LuaControllers for each player option (see [button_controller.lua](https://github.com/cornernote/minetest-rpsls_lc/blob/master/button_controller.lua))
|
||||
- Place 1 LuaController for the reset button (see [reset_controller.lua](https://github.com/cornernote/minetest-rpsls_lc/blob/master/reset_controller.lua))
|
||||
- Place a button in front of each of the button controllers and the reset controller.
|
||||
- Place 1 LuaController for the game logic (see [game_controller.lua](https://github.com/cornernote/minetest-rpsls_lc/blob/master/game_controller.lua))
|
||||
- Place 3 LCD screens, and name them: player1_display, player2_display and vs_display
|
||||
- Connect everything with Digilines Wire
|
||||
- Place a Player Detector and connect it to the game controller using Mesecons Wire
|
||||
|
||||
|
||||
## Resources
|
||||
|
||||
- **[GitHub Project](https://github.com/cornernote/minetest-rpsls_lc)**
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
- Does this README need improvement? Go ahead and [suggest a change](https://github.com/cornernote/minetest-rpsls_lc/edit/master/README.md).
|
||||
- Found a bug, or need help using this project? Check the [open issues](https://github.com/cornernote/minetest-rpsls_lc/issues) or [create an issue](https://github.com/cornernote/minetest-rpsls_lc/issues/new).
|
||||
|
||||
|
||||
## About
|
||||
|
||||
This module is open source, so it's distributed freely. If you find it useful then I ask not for your wealth, but simply to spare your time to consider the world we share by watching [Earthlings](http://earthlings.com/), a multi-award winning film available to watch online for free. A must-see for anyone who wishes to make the world a better place.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[BSD-3-Clause](https://raw.github.com/cornernote/minetest-rpsls_lc/master/LICENSE), Copyright © 2013-2014 [Brett O'Donnell](http://cornernote.github.io/)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
--[[
|
||||
|
||||
Rock Paper Scissors Lizard Spock
|
||||
LuaController for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-rpsls-lc
|
||||
License: BSD-3-Clause
|
||||
|
||||
]]--
|
||||
|
||||
|
||||
player = 'player1' -- player1|player2
|
||||
option = 'rock' -- rock|paper|scissors|lizard|spock
|
||||
|
||||
if (event.type=='on') then
|
||||
digiline_send(player, option)
|
||||
end
|
|
@ -0,0 +1,185 @@
|
|||
--[[
|
||||
|
||||
Rock Paper Scissors Lizard Spock
|
||||
LuaController for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-rpsls-lc
|
||||
License: BSD-3-Clause
|
||||
|
||||
]]--
|
||||
|
||||
|
||||
-- change of human/cpu (via mesecon player detector)
|
||||
if (event.type=='on' or event.type=='off') then
|
||||
if (mem.player2) then
|
||||
mem.human_tmp = event.type
|
||||
else
|
||||
mem.human = event.type
|
||||
if (mem.human=='off') then
|
||||
digiline_send('vs_display', 'VS CPU')
|
||||
else
|
||||
digiline_send('vs_display', 'VS Human')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- digiline signals
|
||||
if (event.type=='digiline') then
|
||||
|
||||
-- reset
|
||||
if (event.channel=='reset') then
|
||||
digiline_send('player1_display', '')
|
||||
digiline_send('player2_display', '')
|
||||
digiline_send('score_display', '')
|
||||
mem.player1 = nil
|
||||
mem.player2 = nil
|
||||
mem.score_player1 = 0
|
||||
mem.score_player2 = 0
|
||||
mem.score_draw = 0
|
||||
if (mem.human_tmp) then
|
||||
mem.human = mem.human_tmp
|
||||
mem.human_tmp = nil
|
||||
if (mem.human=='off') then
|
||||
digiline_send('vs_display', 'VS CPU')
|
||||
else
|
||||
digiline_send('vs_display', 'VS Human')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- player1 choice
|
||||
if (event.channel=='player1' and not mem.player1) then
|
||||
mem.player1 = event.msg
|
||||
if (not mem.player2) then
|
||||
digiline_send('player1_display', 'Selected '..event.msg..'. Waiting on Player2...')
|
||||
end
|
||||
end
|
||||
|
||||
-- player2 choice
|
||||
if (event.channel=='player2' and not mem.player2) then
|
||||
mem.player2 = event.msg
|
||||
mem.human = 'on'
|
||||
if (not mem.player1) then
|
||||
digiline_send('player2_display', 'Selected '..event.msg..'. Waiting on Player1...')
|
||||
end
|
||||
end
|
||||
|
||||
-- cpu choice
|
||||
if (mem.human=='off' and mem.player1 and not mem.player2) then
|
||||
options = {'rock','paper','scissors','lizard','spock'}
|
||||
mem.player2 = options[math.random(5)]
|
||||
end
|
||||
|
||||
-- handle winner
|
||||
if (mem.player1 and mem.player2) then
|
||||
|
||||
-- find the winner and message
|
||||
winner = 'draw'
|
||||
message = 'That\'s a draw!'
|
||||
if (mem.player1=='rock') then
|
||||
if (mem.player2=='scissors') then
|
||||
winner = 'player1'
|
||||
message = 'rock smashes scissors'
|
||||
elseif (mem.player2=='lizard') then
|
||||
winner = 'player1'
|
||||
message = 'rock crushes lizard'
|
||||
end
|
||||
if (mem.player2=='paper') then
|
||||
winner = 'player2'
|
||||
message = 'paper covers rock'
|
||||
elseif (mem.player2=='spock') then
|
||||
winner = 'player2'
|
||||
message = 'spock vaporizes rock'
|
||||
end
|
||||
elseif (mem.player1=='paper') then
|
||||
if (mem.player2=='rock' ) then
|
||||
winner = 'player1'
|
||||
message = 'paper covers rock'
|
||||
elseif (mem.player2=='spock') then
|
||||
winner = 'player1'
|
||||
message = 'paper disproves spock'
|
||||
end
|
||||
if (mem.player2=='lizard') then
|
||||
winner = 'player2'
|
||||
message = 'lizard eats paper'
|
||||
elseif (mem.player2=='scissors') then
|
||||
winner = 'player2'
|
||||
message = 'scissors cuts paper'
|
||||
end
|
||||
elseif (mem.player1=='scissors') then
|
||||
if (mem.player2=='paper') then
|
||||
winner = 'player1'
|
||||
message = 'scissors cuts paper'
|
||||
elseif (mem.player2=='lizard') then
|
||||
winner = 'player1'
|
||||
message = 'scissors decapitates lizard'
|
||||
end
|
||||
if (mem.player2=='rock') then
|
||||
winner = 'player2'
|
||||
message = 'rock crushes scissors'
|
||||
elseif (mem.player2=='spock') then
|
||||
winner = 'player2'
|
||||
message = 'spock smashes scissors'
|
||||
end
|
||||
elseif (mem.player1=='lizard') then
|
||||
if (mem.player2=='paper' ) then
|
||||
winner = 'player1'
|
||||
message = 'lizard eats paper'
|
||||
elseif (mem.player2=='spock') then
|
||||
winner = 'player1'
|
||||
message = 'lizard poisons spock'
|
||||
end
|
||||
if (mem.player2=='rock') then
|
||||
winner = 'player2'
|
||||
message = 'rock crushes lizard'
|
||||
elseif (mem.player2=='scissors') then
|
||||
winner = 'player2'
|
||||
message = 'scissors decapitates lizard'
|
||||
end
|
||||
elseif (mem.player1=='spock') then
|
||||
if (mem.player2=='scissors') then
|
||||
winner = 'player1'
|
||||
message = 'spock smashes scissors'
|
||||
elseif (mem.player2=='rock') then
|
||||
winner = 'player1'
|
||||
message = 'spock vaporizes rock'
|
||||
end
|
||||
if (mem.player2=='lizard') then
|
||||
winner = 'player2'
|
||||
message = 'lizard poisons spock'
|
||||
elseif (mem.player2=='paper') then
|
||||
winner = 'player2'
|
||||
message = 'paper disproves spock'
|
||||
end
|
||||
end
|
||||
|
||||
-- display and reset results
|
||||
if (winner=='draw') then
|
||||
message = mem.player1 .. ' and ' .. mem.player2 .. '? '..message
|
||||
else
|
||||
message = message .. ' - ' .. winner .. ' wins!'
|
||||
end
|
||||
digiline_send('player1_display', message)
|
||||
digiline_send('player2_display', message)
|
||||
mem.player1 = nil
|
||||
mem.player2 = nil
|
||||
|
||||
-- increment and display scores
|
||||
mem['score_'..winner] = mem['score_'..winner] + 1
|
||||
digiline_send('score_display', 'Player1 '..mem.score_player1..' Player2 '..mem.score_player2..' Draw '..mem.score_draw)
|
||||
|
||||
-- handle change of human/cpu during game
|
||||
if (mem.human_tmp) then
|
||||
mem.human = mem.human_tmp
|
||||
mem.human_tmp = nil
|
||||
if (mem.human=='off') then
|
||||
digiline_send('vs_display', 'VS CPU')
|
||||
else
|
||||
digiline_send('vs_display', 'VS Human')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
--[[
|
||||
|
||||
Rock Paper Scissors Lizard Spock
|
||||
LuaController for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-rpsls-lc
|
||||
License: BSD-3-Clause
|
||||
|
||||
]]--
|
||||
|
||||
|
||||
if (event.type=='on') then
|
||||
digiline_send('reset', 'reset')
|
||||
end
|
Binary file not shown.
After Width: | Height: | Size: 202 KiB |
Loading…
Reference in New Issue