p1fort = 150
p2fort = 150
p1gold = 2
p2gold = 2
p1stone = 200
p2stone = 200
p1vinn = 0
p2vinn = 0
p1navn = ""
p2navn = ""
p = 1
vinner = 0
bakgrunn = loadImage("natur.jpg")
println("Hva heter du, player 1?")
p1navn = readln()
println("Og du da, player 2? Hva heter du?")
p2navn = readln()
println("Trykk på 's' for å starte.")
while readChar() != 's' do
done
while TRUE do
if vinner == 1 then
cls()
p1vinn = p1vinn + 1
println("Gratulerer, "p1navn"! Du vant!")
println("")
println(""p1navn": "p1vinn"")
println(""p2navn": "p2vinn"")
println("")
println("Trykk på 'i' for å spille igjen.")
while readChar() != 'i' do
done
vinner = 0
p = 2
endif
if vinner == 2 then
cls()
p2vinn = p2vinn + 1
println("Gratulerer, "p2navn"! Du vant!")
println("")
println(""p1navn": "p1vinn"")
println(""p2navn": "p2vinn"")
println("")
println("Trykk på 'i' for å spille igjen.")
while readChar() != 'i' do
done
vinner = 0
p = 1
endif
p1fort = 150
p2fort = 150
p1gold = 2
p2gold = 2
p1stone = 200
p2stone = 200
while vinner == 0 do
cls()
mye()
wait(20)
done
done
function p1turn()
if keyPressed(49)then
if p1stone > 75 or p1stone == 75 then
p1stone = p1stone - 75
p1gold = p1gold + 1
p = 2
elseif p1stone < 75 then
println("Du har ikke nok stone!")
wait(1000)
endif
elseif keyPressed(50) then
if p1gold > 1 or p1gold == 1 then
p1gold = p1gold - 1
p1stone = p1stone + 75
p = 2
elseif p1gold < 1 then
println("Du har ikke nok gold!")
wait(1000)
endif
elseif keyPressed(51) then
if p1stone > 50 or p1stone == 50 then
repeat 20 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p1fort = p1fort + 2
wait(40)
cls()
done
p = 2
p1stone = p1stone - 50
elseif p1stone < 50 then
println("Du har ikke nok stone!")
wait(1000)
endif
elseif keyPressed(52) then
repeat 25 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p1fort = p1fort - 2
wait(40)
cls()
done
p = 2
p1stone = p1stone + 40
elseif keyPressed(53) then
if p1stone > 130 or p1stone == 130 then
repeat 25 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p2fort = p2fort - 2
wait(40)
cls()
done
p = 2
p1stone = p1stone - 130
elseif p1stone < 130 then
println ("Du har ikke nok stone!")
wait(1000)
endif
elseif keyPressed(54) then
if p1gold > 4 or p1gold == 4 then
p2gold = p2gold - 3
p2stone = p2stone - 100
p1gold = p1gold - 4
p = 2
elseif p1gold < 4 then
println("Du har ikke nok gold!")
wait(1000)
endif
elseif keyPressed(55) then
if p1gold > 5 or p1gold == 5 then
repeat 100 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p2fort = p2fort - 2
wait(40)
cls()
done
p = 2
p1gold = p1gold - 5
elseif p1gold < 5 then
println("Du har ikke nok gold!")
wait(1000)
endif
endif
endfunc
function p2turn()
if keyPressed(49)then
if p2stone > 75 or p2stone == 75 then
p2stone = p2stone - 75
p2gold = p2gold + 1
p = 1
elseif p2stone < 75 then
println("Du har ikke nok stone!")
wait(1000)
endif
elseif keyPressed(50) then
if p2gold > 1 or p2gold == 1 then
p2gold = p2gold - 1
p2stone = p2stone + 75
p = 1
elseif p2gold < 1 then
println("Du har ikke nok gold!")
wait(1000)
endif
elseif keyPressed(51) then
if p2stone > 50 or p2stone == 50 then
repeat 20 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p2fort = p2fort + 2
wait(40)
cls()
done
p = 1
p2stone = p2stone - 50
elseif p2stone < 50 then
println("Du har ikke nok stone!")
wait(1000)
endif
elseif keyPressed(52) then
repeat 25 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p2fort = p2fort - 2
wait(40)
cls()
done
p = 1
p2stone = p2stone + 40
elseif keyPressed(53) then
if p2stone > 130 or p2stone == 130 then
repeat 25 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p1fort = p1fort - 2
wait(40)
cls()
done
p = 1
p2stone = p2stone - 130
elseif p2stone < 130 then
println ("Du har ikke nok stone!")
wait(1000)
endif
elseif keyPressed(54) then
if p2gold > 4 or p2gold == 4 then
p1gold = p1gold - 3
p1stone = p1stone - 100
p2gold = p2gold - 4
p = 1
elseif p2gold < 4 then
println("Du har ikke nok gold!")
wait(1000)
endif
elseif keyPressed(55) then
if p2gold > 5 or p2gold == 5 then
repeat 100 times
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
p1fort = p1fort - 2
wait(40)
cls()
done
p = 1
p2gold = p2gold - 5
elseif p2gold < 5 then
println("Du har ikke nok gold!")
wait(1000)
endif
endif
endfunc
function mye()
if p == 1 then
cls()
grafikk()
readChar()
p1turn()
elseif p == 2 then
cls()
p = 2
grafikk()
readChar()
p2turn()
endif
if p1stone < 0 then
p1stone = 0
endif
if p1gold < 0 then
p1gold = 0
endif
if p1fort < 0 or p1fort == 0 then
vinner = 2
endif
if p1fort > 300 or p1fort == 300then
vinner = 1
endif
if p2stone < 0 then
p2stone = 0
endif
if p2gold < 0 then
p2gold = 0
endif
if p2fort < 0 or p2fort == 0 then
vinner = 1
endif
if p2fort > 300 or p2fort == 300 then
vinner = 2
endif
endfunc
function grafikk()
drawImage(bakgrunn,0,-80)
if p == 1 then
println(" "p1navn"s tur")
elseif p == 2 then
println(" "p2navn"s tur")
endif
println("P1 p2")
println("gold = "p1gold" gold = "p2gold"")
println("stone = "p1stone" stone = "p2stone"")
println("fort = "p1fort" fort = "p2fort"")
color(0,0,255)
fillShape(20,20,20,p1fort + 20,100,p1fort + 20,100,20)
color(255,0,0)
fillShape(width() - 20,20,width() - 20,p2fort + 20,width() - 100,p2fort + 20,width() - 100,20)
color(255,255,255)
println("(1) bruk 75 stone for å få 1 gold (5) bruk 130 stone for å ta 50 fort")
println("(2) bruk 1 gold for å få 75 stone (6) bruk 4 gold for å ta 3 gold og 100 stone")
println("(3) bruk 50 stone for å få 40 fort (7) bruk 5 gold for å ta 200 fort ")
println("(4) bruk 50 fort for å få 40 stone")
endfunc